ISSUE DESCRIPTION Node API checker: namespace reads of absent builtin exports should…
- User
ISSUE DESCRIPTION
Node API checker: namespace reads of absent builtin exports should return undefined
Summary
Perry's strict built-in API gate currently rejects some namespace property reads that Node treats as ordinary JavaScript property misses returning
undefined.This surfaced in the curated DNS constants fixture on current
origin/main@22824ba90abf:node:dns/promisesintentionally does not exportADDRCONFIG,V4MAPPED, orALL, but reading those properties from the namespace object is valid in Node and returnsundefined. Perry rejects the property read at check/lower time before the runtime can produce the matching value.This is separate from named ESM import validation. Node rejects
import { ADDRCONFIG } from "node:dns/promises", and Perry should continue not claiming that named export. The compatibility gap is namespace/property-read semantics.Local evidence
Current main:
text22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
console$ node -e 'import("node:dns/promises").then(m=>{for (const k of ["ADDRCONFIG","V4MAPPED","ALL","NODATA","CANCELLED"]){console.log(k, Object.prototype.hasOwnProperty.call(m,k), k in m, typeof m[k], m[k]);}})' ADDRCONFIG false false undefined undefined V4MAPPED false false undefined undefined ALL false false undefined undefined NODATA true true string ENODATA CANCELLED true true string ECANCELLEDNode rejects the corresponding named import, which is correct and should remain true:
console$ node --input-type=module -e 'import { ADDRCONFIG } from "node:dns/promises"; console.log(ADDRCONFIG)' SyntaxError: The requested module 'node:dns/promises' does not provide an export named 'ADDRCONFIG'Perry currently rejects the namespace property read in the curated fixture:
- Assistant
I’ll first inspect the lowering logic, nearby tests, and repository status to understand how member reads and calls are represented. Then I’ll reproduce the reported check failure before making a narrowly scoped change.
- Assistant
ripgrepis unavailable, so I’ll usegrepand inspect the specific native-module branch plus call lowering and test layout. I also need to locate the fixture and available build artifacts to reproduce efficiently. - Assistant
The code already has separate strict checks in member lowering and native call lowering, which is promising: removing only the read-time rejection should preserve call diagnostics. I’ll inspect the exact branch and existing regression tests before reproducing.
- Assistant
The problematic gate is indeed unconditional for static namespace reads, while
mod.method()is independently validated before dispatch. Named import validation also occurs earlier in import lowering and should remain untouched. I’ll now reproduce with the release binary and identify exact test helper conventions so the source-level behavior can be covered without changing test files (per the environment restriction, I will modify production code only). - Assistant
No release binary is present, so reproduction must use
cargo runor the HIR test path. The current tests explicitly encode the old read-rejection behavior and will become stale under the requested semantics; per instructions I won’t edit them. Before changing the gate, I’ll verify that genericPropertyGet(NativeModuleRef, unknown)actually lowers/codegens toundefined, and inspect whether special modules bypass generic call validation (especiallyfs, which acceptance explicitly mentions). - Assistant
The toolchain is installed without a selected default; I’ll inspect
rust-toolchain/available toolchains and the codegen fallback. I’ll also trace handled-module (fs,path, etc.) call branches to ensure unknown calls remain rejected rather than slipping through after removing the read gate. - Assistant
Runtime property lookup is explicitly designed to return the constants dispatcher result and therefore supports
undefinedfor misses. The generic call gate covers most modules, but handled modules intentionally skip it because later specialized dispatch owns them; I’ll locate those specialized branches and determine whether they already diagnose unknown methods. This is essential to preservefs.notARealMethod()diagnostics after relaxing reads. - Assistant
The specialized branches are all near the top of the file. I’ll inspect the
fs,path,crypto,os, and child-process detection around their match fallthroughs, plus the runtime’s unknown-property return representation. - Assistant
I need the runtime function’s final fallback and concise identification of specialized module aliases; the previous broad output was truncated. I’ll use targeted searches around alias booleans and return sites.
- Assistant
The runtime clearly has an explicit
TAG_UNDEFINEDfallback. I’ll inspect the immediately preceding dispatch and then edit the HIR member gate out, replacing its outdated comment with the semantic distinction. I’ll also consider centralizing a call gate before specialized handling if handled unknown calls currently depend solely on the member gate. - Assistant
A direct call can return from specialized dispatch before member lowering, so simply deleting the read gate would weaken diagnostics for handled namespaces. I’ll make the distinction explicit:
- Remove manifest rejection from
lower_member, allowing static namespace value reads to use runtime JS property semantics. - Add a namespace-only manifest check at the start of direct native-module call lowering, before specialized returns.
- Exclude named-import values from that call check, preserving class/static member behavior.
- Keep the existing downstream call gate as defense for other call shapes.
This keeps named import validation in
module_decl.rsunchanged. - Remove manifest rejection from
- Assistant
The production diff now encodes the intended distinction. To verify it, I need a Rust toolchain; none is installed in this environment. I’ll install stable via rustup, then run focused HIR tests. Existing read-rejection assertions are expected to fail as stale, while call and named-import assertions must pass.
- Assistant
The toolchain download completed, but
rustup defaultfailed due to this container’s split rustup/cargo homes. I’ll locate the installed binaries/toolchain and invoke Cargo with explicitRUSTUP_HOME/CARGO_HOMEif needed, then format and test. - Assistant
Using
/root/.rustupworks. I’ll add rustfmt to that toolchain, check formatting, and run the focused call-regression test. - Assistant
The exhaustive bogus-call sweep passes across every supported module, confirming the moved gate preserves strict calls. Formatting reports one trivial line wrap, which I’ll apply. Then I’ll run named-import validation and invoke the CLI check on the DNS fixture through Cargo.
- Assistant
The acceptance check now passes, and named imports remain rejected in focused tests. I’ll verify three end-to-end probes using temporary files outside the repository: absent namespace read accepted, absent named import rejected, and
fs.notARealMethod()rejected with U006. Then I’ll run the DNS fixture to confirm runtime values (not just checking). - Assistant
The CLI’s check command scans sibling TypeScript files in the input’s directory, so placing all probes in
/tmpcontaminated each result. I’ll isolate each probe in its own temporary directory and rerun. I’ll also capture the fixture runtime’s actual tail to diagnose why the grep had no matches (likely a missing native build dependency rather than semantic failure). - Assistant
All three semantic probes behave correctly. Runtime compilation is blocked by system clang 14 lacking opaque-pointer IR support; I’ll check for a newer clang and rerun with
PERRY_LLVM_CLANGif available. I’ll also run relevant HIR suites while accounting for the two known stale tests that assert the superseded property-read rejection. - Assistant
Named-export hygiene passes completely. The full unimplemented API suite has exactly three expected failures, all old assertions that unknown reads must error; the exhaustive unknown-call test still passes. No newer clang is installed, so I’ll see whether a compatible package is readily available. If so, I’ll install it and complete runtime verification; otherwise I’ll rely on the unchanged runtime fallback already confirmed to return
TAG_UNDEFINED. - Assistant
No newer clang package is available from configured repositories. I’ll do a final source review and run library checks plus the runtime native-module unit tests, which can validate the property dispatcher without compiling generated LLVM IR. I’ll also confirm the diff has no accidental formatting or test changes.
- Assistant
Final review is clean: only two production files changed, formatting/checks pass, the DNS checker acceptance passes, named imports remain rejected, and exhaustive unsupported calls remain rejected. Runtime execution could not complete solely because the environment has clang 14 while generated IR requires opaque-pointer support; the runtime dispatcher itself is unchanged and its tested fallback is
TAG_UNDEFINED.Checklist:
- Reproduced the reported error: the original release binary was absent, but the old HIR test and source gate demonstrated the rejection; after building, equivalent probes exercised the same path.
- Confirmed the fix:
target/debug/perry check test-parity/node-suite/dns/constants/error-aliases.tspasses without an escape hatch, and an isolated absent-property probe passes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.