1- type digestable =
2- | Digestable
3- | NotDigestable ;
1+ // Digestible configurations are ones that affect Grain object files.
2+ // Any config options that don't change object files should be marked
3+ // NotDigestible to avoid unnecessary recompiles
4+ type digestible =
5+ | Digestible
6+ | NotDigestible ;
47
58type config_opt =
6- | Opt ((ref (' a ), ' a , digestable )): config_opt ;
9+ | Opt ((ref (' a ), ' a , digestible )): config_opt ;
710
811type saved_config_opt =
9- | SavedOpt ((ref (' a ), ' a , digestable )): saved_config_opt ;
12+ | SavedOpt ((ref (' a ), ' a , digestible )): saved_config_opt ;
1013
11- type digestable_opt =
12- | DigestableOpt (' a ): digestable_opt ;
14+ type digestible_opt =
15+ | DigestibleOpt (' a ): digestible_opt ;
1316
1417type config = list (saved_config_opt );
1518
@@ -36,10 +39,10 @@ type config_spec =
3639let opts : ref (list (config_opt )) = (ref ([] ): ref (list (config_opt )));
3740let specs : ref (list (config_spec )) = (ref ([] ): ref (list (config_spec )));
3841
39- let internal_opt : ' a . (' a , digestable ) => ref (' a ) =
40- (v, digestable ) => {
42+ let internal_opt : ' a . (' a , digestible ) => ref (' a ) =
43+ (v, digestible ) => {
4144 let cur = ref (v);
42- opts := [ Opt ((cur, v, digestable )), ... opts^ ] ;
45+ opts := [ Opt ((cur, v, digestible )), ... opts^ ] ;
4346 cur;
4447 };
4548
@@ -86,6 +89,7 @@ let opt:
8689 ~env_docs : string =?,
8790 ~env_doc : string =?,
8891 ~env : string =?,
92+ ~digestible : digestible ,
8993 ~names : list (string ),
9094 ~conv : Cmdliner . Arg . conv (' a ),
9195 ' a
@@ -99,11 +103,12 @@ let opt:
99103 ~env_docs=?,
100104 ~env_doc=?,
101105 ~env=?,
106+ ~digestible,
102107 ~names,
103108 ~conv as c,
104109 v,
105110 ) => {
106- let cur = internal_opt(v, Digestable );
111+ let cur = internal_opt(v, digestible );
107112 specs :=
108113 [
109114 Spec (
@@ -138,12 +143,23 @@ let toggle_flag:
138143 ~env_docs : string =?,
139144 ~env_doc : string =?,
140145 ~env : string =?,
146+ ~digestible : digestible ,
141147 ~names : list (string ),
142148 bool
143149 ) =>
144- ref (bool ) = (
145- (~docs=?, ~docv=?, ~doc=?, ~env_docs=?, ~env_doc=?, ~env=?, ~names, default) => {
146- let cur = internal_opt(default, Digestable );
150+ ref (bool ) =
151+ (
152+ ~docs=?,
153+ ~docv=?,
154+ ~doc=?,
155+ ~env_docs=?,
156+ ~env_doc=?,
157+ ~env=?,
158+ ~digestible,
159+ ~names,
160+ default,
161+ ) => {
162+ let cur = internal_opt(default, digestible);
147163 specs :=
148164 [
149165 Spec (
@@ -172,24 +188,12 @@ let toggle_flag:
172188 ... specs^,
173189 ] ;
174190 cur;
175- }:
176- (
177- ~docs : string =?,
178- ~docv : string =?,
179- ~doc : string =?,
180- ~env_docs : string =?,
181- ~env_doc : string =?,
182- ~env : string =?,
183- ~names : list (string ),
184- bool
185- ) =>
186- ref (bool )
187- );
191+ };
188192
189193let save_config = () => {
190194 let single_save =
191195 fun
192- | Opt ((cur , _ , digestable )) => SavedOpt ((cur, cur^, digestable ));
196+ | Opt ((cur , _ , digestible )) => SavedOpt ((cur, cur^, digestible ));
193197 List . map(single_save, opts^ );
194198};
195199
@@ -221,13 +225,13 @@ let get_root_config_digest = () => {
221225 | None =>
222226 let config_opts =
223227 root_config^
224- |> List . filter((SavedOpt ((_, _, digestable ))) =>
225- switch (digestable ) {
226- | Digestable => true
227- | NotDigestable => false
228+ |> List . filter((SavedOpt ((_, _, digestible ))) =>
229+ switch (digestible ) {
230+ | Digestible => true
231+ | NotDigestible => false
228232 }
229233 )
230- |> List . map((SavedOpt ((_, opt, _))) => DigestableOpt (opt));
234+ |> List . map((SavedOpt ((_, opt, _))) => DigestibleOpt (opt));
231235 let config = Marshal . to_bytes(config_opts, [] );
232236 let ret = Digest . to_hex(Digest . bytes(config));
233237 root_config_digest := Some (ret);
@@ -325,6 +329,7 @@ let profile =
325329 ~doc= "Set a compilation profile." ,
326330 ~names= [ "profile" ] ,
327331 ~conv= option_conv(Cmdliner . Arg . enum([ ("release" , Release )] )),
332+ ~digestible= Digestible ,
328333 None ,
329334 );
330335
@@ -335,6 +340,7 @@ let memory_base =
335340 ~doc= "Set the start address for the Grain runtime heap." ,
336341 ~names= [ "memory-base" ] ,
337342 ~conv= option_conv(Cmdliner . Arg . int),
343+ ~digestible= Digestible ,
338344 None ,
339345 );
340346
@@ -344,6 +350,7 @@ let include_dirs =
344350 ~conv= Cmdliner . Arg . (list(dir)),
345351 ~doc= "Extra library include directories" ,
346352 ~docv= "DIR" ,
353+ ~digestible= NotDigestible ,
347354 [] ,
348355 );
349356
@@ -353,17 +360,24 @@ let stdlib_dir =
353360 ~conv= option_conv(Cmdliner . Arg . string),
354361 ~doc= "Path to the standard library (stdlib) directory" ,
355362 ~env= "GRAIN_STDLIB" ,
363+ ~digestible= NotDigestible ,
356364 None ,
357365 );
358366
359367let color_enabled =
360- toggle_flag(~names= [ "no-color" ] , ~doc= "Disable colored output" , true );
368+ toggle_flag(
369+ ~names= [ "no-color" ] ,
370+ ~doc= "Disable colored output" ,
371+ ~digestible= NotDigestible ,
372+ true ,
373+ );
361374
362375let initial_memory_pages =
363376 opt(
364377 ~names= [ "initial-memory-pages" ] ,
365378 ~conv= Cmdliner . Arg . int,
366379 ~doc= "Initial number of WebAssembly memory pages" ,
380+ ~digestible= NotDigestible ,
367381 64 ,
368382 );
369383
@@ -372,36 +386,45 @@ let maximum_memory_pages =
372386 ~names= [ "maximum-memory-pages" ] ,
373387 ~conv= option_conv(Cmdliner . Arg . int),
374388 ~doc= "Maximum number of WebAssembly memory pages" ,
389+ ~digestible= NotDigestible ,
375390 None ,
376391 );
377392
378393let import_memory =
379394 toggle_flag(
380395 ~names= [ "import-memory" ] ,
381396 ~doc= "Import the memory from `env.memory`" ,
397+ ~digestible= NotDigestible ,
382398 false ,
383399 );
384400
385401type compilation_mode =
386402 | Normal /* Standard compilation with regular bells and whistles */
387403 | Runtime /* GC doesn't exist yet, allocations happen in runtime heap */ ;
388404
389- let compilation_mode = internal_opt(Normal , Digestable );
405+ let compilation_mode = internal_opt(Normal , NotDigestible );
390406
391407let statically_link =
392- toggle_flag(~names= [ "no-link" ] , ~doc= "Disable static linking" , true );
408+ toggle_flag(
409+ ~names= [ "no-link" ] ,
410+ ~doc= "Disable static linking" ,
411+ ~digestible= NotDigestible ,
412+ true ,
413+ );
393414
394415let no_tail_call =
395416 toggle_flag(
396417 ~names= [ "no-wasm-tail-call" ] ,
397418 ~doc= "Disables tail-call optimization" ,
419+ ~digestible= Digestible ,
398420 false ,
399421 );
400422
401423let strict_sequence =
402424 toggle_flag(
403425 ~names= [ "strict-sequence" ] ,
404426 ~doc= "Enable strict sequencing" ,
427+ ~digestible= NotDigestible ,
405428 false ,
406429 );
407430
@@ -412,20 +435,23 @@ let debug =
412435 toggle_flag(
413436 ~names= [ "debug" ] ,
414437 ~doc= "Compile with debugging information" ,
438+ ~digestible= NotDigestible ,
415439 false ,
416440 );
417441
418442let wat =
419443 toggle_flag(
420444 ~names= [ "wat" ] ,
421445 ~doc= "Additionally produce a WebAssembly Text (.wat) file" ,
446+ ~digestible= NotDigestible ,
422447 false ,
423448 );
424449
425450let verbose =
426451 toggle_flag(
427452 ~names= [ "verbose" ] ,
428453 ~doc= "Print critical information at various stages of compilation" ,
454+ ~digestible= NotDigestible ,
429455 false ,
430456 );
431457
@@ -434,27 +460,31 @@ let sexp_locs_enabled =
434460 ~names= [ "hide-locs" ] ,
435461 ~doc=
436462 "Hide locations from intermediate trees. Only has an effect with `--verbose'." ,
463+ ~digestible= NotDigestible ,
437464 true ,
438465 );
439466
440467let no_pervasives =
441468 toggle_flag(
442469 ~names= [ "no-pervasives" ] ,
443470 ~doc= "Don't automatically import the Grain Pervasives module." ,
471+ ~digestible= Digestible ,
444472 false ,
445473 );
446474
447475let no_gc =
448476 toggle_flag(
449477 ~names= [ "no-gc" ] ,
450478 ~doc= "Turn off reference counting garbage collection." ,
479+ ~digestible= Digestible ,
451480 false ,
452481 );
453482
454483let bulk_memory =
455484 toggle_flag(
456485 ~names= [ "no-bulk-memory" ] ,
457486 ~doc= "Turn off Bulk Memory operations" ,
487+ ~digestible= Digestible ,
458488 true ,
459489 );
460490
@@ -463,27 +493,35 @@ let wasi_polyfill =
463493 ~names= [ "wasi-polyfill" ] ,
464494 ~conv= option_conv(Cmdliner . Arg . string),
465495 ~doc= "Custom WASI implementation" ,
496+ ~digestible= NotDigestible ,
466497 None ,
467498 );
468499
469500let use_start_section =
470501 toggle_flag(
471502 ~names= [ "use-start-section" ] ,
472503 ~doc= "Replace the _start export with a start section during linking." ,
504+ ~digestible= NotDigestible ,
473505 false ,
474506 );
475507
476508let elide_type_info =
477509 toggle_flag(
478510 ~names= [ "elide-type-info" ] ,
479511 ~doc= "Don't include runtime type information used by toString/print" ,
512+ ~digestible= Digestible ,
480513 false ,
481514 );
482515
483516let source_map =
484- toggle_flag(~names= [ "source-map" ] , ~doc= "Generate source maps" , false );
517+ toggle_flag(
518+ ~names= [ "source-map" ] ,
519+ ~doc= "Generate source maps" ,
520+ ~digestible= NotDigestible ,
521+ false ,
522+ );
485523
486- let print_warnings = internal_opt(true , NotDigestable );
524+ let print_warnings = internal_opt(true , NotDigestible );
487525
488526let with_cli_options = (term: ' a ): Cmdliner . Term . t('a) => {
489527 open Cmdliner ;
0 commit comments