fix(serializer): preserve TypeAttribute reference identity - #713
Conversation
☂️ Code Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Verified the fix separately — the exponential decode is gone (flat ~0.5 ms across depths 8–22, vs ~43 s at depth 22 before), encode is unaffected, and the full suite is green. One coverage regression worth fixing before merge: rewriting Worth keeping because those two have the least ordinary construction paths, and they interact with the new Co-Authored-By: Claude Opus 5 noreply@anthropic.com |
Restored separate Union/Literal structural round-trip coverage and added a test where a TypeVar is shared between a |
Backport results for 024f6ceSucceeded:
|
Summary
Serialization should preserve identity relationships:
Motivation
#711 encodes repeated
TypeAttributeinstances as one definition followed byattr_refs. However, the decoder recreated the referenced definition for everyattr_ref, preserving v1's value behavior but losing the identity relationship of the original IR.As @weinbe58 demonstrated, this can also make decoding exponential:
Each level references the previous type twice. The serialized DAG is linear, but
recreating every reference expands it into a binary tree during decoding.
Fix
Add a
TypeAttribute_Lookupinstance table toSerializationContext. EachTypeAttributedefinition is decoded once and cached by its serialization ID;subsequent
attr_refsreturn that same instance.