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 understanding the issue.
Assistant
The file is long. Let me look at the NativeModuleRef handling and module_has_symbol part.
Assistant
Let me look at the section around line 1741-1840 to understand the gate logic.
Assistant
Assistant
Now let me look at the fixture file and understand the issue, and how calls are handled.
Assistant
Now let me understand the call lowering to see how the unimplemented gate handles calls (so I don't break the
fs.notARealMethod()check). Let me checkexpr_call.rs.Assistant
So the call path has its own gate. Now let me reproduce the error first.
Assistant
Reproduced. Now let me understand the
lookup_native_moduleand how to detect a namespace import (import * as) vs a named import.Assistant
Now I understand the data model.
lookup_native_modulereturns(module, Option<symbol>). For namespace imports (import * as dnsPromises), it returns(module, None). For named imports (import { EventEmitter }), it returns(module, Some("EventEmitter")).Now the gate at line 1810 has the condition
!obj_is_named_import. So for namespace imports,obj_is_named_importisfalseand the gate fires.The fix per the issue: namespace property reads of absent symbols should return
undefined(lower toPropertyGet) instead of bailing. But we must still catch calls likefs.notARealMethod().Let me check how
lower_memberrelates to the call path. When you callfs.notARealMethod(...), the call lowering happens inlower_callwhich handles the member expression. Doeslower_calllower the member part first vialower_member, or does it handle it directly?Let me check the
lower_callentry point.Assistant
Let me see how the generic member-call case is handled at the bottom of
lower_call_inner.Assistant
The call path has its own gate. Now let me check the
module_static.rswhich handlesfs/path/etc. (sincefsis inis_handled_module).Assistant
Let me test the current behavior for a
fs.notARealMethod()style call to make sure my fix won't break it.Assistant
Let me look at the end of the
fshandling inmodule_static.rsto see what happens for unmatched fs methods.Assistant
The
fs/pathcall gate relies onlower_member's gate firing in the call fall-through tail. So my fix needs to distinguish reads (return undefined) from calls (still error). Let me look at the LoweringContext fields.Assistant
There's a field
namespace_import_locals: HashSet. Let me look at how the struct is defined and find where I'd add a new field. Let me find the struct definition.Assistant
Let me check the manifest for dns exports to understand the full scope.
Assistant
Let me check the end of
try_module_static_methodsto confirm it falls through for unmatched methods.Assistant
Let me look at existing tests for the unimplemented API gate to understand the test patterns.
Assistant
Let me look at the lowering tests file to understand how the gate is tested in unit tests.
Assistant
Let me look at the nested_namespace.rs gate that handles
util.types.notReal().Assistant
Now let me look at the
lower_errtest helper and the existing tests structure.Assistant
Now I have a clear plan. Let me implement the fix. First, add a field to the
LoweringContextstruct.Assistant
Now let me add the field to the struct and initialize it.
Assistant
Now initialize the field in
with_class_id_start:Assistant
Now let me modify the gate in
expr_member.rs. Let me view the exact lines.Assistant
Now set the flag in
lower_call's fall-through tail around the callee lowering.Assistant
Now let me build and test.
Assistant
Build succeeded. Now let me test the fixture.
Assistant
The check passes now. Let me run the fixture and compare with Node behavior.
Assistant
The run failure is an environment LLVM/clang issue (opaque pointers), unrelated to my change. Let me check available backends and clang config.
Assistant
The clang-14 doesn't support opaque pointers by default. Let me check how perry invokes clang and whether I can pass flags.
Assistant
Let me try passing
-fopaque-pointersor-Xclang -opaque-pointersvia an env var. Let me check how the clang command is built and whether there's a way to add flags. Let me look at the codegen_steps.rs for the clang invocation.Assistant
That's for codegen steps (npm), not the clang invocation. Let me find the actual clang invocation for compiling the LLVM IR.
Assistant
The clang args are hardcoded with no hook for extra flags. Let me check if there's an alternative backend or interpreter mode for
run.Assistant
Let me try a clang wrapper to add opaque-pointer support, since clang-14 needs the flag.
Assistant
-Xclang -opaque-pointersmakes clang-14 accept opaque pointers. Let me create a wrapper and use it viaPERRY_LLVM_CLANG.Assistant
The wrapper path is shown but the error persists. Let me test the wrapper directly on the generated .ll file.
Assistant
Let me try alternative flags to enable opaque pointers in clang-14.
Assistant
-mllvm -opaque-pointersproduced NO output (no error). Let me check if /tmp/out.o was produced.Assistant
-mllvm -opaque-pointersworks. Let me update the wrapper.Assistant
It's rebuilding the runtime. Let me wait for it to finish.
Assistant
Let me see the full output including the absent properties (ADDRCONFIG, V4MAPPED, ALL).
Assistant
The runtime output matches Node's behavior exactly. Now let me verify the other acceptance criteria: named import rejection and the call gate still erroring.
Assistant
Both work — named import
ADDRCONFIGfromnode:dns/promisesis correctly rejected (matching Node's ESM behavior), andfs.notARealMethodSync()call still errors. Let me clean up temp files and run them in isolation to confirm clearly.Assistant
Both gates work. Let me verify the precise distinction: a bare read of an absent symbol returns undefined (compiles), but a call on the same absent symbol errors.
Assistant
The distinction works perfectly. Now let me run the existing lowering tests to ensure nothing is broken, especially the call-gate regression test.
Assistant
There are 3 failing tests in the unimplemented API check. Let me examine them to determine if they test reads (which the issue wants to change) or calls.
Assistant
Let me look at the full set of tests in this file and run them individually to understand exactly which break (reads vs calls).
Assistant
Let me run the call-form sweep test specifically to confirm calls still error across all modules.
Assistant
The call-form sweep passes — calls still error across all modules. The 3 failing tests are read-form tests that encode the old behavior the issue explicitly wants to change. Per the issue, absent namespace reads should now return
undefined. Let me verify the full perry-hir test picture and confirm only those 3 read-form tests fail.Assistant
Only the 3 read-form tests in
unimplemented_api_check.rsfail (encoding the old behavior). Let me confirm the call-gate regression test inutil_types_lowering.rsstill passes.Assistant
The call-gate regression test passes. The 3 failing read-form tests directly contradict the issue's required behavior (absent reads →
undefined). Per the issue and instructions, these need updating and won't be counted. Let me check whether other test suites (codegen, integration) also exercise the read-form gate to assess broader impact.Assistant
Let me check how default imports vs namespace imports are registered in the native_modules table, to understand the scope precisely.
Assistant
Let me check the
namespace_import_localsfield to see if it distinguishesimport * asnamespace imports from default imports.Assistant
The
namespace_import_localsset is only populated for non-native (JS) namespace imports. To narrow the fix to actual namespace imports (per the issue's "namespace reads" framing) and avoid changing default-import behavior, let me examine hownamespace_import_localsis used elsewhere.Assistant
I need to decide between a broad fix (all NativeModuleRef reads) and a narrow fix (only
import * asnamespace reads, matching the issue's "namespace reads" framing). The narrow fix is more faithful to the issue and keeps the default-import test passing. Let me check the entry conditions of thenamespace_import_localsusages to see if I can safely reuse that set for native namespace imports.Assistant
Let me check all usages of
namespace_import_localsto ensure extending it to native namespace imports is safe.Assistant
I'll go with the narrow fix: only
import * asnamespace reads returnundefined(matching the issue's "namespace reads" framing), while default-import reads keep the strict gate. This is more faithful to the issue and avoids changing unrequested behavior. Let me extendnamespace_import_localsto track native namespace imports and update the gate. First, let me view the current gate state after my edit.Assistant
Now let me refactor the gate for the narrow approach. First, let me add a helper to peel TS wrappers and compute
obj_is_namespace_import, and update the bail condition.Assistant
Now let me add the
peel_member_obj_identhelper function. Let me find a good place to add it (nearlower_process_named_property).Assistant
Now extend
namespace_import_localsto track native namespace imports in module_decl.rs:Assistant
Now let me rebuild and re-test.
Assistant
The narrow fix works as intended: DNS fixture passes, axios default-import read still errors (unchanged). Let me re-run the full distinction tests and the existing test suite.
Assistant
All distinctions work correctly. Now let me run the existing test suite to confirm only the expected read-form tests break.
Assistant
Now only 2 tests fail — both are namespace-import read tests (
crypto_unknown_method_is_rejectedand theevery_supported_module_rejects_bogus_membersweep), which directly contradict the issue's required behavior (namespace reads →undefined). The axios default-import test now passes (10 passed vs 9 before). Let me run the full perry-hir suite to confirm nothing else broke from extendingnamespace_import_locals.Assistant
All perry-hir test binaries pass except the 2 namespace-read tests that the issue explicitly changes. The lib unit tests (132) pass, confirming extending
namespace_import_localsdidn't break array/static-method folding. Let me run the api-manifest and codegen test suites to be thorough, and search for any test referencing the DNS fixture.Assistant
Let me run the perry-codegen test suite to ensure no broader regressions.
Assistant
All perry-codegen tests pass. Let me check the shell-based integration tests that might exercise the gate, especially the perf_frontier gate smoke test.
Assistant
Let me search more broadly for any tests (shell or rust) that assert absent namespace reads error, which would now need updating.
Assistant
Let me verify the
is_cjs_style_native_default_importbehavior to ensure default imports of CJS-style modules (likefs) still behave correctly (they skip the gate viaobj_is_named_import).Assistant
The narrow fix is consistent: namespace imports get undefined-for-absent-reads; default imports keep the strict gate. Let me do a final review of the complete diff.
Assistant
The diff is clean. Let me verify no other crate constructs
LoweringContextvia a struct literal (which would need the new field), and do a full workspace build check.Assistant
Good — it uses the constructor. Let me check the whole workspace for any struct-literal construction of
LoweringContextand confirm the full build compiles.Assistant
No struct-literal construction elsewhere; build succeeds. Let me run a final comprehensive verification of all acceptance criteria.
Assistant
All 7 acceptance criteria pass. Let me run the call-form sweep one final time to confirm calls error across all modules (the regression test for the distinction), then clean up.
Assistant
The call-form sweep passes. Let me verify the git status shows only my intended source changes (no stray files in the repo), and clean up temp files.
Assistant
There's an untracked
error-aliasesartifact from theperry run. Let me check and remove it.Assistant
Only my 5 source changes remain. Let me test a few edge cases — destructuring from a namespace (
const { ADDRCONFIG } = dnsPromises) and usage in expressions — to ensure robustness.Assistant
Destructuring and expression usage compile. Let me verify the runtime values are correct (undefined) for the destructuring case.
Assistant
The clang wrapper was removed in cleanup. Let me recreate it and run the edge case.
Assistant
The edge cases all work correctly (destructuring yields
undefined,??falls back,ifis falsy) — matching Node. Let me clean up artifacts and do a final git status.Assistant
The fix is complete and clean — only my 5 source changes remain. Let me do a final build verification to ensure everything compiles cleanly before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.