Skip to content

Commit

Permalink
chore: Address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Feb 12, 2025
1 parent 2691ae7 commit d8a4cab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions compiler/src/codegen/compcore.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type codegen_env = {
/* Allocated closures which need backpatching */
backpatches: ref(list((Expression.t, closure_data))),
required_imports: list(import),
raw_resolutions: ref(StringSet.t),
foreign_import_resolutions: ref(StringSet.t),
global_import_resolutions: Hashtbl.t(string, string),
func_import_resolutions: Hashtbl.t(string, string),
compilation_mode: Config.compilation_mode,
Expand Down Expand Up @@ -93,7 +93,7 @@ let init_codegen_env =
},
backpatches: ref([]),
required_imports: [],
raw_resolutions: ref(StringSet.empty),
foreign_import_resolutions: ref(StringSet.empty),
global_import_resolutions,
func_import_resolutions,
compilation_mode: Normal,
Expand Down Expand Up @@ -2786,7 +2786,7 @@ and compile_instr = (wasm_mod, env, instr) =>
compiled_args,
Type.create(Array.of_list(List.map(wasm_type, retty))),
);
} else if (StringSet.mem(func_name, env.raw_resolutions^)) {
} else if (StringSet.mem(func_name, env.foreign_import_resolutions^)) {
// Deduplicated imports; call resolved name directly
Expression.Call.make(
wasm_mod,
Expand Down Expand Up @@ -3112,7 +3112,8 @@ let compile_imports = (wasm_mod, env, {imports}, import_map) => {
| MGlobalImport(_, _) =>
Hashtbl.add(env.global_import_resolutions, linked_name, name)
};
env.raw_resolutions := StringSet.add(linked_name, env.raw_resolutions^);
env.foreign_import_resolutions :=
StringSet.add(linked_name, env.foreign_import_resolutions^);
| _ =>
Hashtbl.add(import_map, imp_key, internal_name);
switch (mimp_kind, mimp_type) {
Expand Down
20 changes: 17 additions & 3 deletions compiler/test/suites/includes.re
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,15 @@ describe("includes", ({test, testSkip}) => {
name,
{|
module DeDupeIncludes
// Ensures fd_write is only included once
print("test")
// Ensures test is only included once
foreign wasm test: WasmI32 => WasmI32 from "env"
let test2 = test
foreign wasm test: WasmI32 => WasmI32 from "env"
@unsafe
let _ = {
test(1n)
test2(1n)
}
|},
);
let ic = open_in_bin(outfile);
Expand All @@ -234,11 +241,18 @@ describe("includes", ({test, testSkip}) => {
sections,
);
expect.option(import_section).toBeSome();
expect.int(List.length(Option.get(import_section))).toBe(1);
expect.int(List.length(Option.get(import_section))).toBe(2);
// Runtime printing import
expect.list(Option.get(import_section)).toContainEqual((
WasmFunction,
"wasi_snapshot_preview1",
"fd_write",
));
// Test import
expect.list(Option.get(import_section)).toContainEqual((
WasmFunction,
"env",
"test",
));
});
});

0 comments on commit d8a4cab

Please sign in to comment.