Skip to content

Strict Includes - Attempt 2#1745

Merged
rgrinberg merged 3 commits intoocaml:masterfrom
rgrinberg:strict-includes-take-2
Jan 10, 2019
Merged

Strict Includes - Attempt 2#1745
rgrinberg merged 3 commits intoocaml:masterfrom
rgrinberg:strict-includes-take-2

Conversation

@rgrinberg
Copy link
Copy Markdown
Member

@rgrinberg rgrinberg commented Jan 8, 2019

This is an attempt to revive #430 in the new code base.

TODO:

  • Make requires_compile = requires_link unless this feature is enabled in the dune file.

Questions/Notes:

  • I had to change threads to threads.posix for this to compile dune. I think that's fine for dune, since we might rely on posix semantics. But I don't think that users are going to know to do this. How do we handle threads in this case?

  • My idea is to have the compilation context check if the feature is enabled (in the dune project file) before returning requires_compile. If the feature is disabled, it will simply use requires_link and generate Includes.t with this value.

  • It's a bit annoying to calculate the requires_compile if it isn't going to be used every time. Any ideas on how restructure the code to avoid this? I was thinking perhaps we could make a constructor of Compilation_context.t that consumes a Lib.Compile.t, and have requires_compile be lazy in Lib.Compile.t.

@rgrinberg rgrinberg requested review from a user, bobot and emillon January 8, 2019 06:27
@rgrinberg rgrinberg requested a review from hhugo as a code owner January 8, 2019 06:27
@ghost
Copy link
Copy Markdown

ghost commented Jan 8, 2019

I had to change threads to threads.posix for this to compile dune. I think that's fine for dune, since we might rely on posix semantics. But I don't think that users are going to know to do this. How do we handle threads in this case?

vmthreads are deprecated in 4.08 so eventually this extra complexity will go away. In the meantime, I'm not sure what the best option is :/ We could add a special case for threads though it's not very satisfying. Otherwise we could try to detect by analysing the META file that threads is just an alias rather than a proper library. Or just document that when using this option one needs to use threads.posix rather than threads. My preference is for the last option.

My idea is to have the compilation context check if the feature is enabled (in the dune project file) before returning requires_compile. If the feature is disabled, it will simply use requires_link and generate Includes.t with this value.

Seems good to me.

It's a bit annoying to calculate the requires_compile if it isn't going to be used every time. Any ideas on how restructure the code to avoid this? I was thinking perhaps we could make a constructor of Compilation_context.t that consumes a Lib.Compile.t, and have requires_compile be lazy in Lib.Compile.t.

What about making requires_compile be lazy everywhere?

@rgrinberg
Copy link
Copy Markdown
Member Author

vmthreads are deprecated in 4.08 so eventually this extra complexity will go away. In the meantime, I'm not sure what the best option is

When vmthreads will go away, will threads and threads.posix just be aliases of each other in findlib? If so, then we might as well copy that option.

What about making requires_compile be lazy everywhere?

Will do that

@ghost
Copy link
Copy Markdown

ghost commented Jan 8, 2019

When vmthreads will go away, will threads and threads.posix just be aliases of each other in findlib? If so, then we might as well copy that option.

I'm not sure yet, but possibly. Note that since we always set the mt_posix predicate, with dune threads is always an alias for threads.posix. Although I'm not sure how to take advantage of this fact without silently replacing threads by threads.posix in dependency lists, which doesn't feel right.

@rgrinberg
Copy link
Copy Markdown
Member Author

Although I'm not sure how to take advantage of this fact without silently replacing threads by threads.posix in dependency lists, which doesn't feel right.

What about changing the internal META for threads to alias threads to threads.posix?

In any case, since it's an experimental feature we can certainly just stick to documenting this limitation for now.

@ghost
Copy link
Copy Markdown

ghost commented Jan 8, 2019

the internal META is only used when the one installed by findlib is not found, so it's pretty much never used when using opam. Sticking to documenting the limitation seems like the simplest solution to me as well, and it will make users aware of the issue, which might exist for other libraries.

@rgrinberg rgrinberg force-pushed the strict-includes-take-2 branch 3 times, most recently from 60b167e to 43d79f4 Compare January 8, 2019 19:06
@rgrinberg
Copy link
Copy Markdown
Member Author

Apart from the documentation, this is ready for review.

@ghost
Copy link
Copy Markdown

ghost commented Jan 9, 2019

BTW, if we can indeed simplify requires_compile as suggested, then we should probably make requires_link lazy as in some cases it won't be needed at all and it is more expansive to compute.

@rgrinberg rgrinberg force-pushed the strict-includes-take-2 branch 3 times, most recently from eeac7e5 to c09dd2e Compare January 9, 2019 15:05
@ghost
Copy link
Copy Markdown

ghost commented Jan 9, 2019

Should we make requires_link lazy then? I'm pretty sure it's not needed when building a library.

@rgrinberg
Copy link
Copy Markdown
Member Author

Good point. Will make it lazy

@rgrinberg
Copy link
Copy Markdown
Member Author

Btw, should we rename this into something more descriptive? For example, no_transitive_deps?

@ghost
Copy link
Copy Markdown

ghost commented Jan 10, 2019

I suppose, yeah. It's true that from the point of view of a user who doesn't know much about the low-level details of OCaml compilation, "include" might seem a bit abstract. Maybe no_implicit_transitive_deps to be even more precise?

@rgrinberg
Copy link
Copy Markdown
Member Author

@diml I renamed it. I wonder if it would be good to have this toggle instead:

(implicit_transitive_deps false)

Perhaps if we change the default in dune 2.0, it would be nice for users to go back to the old setting.

@ghost
Copy link
Copy Markdown

ghost commented Jan 10, 2019

Good point, I agree with making it toggle.

Copy link
Copy Markdown
Collaborator

@emillon emillon left a comment

Choose a reason for hiding this comment

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

Looks good! I'm surprised that this "so" simple.
What do you think about adding a test case where the code uses a transitive dep but this mode is not active?

@rgrinberg
Copy link
Copy Markdown
Member Author

rgrinberg commented Jan 10, 2019

Test case added and now it's a boolean valued option

@rgrinberg rgrinberg force-pushed the strict-includes-take-2 branch from 6812e47 to 257745a Compare January 10, 2019 17:46
@rgrinberg
Copy link
Copy Markdown
Member Author

Another case where this option is useful:

Set it in the workspace file and then try to build a duniverse. This will let you discover places where dependencies are imprecise.

@rgrinberg rgrinberg force-pushed the strict-includes-take-2 branch from 257745a to b1e92e9 Compare January 10, 2019 18:24
Libraries should include references to their transitive dependencies

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Now, transitive dependencies must be listed to be compiled against

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@rgrinberg rgrinberg force-pushed the strict-includes-take-2 branch from b1e92e9 to a6217ab Compare January 10, 2019 18:25
@rgrinberg rgrinberg merged commit 53a36ed into ocaml:master Jan 10, 2019
@rgrinberg rgrinberg deleted the strict-includes-take-2 branch January 10, 2019 21:23
@rgrinberg rgrinberg restored the strict-includes-take-2 branch April 20, 2019 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants