Skip to content

Preserve captured relative externals outside dynamic import - #9516

Open
cknitt wants to merge 1 commit into
masterfrom
fix/relative-external-import-9515
Open

cknitt wants to merge 1 commit into
masterfrom
fix/relative-external-import-9515

Conversation

@cknitt

@cknitt cknitt commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #9515. Follow-up to #9506.

Change

Keep ordinary same-file references to relative externals as regular value bindings. Recover the original primitive by the local binding identifier only during dynamic-import translation, so named/default imports and imports requiring FFI adaptation keep working. Qualified references still use the module signature.

Verification

  • Both regression cases fail on the Allow import() of a relative-path external in its own file #9506 compiler and pass on the patched compiler: a getter is captured once, and a tagged template does not acquire a module receiver.
  • Compiled and ran a relative @return(nullable) dynamic import; it returned Some for a present value and None for null.
  • Built the compiler, runtime, and 728-module compiler test project; node scripts/test.js -mocha passed (1,135 tests).
  • OCaml formatting and commit record checks passed locally.

No changelog fragment: this fixes a regression from #9506, which ships in the same release.

Prepared by Christoph's dot.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Changelog

No changelog entry.

Semantic Diff

1 commit · Full page

Preserve captured relative externals outside dynamic import

c780522 · cknitt + Claude · Dec 03, 2026, 19:06 UTC

Why

Restoring the primitive to normal local references re-read properties and changed the receiver of tagged template calls. Keep the binding a value and recover primitive metadata only when lowering dynamic import.

JS modified (ordinary read of a relative external)

js

 let value = Fixture.counter.value;
-return [Fixture.counter.value, Fixture.counter.value];
+return [value, value];

Review

  • Does the fix keep FFI adaptation for dynamic imports? Yes, both native import paths still see the original primitive metadata. The nullable relative import fixture exercises the adapted path.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 653,177,168 → 653,221,652 (+0.01%).

Generated projects: 627,295,178 → 627,358,502 (+0.01%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 8,966,820,936 → 8,967,195,227 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 27,449,936 → 27,450,182 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request c780522 compared with base 7968a96 in this run.

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.54%. Comparing base (82cb108) to head (c780522).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9516   +/-   ##
=======================================
  Coverage   82.54%   82.54%           
=======================================
  Files         469      468    -1     
  Lines       66231    66237    +6     
=======================================
+ Hits        54670    54678    +8     
+ Misses      11561    11559    -2     
Files with missing lines Coverage Δ
compiler/typing/translcore.ml 88.54% <100.00%> (+0.05%) ⬆️
compiler/typing/typemod.ml 77.96% <100.00%> (+0.38%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9516

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9516

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9516

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9516

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9516

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9516

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9516

commit: c780522

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

@cknitt
cknitt force-pushed the fix/relative-external-import-9515 branch from bad5845 to 4b6e97e Compare December 3, 2026 15:22

cknitt commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

Requested by Christoph's dot.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T19:39:55.611672Z c780522 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4b6e97ecb8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review December 3, 2026 15:40
@cknitt
cknitt force-pushed the fix/relative-external-import-9515 branch from 4b6e97e to 2ca4372 Compare December 3, 2026 19:06
@cknitt cknitt added the changelog:skip No release notes needed label Dec 3, 2026
Why:
    Restoring the primitive to normal local references re-read properties
    and changed the receiver of tagged template calls. Keep the binding a
    value and recover primitive metadata only when lowering dynamic import.

JS modified (ordinary read of a relative external):
Before (js):
    let value = Fixture.counter.value;
    return [Fixture.counter.value, Fixture.counter.value];
After (js):
    let value = Fixture.counter.value;
    return [value, value];

Review: Does the fix keep FFI adaptation for dynamic imports? Yes, both native import paths still see the original primitive metadata. The nullable relative import fixture exercises the adapted path.

Signed-off-by: Codex <codex@openai.com>
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gH77iLiiwQFwN8mRDU
@cknitt
cknitt force-pushed the fix/relative-external-import-9515 branch from 2ca4372 to c780522 Compare December 3, 2026 19:07

cknitt commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

Requested by Christoph's dot for the updated green commit c78052296f.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: c78052296f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

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

Labels

changelog:skip No release notes needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relative externals are reread and gain a receiver after the dynamic import fix

1 participant