@@ -4397,9 +4397,6 @@ def _set_replacement(self, a: "sympy.Symbol", tgt: "sympy.Expr", msg: str) -> No
4397
4397
Use this instead of `self.replacements[a] = tgt`.
4398
4398
"""
4399
4399
4400
- if tgt == self .replacements .get (a , None ):
4401
- return
4402
-
4403
4400
# Precondition: a == tgt
4404
4401
assert isinstance (a , sympy .Symbol )
4405
4402
@@ -4490,24 +4487,14 @@ def issubset(x, y):
4490
4487
"[%s not subset of %s (size-oblivious conditions)]" , a , tgt , msg , tgt_bound_so , src_bound_so )
4491
4488
return
4492
4489
4493
- if isinstance (tgt , (sympy .Integer , sympy .Float )):
4494
- # specializing to a constant, which is likely unexpected (unless
4495
- # you specified dynamic=True)
4496
-
4497
- user_tb = TracingContext .extract_stack ()
4498
- trace_structured (
4499
- "symbolic_shape_specialization" ,
4500
- metadata_fn = lambda : {
4501
- "symbol" : repr (a ),
4502
- "sources" : [s .name () for s in self .var_to_sources [a ]],
4503
- "value" : repr (tgt ),
4504
- "reason" : msg ,
4505
- "stack" : structured .from_traceback (CapturedTraceback .extract (skip = 1 ).summary ()),
4506
- "user_stack" : structured .from_traceback (user_tb ) if user_tb else None ,
4507
- }
4508
- )
4490
+ if config .print_specializations and isinstance (tgt , (sympy .Integer , sympy .Float )):
4491
+ # specializing to a constant, which is likely unexpected
4509
4492
4510
- if config .print_specializations :
4493
+ # NOTE(avik): It is possible that we try logging the same specialization multiple times, e.g.,
4494
+ # when adding a to self.replacements, and again when simplifying an expression containing a.
4495
+ # Thus to avoid duplication, checking whether a is in self.replacements isn't enough; if it is,
4496
+ # it must not already map to `tgt`. Fortunately this check is cheap because `tgt` is a constant.
4497
+ if a not in self .replacements or tgt != self .replacements [a ]:
4511
4498
self .log .warning ("Specializing %s to %s" , self .var_to_sources [a ][0 ].name (), tgt )
4512
4499
self .log .debug ("SPECIALIZATION" , stack_info = True )
4513
4500
log .info ("set_replacement %s = %s (%s) %s" , a , tgt , msg , tgt_bound )
0 commit comments