Fix interpreter and glue generator for polymorphic types#9248
Open
lukewilliamboswell wants to merge 5 commits intomainfrom
Open
Fix interpreter and glue generator for polymorphic types#9248lukewilliamboswell wants to merge 5 commits intomainfrom
lukewilliamboswell wants to merge 5 commits intomainfrom
Conversation
…ue generator improvements
Interpreter fixes:
- evalLookupExternal: prefer module-local resolveImports over shared
import_envs map, which could have collisions when platform and app
both use the same import index for different modules (e.g. Keys vs Host)
- dot_access_collect_args: use the dot-access expression's type var
(dac.expr_idx) for hosted method call return types instead of the
lambda expression type, which produced a closure layout and crashed
the ? operator's match
Glue generator fixes:
- Make getSizeAlignForRepr target-aware: box/str/list sizes now use
target pointer width instead of hardcoded 64-bit values
- Compute alt (32-bit vs 64-bit) record layouts and emit comptime
conditional extern structs when field ordering diverges between targets
- Deduplicate anonymous record types by structural signature so
identical records (e.g. { x: F32, y: F32 }) share a single definition
- Fix memory leaks where record reconstruction dropped alt_fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a tag union is compiled in a polymorphic context (e.g., List.get : List(a) -> Result a b), the variant payload layout may be computed as ZST because the type variable was rigid/flex at layout-computation time. At runtime, when we have a concrete structure or alias type, we now compute the correct layout instead of using the stale ZST layout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These trace blocks were leftover debugging aids added during development.
One was specific to a single identifier ("pack"). Remove all 4 blocks
since they add noise without lasting diagnostic value.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Return oomUnknown("record") on allocation failure when collecting fields
from record extension chains, instead of silently dropping fields with
catch {}. Silent failures could produce incorrect struct layouts.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…reter rigid substitution Refactor glue generator to store types without layout info (size/alignment/field_order) and compute layouts separately per target via computeLayoutsForTarget. Parse platform targets section to build target list, deduplicate by pointer width, and pass per-target layouts to Roc glue specs for correct cross-platform struct field ordering and assertions. Fix interpreter rigid type substitution to also check rigid_name_subst (from platform `for` clause), extend variant layout correction from ZST to box_of_zst, and handle ZST/box_of_zst payloads in evalBoxIntrinsic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
088e661 to
aacda63
Compare
|
Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked |
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
List.get : List(a) -> Result a bwhereawas rigid at layout time)rigid_name_subst(from platformforclause), extend variant layout correction tobox_of_zst, and handle ZST/box_of_zst payloads inevalBoxIntrinsiccomputeLayoutsForTargettargetssection to build target list, deduplicate by pointer widthZigGlue.roc,RustGlue.roc) for correct cross-platform struct field ordering and comptime assertionsTargetLayoutandTypeLayout; simplifiedRecordField,RecordRepr,TagUnionRepr,TagVariant(removed inline size/alignment fields)Test plan
zig build minicipasses (all 3107 tests, CLI tests, lints, snapshots)🤖 Generated with Claude Code