Repository navigation
A global whose initializer branches becomes a constructor (#462) - #474
Merged
Merged
Conversation
`let g: Node | null | undefined = mkU()`, with mkU returning `Node | undefined`, failed in every model with "'ts.Global' op expects region #0 to have 0 or 1 blocks", and so did any conditional global initializer (`let x = on() ? 1 : 2`). The optional's widening into the union, like a conditional, is a ts.If; the affine lowering turns it into blocks, and ts.Global's SingleBlockImplicitTerminator trait rejected them. The trait is dropped (MLIRGen still builds one block ending in ts.GlobalResult, and nothing reads the initializer as one block after the affine lowering), and GlobalOpLowering makes a global whose initializer has more than one block a constructor: only a function can hold the branches. Under rc the widened optional then lost its object: the call runs before the ts.If, and the branch yields it through views (ts.Value, a cast, ts.OptionalValue), so the global never took its reference over and the call's was given back at the end of the initializer. claimGlobalInitializers now follows a ts.If whose branches all yield one owned producer from before it through views, or a value that holds nothing (the empty optional, null, undefined), and the global takes the count. Test: 00global_initializer_branches (compile and JIT, and in the rc/none corpus): an optional widened into a union (set and empty), and conditional number, string and object globals. It failed to compile before the change. The own corpus is unchanged. Fixes #462. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #462.
let g: Node | null | undefined = mkU(), wheremkUreturnsNode | undefined, failed in every model with "'ts.Global' op expects region #0 to have 0 or 1 blocks". Every conditional global initializer, such aslet x = on() ? 1 : 2, failed the same way.Widening the optional into the union is a
ts.If, just like a conditional. The affine lowering turns that into blocks, and theSingleBlockImplicitTerminatortrait onts.Globalrejected them.Changes
ts.GlobalResult, and nothing reads the initializer as a single block after the affine lowering.GlobalOpLoweringmakes a global whose initializer has more than one block a constructor, because only a function can hold the branches.ts.If, and the branch yields its value through views (ts.Value, a cast,ts.OptionalValue).claimGlobalInitializers(rc: a global takes the reference of an owned producer through a widening view (#459) #468) now follows ats.Ifwhose branches all yield either one owned producer from before it, through views, or a value that holds nothing (the empty optional,null,undefined).Tests
00global_initializer_branches.ts, registered as compile and JIT tests and in the rc/none corpus. It failed to compile before the change. It covers:test-compile-gc-defaultlib-collector, the known local LNK2005 against the stale installed default library, which fails on main the same way.🤖 Generated with Claude Code