Skip to content

Commit d786146

Browse files
committed
Rename 'defined' attribute to 'in_local' to more accurately reflect how it is used
1 parent 45199ae commit d786146

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

Tools/cases_generator/generators_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def stackref_kill(
303303
f"'{live}' is still live", name)
304304
var.kill()
305305
break
306-
if var.defined:
306+
if var.in_local:
307307
live = var.name
308308
return True
309309

@@ -577,15 +577,15 @@ def _emit_block(
577577
if tkn in local_stores:
578578
for var in storage.inputs:
579579
if var.name == tkn.text:
580-
if var.defined or var.in_memory:
580+
if var.in_local or var.in_memory:
581581
msg = f"Cannot assign to already defined input variable '{tkn.text}'"
582582
raise analysis_error(msg, tkn)
583-
var.defined = True
583+
var.in_local = True
584584
var.in_memory = False
585585
break
586586
for var in storage.outputs:
587587
if var.name == tkn.text:
588-
var.defined = True
588+
var.in_local = True
589589
var.in_memory = False
590590
break
591591
if tkn.text.startswith("DISPATCH"):

Tools/cases_generator/optimizer_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def emit_default(out: CWriter, uop: Uop, stack: Stack) -> None:
8484
local = Local.undefined(var)
8585
stack.push(local)
8686
if var.name != "unused" and not var.peek:
87-
local.defined = True
87+
local.in_local = True
8888
if var.is_array():
8989
if var.size == "1":
9090
out.emit(f"{var.name}[0] = sym_new_not_null(ctx);\n")
@@ -145,7 +145,7 @@ def write_uop(
145145
emitter = OptimizerEmitter(out, {})
146146
# No reference management of inputs needed.
147147
for var in storage.inputs: # type: ignore[possibly-undefined]
148-
var.defined = False
148+
var.in_local = False
149149
storage = emitter.emit_tokens(override, storage, None)
150150
out.start_line()
151151
storage.flush(out)

Tools/cases_generator/stack.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def var_size(var: StackItem) -> str:
3333
class Local:
3434
item: StackItem
3535
in_memory: bool
36-
defined: bool
36+
in_local: bool
3737

3838
def __repr__(self) -> str:
39-
return f"Local('{self.item.name}', mem={self.in_memory}, defined={self.defined}, array={self.is_array()})"
39+
return f"Local('{self.item.name}', mem={self.in_memory}, local={self.in_local}, array={self.is_array()})"
4040

4141
def compact_str(self) -> str:
4242
mtag = "M" if self.in_memory else ""
43-
dtag = "D" if self.defined else ""
43+
dtag = "D" if self.in_local else ""
4444
atag = "A" if self.is_array() else ""
4545
return f"'{self.item.name}'{mtag}{dtag}{atag}"
4646

@@ -63,14 +63,14 @@ def from_memory(defn: StackItem) -> "Local":
6363
return Local(defn, True, True)
6464

6565
def kill(self) -> None:
66-
self.defined = False
66+
self.in_local = False
6767
self.in_memory = False
6868

6969
def copy(self) -> "Local":
7070
return Local(
7171
self.item,
7272
self.in_memory,
73-
self.defined
73+
self.in_local
7474
)
7575

7676
@property
@@ -90,7 +90,7 @@ def __eq__(self, other: object) -> bool:
9090
return (
9191
self.item is other.item
9292
and self.in_memory is other.in_memory
93-
and self.defined is other.defined
93+
and self.in_local is other.in_local
9494
)
9595

9696

@@ -242,7 +242,7 @@ def pop(self, var: StackItem) -> tuple[str, Local]:
242242
if not var.used:
243243
return "", popped
244244
self.defined.add(var.name)
245-
if popped.defined:
245+
if popped.in_local:
246246
if popped.name == var.name:
247247
return "", popped
248248
else:
@@ -295,7 +295,7 @@ def flush(self, out: CWriter) -> None:
295295
var_offset = self.base_offset.copy()
296296
for var in self.variables:
297297
if (
298-
var.defined and
298+
var.in_local and
299299
not var.in_memory
300300
):
301301
Stack._do_emit(out, var.item, var_offset, self.cast_type, self.extract_bits)
@@ -355,7 +355,7 @@ def merge(self, other: "Stack", out: CWriter) -> None:
355355
for self_var, other_var in zip(self.variables, other.variables):
356356
if self_var.name != other_var.name:
357357
raise StackError(f"Mismatched variables on stack: {self_var.name} and {other_var.name}")
358-
self_var.defined = self_var.defined and other_var.defined
358+
self_var.in_local = self_var.in_local and other_var.in_local
359359
self_var.in_memory = self_var.in_memory and other_var.in_memory
360360
self.align(other, out)
361361

@@ -403,21 +403,21 @@ class Storage:
403403
@staticmethod
404404
def needs_defining(var: Local) -> bool:
405405
return (
406-
not var.defined and
406+
not var.in_local and
407407
not var.is_array() and
408408
var.name != "unused"
409409
)
410410

411411
@staticmethod
412412
def is_live(var: Local) -> bool:
413413
return (
414-
var.defined and
414+
var.in_local and
415415
var.name != "unused"
416416
)
417417

418418
def first_input_not_cleared(self) -> str:
419419
for input in self.inputs:
420-
if input.defined:
420+
if input.in_local:
421421
return input.name
422422
return ""
423423

@@ -440,22 +440,22 @@ def clear_dead_inputs(self) -> None:
440440
self.inputs.pop()
441441
self.stack.pop(tos.item)
442442
for var in self.inputs:
443-
if not var.defined and not var.is_array() and var.name != "unused":
443+
if not var.in_local and not var.is_array() and var.name != "unused":
444444
raise StackError(
445445
f"Input '{var.name}' is not live, but '{live}' is"
446446
)
447447

448448
def _push_defined_outputs(self) -> None:
449449
defined_output = ""
450450
for output in self.outputs:
451-
if output.defined and not output.in_memory:
451+
if output.in_local and not output.in_memory:
452452
defined_output = output.name
453453
if not defined_output:
454454
return
455455
self.clear_inputs(f"when output '{defined_output}' is defined")
456456
undefined = ""
457457
for out in self.outputs:
458-
if out.defined:
458+
if out.in_local:
459459
if undefined:
460460
f"Locals not defined in stack order. "
461461
f"Expected '{undefined}' to be defined before '{out.name}'"
@@ -467,7 +467,7 @@ def _push_defined_outputs(self) -> None:
467467

468468
def locals_cached(self) -> bool:
469469
for out in self.outputs:
470-
if out.defined:
470+
if out.in_local:
471471
return True
472472
return False
473473

@@ -564,7 +564,7 @@ def sanity_check(self) -> None:
564564

565565
def is_flushed(self) -> bool:
566566
for var in self.outputs:
567-
if var.defined and not var.in_memory:
567+
if var.in_local and not var.in_memory:
568568
return False
569569
return self.stack.is_flushed()
570570

@@ -577,7 +577,7 @@ def merge(self, other: "Storage", out: CWriter) -> None:
577577
diff = self.inputs[-1] if len(self.inputs) > len(other.inputs) else other.inputs[-1]
578578
raise StackError(f"Unmergeable inputs. Differing state of '{diff.name}'")
579579
for var, other_var in zip(self.inputs, other.inputs):
580-
if var.defined != other_var.defined:
580+
if var.in_local != other_var.in_local:
581581
raise StackError(f"'{var.name}' is cleared on some paths, but not all")
582582
if len(self.outputs) != len(other.outputs):
583583
self._push_defined_outputs()
@@ -653,7 +653,7 @@ def close_variable(var: Local, overwrite: str) -> None:
653653
if var.is_array():
654654
if len(self.inputs) > 1:
655655
raise StackError("Cannot call DECREF_INPUTS with multiple live input(s) and array output")
656-
elif var.defined:
656+
elif var.in_local:
657657
if output is not None:
658658
raise StackError("Cannot call DECREF_INPUTS with more than one live output")
659659
output = var
@@ -669,29 +669,29 @@ def close_variable(var: Local, overwrite: str) -> None:
669669
raise StackError("Cannot call DECREF_INPUTS with non fixed size array as lowest input on stack")
670670
if size > 1:
671671
raise StackError("Cannot call DECREF_INPUTS with array size > 1 as lowest input on stack")
672-
output.defined = False
672+
output.in_local = False
673673
close_variable(lowest, output.name)
674674
else:
675675
lowest.in_memory = False
676-
output.defined = False
676+
output.in_local = False
677677
close_variable(lowest, output.name)
678678
to_close = self.inputs[: 0 if output is not None else None: -1]
679679
if len(to_close) == 1 and not to_close[0].is_array():
680680
self.reload(out)
681-
to_close[0].defined = False
681+
to_close[0].in_local = False
682682
self.flush(out)
683683
self.save_inputs(out)
684684
close_variable(to_close[0], "")
685685
self.reload(out)
686686
else:
687687
for var in to_close:
688-
assert var.defined or var.is_array()
688+
assert var.in_local or var.is_array()
689689
close_variable(var, "PyStackRef_NULL")
690690
self.reload(out)
691691
for var in self.inputs:
692-
var.defined = False
692+
var.in_local = False
693693
if output is not None:
694-
output.defined = True
694+
output.in_local = True
695695
# MyPy false positive
696-
lowest.defined = False # type: ignore[possibly-undefined]
696+
lowest.in_local = False # type: ignore[possibly-undefined]
697697
self.flush(out)

0 commit comments

Comments
 (0)