Skip to content

Fix namespace variable export ABI#6315

Open
TheHypnoo wants to merge 4 commits into
mainfrom
fix/namespace-variable-export-abi
Open

Fix namespace variable export ABI#6315
TheHypnoo wants to merge 4 commits into
mainfrom
fix/namespace-variable-export-abi

Conversation

@TheHypnoo

@TheHypnoo TheHypnoo commented Jul 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Route variable-shaped namespace exports through their zero-argument getter and js_closure_callN for every namespace import form.
  • Classify aliases and default-origin re-exports consistently, including CJS re-exports.
  • Remove the obsolete namespace re-export routing state and its object-cache discriminator.
  • Add multi-module regression coverage and remove the obsolete target/deepwiki artifacts.

Root cause

Namespace static-member calls treated variable-shaped exports as direct functions unless the namespace came from one specific re-export form. Those exports are getter symbols returning closures, so direct calls returned the closure rather than invoking it.

Validation

  • cargo fmt --check
  • CARGO_INCREMENTAL=0 cargo test -p perry --test namespace_variable_export_abi -- --nocapture
  • CARGO_INCREMENTAL=0 cargo check -p perry -p perry-codegen

Summary by CodeRabbit

  • Bug Fixes

    • Fixed namespace-bound variable export ABI behavior for named, aliased, default, and namespace re-exported values.
    • Improved dispatch for variables accessed through namespace bindings, including correct behavior with cyclic module dependencies and preserved initialization order.
  • Tests

    • Added an integration test that compiles and runs a Node/TypeScript fixture to validate namespace variable exports across ESM and a small CJS dependency.
    • Updated existing compiler regression tests to match the revised namespace import handling.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 61cecf1e-acf7-4176-a6b9-9db7de782738

📥 Commits

Reviewing files that changed from the base of the PR and between dd15064 and effafef.

📒 Files selected for processing (9)
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/codegen/opts.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-codegen/tests/native_proof_regressions.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/perry-codegen/tests/native_proof_regressions.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/codegen/opts.rs

📝 Walkthrough

Walkthrough

The compiler replaces namespace re-export tracking with namespace import tracking, broadens variable-shaped namespace dispatch, adjusts object-cache keys, updates compile-option fixtures, and adds integration coverage for cyclic namespace variable exports.

Changes

Namespace export ABI

Layer / File(s) Summary
Namespace context contract
crates/perry-codegen/src/codegen/{opts,mod,closure,entry,function,method}.rs, crates/perry-codegen/src/expr/mod.rs, crates/perry/src/commands/compile/run_pipeline.rs
Removes namespace_reexport_named_imports from compilation contexts and wires namespace import tracking through code generation.
Namespace member lowering
crates/perry-codegen/src/expr/static_method.rs, crates/perry/src/commands/compile/run_pipeline.rs, test-files/issue_321_named_namespace_reexport/main.ts
Expands variable-shaped namespace member classification and uses getter-based closure dispatch for imported variables.
Cache and regression validation
crates/perry/src/commands/compile/object_cache.rs, crates/perry-codegen/tests/*, crates/perry/tests/namespace_variable_export_abi.rs
Removes the obsolete cache-key discriminator, updates option fixtures, and adds runtime coverage for namespace exports across aliases, cycles, and CommonJS imports.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • PerryTS/perry#5874 — Updates the same FnCtx construction sites and namespace plumbing.

Sequence Diagram(s)

sequenceDiagram
  participant ModuleCompiler
  participant NamespaceResolver
  participant StaticMethodLowering
  participant ClosureCallHelpers
  ModuleCompiler->>NamespaceResolver: resolve namespace re-export origin
  NamespaceResolver->>ModuleCompiler: classify imported variable and store origin mapping
  ModuleCompiler->>StaticMethodLowering: lower namespace member call
  StaticMethodLowering->>ClosureCallHelpers: retrieve getter closure and invoke with arguments
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has summary, root cause, and validation, but it omits the template's Changes, Related issue, and checklist-style Test plan sections. Add a concrete Changes bullet list, a Related issue entry (or n/a), and a Test plan section using the repo's checklist items; include checklist and optional screenshots if relevant.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and directly matches the PR's main change: fixing namespace variable export ABI handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/namespace-variable-export-abi

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-codegen/src/expr/static_method.rs`:
- Around line 265-267: Replace the flat imported_vars check in static-method
handling with a namespace-qualified variable classification keyed by
(class_name, method_name). Populate this set in run_pipeline.rs alongside
namespace_member_prefixes, use it to identify closure-valued namespace exports,
and retain imported_vars for named-import value lowering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 312e728b-a0d7-4765-97fc-b0b901dadaa3

📥 Commits

Reviewing files that changed from the base of the PR and between 0960415 and dd15064.

📒 Files selected for processing (27)
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/codegen/opts.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-codegen/src/expr/static_method.rs
  • crates/perry-codegen/tests/argless_builtin_extra_args.rs
  • crates/perry-codegen/tests/class_keys_gc_root.rs
  • crates/perry-codegen/tests/constructor_recursion.rs
  • crates/perry-codegen/tests/destructure_call_location.rs
  • crates/perry-codegen/tests/large_object_barriers.rs
  • crates/perry-codegen/tests/macos_bundle_chdir_gate.rs
  • crates/perry-codegen/tests/native_proof_buffer_views.rs
  • crates/perry-codegen/tests/native_proof_regressions.rs
  • crates/perry-codegen/tests/shadow_slot_hygiene.rs
  • crates/perry-codegen/tests/static_symbol_hygiene.rs
  • crates/perry-codegen/tests/typed_feedback.rs
  • crates/perry-codegen/tests/typed_shape_descriptor.rs
  • crates/perry-codegen/tests/typed_shape_descriptors.rs
  • crates/perry/src/commands/compile/object_cache.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
  • crates/perry/tests/namespace_variable_export_abi.rs
  • target/deepwiki/arraybuffer-dataview-semantics.md
  • target/deepwiki/object-literal-semantics.md
  • test-files/issue_321_named_namespace_reexport/main.ts
💤 Files with no reviewable changes (23)
  • crates/perry-codegen/tests/static_symbol_hygiene.rs
  • crates/perry-codegen/tests/argless_builtin_extra_args.rs
  • target/deepwiki/arraybuffer-dataview-semantics.md
  • crates/perry-codegen/tests/constructor_recursion.rs
  • crates/perry-codegen/tests/typed_shape_descriptors.rs
  • crates/perry-codegen/tests/large_object_barriers.rs
  • crates/perry-codegen/tests/shadow_slot_hygiene.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/tests/macos_bundle_chdir_gate.rs
  • crates/perry-codegen/src/codegen/method.rs
  • target/deepwiki/object-literal-semantics.md
  • crates/perry-codegen/tests/class_keys_gc_root.rs
  • crates/perry-codegen/tests/typed_feedback.rs
  • crates/perry-codegen/tests/native_proof_buffer_views.rs
  • crates/perry-codegen/tests/native_proof_regressions.rs
  • crates/perry-codegen/tests/typed_shape_descriptor.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry/src/commands/compile/object_cache.rs
  • crates/perry-codegen/tests/destructure_call_location.rs
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-codegen/src/codegen/opts.rs

Comment on lines +265 to +267
// Both wildcard imports and namespaces reached through a
// re-export use the same getter ABI.
if ctx.imported_vars.contains(method_name) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Scope variable classification by namespace.

imported_vars is a flat set. If A.make is a declared function and B.make is a closure-valued export, importing both namespaces inserts "make" and makes A.make() call its function body as a zero-arg getter, then invoke its return value as a closure.

Add a namespace-qualified variable set, populated in run_pipeline.rs alongside namespace_member_prefixes, and consult (class_name, method_name) here. Keep the flat set for named-import value lowering.

Proposed direction
- if ctx.imported_vars.contains(method_name) {
+ if ctx
+     .namespace_imported_vars
+     .contains(&(class_name.clone(), method_name.clone()))
+ {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-codegen/src/expr/static_method.rs` around lines 265 - 267,
Replace the flat imported_vars check in static-method handling with a
namespace-qualified variable classification keyed by (class_name, method_name).
Populate this set in run_pipeline.rs alongside namespace_member_prefixes, use it
to identify closure-valued namespace exports, and retain imported_vars for
named-import value lowering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant