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:
22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
$ 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:
$ 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:
$ target/release/perry check test-parity/node-suite/dns/constants/error-aliases.ts error[U006]: `dns/promises.ADDRCONFIG` is not implemented in Perry — see `perry --print-api-manifest` for the supported surface, or set `PERRY_ALLOW_UNIMPLEMENTED=1` to ignore. (#463) --> test-parity/node-suite/dns/constants/error-aliases.ts:9:48The manifest matches Node for named exports:
dns/promisesincludes DNS error aliases likeNODATAandCANCELLED, but does not includeADDRCONFIG,V4MAPPED, orALL.With the gate bypassed, Perry's runtime output matches Node for this fixture, including the absent namespace properties:
- Assistant
I'll start by exploring the repository structure and reproducing the issue with the DNS constants fixture.
- Assistant
Next I'll inspect the failing fixture and the member-expression lowering code that rejects missing namespace properties.
- Assistant
I'll inspect the namespace PropertyGet path in
expr_member.rsand check whether a release binary is already available. - Assistant
rg is not available, let me use grep instead.
- Assistant
I'll open the unimplemented-API gate logic around the NativeModuleRef path.
- Assistant
Let me continue reading the rest of this gate logic.
- Assistant
I'll search for other places where the unimplemented-API gate runs, especially on calls.
- Assistant
I'll inspect the call-site gate and existing unimplemented-API tests to see how property reads vs. calls are distinguished.
- Assistant
So calls are already gated in the call path. Property reads are gated in expr_member.rs. The claim is that property reads of missing members should return undefined (like Node), while calls of missing...
- Assistant
There's a test that specifically expects
crypto.foobarproperty read to error! According to the issue, this should instead return undefined. Let me continue... - Assistant
Looking at codegen next—how missing NativeModuleRef property gets are handled at runtime.
- Assistant
I'll check the API manifest design for any node-export completeness metadata.
- Assistant
Looking at this more carefully, the issue says: The core fix is in
crates/perry-hir/src/lower/expr_member.rs. I need to change the gate so that when we see a property read on a native module namespace, we allow it even if the symbol is absent (returnundefined), but keep the strict gate for calls.Let me think about the exact change needed. The current code fails on
module_has_symbol(module, prop) is Nonefor PropertyGet. We should only fail for calls, not for reads.Looking at the code structure, I need to distinguish between the two cases.
- Assistant
Let me look at property_get.rs for NativeModuleRef handling.
- Assistant
I'll check for destructuring and other read paths that might still hit the strict gate.
- Assistant
I'll also look for related history and how heavy a release build is before changing the gate.
- Assistant
Looking at the issue more carefully again: I understand the core issue: the current gate in
expr_member.rsis too strict for namespace property reads on Node core modules, rejecting validundefinedreturns that Node accepts. The fix should distinguish property reads from calls, allowing reads for absent properties while preserving call gates and named import rejection. - Assistant
There's already a call-form regression test which we should keep, while the property-read tests will need to change for the new semantics.
- Assistant
I need to check if dns/promises has NODATA and CANCELLED properties.
- Assistant
Good - dns has ADDRCONFIG but dns/promises doesn't. My fix is clear.
- Assistant
I'll update the property-read gate in
expr_member.rsso absent native-module namespace reads lower toundefinedwhile call sites stay strict. - Assistant
The edit landed in the wrong file — I'll reseit and apply the change to
expr_member.rsinstead. - Assistant
Now I'll apply the property-read gate change in the correct file.
- Assistant
There's a stray
}left from the old if-block — removing it. - Assistant
First I'll clean up a couple of comment typos, then check whether string-literal computed access is special-cased.
- Assistant
The PropertyGet path looks good. Next I'll update related docs/comments and build to verify.
- Assistant
I'll open the module docs around line 190 and fix the wording there...
- Assistant
I accidentally broke the module docs structure — restoring the perry-codegen bullet.
- Assistant
I'll restore the blank line before
#![deny]and update themodule_has_symboldocs. - Assistant
Let me update the module_has_symbol docs and the ApiEntry.module_export comment about "strict property gate".
- Assistant
I'll build and run the relevant HIR tests plus the DNS fixture to verify the change.
- Assistant
Need to set up the Rust toolchain first.
- Assistant
Rust is ready — next I'll run the HIRC tests and build perry.
- Assistant
Some modules still depended on the property-read gate for call rejection. I need to inspect how handled modules lower call callees.
- Assistant
So for handled modules (patheth, fs, crypto, os, child_process), call form continues past the gate. I need to see how they further process unknown methods.
- Assistant
For handled chines modules the call falls through. I'll check how egen the callee is then lowered.
- Assistant
I'll move the unimplemented call-site gate ahead so handledmodulesmodules like
fs/crypto/pathare covered too. - Assistant
I'll restructure the call-site gate so it runs for all modules, including path/fs/crypto and path submodules.
- Assistant
I'll verify the end of the function for brace/structure issues.
- Assistant
There's leftover metastatic duplicate code from the oldDijkstra block — removing it.
- Assistant
There are still extra closing braces; I'll inspect more enclosing structure next.
- Assistant
I'll remove the duplicate trailing braces.
- Assistant
Looks better. Let me verify braces match by compiling and running tests.
- Assistant
Call-form rejection works. Next I'll build perry and verify the DNS fixture plus named-import/call behavior.
- Assistant
Build succeeded. Now I'll run the DNS fixture and regression probes.
- Assistant
There's an interactive telemetry prompt blocking us — I'll find how to disable it.
- Assistant
Using
PERRY_NO_TELEMETRY=1to skip the prompt. - Assistant
Check passes. Now I'll run the fixture and the other probes.
- Assistant
Check looks good; runtime is blocked by an old clang. I'll re-run checks in isolation and look for a backend that doesn't need a newer clang.
- Assistant
Checks match acceptance. Next I'll try installing a newer clang so we canverify runtime output.
- Assistant
I'll check whether perry offers a backend that doesn't need a newer clang.
- Assistant
I'll run a few related HIR tests and print HIR for the fixture to make sure lowering is sound.
- Assistant
HIR is correct. I'll try fetching a newer clang so we can confirm the runtime behavior.
- Assistant
I'll run one more call-form probe on the missing namespace property and print HIR for the curated fixture.
- Assistant
I'll search the project for a way to compile without system clang.
- Assistant
I'll grab a portable newer clang binary so we can run the fixture.
- Assistant
Download complete — extracting just the clang binary next.
- Assistant
Need libtinfo.so.5
- Assistant
Clang 18 is ready — running the DMS fixture end-to-end.
- Assistant
I'll skip auto-optimize and use the prebuilt runtime to finish faster.
- Assistant
Need to use compile then run, or pass differently.
- Assistant
I need to build perry-runtime (and likely stdlib) before linking.
- Assistant
Good. Now compile and run the fixture.
- Assistant
Everything matches Node. Final diff review, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.