-
Notifications
You must be signed in to change notification settings - Fork 416
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
feature(coq): automatic detection of native #6409
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,9 +178,24 @@ end | |
(* get_libraries from Coq's ML dependencies *) | ||
let libs_of_coq_deps ~lib_db = Resolve.Memo.List.map ~f:(Lib.DB.resolve lib_db) | ||
|
||
let select_native_mode ~sctx ~(buildable : Buildable.t) : Coq_mode.t = | ||
let profile = (Super_context.context sctx).profile in | ||
if Profile.is_dev profile then VoOnly else snd buildable.mode | ||
let select_native_mode ~sctx ~dir (buildable : Coq_stanza.Buildable.t) = | ||
match buildable.mode with | ||
| Some x -> | ||
if | ||
buildable.coq_lang_version < (0, 7) | ||
&& Profile.is_dev (Super_context.context sctx).profile | ||
then Memo.return Coq_mode.VoOnly | ||
else Memo.return x | ||
| None -> ( | ||
if buildable.coq_lang_version < (0, 3) then Memo.return Coq_mode.Legacy | ||
else if buildable.coq_lang_version < (0, 7) then Memo.return Coq_mode.VoOnly | ||
else | ||
let* coqc = resolve_program sctx ~dir ~loc:buildable.loc "coqc" in | ||
let+ config = Coq_config.make ~bin:(Action.Prog.ok_exn coqc) in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an fyi, this breaks lazy loading absolutely everywhere where coq stanzas are present. I'm not sure if you care though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we already broke lazy loading since coqc and coqdep were being resolved in the common context in Coq_rules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the resolution inside the monad tho? |
||
match Coq_config.by_name config "coq_native_compiler_default" with | ||
| Some (Coq_config.Value.String "yes") | ||
| Some (Coq_config.Value.String "ondemand") -> Coq_mode.Native | ||
| _ -> Coq_mode.VoOnly) | ||
|
||
let rec resolve_first lib_db = function | ||
| [] -> assert false | ||
|
@@ -330,7 +345,7 @@ module Context = struct | |
let ml_flags, mlpack_rule = | ||
Coq_plugin.of_buildable ~context ~theories_deps ~lib_db buildable | ||
in | ||
let mode = select_native_mode ~sctx ~buildable in | ||
let* mode = select_native_mode ~sctx ~dir buildable in | ||
let* native_includes = | ||
let open Resolve.Memo.O in | ||
resolve_first lib_db [ "coq-core.kernel"; "coq.kernel" ] >>| fun lib -> | ||
|
@@ -692,8 +707,8 @@ let install_rules ~sctx ~dir s = | |
match s with | ||
| { Theory.package = None; _ } -> Memo.return [] | ||
| { Theory.package = Some package; buildable; _ } -> | ||
let mode = select_native_mode ~sctx ~buildable in | ||
let loc = s.buildable.loc in | ||
let* mode = select_native_mode ~sctx ~dir buildable in | ||
let* scope = Scope.DB.find_by_dir dir in | ||
let* dir_contents = Dir_contents.get sctx ~dir in | ||
let name = snd s.name in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ module Buildable = struct | |
type t = | ||
{ flags : Ordered_set_lang.Unexpanded.t | ||
; coq_lang_version : Dune_sexp.Syntax.Version.t | ||
; mode : Loc.t * Coq_mode.t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed the Loc since we don't even use it. |
||
; mode : Coq_mode.t option | ||
; use_stdlib : bool | ||
; plugins : (Loc.t * Lib_name.t) list (** ocaml libraries *) | ||
; theories : (Loc.t * Coq_lib_name.t) list (** coq libraries *) | ||
|
@@ -57,12 +57,9 @@ module Buildable = struct | |
let+ loc = loc | ||
and+ flags = Ordered_set_lang.Unexpanded.field "flags" | ||
and+ mode = | ||
let default = | ||
if coq_lang_version < (0, 3) then Coq_mode.Legacy else Coq_mode.VoOnly | ||
in | ||
located | ||
(field "mode" ~default | ||
(Dune_lang.Syntax.since coq_syntax (0, 3) >>> Coq_mode.decode)) | ||
field_o "mode" | ||
(Dune_lang.Syntax.since coq_syntax (0, 3) | ||
>>> Coq_mode.decode ~coq_syntax) | ||
and+ use_stdlib = | ||
field ~default:true "stdlib" | ||
(Dune_lang.Syntax.since coq_syntax (0, 6) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(lang dune 3.7) | ||
|
||
(using coq 0.3) | ||
(using coq 0.7) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better for this to correspond to the version the test was introduced? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point would be consistency with the common practice we do, the test doesn't require coq lang 0.7 so in this sense the new constraint is an over-requirement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But 0.2 brings out the legacy native mode which is broken. I guess the next one to choose would be 0.3, but why not just use 0.7? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
Testing that the correct flags are being passed to dune coq top | ||
|
||
The flags passed to coqc: | ||
$ dune build && tail -1 _build/log | sed 's/(cd .*coqc/coqc/' | sed 's/$ //' | ||
coqc -w -notation-overridden -w -deprecated-native-compiler-option -w -native-compiler-disabled -native-compiler ondemand -R . minimal Test.v) | ||
$ dune build && tail -1 _build/log | sed 's/(cd .*coqc/coqc/' | sed 's/$ //' | sed 's/-nI .*coq-core/some-coq-core/' | ||
coqc -w -notation-overridden -w -deprecated-native-compiler-option -native-output-dir . -native-compiler on some-coq-core/kernel -nI . -R . minimal Test.v) | ||
|
||
The flags passed to coqtop: | ||
$ dune coq top --toplevel=echo Test.v | sed 's/-nI .*coq-core/some-coq-core/' | ||
-topfile $TESTCASE_ROOT/_build/default/Test.v -w -notation-overridden -w -deprecated-native-compiler-option -w -native-compiler-disabled -native-compiler ondemand -R $TESTCASE_ROOT/_build/default minimal | ||
-topfile $TESTCASE_ROOT/_build/default/Test.v -w -notation-overridden -w -deprecated-native-compiler-option -native-output-dir . -native-compiler on some-coq-core/kernel -nI $TESTCASE_ROOT/_build/default -R $TESTCASE_ROOT/_build/default minimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the behavior is kept, the sentence "The regular
dev
profile skips native compilation to make the build faster." should also be kept. It can be a pretty disturbing behavior, so I think it should at the very least be documented.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I am not a fan of it at all TBH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither, for the following reason, after this PR:
mode
stanza)mode vo
can be usedmode native
has probably no other use than to test compilation with native, the more complex behavior where it is disabled in dev mode can then be more disturbing than anything for those users(of course I might be missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove it. If we want something like this in the future, we should support it correctly. Either we add the split native compilation which will allow users to compile native as a second step or we allow users to explicitly disable native themselves in their profiles.
But keeping this confusing default behavior isn't great. As you said,
(mode vo)
can always be used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode native
is indeed made obsolete by this PR.dev
disabling native is indeed a mixed bag, and was also motivated by the lack of dynamic configuration, previosly you had to edit the stanza to disable native for example when developing Coq, as you don't want to take the expensive compilation route.Now you can set it at configure time, so the tradeoff is a bit better.