Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Don't trigger recompilation for unnecessary compiler flags #2106

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 59 additions & 21 deletions compiler/src/utils/config.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Digestable configurations are ones that affect Grain object files.
// Any config options that don't change object files should be marked
// NotDigestable to avoid unnecessary recompiles
type digestable =
| Digestable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit typo on digestible

| NotDigestable;
Expand Down Expand Up @@ -86,6 +89,7 @@ let opt:
~env_docs: string=?,
~env_doc: string=?,
~env: string=?,
~digestable: digestable,
~names: list(string),
~conv: Cmdliner.Arg.conv('a),
'a
Expand All @@ -99,11 +103,12 @@ let opt:
~env_docs=?,
~env_doc=?,
~env=?,
~digestable,
~names,
~conv as c,
v,
) => {
let cur = internal_opt(v, Digestable);
let cur = internal_opt(v, digestable);
specs :=
[
Spec(
Expand Down Expand Up @@ -138,12 +143,23 @@ let toggle_flag:
~env_docs: string=?,
~env_doc: string=?,
~env: string=?,
~digestable: digestable,
~names: list(string),
bool
) =>
ref(bool) = (
(~docs=?, ~docv=?, ~doc=?, ~env_docs=?, ~env_doc=?, ~env=?, ~names, default) => {
let cur = internal_opt(default, Digestable);
ref(bool) =
(
~docs=?,
~docv=?,
~doc=?,
~env_docs=?,
~env_doc=?,
~env=?,
~digestable,
~names,
default,
) => {
let cur = internal_opt(default, digestable);
specs :=
[
Spec(
Expand Down Expand Up @@ -172,19 +188,7 @@ let toggle_flag:
...specs^,
];
cur;
}:
(
~docs: string=?,
~docv: string=?,
~doc: string=?,
~env_docs: string=?,
~env_doc: string=?,
~env: string=?,
~names: list(string),
bool
) =>
ref(bool)
);
};

let save_config = () => {
let single_save =
Expand Down Expand Up @@ -325,6 +329,7 @@ let profile =
~doc="Set a compilation profile.",
~names=["profile"],
~conv=option_conv(Cmdliner.Arg.enum([("release", Release)])),
~digestable=Digestable,
None,
);

Expand All @@ -335,6 +340,7 @@ let memory_base =
~doc="Set the start address for the Grain runtime heap.",
~names=["memory-base"],
~conv=option_conv(Cmdliner.Arg.int),
~digestable=Digestable,
None,
);

Expand All @@ -344,6 +350,7 @@ let include_dirs =
~conv=Cmdliner.Arg.(list(dir)),
~doc="Extra library include directories",
~docv="DIR",
~digestable=NotDigestable,
[],
);

Expand All @@ -353,17 +360,24 @@ let stdlib_dir =
~conv=option_conv(Cmdliner.Arg.string),
~doc="Path to the standard library (stdlib) directory",
~env="GRAIN_STDLIB",
~digestable=Digestable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remind me why the stdlib option would be Digestable but include_dirs is not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to be, good catch.

None,
);

let color_enabled =
toggle_flag(~names=["no-color"], ~doc="Disable colored output", true);
toggle_flag(
~names=["no-color"],
~doc="Disable colored output",
~digestable=NotDigestable,
true,
);

let initial_memory_pages =
opt(
~names=["initial-memory-pages"],
~conv=Cmdliner.Arg.int,
~doc="Initial number of WebAssembly memory pages",
~digestable=NotDigestable,
64,
);

Expand All @@ -372,36 +386,45 @@ let maximum_memory_pages =
~names=["maximum-memory-pages"],
~conv=option_conv(Cmdliner.Arg.int),
~doc="Maximum number of WebAssembly memory pages",
~digestable=NotDigestable,
None,
);

let import_memory =
toggle_flag(
~names=["import-memory"],
~doc="Import the memory from `env.memory`",
~digestable=NotDigestable,
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 compilation_mode = internal_opt(Normal, NotDigestable);

let statically_link =
toggle_flag(~names=["no-link"], ~doc="Disable static linking", true);
toggle_flag(
~names=["no-link"],
~doc="Disable static linking",
~digestable=NotDigestable,
true,
);

let no_tail_call =
toggle_flag(
~names=["no-wasm-tail-call"],
~doc="Disables tail-call optimization",
~digestable=Digestable,
false,
);

let strict_sequence =
toggle_flag(
~names=["strict-sequence"],
~doc="Enable strict sequencing",
~digestable=NotDigestable,
false,
);

Expand All @@ -412,20 +435,23 @@ let debug =
toggle_flag(
~names=["debug"],
~doc="Compile with debugging information",
~digestable=NotDigestable,
false,
);

let wat =
toggle_flag(
~names=["wat"],
~doc="Additionally produce a WebAssembly Text (.wat) file",
~digestable=NotDigestable,
false,
);

let verbose =
toggle_flag(
~names=["verbose"],
~doc="Print critical information at various stages of compilation",
~digestable=NotDigestable,
false,
);

Expand All @@ -434,27 +460,31 @@ let sexp_locs_enabled =
~names=["hide-locs"],
~doc=
"Hide locations from intermediate trees. Only has an effect with `--verbose'.",
~digestable=NotDigestable,
true,
);

let no_pervasives =
toggle_flag(
~names=["no-pervasives"],
~doc="Don't automatically import the Grain Pervasives module.",
~digestable=Digestable,
false,
);

let no_gc =
toggle_flag(
~names=["no-gc"],
~doc="Turn off reference counting garbage collection.",
~digestable=Digestable,
false,
);

let bulk_memory =
toggle_flag(
~names=["no-bulk-memory"],
~doc="Turn off Bulk Memory operations",
~digestable=Digestable,
true,
);

Expand All @@ -463,25 +493,33 @@ let wasi_polyfill =
~names=["wasi-polyfill"],
~conv=option_conv(Cmdliner.Arg.string),
~doc="Custom WASI implementation",
~digestable=NotDigestable,
None,
);

let use_start_section =
toggle_flag(
~names=["use-start-section"],
~doc="Replace the _start export with a start section during linking.",
~digestable=NotDigestable,
false,
);

let elide_type_info =
toggle_flag(
~names=["elide-type-info"],
~doc="Don't include runtime type information used by toString/print",
~digestable=Digestable,
false,
);

let source_map =
toggle_flag(~names=["source-map"], ~doc="Generate source maps", false);
toggle_flag(
~names=["source-map"],
~doc="Generate source maps",
~digestable=NotDigestable,
false,
);

let print_warnings = internal_opt(true, NotDigestable);

Expand Down
Loading