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 start by exploring the repository structure and understanding the codebase, then reproduce the issue, and finally implement the fix.
- Assistant
Let me start with one command at a time.
- Assistant
Good, the key file is
crates/perry-hir/src/lower/expr_member.rs. Let me open it. - Assistant
Let me search for the specific area mentioned in the issue - where namespace PropertyGet on NativeModuleRef fails when module_has_symbol is None.
- Assistant
Let me look at the area around line 1741 where the NativeModuleRef property read happens:
- Assistant
Now I can see the issue. Let me understand the code around line 1813. The check rejects namespace property reads when
module_has_symbolreturnsNone. But for namespace property reads (not calls), Node.js returnsundefinedfor missing properties. Let me look at the test file and understand the full context. - Assistant
Let me look at the call lowering to understand how it interacts with this gate:
- Assistant
The file doesn't exist or has no matches. Let me look for it.
- Assistant
Let me search for where call expressions are lowered.
- Assistant
Let me look at the expr_call directory:
- Assistant
Let me check the native_module.rs file for how calls to native modules are handled.
- Assistant
Let me check the native_module.rs more carefully around line 1306:
- Assistant
Let me look at the code around lines 1830-1870 to see what happens after the gate check:
- Assistant
Now let me look at how
lower_callprocesses calls to understand the full flow: - Assistant
Let me search for where calls to NativeModuleRef properties are handled:
- Assistant
Let me check how calls are handled in the lower flow:
- Assistant
Let me look more carefully at the member lowering code around the NativeModuleRef gate:
- Assistant
Let me look at the call-side gate to understand how it works:
- Assistant
Now I understand the issue. Let me look at the test for this specific scenario and also check what tests exist:
- Assistant
Let me look at the tests directory structure:
- Assistant
Let me look at the existing test for unimplemented API checks:
- Assistant
Let me look at the lower_expr.rs to understand how calls are dispatched:
- Assistant
Let me look at how lower_call processes the callee to understand the flow:
- Assistant
Let me look at lines 448-560 to see the full callee lowering flow:
- Assistant
Now I understand the flow. Let me now reproduce the issue to confirm it exists:
- Assistant
Let me check the build system and build the project:
- Assistant
Let me build the project first:
- Assistant
Let me check what Rust toolchain is available:
- Assistant
Let me check if there's a rust-toolchain file or if we can install a toolchain.
- Assistant
Let me try to install the toolchain or see what's available.
- Assistant
Let me try installing a stable toolchain:
- Assistant
Good, now I have Rust installed. Let me build the project and reproduce the issue:
- Assistant
Good, the build succeeded. Now let me reproduce the issue:
- Assistant
Need to bypass the interactive prompt:
- Assistant
I've reproduced the issue. Now I need to understand the code flow better. Let me look at the
lower_call_innerfunction to understand how it dispatches: - Assistant
Now I understand the flow. The key issue is that the gate in
lower_member_innerfires for ALL property reads on NativeModuleRef, but it should only fire for method calls (which are handled separately intry_native_module_methods). Let me look at the LoweringContext to understand how to add a context flag: - Assistant
Let me look at the LoweringContext fields:
- Assistant
Let me look at the context.rs for existing flags:
- Assistant
Let me look at more fields in the context:
- Assistant
Let me look at what happens in
try_native_module_methodswhen a module is not recognized: - Assistant
Let me look at how the native module dispatch handles modules that are looked up via
lookup_native_module: - Assistant
Now I have a good understanding of the code flow. Let me now trace what happens when a bare property read vs a method call goes through the member lowering:
- Assistant
Now I have a clear understanding of the issue. Let me now implement the fix. The key insight is:
- The call-side gate in
try_native_module_methods(line ~1310) already handles method calls - The member-side gate in
lower_member_inner(line ~1813) fires for ALL property reads including bare reads - For bare property reads, we should allow them to pass through and return
undefinedat runtime (matching Node behavior)
The fix is to modify the member-side gate to not fire for bare property reads on namespace imports. Let me implement this:
- The call-side gate in
- Assistant
Now I understand the full picture. Let me look at how the flow works: for
dnsPromises.resolve(), thetry_native_module_methodsfunction handles it with its own gate. FordnsPromises.ADDRCONFIG(bare read), it goes directly throughlower_member_inner. The issue is thatlower_member_innercan't distinguish between the two contexts.The cleanest approach is to add a context flag. Let me check what flags are available in the context:
- Assistant
Let me look at how the existing test verifies named import rejection:
- Assistant
Now I have a complete understanding of the code flow. Let me now implement the fix. The key insight is:
- For method calls (
dnsPromises.resolve()), the flow goes throughtry_native_module_methodsinexpr_call/native_module.rswhich has its own gate at line 1310 - For bare property reads (
dnsPromises.ADDRCONFIG), the flow goes throughlower_member_innerwhich has the problematic gate - The gate in
lower_member_innerfires for ALL property reads, but it should only fire for method calls
The fix is to remove the gate from
lower_member_innersince method calls are already handled by the call-side gate. Let me implement this: - For method calls (
- Assistant
Now I'll implement the fix. I need to remove the gate from
lower_member_inner(lines 1810-1832). The gate at line 1810-1832 is inside theif letblock. I'll remove just the gate condition and its body: - Assistant
Let me verify the edit looks correct:
- Assistant
I see the issue - I removed the closing brace of the
if letblock. Let me look at the context to understand what needs to be there. - Assistant
I see the issue - I removed the closing brace of the
if letblock. Let me fix this by adding back the closing brace: - Assistant
I need to add a closing brace after the
};to close theif letblock. Let me fix this: - Assistant
Let me verify the edit looks correct now:
- Assistant
Good, the structure looks correct. Now let me build and test:
- Assistant
Good, the build succeeded. Now let me test the fix:
- Assistant
The fix works for the basic check. Now let me verify the runtime output:
- Assistant
The compilation is failing due to an LLVM/clang backend issue, not related to my change. Let me run the existing tests to make sure my change doesn't break anything:
- Assistant
Let me look at the failing tests to understand what they expect:
- Assistant
Let me look at the full test output to understand which tests fail:
- Assistant
Let me look at the
supported_module_with_unknown_member_is_rejectedtest to understand what it expects: - Assistant
Let me understand the failing tests better. Let me look at what
supported_module_with_unknown_member_is_rejecteddoes more closely: - Assistant
I see - my approach of removing the entire gate was too broad. I need a more nuanced approach. The issue says bare property READS should return undefined, but API CALLS should still be rejected. Let me think about this more carefully.
The key insight is that:
- For method calls (
dnsPromises.resolve()), the callee is lowered as part oflower_call→ fallthrough path →lower_expr - For bare property reads (
dnsPromises.ADDRCONFIG), it goes directly throughlower_member
I need to add a context flag to distinguish these two cases. Let me revert my change and implement a proper solution:
- For method calls (
- Assistant
Good, the file is reverted. Now let me take a better approach. I need to add a context flag to distinguish between bare property reads and method calls. Let me first look at the LoweringContext struct more carefully:
- Assistant
Now let me look at the structure of the
lower_call_innerfunction to understand where to add the flag: - Assistant
Now I understand the full picture. I need to add a context flag to distinguish bare property reads from method call targets. Let me implement this properly:
- Add a
lowering_calleeflag toLoweringContext - Set it when lowering the callee in
lower_call_inner - Check it in the gate in
lower_member_inner
- Add a
- Assistant
Now let me add the
lowering_calleeflag to theLoweringContextstruct: - Assistant
Let me add the field before the closing brace of the struct.
- Assistant
Let me verify the edit:
- Assistant
Good. Now I need to set the flag in
lower_call_innerbefore the fall-through callee lowering. Let me find that location: - Assistant
Now let me add the flag setting around the callee lowering:
- Assistant
Let me verify the edit:
- Assistant
Good. Now I need to modify the gate in
lower_member_innerto check thelowering_calleeflag: - Assistant
Now I need to modify the gate condition to also check
ctx.lowering_callee. The gate should only fire when we're lowering a callee (method call target), not for bare property reads. - Assistant
Let me verify the edit:
- Assistant
The edit went wrong - it duplicated lines. Let me revert and try again with a different approach:
- Assistant
Good. Let me now use the
editcommand to make a precise change: - Assistant
Now I can see the exact code. Let me use the
editcommand to add thectx.lowering_calleecheck to the gate condition: - Assistant
Good, the edit looks correct. Now let me build and test:
- Assistant
There's a compilation error. Let me see the full error:
- Assistant
I need to initialize the
lowering_calleefield in the LoweringContext constructor. Let me find it: - Assistant
Let me find where LoweringContext is constructed:
- Assistant
Let me look at the constructor context:
- Assistant
Let me add the initialization:
- Assistant
Let me verify the edit:
- Assistant
Good. Now let me build again:
- Assistant
Good, the build succeeded. Now let me build the full perry binary and test:
- Assistant
Good, the build succeeded. Now let me test the fix:
- Assistant
The DNS constants fixture passes. Now let me run the existing tests:
- Assistant
Good progress!
every_supported_module_rejects_bogus_callpasses now! The 3 remaining failures are expected - they test bare property reads. Let me look at thecrypto_unknown_method_is_rejectedtest: - Assistant
These 3 failing tests are testing bare property reads (not method calls), which is the behavior we're intentionally changing. The issue says bare namespace property reads should return undefined, matching Node behavior. Let me look at the test names more carefully to verify:
- Assistant
Let me verify which tests pass:
- Assistant
Good! The results show:
every_supported_module_rejects_bogus_call- PASSES ✅ (method calls still rejected)every_supported_module_rejects_bogus_member- FAILS (expected - bare property reads now compile)crypto_unknown_method_is_rejected- FAILS (expected - bare property read now compiles)supported_module_with_unknown_member_is_rejected- FAILS (expected - bare property read now compiles)node_builtin_dispatch_only_named_imports_are_rejected- PASSES ✅ (named imports still rejected)
The 3 failing tests are testing bare property reads which we're intentionally changing per the issue. Let me run the broader test suite to make sure nothing else is broken:
- Assistant
Let me run some other tests to make sure nothing else is broken:
- Assistant
Let me run more tests:
- Assistant
All node_named_export_hygiene tests pass. Let me run more tests:
- Assistant
Good, all dynamic_stdlib_dispatch tests pass. Let me run the remaining tests:
- Assistant
Let me check the full test results:
- Assistant
All other tests pass. Only the 3 tests that test bare property reads fail, which is the expected behavior change. Let me also run the codegen tests:
- Assistant
All codegen tests pass. Let me also run the transform tests:
- Assistant
All other tests pass. Let me now review the complete changes I've made:
- Assistant
The changes look clean and correct. Let me verify the acceptance criteria one final time:
- Assistant
Let me verify the method call gate still works:
- Assistant
Let me also verify the named import rejection:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.