@@ -156,6 +156,8 @@ def effect_str(effects: list[StackEffect]) -> str:
156156 return str (n_effect )
157157
158158 instr : AnyInstruction | None
159+ popped : str | None = None
160+ pushed : str | None = None
159161 match thing :
160162 case parsing .InstDef ():
161163 if thing .kind != "op" or self .instrs [thing .name ].is_viable_uop ():
@@ -173,21 +175,22 @@ def effect_str(effects: list[StackEffect]) -> str:
173175 instr = self .pseudo_instrs [thing .name ]
174176 # Calculate stack effect, and check that it's the the same
175177 # for all targets.
176- for idx , target in enumerate ( self .pseudos [thing .name ].targets ) :
178+ for target in self .pseudos [thing .name ].targets :
177179 target_instr = self .instrs .get (target )
178180 # Currently target is always an instr. This could change
179181 # in the future, e.g., if we have a pseudo targetting a
180182 # macro instruction.
181183 assert target_instr
182184 target_popped = effect_str (target_instr .input_effects )
183185 target_pushed = effect_str (target_instr .output_effects )
184- if idx == 0 :
186+ if popped is None :
185187 popped , pushed = target_popped , target_pushed
186188 else :
187189 assert popped == target_popped
188190 assert pushed == target_pushed
189191 case _:
190192 assert_never (thing )
193+ assert popped is not None and pushed is not None
191194 return instr , popped , pushed
192195
193196 @contextlib .contextmanager
@@ -376,6 +379,7 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
376379 # Compute the set of all instruction formats.
377380 all_formats : set [str ] = set ()
378381 for thing in self .everything :
382+ format : str | None = None
379383 match thing :
380384 case OverriddenInstructionPlaceHolder ():
381385 continue
@@ -384,15 +388,16 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
384388 case parsing .Macro ():
385389 format = self .macro_instrs [thing .name ].instr_fmt
386390 case parsing .Pseudo ():
387- for idx , target in enumerate ( self .pseudos [thing .name ].targets ) :
391+ for target in self .pseudos [thing .name ].targets :
388392 target_instr = self .instrs .get (target )
389393 assert target_instr
390- if idx == 0 :
394+ if format is None :
391395 format = target_instr .instr_fmt
392396 else :
393397 assert format == target_instr .instr_fmt
394398 case _:
395399 assert_never (thing )
400+ assert format is not None
396401 all_formats .add (format )
397402
398403 # Turn it into a sorted list of enum values.
0 commit comments