mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	GH-98831: Modernize a ton of simpler instructions (#100545)
* load_const and load_fast aren't families for now * Don't decref unmoved names * Modernize GET_ANEXT * Modernize GET_AWAITABLE * Modernize ASYNC_GEN_WRAP * Modernize YIELD_VALUE * Modernize POP_EXCEPT (in more than one way) * Modernize PREP_RERAISE_STAR * Modernize LOAD_ASSERTION_ERROR * Modernize LOAD_BUILD_CLASS * Modernize STORE_NAME * Modernize LOAD_NAME * Modernize LOAD_CLASSDEREF * Modernize LOAD_DEREF * Modernize STORE_DEREF * Modernize COPY_FREE_VARS (mark it as done) * Modernize LIST_TO_TUPLE * Modernize LIST_EXTEND * Modernize SET_UPDATE * Modernize SETUP_ANNOTATIONS * Modernize DICT_UPDATE * Modernize DICT_MERGE * Modernize MAP_ADD * Modernize IS_OP * Modernize CONTAINS_OP * Modernize CHECK_EXC_MATCH * Modernize IMPORT_NAME * Modernize IMPORT_STAR * Modernize IMPORT_FROM * Modernize JUMP_FORWARD (mark it as done) * Modernize JUMP_BACKWARD (mark it as done)
This commit is contained in:
		
							parent
							
								
									3dc48dabd4
								
							
						
					
					
						commit
						08e5594cf3
					
				
					 3 changed files with 242 additions and 349 deletions
				
			
		|  | @ -125,6 +125,7 @@ class Instruction: | |||
|     # Set later | ||||
|     family: parser.Family | None = None | ||||
|     predicted: bool = False | ||||
|     unmoved_names: frozenset[str] = frozenset() | ||||
| 
 | ||||
|     def __init__(self, inst: parser.InstDef): | ||||
|         self.inst = inst | ||||
|  | @ -141,6 +142,13 @@ def __init__(self, inst: parser.InstDef): | |||
|             effect for effect in inst.inputs if isinstance(effect, StackEffect) | ||||
|         ] | ||||
|         self.output_effects = inst.outputs  # For consistency/completeness | ||||
|         unmoved_names: set[str] = set() | ||||
|         for ieffect, oeffect in zip(self.input_effects, self.output_effects): | ||||
|             if ieffect.name == oeffect.name: | ||||
|                 unmoved_names.add(ieffect.name) | ||||
|             else: | ||||
|                 break | ||||
|         self.unmoved_names = frozenset(unmoved_names) | ||||
| 
 | ||||
|     def write(self, out: Formatter) -> None: | ||||
|         """Write one instruction, sans prologue and epilogue.""" | ||||
|  | @ -175,12 +183,8 @@ def write(self, out: Formatter) -> None: | |||
|         out.stack_adjust(diff) | ||||
| 
 | ||||
|         # Write output stack effect assignments | ||||
|         unmoved_names: set[str] = set() | ||||
|         for ieffect, oeffect in zip(self.input_effects, self.output_effects): | ||||
|             if ieffect.name == oeffect.name: | ||||
|                 unmoved_names.add(ieffect.name) | ||||
|         for i, oeffect in enumerate(reversed(self.output_effects), 1): | ||||
|             if oeffect.name not in unmoved_names: | ||||
|             if oeffect.name not in self.unmoved_names: | ||||
|                 dst = StackEffect(f"PEEK({i})", "") | ||||
|                 out.assign(dst, oeffect) | ||||
| 
 | ||||
|  | @ -235,7 +239,8 @@ def write_body(self, out: Formatter, dedent: int, cache_adjust: int = 0) -> None | |||
|             elif m := re.match(r"(\s*)DECREF_INPUTS\(\);\s*$", line): | ||||
|                 space = m.group(1) | ||||
|                 for ieff in self.input_effects: | ||||
|                     out.write_raw(f"{extra}{space}Py_DECREF({ieff.name});\n") | ||||
|                     if ieff.name not in self.unmoved_names: | ||||
|                         out.write_raw(f"{extra}{space}Py_DECREF({ieff.name});\n") | ||||
|             else: | ||||
|                 out.write_raw(extra + line) | ||||
| 
 | ||||
|  | @ -533,7 +538,7 @@ def stack_analysis( | |||
|     ) -> tuple[list[StackEffect], int]: | ||||
|         """Analyze a super-instruction or macro. | ||||
| 
 | ||||
|         Print an error if there's a cache effect (which we don't support yet). | ||||
|         Ignore cache effects. | ||||
| 
 | ||||
|         Return the list of variable names and the initial stack pointer. | ||||
|         """ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum