[dynamo] Use sentinel value for guard filter. (#151131)

Summary: `None` can collide with the real values in the scope, so we should use a separate value. Also added "has_value" to the struct so that it's more clear whether the value is absent or not.

Test Plan: CI

Differential Revision: D72881300

Pull Request resolved: https://github.com/pytorch/pytorch/pull/151131
Approved by: https://github.com/jansel, https://github.com/anijain2305
This commit is contained in:
Zhengxu Chen 2025-04-12 15:29:57 +00:00 committed by PyTorch MergeBot
parent 5b16a0704e
commit be24e7b4b4
2 changed files with 6 additions and 1 deletions

View File

@ -2485,10 +2485,13 @@ class CheckFunctionManager:
if guard_filter_fn:
def make_guard_filter_entry(guard):
MISSING = object()
name = strip_local_scope(guard.name)
if name == "":
value = None
has_value = False
value = MISSING
else:
has_value = True
value = builder.get(guard.name)
is_global = is_from_global_source(guard.originating_source)
guard_fn = guard.create_fn
@ -2496,6 +2499,7 @@ class CheckFunctionManager:
guard_fn = guard.create_fn.func
return GuardFilterEntry(
name=name,
has_value=has_value,
value=value,
guard_type=guard_fn.__name__,
derived_guard_types=tuple(guard.guard_types)

View File

@ -40,6 +40,7 @@ class GuardFail(NamedTuple):
@dataclasses.dataclass(frozen=True)
class GuardFilterEntry:
name: str
has_value: bool
value: object
guard_type: str
derived_guard_types: tuple[str, ...]