Repository navigation
An array literal in a ternary is an array, and Android builds own - #624
Merged
Merged
Conversation
- `i < 3 ? ["a"] : null` failed MLIR verification under every model: the ternary was a `const_array | null`, and the generated function casting it to `string[] | null` narrowed the literal to a copy that its narrowed name owned, released outside the branch. A literal array in a branch of `?:` is now an array there, handed out with a reference of its own as `new C()` is, so -mm=own accepts array ternaries too. - `if (a)` of a `string[] | null` narrows it (an untagged union of arrays and null); `a[0]` indexed the union before. - The Android link test links an executable and a shared library under own as well as gc. 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.
Closes the last two open items in the own markers spec.
Ternary of an array literal or null.
return i < 3 ? ["a"] : nullfailed MLIR verification ("operand #0 does not dominate this use") under every model, gc included. The cause:const_array<string,1> | null.___castfunction that makes it astring[] | nullnarrowstin itselsebranch. Narrowing aconst_arraygives the narrowed name storage of its own: a heap copy that it owns.Now a literal array in a branch of
?:is widened to an array in that branch, as TypeScript types it. Each branch also hands its array out with a reference of its own, asnew C()is (Retain plus__owned_result). That letsconsumeConditionalResultssettle the merge, so-mm=ownaccepts array ternaries. Before, own rejected evenc ? ["a"] : ["b"]. rc passes--verify-ownershipon the new test.if (a)of astring[] | nulldidn't narrowa, because truthiness narrowing required a tagged union. An array keeps null in its own pointer, soa[0]indexed the union. Truthiness narrowing now also covers untagged unions of arrays and null. It deliberately leavesShared<T> | nullalone: own reads a counted handle through the variable itself, andown_shared_graphbreaks otherwise.Test:
tests/00narrow_array_null.ts, under gc, rc, none and own, compiled and JIT. It covers ternaries overif,whileandfor, andpushafter churn.Android own.
android-link.cmakenow links an executable and a shared library under own as well as gc. This needs the own Android default library from ASDAlexander77/TypeScriptCompilerDefaultLib#38. I ran an own executable on the API 29 x86_64 emulator:matchAll,padStart,repeat, arrays and classes all gave correct output. The README and the spec are updated.Full suite: 4834/4834 (Release, Windows).
🤖 Generated with Claude Code