-
Notifications
You must be signed in to change notification settings - Fork 413
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
Add test to show lib name collision in contexts #9839
Conversation
Your test indeed demonstrates a limitation of dune's rules. You're welcome to try and lift this limitation. See Note that after you lift it, likely it will not be enough because |
Thanks for the pointers, will take a look.
What kind of new arguments do you have in mind? |
Sharing here some notes of what I've been able to find out. Currently, there is a uniform "view" (for lack of a better name) of library dbs that is shared across all contexts. It is created in the Scope.DB.all function, which is called at the very beginning of each Dune run. Having a uniform view of the library dbs makes it impossible to keep checking for duplication of libraries when I wonder if rather than using Line 336 in 07ba176
The Dune docs only mention Lines 193 to 196 in 07ba176
I think |
You need to change the map, but it's enough to just make it list valued. Right now it just returns a single Adding specialized fields would make the whole thing more confusing. |
I'm leaving here some notes, as I have very limited idea of what i'm doing, so maybe they can serve to surface if I'm going in the wrong direction:
The second approach seems to be working out, I had to disable some odoc rules due to some internal errors:
I will continue down this path tomorrow, fixing the odoc rules and any other potential breakage after the change. |
It will work out, but it will make the errors worse. Our rules distinguish the following two errors:
Your change would convert all errors of type 2. to type 1. A better approach is the following:
For inspiration, you can take a look at |
@rgrinberg Thanks for the pointers, they are super helpful. I made some progress on the new handling of lib dbs following the steps mentioned (see 1b0c2c3). Also fixed a cryptic runtime error coming from some dune/src/dune_rules/gen_rules.ml Line 115 in c11c1f1
Tomorrow, I'll try to figure out why the There are also some errors that have regressed, from |
I've nothing useful to say about odoc issues. It's been a while since I've looked at that stuff. Seems like my comment
is giving us a useful hint. I'd push
|
I have been looking into a weird issue. When I defined a test using a public library using the code in this PR:
The There are two usages of
What exactly is |
Unrelated to the comment above (sorry for the unordered stream of comments). I have some suspicions that this calculation of dune/src/dune_rules/gen_rules.ml Line 117 in 21557d8
The reason is that it does not take the current context into account, so in the test that is included in this PR, it always returns The reason is that in the case of the test, where there are two libraries with the same name (one for each context) there will always exist some library available with the given name. It seems the accurate way to check if a library is enabled is to get that information using |
In 548fabd, I updated the test to show the issue I've been trying to figure out for the last few days. |
A library database is context specific, so it will should account for the when evaluating the availability. See the call to |
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
This reverts commit 30e879f. Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
548fabd
to
00e26fa
Compare
Pushed a fix. The following check for availability was no longer correct:
Using your test as an example:
The solution is to make the availability check more specific. Instead of checking if the name The simplex fix I did addresses the problem, but we should improve the API to make it harder to make this error. E.g.
|
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
@rgrinberg I added a test for the case you mentioned in #10026. Re: the issues with Let's say there are two contexts
I am not sure what |
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
d097fcc
to
ff91664
Compare
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
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.
@rgrinberg I think I got things to be in a place where all the use cases I wanted to support are working, and nothing existing seems to have regressed (at least from the functionality being tested).
I added some inline notes to help reviewing, the diff might look less noisy without the whitespace.
~dialects:(Dune_project.dialects (Scope.project scope)) | ||
~ident:(Lib.Compile.merlin_ident compile_info) | ||
~modes:(`Lib (Lib_info.modes lib_info)) ) | ||
match enabled with |
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.
This check might look redundant, but if we don't conditionally return merlin config, the eif-library-name-collision-same-folder
test fails with multiple rules for cmxs:
Error: Multiple rules generated for _build/alt-context/foo.cmxs:
- dune:4
- dune:1
Error: Multiple rules generated for _build/default/foo.cmxs:
- dune:4
- dune:1
@@ -2092,39 +2180,3 @@ let to_dune_lib | |||
in | |||
Dune_package.Lib.of_dune_lib ~info ~main_module_name | |||
;; | |||
|
|||
module Local : sig |
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.
This module was just moved up to make Local
available in scope for get_compile_info
.
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
test/blackbox-tests/test-cases/enabled_if/eif-library-name-collision-same-folder.t
Outdated
Show resolved
Hide resolved
test/blackbox-tests/test-cases/enabled_if/eif-library-name-collision.t
Outdated
Show resolved
Hide resolved
Co-authored-by: Alpha Issiaga DIALLO <alpha@tarides.com> Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
@anmonteiro could you review this one? |
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
> EOF | ||
|
||
$ dune build | ||
Error: Library foo is defined twice: |
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.
are you planning on addressing this limitation too in a future PR?
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.
|
||
If no public lib is available, the build finishes fine as there are no consumers of the libraries | ||
|
||
$ dune build |
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.
it's a bit weird that this doesn't error?
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.
probably related to them being private libraries, but still weird to me 🤔
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 agree it's strange. I still not fully understand why this happens yet.
> EOF | ||
|
||
$ dune build | ||
Error: Library foo is defined twice: |
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.
have you thought about how we might make it work for public libraries?
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 have started an attempt in 619ea9d.
This doesn't work yet, as it seems the result from querying the DB to find a public library is ignored. There's a call to find
here:
Line 392 in 98c576e
let+ lib = Lib.DB.find public_libs (Public_lib.name pub) in |
But this function already skips all invalid results to just return None
:
Line 1866 in 98c576e
| Ignore | Not_found | Invalid _ | Hidden _ -> None |
And then back in the call point, there's a comment that shows that somehow this should be dealt with:
Lines 395 to 397 in 98c576e
(* Skip hidden or unavailable libraries. TODO we should assert | |
that the library name is always found somehow *) | |
acc |
It seems if the result is Invalid
(because there are 2 libraries defined) we should do something else?
@@ -132,6 +132,18 @@ module Error = struct | |||
] | |||
;; | |||
|
|||
let duplicated ~loc ~name ~dir_a ~dir_b = |
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.
nit: this only seems to be used once. I'd probably inline it in its usage site.
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.
We'll need it for public libs as well (see failed attempt in 619ea9d).
| Found info, Redirect (loc, _) | Redirect (loc, _), Found info -> | ||
Error (loc, Lib_info.loc info) | ||
(* todo: should this not be an error? *) |
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.
still a TODO here.
a pending question: what if info
is the empty list? should we try List.hd info2
?
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.
there's some Nonempty_list
module. Maybe I could add it eventually.
`Library (lib, sources, modules, obj_dir) | ||
let* lib_config = lib_config in | ||
let info = Library.to_lib_info lib ~dir ~lib_config in | ||
let* enabled_if = Lib_info.enabled info in |
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.
refactoring suggestion:
- rename
Lib_info.enabled
toLib_info.to_enabled_if
- add
Lib_info.enabled
which isval enabled: Lib_info.t -> bool Memo.t
- implementation is your conversion from the variant to bool (saw that a few times in the PR)
and* () = Module_compilation.build_all cctx | ||
and* expander = Super_context.expander sctx ~dir | ||
and* lib_info = | ||
let* lib_info = |
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.
are there unpredictable consequences of getting the lib info before doing the cycle check on its modules?
Co-authored-by: Antonio Nuno Monteiro <anmonteiro@gmail.com> Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
…ision Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Co-authored-by: Antonio Nuno Monteiro <anmonteiro@gmail.com> Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
Thanks for the reviews and guidance. This PR got a bit long and messy, it has served its purpose as many parts of it were extracted into separate PRs. Starting again with a much smaller diff (for now) in #10179. |
I am checking Dune workspaces as part of some exploration to find better ways to configure projects that use both Melange and OCaml libraries with some shared code.
My assumption was that a workspace has its own library namespace, and it is not shared with other workspaces. So it would be possible to define a library
foo
in two workspaces A and B and avoid collisions through theenabled_if
field.As this test shows, this is not the case, and Dune will error out because the library is defined twice.
Is the assumption incorrect? If it isn't, I would be happy to contribute a fix for it to continue this exploration, thanks!