-
-
Notifications
You must be signed in to change notification settings - Fork 159
feat(codegen): admit class-typed parameters into the guarded specialization path #8165
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
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,42 @@ | ||
| ### Performance | ||
|
|
||
| - Admit class-typed parameters into the #8094 guarded specialization path. A | ||
| class descriptor now carries the class id — giving | ||
| `param_type_guard.rs`'s `class_chain_reaches` branch its first caller, which | ||
| codegen had never reached — plus every declared field on the inheritance | ||
| chain, validated by name. A class-annotated parameter recovers the same | ||
| lowering an interface-annotated one already got (`js_dynamic_string_or_ | ||
| number_add` becomes a string concat), while a structurally identical object | ||
| literal fails the identity check and takes the generic fallback (#8099). | ||
|
|
||
| The refusal this replaces rested on a stale claim that compact class | ||
| instances carry no `keys_array`. They do — | ||
| `object_alloc_class_inline_keys_impl` installs a per-class array built once | ||
| at module init — so the same by-name field validation that serves interfaces | ||
| serves classes. The stale note on `ObjectHeader::keys_array` is corrected | ||
| too. | ||
|
|
||
| Identity **without** the field types was implemented, measured and reverted: | ||
| the emitted clone came out structurally identical to the `$generic` sibling | ||
| it routes around (same line count, same call multiset), because a | ||
| class-annotated receiver already reaches the class-field guard path without | ||
| any parameter evidence. It bought nothing and cost one `js_param_type_guard` | ||
| call per invocation — `tree` 1.089 s → 1.646 s (+51%) and `tree_wide` | ||
| 1.775 s → 2.304 s (+30%), best-of-5 on the quiet M1 mini. That also answers | ||
| the `tree` row #8099 was filed about: the hot recursive walker is refused by | ||
| #8094's aliasing rule, not by the class refusal, and the only descriptor | ||
| cheap enough to admit there is the one that buys nothing. | ||
|
|
||
| Cost stays bounded by the existing rule rather than a new one: a | ||
| field-bearing descriptor claims heap contents, so a reference-typed | ||
| parameter carrying one is refused in any body containing a call. A recursive | ||
| class (`Tree.left: Tree`) therefore cannot be guarded inside the recursive | ||
| walker that would make its validation O(nodes x depth). | ||
|
|
||
| Validated: the 19-program specialization corpus emits **identical LLVM IR** | ||
| before and after, so nothing already-specializing moved; the extended | ||
| `test_gap_specabi_ordinary_param_guards` fixture is byte-exact against node | ||
| `v26.5.1`, including under `PERRY_GC_ZEAL=1 PERRY_GC_PROTECT_FROMSPACE=1` | ||
| (40 copying minors, 40 from-space protections — the instrument was live); | ||
| and `cargo test -p perry-codegen` adds no failure against a clean-`main` | ||
| baseline run. | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add full affected file paths to the changelog.
The entry names
param_guard.rsandObjectHeader::keys_array, but it does not identify the repository paths. Addcrates/perry-codegen/src/codegen/param_guard.rsandcrates/perry-runtime/src/object/mod.rsso the release note identifies both implementation sites.Based on learnings: “Changelog fragments in
changelog.d/should use the repository’s detailed format: include a long-form root-cause explanation, affected file paths, and validation notes.”🤖 Prompt for AI Agents
Source: Learnings