-
Notifications
You must be signed in to change notification settings - Fork 409
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(coq): make loading of theories in scope lazier #7754
fix(coq): make loading of theories in scope lazier #7754
Conversation
1acbeec
to
103bffa
Compare
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.
Thanks a lot for the quick fix @Alizter , code looks good to me, and indeed the new type seems like the right one.
Sorry for the oversight in the initial implementation.
should also fix the other one, tho your previous PR did also fix that one, so maybe we can mark both PRs as fixing that bug. |
Actually, I will let @emillon close those since he will do another opam build. |
Changelog / PRs description should reflect bugs numbers tho, right? |
I'll mention them in the PR description but we don't need a changelog since we are fixing a bug about a feature we just introduced in this version. |
Looks like there are some changes with the other of execution in the tests, which is expected. However there appears to be a real regression: --- a/_build/.sandbox/b82be76bda38e00daf81cc2b9fff35ef/default/test/blackbox-tests/test-cases/coq/compose-projects-boot.t/run.t
+++ b/_build/.sandbox/b82be76bda38e00daf81cc2b9fff35ef/default/test/blackbox-tests/test-cases/coq/compose-projects-boot.t/run.t.corrected
@@ -49,7 +49,12 @@ However if this boot library is public Dune will complain
Error: Cannot have more than one boot theory in scope:
- Coq at Coq/dune:1
- Coq at B/Coq/dune:2
- -> required by _build/default/B/Foo.dune-package
+ -> required by alias B/default
+ Error: Multiple rules generated for
+ _build/install/default/lib/coq/theories/Init/Prelude.v:
+ - Coq/dune:1
+ - B/Coq/dune:2
+ -> required by _build/default/B/Foo.install
-> required by alias B/all
-> required by alias B/default
[1] and there is an error that is not caught in another test, which I suppose is fine: --- a/_build/.sandbox/7973c170e23642b9455c3a9c82ae3cfa/default/test/blackbox-tests/test-cases/coq/compose-installed-sub.t/run.t
+++ b/_build/.sandbox/7973c170e23642b9455c3a9c82ae3cfa/default/test/blackbox-tests/test-cases/coq/compose-installed-sub.t/run.t.corrected
@@ -182,10 +182,4 @@ build.
$ dune build --root user
Entering directory 'user'
- Error: Coq theory global is defined twice:
- - theory global in
- $TESTCASE_ROOT/another-place/lib/coq/user-contrib/global
- - theory global in
- $TESTCASE_ROOT/lib/coq/user-contrib/global
Leaving directory 'user'
- [1] |
OK so in the first case, the first error is the one we want, however because it is very lazy it is being delayed until rule loading causing it to emit both errors. Ideally we would want only the first error like before. Not sure what the best way to fix this is. Perhaps during rule loading, we can force the database to be constructed. The second one also looks like a straight up bug. |
Indeed our current approach to side-effects seems kind of fragile, I do dislike the style where we recover the scope imperatively inside coq_rules helper functions. We should make sure the library resolution is actually memoized, and we are not scanning twice. We resolve now the Coq DB a lot of times per-module, so beware of performance impact. I would be much more comfortable if we would try to resolve a bit more in the top-level (but again this needs to be done with care) As for the second error, that's indeed strange, is the test running with the cache enabled? Seems like no rule is triggered and thus no db is built. Indeed we may have a soundness bug here, as the DB build needs to depend on the contents of the directories that are in COQPATH and user contrib. (Rules should already depend on that) |
I'm not sure there will be a perf impact since the database we are resolving is memod. The other test does not have caching enabled. (as in behaves the same when explicitly disabling) @ejgallego I'd appreciate if you could take a look since I am not sure what more I can do here any longer. |
I meant we should make sure the DB is memoed properly.
I see thanks.
I did have a look and I have no idea what is going on. I need to leave now, I'd try to put a few printfs in the DB creation code to try to see if the DB code is called and with what paths. |
I confirm that at the moment this fixes both regressions on opam. But yeah, don't bother closing these in the PR, I'll do it manually while reviewing the milestone. |
I don't mind the "multiple rules generated" error message since that is just extra noise essentially, however the other error is a bit more serious. In that case, the duplicate checking in the install directory isn't being carried out, so I would prefer to fix that. |
103bffa
to
cefe925
Compare
OK so the missing duplicate checking was actually an incorrectly set up test. Good thing we caught it. I've fixed that and a few other tests now. I will have a look at the multiple rules issue now. |
cefe925
to
04e756b
Compare
There isn't much I can do right now about the extra error message. I've decided that since it is quite a niche case about duplicate boot libraries, and the only damage is an extra error message, that it is not really worth fixing at the moment (or even in the future). Therefore I have updated that test. This should now pass and I am now willing to merge this. |
576b9db
to
273ca0a
Compare
This test makes sure that the call to coqc -config in scope.ml is lazy enough. At the moment this is not the case and is therefore a bug. Signed-off-by: Ali Caglayan <alizter@gmail.com>
Signed-off-by: Ali Caglayan <alizter@gmail.com>
This fixes a bug where theories were being loaded too eagarly in scope.ml causing an early call of coqc -config. Signed-off-by: Ali Caglayan <alizter@gmail.com>
Signed-off-by: Ali Caglayan <alizter@gmail.com>
Due to lazy loading of rules we get an extra error message about multiple rules for the same target. This makes the error messages noisier for the user, however since boot libraries are quite niche this isn't really worth fixing at the moment. Signed-off-by: Ali Caglayan <alizter@gmail.com>
273ca0a
to
e38e74d
Compare
Great work, thanks @Alizter . Indeed the duplicate target error is a bit annoying but really a corner case, if someone complains we can fine-tune it easily. |
We make the loading of theories even lazier in scope.ml. This required refactoring the coq db into a Memo.Lazy.t. I'm open to a better way of doing this but this at least fixes the bug observed in #7747 and #7748.
I added a test case for #7747 and showed that this patch fixes it also.
This PR fixes the following issues, however they will be closed on a new run of the opam ci: