Skip to content

regression(hir): ambient declare function require shadows the require intrinsic since #8343 — links against a nonexistent require symbol #8447

Description

@proggeramlug

Since #8343 (6674f59, 2026-08-18), a module that carries the standard TypeScript ambient declaration

declare function require(name: string): any;
const fs = require("node:fs");

fails to link:

Undefined symbols for architecture arm64:
  "_require", referenced from: perry_fn_..._warmAndSummarize ...

Mechanism

  1. A body-less declare function require(...) has always been registered as an external FFI declaration (register_imported_func) by lower_module_fn.rs — the generic "no body ⇒ extern" rule.
  2. Before fix(cjs-wrap): stop HIR from dropping built-in require bindings in wrapped modules #8343 this was harmless for the const x = require("<builtin>") shape: the destructuring var-decl pass consumed the call into a native-module namespace binding before call lowering, so the FFI registration was never consulted.
  3. fix(cjs-wrap): stop HIR from dropping built-in require bindings in wrapped modules #8343 added require_is_shadowed_by_local, which bails out of that destructuring path when lookup_imported_func("require") is Some — which the ambient declare makes true. The call now falls through to plain call lowering, resolves to the "imported func" require, and codegen emits a call to the symbol require, which no archive defines (it was always a compile-time intrinsic).

Blast radius: test-files/test_issue_8002_8003_thread_realm_caches.ts (COMPILE_FAIL in the 08-19 dispatch run 32298711372: compile-smoke red + one of parity's 27 compile_fails). Any user code using the ambient-declare idiom hits the same wall.

Fix direction: an ambient declare function require names the global intrinsic — it must not register as an FFI extern. #8343's CJS-wrap shadowing (a synthetic function require(...) with a body) is unaffected: that registers via register_func/locals, which correctly keeps shadowing.

Reproduced locally on a 0.5.1512 binary (macOS arm64); same failure as CI's Linux undefined reference to 'require'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions