Repository navigation
Builtin iterator methods without the default library: a.map(f).map(g) - #443
Merged
Merged
Conversation
With --no-default-lib, an array's map/filter/forEach/every/some are
builtins, and what map and filter give is a generator, which had none of
them: `a.map(f).map(g)` failed to compile under every model. An iterator
(anything whose next() returns {value, done}) now has the same builtins,
as the default library's __Iterator gives them; each is a for...of over
its receiver. The fallback comes after extension functions, so a user's
own `map` still wins. reduce stays array-only: its builtin takes `T[]`.
The generator map/filter build was named by where the call starts, and
`a.map(f).map(g)`'s two calls start together: "redefinition of symbol
... .next". It is named by its callback's location too.
Part of #442.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Rechecked
So |
This was referenced Oct 2, 2026
Merged
ASDAlexander77
added a commit
that referenced
this pull request
Oct 4, 2026
…n too (#442) (#499) `if (o.foo)` on an object with no `foo` reported only "the condition has no value", and `const v = o.foo` only "can't resolve name: v", neither naming the property. The failure happens in the run that infers the function's return type (allowPartialResolve), where mlirGenPropertyAccessExpression gives success with no value and no message, so that a sibling method an object literal has not registered yet can resolve in a later run; the compile then fails in that run on what the caller makes of no value, and the run that would have said "Can't resolve property" is never reached. The access now emits "Can't resolve property 'foo' of type {x:s32}" in that run as well, still returning success. A message is shown only if the module fails to compile, and each retry cycle starts with none, so a property that resolves later costs nothing. The caller's own message ("the condition has no value") follows it. Part 1 of the issue (a.map(f).map(g) without the default library) was fixed by #443. Closes #442 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.
Part of #442: the first of its two bugs. With
--no-default-lib,a.map(f).map(g)failed to compile under every memory model.Cause
Without the default library, an array's
map,filter,forEach,everyandsomeare MLIRGen builtins.mapandfilterbuild a generator and return it, and a generator had none of these methods. With the default library the same code works: itsnamespace __Iteratorgives every iterator these methods as extension functions.Change
next()returns{value, done}: the result ofmaporfilter, or a generator of your own.mlirGenPropertyAccessExpressionBaseLogic, and applies only underenableBuiltins && noDefaultLib.for...ofover its receiver.mapstill wins, as it does with the default library.reducestays array-only. Its builtin is a generic function that takesT[].MLIRPropertyAccessCodeLogic::ArrayintoCustomMethod(elementType), so arrays and iterators share it.hasIteratornow wraps a newgetIteratorValueType, which returnsnext()'svaluetype.a.map(f).map(g)then failed with "redefinition of symbol ... .next".LocationHelper::getSpanhas no real span end to tell them apart.Not in this PR
success()it comes from (thedummyRun/allowPartialResolvereturn inmlirGenPropertyAccessExpressionBaseLogic) is deliberate, for sibling-method discovery, so changing it is a separate change with its own risk..length,[i]andreduceon amapresult: they still fail. The result is a generator, not an array.-mm=own: every chain is rejected with "'this value' borrows a field and cannot be stored, returned or captured", the 5b capture error, because the outermap's closure box captures a generator. Phase 7b (-mm=own phase 7b: a generator over a parameter's block borrows it; .map and .filter #441) changes how generators borrow, so I'll recheck after it merges. Accepting a chain would mean a box inheriting its contents' bound, which would be new inference work.Verification
Release suite: 3389 of 3390 pass. The one failure,
test-compile-gc-defaultlib-collector, is the stale installed default library, as on -mm=own phase 5a: a closure that does not escape borrows what it captures #436--mm=own phase 7b: a generator over a parameter's block borrows it; .map and .filter #441.WSL/GCC: builds; the 392 tests run there (the new ones,
own, and the map/filter/every/some tests) all pass.Memory: a loop of chains (
map.filter.map,map.forEach,map.some), AOT,measure.ps1, in MB:rc stays flat, so the chained generators leak nothing.
Own corpus: 359 compile, the same files as on main.
Tests
tests/00iterator_methods.tscovers:forEachthrough a variable;everyandsome, both true and false;next()on amapresult;It is registered for AOT and JIT, and in
TSLANG_CORPUS, so it also runs under rc and none.🤖 Generated with Claude Code