Skip to content

Commit 97c00e1

Browse files
authored
fix(compiler): Allow reproviding from submodules (#1888)
1 parent 68be62d commit 97c00e1

File tree

8 files changed

+37
-31
lines changed

8 files changed

+37
-31
lines changed

compiler/src/middle_end/linearize.re

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ let lookup_symbol = (~env, ~allocation_type, ~repr, path) => {
134134
item =>
135135
switch (item) {
136136
| TSigValue(_, {val_fullpath: PIdent(id)}) =>
137-
Hashtbl.add(mod_map, Ident.name(id), id)
137+
let name = Ident.name(id);
138+
Hashtbl.add(mod_map, name, id);
139+
Path_tbl.add(include_map, PExternal(mod_, name), id);
138140
| TSigValue(_) =>
139141
failwith("Impossible: internal value with external path")
140142
| TSigType(_, _, _)

compiler/src/typed/typemod.re

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,7 @@ let rec type_module = (~toplevel=false, anchor, env, statements) => {
683683
{tex_id: id, tex_path: path, tex_loc: val_loc},
684684
...provided_values^,
685685
];
686-
// If this module was imported, we'll set the internal path
687-
// to be picked up later to be re-exported. Otherwise, these
688-
// values originated in this module.
689-
let val_internalpath =
690-
switch (mod_decl.md_filepath) {
691-
| Some(_) => path
692-
| _ => val_internalpath
693-
};
694-
TSigValue(id, {...vd, val_internalpath});
686+
TSigValue(id, {...vd, val_internalpath: path});
695687
| TSigModule(
696688
id,
697689
{md_type: TModSignature(signature)} as md,

compiler/test/suites/includes.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ describe("includes", ({test, testSkip}) => {
175175
"./broken.gr\", line 4, characters 8-15",
176176
);
177177
assertRun(
178-
"reprovide_type",
179-
"include \"reprovideType\"; from ReprovideType use { type Type }; print(A)",
180-
"A\n",
178+
"reprovide_values",
179+
"include \"reprovideContents\"; from ReprovideContents use { type Type, module Mod }; print(A); print(Mod.val)",
180+
"A\n123\n",
181181
);
182182
});

compiler/test/suites/provides.re

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("provides", ({test, testSkip}) => {
99
test,
1010
);
1111
let assertCompileError = makeCompileErrorRunner(test);
12-
let assertHasWasmExport = (name, prog, export) => {
12+
let assertHasWasmExport = (name, prog, expectedExports) => {
1313
test(
1414
name,
1515
({expect}) => {
@@ -34,7 +34,7 @@ describe("provides", ({test, testSkip}) => {
3434
);
3535
},
3636
);
37-
expect.list(exports).toContainEqual(export);
37+
List.iter(expect.list(exports).toContainEqual, expectedExports);
3838
| _ => assert(false)
3939
};
4040
},
@@ -174,11 +174,19 @@ describe("provides", ({test, testSkip}) => {
174174
assertHasWasmExport(
175175
"issue_918_annotated_func_provide",
176176
"module Test; provide let foo: () => Number = () => 5",
177-
("foo", Binaryen.Export.external_function),
177+
[("foo", Binaryen.Export.external_function)],
178178
);
179179
assertHasWasmExport(
180180
"issue_918_annotated_func_provide2",
181181
"module Test; provide let rec foo: () => Number = () => 5",
182-
("foo", Binaryen.Export.external_function),
182+
[("foo", Binaryen.Export.external_function)],
183+
);
184+
assertHasWasmExport(
185+
"issue_1872_reprovide_from_submodule",
186+
"module Test; module M { provide let x = 1; provide let y = 2 }; from M use *; provide { x, y }",
187+
[
188+
("GRAIN$EXPORT$x", Binaryen.Export.external_global),
189+
("GRAIN$EXPORT$y", Binaryen.Export.external_global),
190+
],
183191
);
184192
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module ProvideContents
2+
3+
provide enum Type {
4+
A,
5+
B,
6+
C,
7+
}
8+
9+
provide module Mod {
10+
provide let val = 123
11+
}

compiler/test/test-libs/provideType.gr

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module ReprovideContents
2+
3+
include "./provideContents"
4+
5+
from ProvideContents use { type Type, module Mod }
6+
7+
provide { type Type, module Mod }

compiler/test/test-libs/reprovideType.gr

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)