-
-
Notifications
You must be signed in to change notification settings - Fork 161
diag(hir): PERRY_NATIVEINST_DIAG — report every native-instance tag at the two entry points that create them #9850
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| `PERRY_NATIVEINST_DIAG=1` reports every native-instance tag as it is created. | ||
|
|
||
| `register_native_instance` and `push_module_native_instance` are the only two | ||
| entry points through which such a tag can come into existence, so a diagnostic | ||
| on them cannot miss one the way a diagnostic on guessed construction sites can | ||
| — which is why it is placed there. One line per registration: | ||
|
|
||
| ``` | ||
| [nativeinst] REGISTER push_module name="O" -> child_process::Instance | ||
| ``` | ||
|
|
||
| The env var is excluded from the build-level cache, because a cached build | ||
| reuses the finished binary and never lowers HIR, so the report would print | ||
| nothing — and nothing is indistinguishable from "no tag was ever registered". | ||
|
|
||
| Off, the cost is one relaxed atomic load per registration. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1461,6 +1461,7 @@ impl LoweringContext { | |
| module_name: String, | ||
| class_name: String, | ||
| ) -> bool { | ||
| nativeinst_registry_diag("register", &local_name, &module_name, &class_name); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 8 'register_native_instance\s*\(' crates/perry-hir
rg -n -C 8 'is_compile_package_override\s*\(' crates/perry-hirRepository: PerryTS/perry Length of output: 50370 🤖 get_repo_knowledge executed:
Length of output: 21405 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- register_native_instance ---'
sed -n '1448,1495p' crates/perry-hir/src/lower/context.rs
printf '%s\n' '--- override helper and usages ---'
rg -n -C 12 'fn is_compile_package_override|is_compile_package_override\(' crates/perry-hir/src/lower/context.rs crates/perry-hir/src/lower
printf '%s\n' '--- diagnostic helper ---'
rg -n -C 12 'fn nativeinst_registry_diag|nativeinst_registry_diag\(' crates/perry-hir/src/lower/context.rsRepository: PerryTS/perry Length of output: 11364 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- override definition and compilePackages configuration ---'
rg -n -C 8 'compilePackages|compile_packages|is_compile_package_override' crates/perry-hir crates/perry-runtime crates/perry
printf '%s\n' '--- return-value consumers ---'
rg -n -C 6 'register_native_instance\([^;]*\)|register_native_instance' crates/perry-hir/src/lower crates/perry-hir/src/lower_decl crates/perry-hir/src/destructuring | rg -n -C 3 'protect_native_param|if|register_native_instance|let .*='Repository: PerryTS/perry Length of output: 50370 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- exact override binding ---'
rg -n 'is_compile_package_override|fn is_compile_package|compile_package_override' crates --glob '*.rs'
printf '%s\n' '--- registration result consumers ---'
rg -n -C 4 'register_native_instance' crates/perry-hir/src --glob '*.rs' \
| rg 'if .*register_native_instance|register_native_instance.*if|let .*register_native_instance|protect_native_param|register_native_instance'
printf '%s\n' '--- diagnostic contract text ---'
sed -n '1918,1948p' crates/perry-hir/src/lower/context.rsRepository: PerryTS/perry Length of output: 14290 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,115p' crates/perry-hir/src/ir/constants.rs
sed -n '1,38p' crates/perry-hir/src/ir/mod.rsRepository: PerryTS/perry Length of output: 7702 Align the diagnostic with the registration result. When 🤖 Prompt for AI Agents |
||
| // #5137: if the user opted this package into `perry.compilePackages`, | ||
| // its real npm source is being compiled and the binding resolves to | ||
| // the compiled-from-source class. Registering a native instance here | ||
|
|
@@ -1679,6 +1680,7 @@ impl LoweringContext { | |
| /// scans these in reverse (last-match-wins), so the index stores the LAST | ||
| /// pushed entry per name (overwrite). | ||
| pub(crate) fn push_module_native_instance(&mut self, entry: (String, String, String)) { | ||
| nativeinst_registry_diag("push_module", &entry.0, &entry.1, &entry.2); | ||
| let idx = self.module_native_instances.len(); | ||
| self.module_native_instances_index | ||
| .insert(entry.0.clone(), idx); | ||
|
|
@@ -1909,3 +1911,36 @@ pub(crate) fn perry_ui_factory_returns_handle(name: &str) -> bool { | |
| || perry_dispatch::perry_ui_lookup(name) | ||
| .is_some_and(|row| row.ret == perry_dispatch::ReturnKind::Widget) | ||
| } | ||
|
|
||
| /// #9847: report every native-instance tag as it is created. | ||
| /// | ||
| /// `register_native_instance` and `push_module_native_instance` are the only | ||
| /// two entry points through which a native-instance tag can come into | ||
| /// existence, so a diagnostic on *them* cannot miss a tag the way one on | ||
| /// guessed construction sites can — which is the whole reason this exists. | ||
| /// | ||
| /// What it prints, one line per registration: | ||
| /// | ||
| /// ```text | ||
| /// [nativeinst] REGISTER push_module name="O" -> child_process::Instance | ||
| /// ``` | ||
| /// | ||
| /// The tag table is keyed by identifier TEXT with module-wide scope, so on a | ||
| /// minified single-module bundle the same short name is routinely claimed by | ||
| /// several unrelated native classes and every method call on any local with | ||
| /// that name is lowered as a native-instance call of whichever won. This | ||
| /// report is what makes that visible: on `cli_2.1.112.js` it prints 795 lines | ||
| /// whose most-registered identifiers are `Y`(71), `z`(65), `K`(65), `_`(65), | ||
| /// `A`(54), `O`(52), `w`(37), `q`(35) — every one a single letter. | ||
| /// | ||
| /// Enable with `PERRY_NATIVEINST_DIAG=1`. Off, this is one relaxed atomic load | ||
| /// per registration and nothing else. | ||
| pub(crate) fn nativeinst_registry_diag(kind: &str, name: &str, module: &str, class: &str) { | ||
| static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); | ||
| let on = *ON.get_or_init( | ||
| || matches!(std::env::var("PERRY_NATIVEINST_DIAG"), Ok(v) if !v.is_empty() && v != "0"), | ||
| ); | ||
| if on { | ||
| eprintln!("[nativeinst] REGISTER {kind} name={name:?} -> {module}::{class}"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -841,6 +841,14 @@ fn eligibility(args: &CompileArgs, project_root: &Path) -> Result<(), String> { | |||||||||||||||
| if std::env::var("PERRY_OUTLINE_ENTRY_REPORT").is_ok() { | ||||||||||||||||
| return Err("outline-entry-report".to_string()); | ||||||||||||||||
| } | ||||||||||||||||
| // #9847: same reasoning as `opt-report` above. A cached build reuses the | ||||||||||||||||
| // finished binary and never lowers HIR, so the native-instance report | ||||||||||||||||
| // would print nothing — and nothing is indistinguishable from "no tag was | ||||||||||||||||
| // ever registered", which is the reading this diagnostic exists to make | ||||||||||||||||
| // impossible. | ||||||||||||||||
| if std::env::var("PERRY_NATIVEINST_DIAG").is_ok() { | ||||||||||||||||
| return Err("nativeinst-diag".to_string()); | ||||||||||||||||
|
Comment on lines
+849
to
+850
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win Match cache gating to the diagnostic-enabled predicate.
Proposed fix- if std::env::var("PERRY_NATIVEINST_DIAG").is_ok() {
+ if matches!(
+ std::env::var("PERRY_NATIVEINST_DIAG"),
+ Ok(value) if !value.is_empty() && value != "0"
+ ) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| } | ||||||||||||||||
| if args.verify_native_regions || args.emit_attest || args.emit_sandbox { | ||||||||||||||||
| return Err("sidecar-or-verify".to_string()); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
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 a language tag to the fenced example.
markdownlint-cli2reports MD040 for this fence. Usetextfor the diagnostic output.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 8-8: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Source: Linters/SAST tools