Skip to content

Map and Set under -mm=own; size after delete - #39

Merged
ASDAlexander77 merged 3 commits into
mainfrom
own-generic-iterators
Oct 26, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
own-generic-iterators

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Depends on ASDAlexander77/TypeScriptCompiler#693 (merge that first): under -mm=own these changes need its analysis. Under gc, rc and none they work with the current compiler too.

Makes Map and Set in src/generics/lib.generics.ts compile under -mm=own for number, boolean and string keys and values:

  • @borrows("this") on the iterators (iter, iterKey, iterValue) and their forwarders (entries, keys, values, [Symbol.iterator]). The iterators read this._entries[i] at each step instead of keeping the array in their state.
  • forEach is a loop over the entries, not over iter().
  • resizeHelper grows _entries in place instead of moving each entry into a new array.
  • An entry is stored as a tuple cast to the entry type, in one place after the search loop. Set's overwrite branch was dead (a set never overwrites an equal value) and is gone.
  • hashCodeGeneral hashes the parameter's own bytes (Ref(key)) instead of a local copy.

Bug fix, every model: size returned count, which still counts deleted entries on the free list, so m.delete(k) left m.size unchanged. New test tests/map_size_delete.ts.

Tests (AOT release, compiler from #693): own 80 → 87 passing, no regressions (map_delete, map_get, map_get_number, map_has, map_set, map_set_overwrite, map_values_reduce now pass); gc 167/167; rc 166/167 (weakref_basic, gc-only). Still failing under own: Map/Set with any elements, including untyped new Map() / new Set([1, 2]) (see the compiler PR's notes). Debug and JIT passes not run.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits October 26, 2026 15:38
…s deleted entries out

lib.generics.ts is compiled into each program, and none of Map and Set compiled under -mm=own.
With the compiler's own-generator-this-borrows branch they do for number, boolean and string keys
and values:

- @borrows("this") on the iterators and their forwarders; the iterators read the entries through
  `this` at each step instead of keeping the array in their state.
- forEach is a loop over the entries, not over iter().
- resizeHelper grows the entries array in place instead of moving each entry into a new one.
- An entry is stored as a tuple cast to the entry type, in one place after the search loop; Set's
  overwrite branch was dead and is gone.
- hashCodeGeneral hashes the parameter's own bytes instead of a local copy.

Bug fix, every model: size was count, which still counts the deleted entries on the free list
(`m.delete(k)` left `m.size` unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 05af031 into main Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant