diff --git a/compiler/src/compile.re b/compiler/src/compile.re index 72e4a55a4d..cc7671b435 100644 --- a/compiler/src/compile.re +++ b/compiler/src/compile.re @@ -128,8 +128,8 @@ let next_state = (~is_root_file=false, {cstate_desc, cstate_filename} as cs) => Parsed(parsed); | Parsed(p) => Grain_utils.Config.apply_attribute_flags( - ~no_pervasives=p.compile_flags.no_pervasives, - ~runtime_mode=p.compile_flags.runtime_mode, + ~no_pervasives=p.attributes.no_pervasives, + ~runtime_mode=p.attributes.runtime_mode, ); if (is_root_file) { Grain_utils.Config.set_root_config(); diff --git a/compiler/src/formatting/format.re b/compiler/src/formatting/format.re index 767a120723..fbf94a8ef9 100644 --- a/compiler/src/formatting/format.re +++ b/compiler/src/formatting/format.re @@ -5235,14 +5235,14 @@ let format_ast = ); let attrs = ( - if (parsed_program.compile_flags.no_pervasives) { + if (parsed_program.attributes.no_pervasives) { [(Location.mknoloc("noPervasives"), [])]; } else { []; } ) @ ( - if (parsed_program.compile_flags.runtime_mode) { + if (parsed_program.attributes.runtime_mode) { [(Location.mknoloc("runtimeMode"), [])]; } else { []; diff --git a/compiler/src/parsing/driver.re b/compiler/src/parsing/driver.re index bae5182a1f..8d9bffe0a1 100644 --- a/compiler/src/parsing/driver.re +++ b/compiler/src/parsing/driver.re @@ -160,8 +160,8 @@ let read_imports = (program: Parsetree.parsed_program) => { }, Grain_utils.Config.with_attribute_flags( ~on_error=_ => (), - ~no_pervasives=program.compile_flags.no_pervasives, - ~runtime_mode=program.compile_flags.runtime_mode, + ~no_pervasives=program.attributes.no_pervasives, + ~runtime_mode=program.attributes.runtime_mode, Grain_utils.Config.get_implicit_opens, ), ); diff --git a/compiler/src/parsing/parser_header.re b/compiler/src/parsing/parser_header.re index 5ce16cbf96..c8055ea8ab 100644 --- a/compiler/src/parsing/parser_header.re +++ b/compiler/src/parsing/parser_header.re @@ -132,7 +132,7 @@ let make_program = (module_attrs, module_name, statements) => { module_attrs, ); fix_blocks({ - compile_flags: { + attributes: { no_pervasives, runtime_mode, }, diff --git a/compiler/src/parsing/parsetree.re b/compiler/src/parsing/parsetree.re index bd5c76064c..519ccaa69e 100644 --- a/compiler/src/parsing/parsetree.re +++ b/compiler/src/parsing/parsetree.re @@ -660,14 +660,14 @@ type comment = /** The type for parsed programs */ [@deriving (sexp, yojson)] -type compile_flags = { +type module_attributes = { no_pervasives: bool, runtime_mode: bool, }; [@deriving (sexp, yojson)] type parsed_program = { - compile_flags, + attributes: module_attributes, module_name: loc(string), statements: list(toplevel_stmt), comments: list(comment), diff --git a/compiler/src/typed/typemod.re b/compiler/src/typed/typemod.re index 0a344f3843..9afa32b611 100644 --- a/compiler/src/typed/typemod.re +++ b/compiler/src/typed/typemod.re @@ -1020,8 +1020,7 @@ let type_implementation = prog => { let signature = Env.build_signature(normalized_sig, module_name, filename, type_metadata); { - has_flags: - prog.compile_flags.no_pervasives || prog.compile_flags.runtime_mode, + has_flags: prog.attributes.no_pervasives || prog.attributes.runtime_mode, module_name: prog.module_name, statements, env: finalenv, diff --git a/compiler/test/runner.re b/compiler/test/runner.re index a48f51b0b7..ae089fc23c 100644 --- a/compiler/test/runner.re +++ b/compiler/test/runner.re @@ -210,17 +210,17 @@ let doc = (file, arguments) => { let module_header = "module Test; "; -let create_compile_flags = compile_flags => +let create_module_attributes = attributes => Grain_parsing.Parsetree.( ( - if (compile_flags.no_pervasives) { + if (attributes.no_pervasives) { "@noPervasives\n"; } else { ""; } ) ++ ( - if (compile_flags.runtime_mode) { + if (attributes.runtime_mode) { "@runtimeMode\n"; } else { ""; @@ -316,7 +316,7 @@ let makeRunner = test, ~num_pages=?, ~config_fn=?, - ~compile_flags=Test_utils.default_compile_flags, + ~attributes=Test_utils.default_module_attributes, name, prog, expected, @@ -328,7 +328,7 @@ let makeRunner = ~num_pages?, ~config_fn?, name, - create_compile_flags(compile_flags) ++ module_header ++ prog, + create_module_attributes(attributes) ++ module_header ++ prog, ); let (result, _) = run(~num_pages?, wasmfile(name)); expect.string(result).toEqual(expected); @@ -459,10 +459,10 @@ let makeParseRunner = }; let strip_locs = ( - {compile_flags, module_name, statements, comments}: Parsetree.parsed_program, + {attributes, module_name, statements, comments}: Parsetree.parsed_program, ) => Parsetree.{ - compile_flags, + attributes, module_name: { ...module_name, loc: Location.dummy_loc, diff --git a/compiler/test/suites/arrays.re b/compiler/test/suites/arrays.re index 0faf03bd63..3aba4ca946 100644 --- a/compiler/test/suites/arrays.re +++ b/compiler/test/suites/arrays.re @@ -123,7 +123,7 @@ describe("arrays", ({test, testSkip}) => { state[0] = 5", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( diff --git a/compiler/test/suites/basic_functionality.re b/compiler/test/suites/basic_functionality.re index efa67c72ca..73e17d978c 100644 --- a/compiler/test/suites/basic_functionality.re +++ b/compiler/test/suites/basic_functionality.re @@ -255,7 +255,7 @@ describe("basic functionality", ({test, testSkip}) => { type Über = Number |}, { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.data([ diff --git a/compiler/test/suites/blocks.re b/compiler/test/suites/blocks.re index 5994c9a773..5559fe7d01 100644 --- a/compiler/test/suites/blocks.re +++ b/compiler/test/suites/blocks.re @@ -12,7 +12,7 @@ describe("blocks", ({test}) => { "block_parse_lone_no_args_enum", "module Test; { Foo }", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( diff --git a/compiler/test/suites/chars.re b/compiler/test/suites/chars.re index bb48216531..a411162c77 100644 --- a/compiler/test/suites/chars.re +++ b/compiler/test/suites/chars.re @@ -102,7 +102,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|}, "char_loc_simple", "module Test\n'a'", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", @@ -122,7 +122,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|}, "char_loc_code", "module Test\n'\\u{1F3F4}'", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", @@ -142,7 +142,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|}, "char_loc_emoji", "module Test\n'πŸ’―'", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", diff --git a/compiler/test/suites/comments.re b/compiler/test/suites/comments.re index bf0b1cb330..bac507bb63 100644 --- a/compiler/test/suites/comments.re +++ b/compiler/test/suites/comments.re @@ -12,7 +12,7 @@ describe("comments", ({test}) => { "comment_parse_1", "// Test\nmodule Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -29,7 +29,7 @@ describe("comments", ({test}) => { "comment_parse_2", "/* Test */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -46,7 +46,7 @@ describe("comments", ({test}) => { "comment_parse_block_multiline_trim", "/* Test\n Weird indent\n Normal indent */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -63,7 +63,7 @@ describe("comments", ({test}) => { "comment_parse_block_multiline_trim2", "/* Test\r\n Weird indent\r\n Normal indent */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -80,7 +80,7 @@ describe("comments", ({test}) => { "comment_parse_3", "/** Test */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -97,7 +97,7 @@ describe("comments", ({test}) => { "comment_parse_doc_multiline_trim_all_same_indent", "/**\n Test\n Weird indent\n Normal indent */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -114,7 +114,7 @@ describe("comments", ({test}) => { "comment_parse_doc_multiline_trim_keeps_differnt_indent", "/** Test\n Weird indent\n Normal indent */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -132,7 +132,7 @@ describe("comments", ({test}) => { // Note: There are explicit tab characters in this string to test them "/**\n Test\r\n Weird indent\r\n Normal indent */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -149,7 +149,7 @@ describe("comments", ({test}) => { "comment_parse_4", "#!/bin/grain\nmodule Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -166,7 +166,7 @@ describe("comments", ({test}) => { "comment_parse_block_deasterisk", "/* Test\n* no space before\n * space before\n * tab before\n *no space after */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -183,7 +183,7 @@ describe("comments", ({test}) => { "comment_parse_doc_deasterisk", "/** Test\n* no space before\n * space before\n * tab before\n *no space after */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ @@ -200,7 +200,7 @@ describe("comments", ({test}) => { "comment_parse_doc_deasterisk2", "/** Test\n* no space before\n * space before\n * tab before\n * trailing space after */module Test", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [ diff --git a/compiler/test/suites/parsing.re b/compiler/test/suites/parsing.re index 13d90afbb2..c4f34307c4 100644 --- a/compiler/test/suites/parsing.re +++ b/compiler/test/suites/parsing.re @@ -39,7 +39,7 @@ describe("parsing", ({test, testSkip}) => { op, "module Test; a " ++ op ++ " b", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -109,7 +109,7 @@ describe("parsing", ({test, testSkip}) => { "custom_op_precedence_1", "module Test; a +++ b *** c", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -143,7 +143,7 @@ describe("parsing", ({test, testSkip}) => { "custom_op_precedence_2", "module Test; a &&-- b &-- c", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -177,7 +177,7 @@ describe("parsing", ({test, testSkip}) => { "custom_op_precedence_3", "module Test; a ||-- b |-- c", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -211,7 +211,7 @@ describe("parsing", ({test, testSkip}) => { "regression_issue_1473", "module Test; a << b >> c", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -245,7 +245,7 @@ describe("parsing", ({test, testSkip}) => { "regression_issue_1609", "module Test; return -1", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [ Toplevel.expr( @@ -293,7 +293,7 @@ describe("parsing", ({test, testSkip}) => { \xe2\x80\xa9 ", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [], comments: [], @@ -326,7 +326,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_linefeed", "module Test; a\x0ab", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -337,7 +337,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_formfeed", "module Test; a\x0cb", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -348,7 +348,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_carriagereturn", "module Test; a\x0db", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -359,7 +359,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_crlf", "module Test; a\x0d\x0ab", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -370,7 +370,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_nextline", "module Test; a\xc2\x85b", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -381,7 +381,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_lineseparator", "module Test; a\xe2\x80\xa8b", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], @@ -392,7 +392,7 @@ describe("parsing", ({test, testSkip}) => { "end_of_statement_paragraphseparator", "module Test; a\xe2\x80\xa9b", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [Toplevel.expr(a), Toplevel.expr(b)], comments: [], diff --git a/compiler/test/suites/strings.re b/compiler/test/suites/strings.re index 80c383f3bf..4c65471afc 100644 --- a/compiler/test/suites/strings.re +++ b/compiler/test/suites/strings.re @@ -41,7 +41,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_dqs1", "module Test; \"foo\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("foo")], comments: [], @@ -52,7 +52,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_dqs2", "module Test; \"bar\\nbaz\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("bar\nbaz")], comments: [], @@ -63,7 +63,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_sqs1", "module Test; \"foobar\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("foobar")], comments: [], @@ -74,7 +74,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_sqs2", "module Test; \"bar\\u{41}\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("barA")], comments: [], @@ -85,7 +85,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_sqs3", "module Test; \"bar\\x41\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("barA")], comments: [], @@ -96,7 +96,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_sqs4", "module Test; \"bar\\101\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("barA")], comments: [], @@ -107,7 +107,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_sqs5", "module Test; \"bar\\u0041\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("barA")], comments: [], @@ -118,7 +118,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_emoji_escape", "module Test; \"πŸ˜‚\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("πŸ˜‚")], comments: [], @@ -129,7 +129,7 @@ describe("strings", ({test, testSkip}) => { "string_parse_emoji_literal", "module Test; \"πŸ’―\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mknoloc("Test"), statements: [str("πŸ’―")], comments: [], @@ -141,7 +141,7 @@ describe("strings", ({test, testSkip}) => { "string_loc_single_line", "module Test\n\"foo\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", @@ -161,7 +161,7 @@ describe("strings", ({test, testSkip}) => { "string_loc_multi_line", "module Test\n\"foo\nbar\nbaz\nqux\nquux\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", @@ -181,7 +181,7 @@ describe("strings", ({test, testSkip}) => { "string_loc_single_line_emoji", "module Test\n\"πŸ’―\"", { - compile_flags: Grain_tests.Test_utils.default_compile_flags, + attributes: Grain_tests.Test_utils.default_module_attributes, module_name: Location.mkloc( "Test", diff --git a/compiler/test/test_utils.re b/compiler/test/test_utils.re index 45942da0db..79f566fdf7 100644 --- a/compiler/test/test_utils.re +++ b/compiler/test/test_utils.re @@ -21,5 +21,5 @@ let waitpid_timeout = (timeout: float, ~wait=0.1, pid: int) => { (retpid^, status^); }; -let default_compile_flags = +let default_module_attributes = Grain_parsing.Parsetree.{no_pervasives: false, runtime_mode: false};