Skip to content

Commit

Permalink
fixed wasi issue, removed internal runtime mode CLI flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-snezhko committed Apr 25, 2023
1 parent bcbed31 commit c035ccc
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 229 deletions.
2 changes: 1 addition & 1 deletion compiler/src/compile.re
Expand Up @@ -251,7 +251,7 @@ let compile_wasi_polyfill = () => {
switch (Grain_utils.Config.wasi_polyfill^) {
| Some(file) =>
Grain_utils.Config.preserve_config(() => {
Grain_utils.Config.runtime_mode := true;
Grain_utils.Config.compilation_mode := Grain_utils.Config.Runtime;
let cstate = {
cstate_desc: Initial(InputFile(file)),
cstate_filename: Some(file),
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/typed/env.re
Expand Up @@ -658,11 +658,7 @@ let get_components = c =>
| Some(c) => c
};

type compilation_mode =
| Normal /* Standard compilation with regular bells and whistles */
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;

let current_unit = ref(("", "", Normal));
let current_unit = ref(("", "", Grain_utils.Config.Normal));

let set_unit = unit => current_unit := unit;

Expand Down
9 changes: 2 additions & 7 deletions compiler/src/typed/env.rei
Expand Up @@ -161,13 +161,8 @@ let add_local_type: (Path.t, type_declaration, t) => t;
let add_item: (signature_item, t) => t;
let add_signature: (signature, t) => t;

/* Remember the current compilation unit: modname * filename * compilation mode. */
type compilation_mode =
| Normal
| Runtime;

let set_unit: ((string, string, compilation_mode)) => unit;
let get_unit: unit => (string, string, compilation_mode);
let set_unit: ((string, string, Grain_utils.Config.compilation_mode)) => unit;
let get_unit: unit => (string, string, Grain_utils.Config.compilation_mode);
let is_runtime_mode: unit => bool;

/* Insertion of a module */
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/typed/typed_well_formedness.re
Expand Up @@ -299,7 +299,8 @@ module WellFormednessArg: TypedtreeIter.IteratorArgument = {
if (exp_is_wasm_unsafe(exp)
&& !(
Grain_utils.Config.no_gc^
|| Grain_utils.Config.runtime_mode^
|| Grain_utils.Config.compilation_mode^
== Grain_utils.Config.Runtime
|| is_unsafe()
)) {
raise(Error(exp_loc, WasmOutsideDisableGc));
Expand Down
13 changes: 5 additions & 8 deletions compiler/src/typed/typemod.re
Expand Up @@ -999,17 +999,14 @@ let initial_env = () => {
);
};

let get_compilation_mode = () =>
if (Grain_utils.Config.runtime_mode^) {
Env.Runtime;
} else {
Env.Normal;
};

let type_implementation = prog => {
let sourcefile = prog.prog_loc.loc_start.pos_fname;
let module_name = prog.module_name.txt;
Env.set_unit((module_name, sourcefile, get_compilation_mode()));
Env.set_unit((
module_name,
sourcefile,
Grain_utils.Config.compilation_mode^,
));
let initenv = initial_env();
let (statements, sg, finalenv) = type_module(initenv, prog.statements);
let simple_sg = simplify_signature(sg);
Expand Down
48 changes: 24 additions & 24 deletions compiler/src/utils/config.re
Expand Up @@ -305,22 +305,6 @@ let preserve_config = thunk => {
let preserve_all_configs = thunk =>
preserve_root_config(() => preserve_config(thunk));

let with_cli_options = (term: 'a): Cmdliner.Term.t('a) => {
open Cmdliner;
open Term;
let process_option = acc =>
fun
| Spec(arg, names, box) =>
const((a, b) => {
box := a;
b;
})
$ Arg.value(arg)
$ acc;
let folded = List.fold_left(process_option, const(term), specs^);
folded;
};

let option_conv = ((prsr, prntr)) => (
x =>
switch (prsr(x)) {
Expand Down Expand Up @@ -398,12 +382,11 @@ let import_memory =
false,
);

let runtime_mode =
toggle_flag(
~names=["compilation-mode"],
~doc="Compilation mode (advanced use only)",
false,
);
type compilation_mode =
| Normal /* Standard compilation with regular bells and whistles */
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;

let compilation_mode = internal_opt(Normal, Digestable);

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

let print_warnings = internal_opt(true, NotDigestable);

let with_cli_options = (term: 'a): Cmdliner.Term.t('a) => {
open Cmdliner;
open Term;
let process_option = acc =>
fun
| Spec(arg, names, box) =>
const((a, b) => {
box := a;
b;
})
$ Arg.value(arg)
$ acc;
let folded = List.fold_left(process_option, const(term), specs^);
compilation_mode := Normal;
folded;
};

let stdlib_directory = (): option(string) =>
Option.map(
path => Filepath.(to_string(String.derelativize(path))),
Expand Down Expand Up @@ -529,7 +529,7 @@ let apply_attribute_flags = (~no_pervasives as np, ~runtime_mode as rm) => {
no_pervasives := true;
};
if (rm) {
runtime_mode := true;
compilation_mode := Runtime;
};
};

Expand All @@ -551,7 +551,7 @@ let get_implicit_opens = () => {
} else {
[Pervasives_mod];
};
if (runtime_mode^) {
if (compilation_mode^ == Runtime) {
[];
} else {
// Pervasives goes first, just for good measure.
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/utils/config.rei
@@ -1,6 +1,10 @@
type profile =
| Release;

type compilation_mode =
| Normal /* Standard compilation with regular bells and whistles */
| Runtime /* GC doesn't exist yet, allocations happen in runtime heap */;

/** The Grain stdlib directory, based on the current configuration */
let stdlib_directory: unit => option(string);

Expand Down Expand Up @@ -80,7 +84,7 @@ let import_memory: ref(bool);

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

let runtime_mode: ref(bool);
let compilation_mode: ref(compilation_mode);

/** Statically link modules after compilation */

Expand Down
5 changes: 1 addition & 4 deletions compiler/test/runner.re
Expand Up @@ -302,10 +302,7 @@ let makeRunner =
test,
~num_pages=?,
~config_fn=?,
~compile_flags=Grain_parsing.Parsetree.{
no_pervasives: false,
runtime_mode: false,
},
~compile_flags=Test_utils.default_compile_flags,
name,
prog,
expected,
Expand Down
5 changes: 1 addition & 4 deletions compiler/test/suites/arrays.re
Expand Up @@ -123,10 +123,7 @@ describe("arrays", ({test, testSkip}) => {
state[0] =
5",
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.expr(
Expand Down
5 changes: 1 addition & 4 deletions compiler/test/suites/basic_functionality.re
Expand Up @@ -255,10 +255,7 @@ describe("basic functionality", ({test, testSkip}) => {
type 脺ber = Number
|},
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.data([
Expand Down
5 changes: 1 addition & 4 deletions compiler/test/suites/blocks.re
Expand Up @@ -12,10 +12,7 @@ describe("blocks", ({test}) => {
"block_parse_lone_no_args_enum",
"module Test; { Foo }",
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.expr(
Expand Down
15 changes: 3 additions & 12 deletions compiler/test/suites/chars.re
Expand Up @@ -102,10 +102,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_simple",
"module Test\n'a'",
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name:
Location.mkloc(
"Test",
Expand All @@ -125,10 +122,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_code",
"module Test\n'\\u{1F3F4}'",
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name:
Location.mkloc(
"Test",
Expand All @@ -148,10 +142,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_emoji",
"module Test\n'馃挴'",
{
compile_flags: {
no_pervasives: false,
runtime_mode: false,
},
compile_flags: Grain_tests.Test_utils.default_compile_flags,
module_name:
Location.mkloc(
"Test",
Expand Down

0 comments on commit c035ccc

Please sign in to comment.