Skip to content

Commit c035ccc

Browse files
committed
fixed wasi issue, removed internal runtime mode CLI flag
1 parent bcbed31 commit c035ccc

File tree

17 files changed

+187
-229
lines changed

17 files changed

+187
-229
lines changed

compiler/src/compile.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ let compile_wasi_polyfill = () => {
251251
switch (Grain_utils.Config.wasi_polyfill^) {
252252
| Some(file) =>
253253
Grain_utils.Config.preserve_config(() => {
254-
Grain_utils.Config.runtime_mode := true;
254+
Grain_utils.Config.compilation_mode := Grain_utils.Config.Runtime;
255255
let cstate = {
256256
cstate_desc: Initial(InputFile(file)),
257257
cstate_filename: Some(file),

compiler/src/typed/env.re

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,7 @@ let get_components = c =>
658658
| Some(c) => c
659659
};
660660

661-
type compilation_mode =
662-
| Normal /* Standard compilation with regular bells and whistles */
663-
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;
664-
665-
let current_unit = ref(("", "", Normal));
661+
let current_unit = ref(("", "", Grain_utils.Config.Normal));
666662

667663
let set_unit = unit => current_unit := unit;
668664

compiler/src/typed/env.rei

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,8 @@ let add_local_type: (Path.t, type_declaration, t) => t;
161161
let add_item: (signature_item, t) => t;
162162
let add_signature: (signature, t) => t;
163163

164-
/* Remember the current compilation unit: modname * filename * compilation mode. */
165-
type compilation_mode =
166-
| Normal
167-
| Runtime;
168-
169-
let set_unit: ((string, string, compilation_mode)) => unit;
170-
let get_unit: unit => (string, string, compilation_mode);
164+
let set_unit: ((string, string, Grain_utils.Config.compilation_mode)) => unit;
165+
let get_unit: unit => (string, string, Grain_utils.Config.compilation_mode);
171166
let is_runtime_mode: unit => bool;
172167

173168
/* Insertion of a module */

compiler/src/typed/typed_well_formedness.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ module WellFormednessArg: TypedtreeIter.IteratorArgument = {
299299
if (exp_is_wasm_unsafe(exp)
300300
&& !(
301301
Grain_utils.Config.no_gc^
302-
|| Grain_utils.Config.runtime_mode^
302+
|| Grain_utils.Config.compilation_mode^
303+
== Grain_utils.Config.Runtime
303304
|| is_unsafe()
304305
)) {
305306
raise(Error(exp_loc, WasmOutsideDisableGc));

compiler/src/typed/typemod.re

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -999,17 +999,14 @@ let initial_env = () => {
999999
);
10001000
};
10011001

1002-
let get_compilation_mode = () =>
1003-
if (Grain_utils.Config.runtime_mode^) {
1004-
Env.Runtime;
1005-
} else {
1006-
Env.Normal;
1007-
};
1008-
10091002
let type_implementation = prog => {
10101003
let sourcefile = prog.prog_loc.loc_start.pos_fname;
10111004
let module_name = prog.module_name.txt;
1012-
Env.set_unit((module_name, sourcefile, get_compilation_mode()));
1005+
Env.set_unit((
1006+
module_name,
1007+
sourcefile,
1008+
Grain_utils.Config.compilation_mode^,
1009+
));
10131010
let initenv = initial_env();
10141011
let (statements, sg, finalenv) = type_module(initenv, prog.statements);
10151012
let simple_sg = simplify_signature(sg);

compiler/src/utils/config.re

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,6 @@ let preserve_config = thunk => {
305305
let preserve_all_configs = thunk =>
306306
preserve_root_config(() => preserve_config(thunk));
307307

308-
let with_cli_options = (term: 'a): Cmdliner.Term.t('a) => {
309-
open Cmdliner;
310-
open Term;
311-
let process_option = acc =>
312-
fun
313-
| Spec(arg, names, box) =>
314-
const((a, b) => {
315-
box := a;
316-
b;
317-
})
318-
$ Arg.value(arg)
319-
$ acc;
320-
let folded = List.fold_left(process_option, const(term), specs^);
321-
folded;
322-
};
323-
324308
let option_conv = ((prsr, prntr)) => (
325309
x =>
326310
switch (prsr(x)) {
@@ -398,12 +382,11 @@ let import_memory =
398382
false,
399383
);
400384

401-
let runtime_mode =
402-
toggle_flag(
403-
~names=["compilation-mode"],
404-
~doc="Compilation mode (advanced use only)",
405-
false,
406-
);
385+
type compilation_mode =
386+
| Normal /* Standard compilation with regular bells and whistles */
387+
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;
388+
389+
let compilation_mode = internal_opt(Normal, Digestable);
407390

408391
let statically_link =
409392
toggle_flag(~names=["no-link"], ~doc="Disable static linking", true);
@@ -502,6 +485,23 @@ let source_map =
502485

503486
let print_warnings = internal_opt(true, NotDigestable);
504487

488+
let with_cli_options = (term: 'a): Cmdliner.Term.t('a) => {
489+
open Cmdliner;
490+
open Term;
491+
let process_option = acc =>
492+
fun
493+
| Spec(arg, names, box) =>
494+
const((a, b) => {
495+
box := a;
496+
b;
497+
})
498+
$ Arg.value(arg)
499+
$ acc;
500+
let folded = List.fold_left(process_option, const(term), specs^);
501+
compilation_mode := Normal;
502+
folded;
503+
};
504+
505505
let stdlib_directory = (): option(string) =>
506506
Option.map(
507507
path => Filepath.(to_string(String.derelativize(path))),
@@ -529,7 +529,7 @@ let apply_attribute_flags = (~no_pervasives as np, ~runtime_mode as rm) => {
529529
no_pervasives := true;
530530
};
531531
if (rm) {
532-
runtime_mode := true;
532+
compilation_mode := Runtime;
533533
};
534534
};
535535

@@ -551,7 +551,7 @@ let get_implicit_opens = () => {
551551
} else {
552552
[Pervasives_mod];
553553
};
554-
if (runtime_mode^) {
554+
if (compilation_mode^ == Runtime) {
555555
[];
556556
} else {
557557
// Pervasives goes first, just for good measure.

compiler/src/utils/config.rei

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
type profile =
22
| Release;
33

4+
type compilation_mode =
5+
| Normal /* Standard compilation with regular bells and whistles */
6+
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;
7+
48
/** The Grain stdlib directory, based on the current configuration */
59
let stdlib_directory: unit => option(string);
610

@@ -80,7 +84,7 @@ let import_memory: ref(bool);
8084

8185
/** Whether this module should be compiled in runtime mode */
8286

83-
let runtime_mode: ref(bool);
87+
let compilation_mode: ref(compilation_mode);
8488

8589
/** Statically link modules after compilation */
8690

compiler/test/runner.re

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ let makeRunner =
302302
test,
303303
~num_pages=?,
304304
~config_fn=?,
305-
~compile_flags=Grain_parsing.Parsetree.{
306-
no_pervasives: false,
307-
runtime_mode: false,
308-
},
305+
~compile_flags=Test_utils.default_compile_flags,
309306
name,
310307
prog,
311308
expected,

compiler/test/suites/arrays.re

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ describe("arrays", ({test, testSkip}) => {
123123
state[0] =
124124
5",
125125
{
126-
compile_flags: {
127-
no_pervasives: false,
128-
runtime_mode: false,
129-
},
126+
compile_flags: Grain_tests.Test_utils.default_compile_flags,
130127
module_name: Location.mknoloc("Test"),
131128
statements: [
132129
Toplevel.expr(

compiler/test/suites/basic_functionality.re

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ describe("basic functionality", ({test, testSkip}) => {
255255
type Über = Number
256256
|},
257257
{
258-
compile_flags: {
259-
no_pervasives: false,
260-
runtime_mode: false,
261-
},
258+
compile_flags: Grain_tests.Test_utils.default_compile_flags,
262259
module_name: Location.mknoloc("Test"),
263260
statements: [
264261
Toplevel.data([

0 commit comments

Comments
 (0)