-
Notifications
You must be signed in to change notification settings - Fork 28
perf(ir): move inferred types to a positional side table — ~100x faster type writes #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6935863
perf(ir): move inferred types to a positional side table, off the ins…
mparrett 9d8070e
fix(ir): carry the :types side-table entry in clone-inst; document sl…
mparrett ca69b25
test(ir): pin the :types side-table contract; document set-type!'s sy…
mparrett 55f4192
docs(ir): note the deliberate discarded conj! return in ensure-types!…
mparrett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2026 Norman Nunley, Jr <nnunley@gmail.com> | ||
| * Part of the let-go project; see CONTRIBUTORS for full list of authors. | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| package ir_test | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestTypeSideTableContract pins the :types side-table invariants introduced | ||
| // when inferred types moved off the inst tuple (PR #558). type-of, the | ||
| // lattice seed, and clone-inst each implement the same precedence rule — | ||
| // side table first, tuple slot 5 (construction-time :unknown) as fallback — | ||
| // and the clone carry was a review catch, so lock the contract down: | ||
| // | ||
| // 1. fallback: an inst with no side-table entry reads :unknown | ||
| // 2. set-type! writes are read back through type-of (side table wins) | ||
| // 3. overwrite: the last write wins | ||
| // 4. sparse growth: setting only a high nid grows the table; untouched | ||
| // nids in the gap still read the fallback | ||
| // 5. clone-inst carries the side-table entry (typed clone keeps its type, | ||
| // untyped clone stays :unknown) | ||
| // 6. seed-state-from-inst-types! reads the same merged view | ||
| func TestTypeSideTableContract(t *testing.T) { | ||
| ensureLoader() | ||
| got := runLispString(t, `(pr-str | ||
| (let [f (ir.build/build-fn '(defn t558 [x] (+ x 1))) | ||
| nid (first (ir/block-insts (ir/entry-block f) f)) | ||
| last-nid (- (ir/inst-count f) 1) | ||
| mid-nid (- last-nid 1)] | ||
| [;; 1. fallback: nothing set yet -> construction default | ||
| (ir/type-of nid f) | ||
| ;; 2. side table wins once set | ||
| (do (ir/set-type! f nid :int) (ir/type-of nid f)) | ||
| ;; 3. overwrite: last write wins | ||
| (do (ir/set-type! f nid :float) (ir/type-of nid f)) | ||
| ;; 4. sparse: only the high nid is set; the gap nid still falls back | ||
| (do (ir/set-type! f last-nid :string) | ||
| [(ir/type-of last-nid f) (ir/type-of mid-nid f)]) | ||
| ;; 5. clone carry: typed clone keeps the type, untyped stays :unknown | ||
| (ir/type-of (ir/clone-inst f nid) f) | ||
| (ir/type-of (ir/clone-inst f mid-nid) f) | ||
| ;; 6. the typeinfra seed reads the merged view (side table first) | ||
| (let [s (ir.lattice/seed-state-from-inst-types! (ir.lattice/new-typeinfra-state f) f)] | ||
| (ir.lattice/state-type s nid))]))`) | ||
| want := `[:unknown :int :float [:string :unknown] :float :unknown :float]` | ||
| if got != want { | ||
| t.Fatalf("side-table contract mismatch:\n got: %s\nwant: %s", got, want) | ||
| } | ||
| } |
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
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
Binary file not shown.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.