Fix segfault when pattern matching on opaque types from lists#9115
Draft
lukewilliamboswell wants to merge 1 commit intomainfrom
Draft
Fix segfault when pattern matching on opaque types from lists#9115lukewilliamboswell wants to merge 1 commit intomainfrom
lukewilliamboswell wants to merge 1 commit intomainfrom
Conversation
5a19277 to
737fa6a
Compare
…9113) This PR fixes two related issues: 1. **List element re-boxing (original fix)**: When a recursive opaque type (like `Element`) is stored in a list, elements are auto-boxed for uniform size. When these elements are later used as tag union payloads, the code now correctly re-boxes them to match the expected layout. 2. **Incorrect auto-boxing in record_collect (new fix)**: The `record_collect` continuation was incorrectly auto-boxing fields based on whether the field's type is self-recursive. This caused layout mismatches when a separate recursive type (like `NodeA`) was used in a different type's record field (like `NodeB`'s `FoldB` payload). The fix removes this incorrect auto-boxing. The type-based layout is the source of truth: - When a type references itself (`Type := [Node({ child: Type })]`), the layout system correctly creates `Box(Type)` during computation. - When a separate recursive type is used (`{ event: NodeA }`), it should NOT be boxed because `NodeA` is already a complete type. Test cases added: - `issue9113_simple.roc`: Tests the original list re-boxing fix - `list_opaque_pattern_match_bug.roc`: Tests nested opaque types in lists Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
737fa6a to
7625b29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix segfault (issue #9113) when pattern matching on recursive opaque types extracted from lists. This PR addresses two related issues:
1. List element re-boxing (original fix)
When a recursive opaque type (like
Element) is stored in a list, elements are auto-boxed for uniform size. When these elements are later used as tag union payloads, the code now correctly re-boxes them to match the expected layout.2. Incorrect auto-boxing in record_collect (new fix)
The
record_collectcontinuation was incorrectly auto-boxing fields based on whether the field's type is self-recursive. This caused layout mismatches when a separate recursive type (likeNodeA) was used in a different type's record field (likeNodeB'sFoldBpayload).The fix removes this incorrect auto-boxing. The type-based layout is the source of truth:
Type := [Node({ child: Type })]), the layout system correctly createsBox(Type)during layout computation.{ event: NodeA }), it should NOT be boxed becauseNodeAis already a complete type.Changes
boxbut the actual list has non-boxed elements, re-box each elementTest plan
test/fx/issue9113_simple.roc(tests list re-boxing)test/fx/list_opaque_pattern_match_bug.roc(tests nested opaque types)zig build minicipassesFixes #9113
🤖 Generated with Claude Code