dslx: replace NameDefTree with PatternTree - #4614
Conversation
|
@richmckeever One compatibility question for review: this PR keeps Is explicit rejection the right boundary here, or should we preserve backward compatibility for those artifacts? If compatibility is needed, what reader behavior should we support without silently interpreting the old wrapper shape as the new tuple-pattern node? |
I think we are good with your choice of explicit rejection. To my knowledge, there are no stored serialized records in proto form; only test data files for type_info_to_proto_test which are in the string format. |
Use tuple_pattern and tuple_pattern_type in HandleTuplePatternChild, and update its contract comment to match the surrounding PatternTree vocabulary. This removes the remaining generic tree naming from the helper without changing behavior. Validated with clang-format, git diff --check, and //xls/dslx/type_system_v2:typecheck_module_v2_array_tuple_test on devbox-ubuntu2404.
Reserve wire value 21 now that NameDefTree is no longer a concrete AST kind. Decode raw value 21 explicitly as an unsupported legacy artifact while TuplePattern remains the new concrete enum value. The focused test now injects the raw legacy value so schema reservation cannot hide the rejection path. Validated with clang-format, git diff --check, and //xls/dslx/type_system:type_info_to_proto_test on devbox-ubuntu2404 with test-result caching disabled.
69ec3df to
dd56c33
Compare
dplassgit
left a comment
There was a problem hiding this comment.
Thanks for the update.
Summary
NameDefTreewrapper with aPatternTreevariant whose leaves are concrete pattern AST nodes.TuplePattern, preserving empty, singleton, trailing-comma, and nested shapes.AST_NODE_KIND_NAME_DEF_TREE = 21, addAST_NODE_KIND_TUPLE_PATTERN, and reject legacy value 21 explicitly.Why This Change
This is the foundational part of the direction requested in the PR #4457 review discussion: remove
NameDefTree, make concrete pattern nodes directPatternTreealternatives, and separate tuple and struct pattern shapes so later struct patterns can also serve ordinary structs. This PR lands only the tuple-pattern foundation used by current DSLX. TheStructPatternand nominal/sum-variant pattern work described in that review thread remains in the follow-on semantic-sum PR stack.NameDefTreecurrently represents both concrete pattern leaves and parenthesized tuple-pattern structure. That conflates what a pattern is with how tuple nesting is written, which makes later nominal or struct pattern forms awkward to add without more wrapper-specific behavior throughout the compiler.For example:
After this change, the outer and inner parentheses are
TuplePatternnodes, whilea,b, andcare directNameDef*alternatives insidePatternTree. A direct binding such aslet a = value;remains a direct leaf instead of becoming a one-element wrapper tree.Compatibility
This intentionally changes the internal C++ AST API: live
NameDefTreeAPIs are removed and all in-repository callers now usePatternTreeandTuplePattern. DSLX source behavior is unchanged.This is backward incompatible for serialized type-info artifacts containing AST kind value
21: decoding now returns an explicit unsupported-legacy error. The old number remains reserved so it cannot be silently reinterpreted as the new tuple-pattern node kind.Testing
bazel test //xls/dslx/type_system_v2:typecheck_module_v2_array_tuple_testbazel test //xls/dslx/type_system:type_info_to_proto_test