Repository navigation
Commit a278540
Export nested make values flat, derived from the signature (#8904)
* Export nested make values flat, derived from the signature
Every `make` in a nested module of a file's final signature is also exported
as `A$B$make`, and other modules read it through that name. React Server
Components only pass a client module's top-level exports to the client, so
`<Sidebar.Provider />` no longer reads `.make` from a client reference. Both
sides decide from the signature alone, which replaces `@res.hoistedFunction`
and its `.cmj` table (#8402); see #8901.
Example (rescript):
// Sidebar.res
module Provider = {
@react.component
let make = (~children) => children
}
// Page.res
let page = <Sidebar.Provider> {React.null} </Sidebar.Provider>
Before (js):
// Page.res.js
JsxRuntime.jsx(Sidebar.Provider.make, {children: null})
After (js):
// Sidebar.res.js
let Provider$make = Sidebar$Provider;
export { Provider, Provider$make }
// Page.res.js
JsxRuntime.jsx(Sidebar.Provider$make, {children: null})
Source: After from tests/build_tests/react_ppx/src/nested_component_*.res.js
in this diff. Before is master's fallback for a nested read without a
`.cmj` hoisting entry.
Breaking: `@res.hoistedFunction` is gone; it now reports the unused-attribute
warning 101. Nested functions other than `make` are no longer exported flat.
Consumers read `Lib.A$make` instead of `Lib.A.make`, so test spies or mocks
that replace `make` on the module object no longer intercept those reads.
Review: Why can't a `.resi` edit leave consumers stale, as in #8886? The
flat export set is a function of the signature, so it changes exactly when
the `.cmi` does, and both build systems already rebuild dependents then.
Changing only `Sidebar.res` behind an unchanged `.resi` (a module alias, an
external, a functor application, `include`) kept the `.cmi` byte-identical
and every flat export in a scratch build.
Review: Do the aliases defeat tree-shaking? When the module field holds a
top-level binding, the alias is `let A$B$make = make`. Only fields without
one (a wrapped value such as `Some(make)`, a functor result, an awaited
module) fall back to a property read.
Review: What about name clashes? A flat name already used by a top-level
binding is a compile error, as it was for `@res.hoistedFunction`.
Area: lambda codegen frontend typechecker playground tests
Output: changed programs with nested `make` values gain flat exports and
read them from other modules; 26 committed outputs change, all additive
apart from the rewritten reads, and 3 go with the removed tests
Formatting: unchanged
Formats: cmi
PPX: unchanged
Editor: unchanged
Errors: none, because the new clash error is an inline raise_errorf, outside
the catalog's scope
Tests: +tests/build_tests/react_ppx/src/nested_component_producer.res
+tests/build_tests/react_ppx/src/nested_component_consumer.res
+tests/build_tests/super_errors/fixtures/flat_make_export_collision.res
~tests/tests/src/flat_make_export*.res (from hoisted_function_attr*.res)
~tests/tests/src/import2.res
~tests/build_tests/super_errors/fixtures/warning_101_bs_unused_attribute.res
-tests/build_tests/super_errors/fixtures/hoisted_function_*.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GUg1NbeoJMi6t6V89yBWh
Signed-off-by: Christoph Knittel <ck@cca.io>
* Check flat export names only against exported bindings
A flat `A$B$make` export now only clashes with another export. A binding
hidden by the interface may have the same JS name: the printer renames the
local and exports the alias under the flat name.
Example (rescript):
// Lib.resi exposes A.B.make and both, but not \"A$B$make"
module A = {
module B = {
let make = () => 1
}
}
let \"A$B$make" = () => Math.random() > 2. ? 0 : 2
let both = () => A.B.make() + \"A$B$make"()
After (js):
function A$B$make() { ... }
let A$B$make$1 = make;
export { A, both, A$B$make$1 as A$B$make }
Source: tests/tests/src/flat_make_export_hidden.mjs in this diff; the
previous commit rejected this file.
Review: Codex finding on #8904, lam_compile_main.ml:186.
Area: lambda tests
Output: changed tests/tests/src/flat_make_export_*.mjs only, for the new test
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged
Tests: +tests/tests/src/flat_make_export_hidden.res
~tests/tests/src/flat_make_export_test.res
~tests/build_tests/super_errors/expected/flat_make_export_collision.res.expected
PR: #8904
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GUg1NbeoJMi6t6V89yBWh
Signed-off-by: Christoph Knittel <ck@cca.io>
* Carry flat make paths in Translmod.implementation
The paths are a field of `Translmod.implementation`, built from the final
signature by `transl_implementation`, and `Lam_compile_main.compile` takes
the whole record. Each step of a path is a `{pos; name}` record instead of
an `(int * string)` pair. Consumer reads and dynamic imports share
`Translmod.flat_make_name`, and the aliases are plain `(ident, value)`
pairs.
Review: fhammerschmidt on #8904, lam_compile_main.mli:33, asked for a
labeled argument or a named type instead of `(int * string) list list`.
Area: lambda codegen playground tests
Output: unchanged, node scripts/test.js -all rebuilds every test project
with no generated file changing
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged
Tests: none, because the change is a refactor covered by the existing
flat_make_export and nested_component tests
PR: #8904
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GUg1NbeoJMi6t6V89yBWh
Signed-off-by: Christoph Knittel <ck@cca.io>
* Read flat exports through re-exports and awaited modules
A flat export of a module that re-exports another file's module, as in
`module Provider = Sidebar.Provider`, now aliases that file's flat export
instead of reading `make` from its module object. Reads below a local bound
to an awaited module, `module D = await Sidebar`, use the flat names too. Both
cases read `make` from a React Server Components client reference before.
Example (rescript):
// Reexport.res, with a .resi exposing Provider.make
module Provider = Sidebar.Provider
// Page.res
let load = async () => {
module D = await Sidebar
<D.Provider> {React.null} </D.Provider>
}
Before (js):
// Reexport.res.js
let Provider$make = Provider.make;
// Page.res.js
let D = await import("./Sidebar.res.js");
return JsxRuntime.jsx(D.Provider.make, {children: null});
After (js):
// Reexport.res.js
let Provider$make = Sidebar.Provider$make;
// Page.res.js
let D = await import("./Sidebar.res.js");
return JsxRuntime.jsx(D.Provider$make, {children: null});
Source: bsc of the previous commit and of this one on a scratch copy of
the two files; the same shapes are in
tests/build_tests/react_ppx/src/nested_component_{reexport,consumer}.res.js.
Review: fhammerschmidt's Next.js end-to-end run on #8904 failed
prerendering for exactly these two cases (rescript-lang/end-to-end#16).
Review: `module P = await Sidebar.Group` still reads `P.Provider.make`: `P`
is Sidebar's `Group` export, so its flat names are out of reach without
changing what `P` holds.
Area: lambda codegen tests
Output: changed tests/tests/src/Import.mjs, where an alias now reads the
awaited module directly (`O.make` instead of `N1.O.make`), and the new
test outputs
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged
Tests: +tests/build_tests/react_ppx/src/nested_component_reexport.res
~tests/build_tests/react_ppx/src/nested_component_consumer.res
+tests/tests/src/flat_make_export_reexport.res
~tests/tests/src/flat_make_export_test.res
PR: #8904
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GUg1NbeoJMi6t6V89yBWh
Signed-off-by: Christoph Knittel <ck@cca.io>
---------
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 2d0a9f0 commit a278540
95 files changed
Lines changed: 1129 additions & 779 deletions
File tree
- changes
- compiler
- core
- ext
- frontend
- jsoo
- ml
- tests
- build_tests
- react_ppx/src
- super_errors
- expected
- fixtures
- gentype_tests/typescript-react-example/src
- ounit_tests
- tests/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 48 | | |
59 | 49 | | |
60 | | - | |
61 | 50 | | |
62 | 51 | | |
63 | 52 | | |
64 | 53 | | |
65 | 54 | | |
66 | | - | |
67 | | - | |
| 55 | + | |
68 | 56 | | |
69 | 57 | | |
70 | 58 | | |
| |||
75 | 63 | | |
76 | 64 | | |
77 | 65 | | |
78 | | - | |
79 | 66 | | |
80 | 67 | | |
81 | 68 | | |
| |||
173 | 160 | | |
174 | 161 | | |
175 | 162 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | 163 | | |
184 | 164 | | |
185 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 64 | | |
75 | 65 | | |
76 | | - | |
77 | 66 | | |
78 | 67 | | |
79 | 68 | | |
80 | 69 | | |
81 | 70 | | |
82 | 71 | | |
83 | 72 | | |
84 | | - | |
85 | 73 | | |
86 | 74 | | |
87 | 75 | | |
88 | 76 | | |
89 | 77 | | |
90 | 78 | | |
91 | 79 | | |
92 | | - | |
93 | | - | |
94 | 80 | | |
95 | 81 | | |
96 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
146 | 147 | | |
| 148 | + | |
| 149 | + | |
147 | 150 | | |
148 | | - | |
149 | | - | |
150 | | - | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
269 | 265 | | |
270 | 266 | | |
271 | 267 | | |
272 | | - | |
| 268 | + | |
273 | 269 | | |
274 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
275 | 274 | | |
276 | 275 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| |||
1633 | 1633 | | |
1634 | 1634 | | |
1635 | 1635 | | |
1636 | | - | |
1637 | | - | |
| 1636 | + | |
| 1637 | + | |
1638 | 1638 | | |
1639 | | - | |
1640 | | - | |
| 1639 | + | |
1641 | 1640 | | |
1642 | 1641 | | |
1643 | 1642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 78 | | |
82 | 79 | | |
83 | 80 | | |
| |||
0 commit comments