Skip to content

Conversation

@shonfeder
Copy link
Member

Closes #12085
Supersedes #12002

This PR is the second of a set of four PRs related to the introduction of Parameterized Libraries in Dune.

⚠️ This feature is only available with OxCaml until it is upstream to the compiler.

It contains multiples changes:

  • It adds support for parameter in the implements field.
  • It provides some tests to make sure the functionality act according to the specification. They are still guarded by the oxcaml variable.
  • It extends the documentation with our case. More explanation about the feature will be addressed in future PRs, specific to the documentation.

TODO

@shonfeder shonfeder force-pushed the maiste/library_param_impl branch from f7c52d8 to 08b368d Compare September 4, 2025 02:53
Copy link
Member Author

@shonfeder shonfeder left a comment

Choose a reason for hiding this comment

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

Copying over the outstanding change requests from #12002

@art-w art-w force-pushed the maiste/library_param_impl branch 2 times, most recently from a9b566d to dcb3793 Compare September 4, 2025 10:58
@shonfeder
Copy link
Member Author

Thanks for the fixes, @art-w! I'll let you take this from here :D

IIUC, this is ready for review, so I will mark it as such.

@shonfeder shonfeder marked this pull request as ready for review September 4, 2025 23:53
(Lib_name.to_string implements)
];
(match Lib_info.kind info with
| Parameter | Virtual -> ()
Copy link
Member

Choose a reason for hiding this comment

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

The Parameter case should be "assert false" I believe

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm in the current implementation the Parameter case is useful, as a library that has an implements still get turned into a "vlib" which associates the library with the (virtual or parameter) lib it implements. I suppose we could avoid reusing parts of the virtual logic however, with a new sum type above. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's confusing indeed then. Turning it into a sum type (or a record with a kind field) would clarify this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I pushed a refactoring of Virtual_rules to distinguish between the three implements possibilities: no implements, implementing a virtual module or implementing a parameter. I think virtual_rules.ml could be further renamed to implements.ml, if the name "virtual" has too much connotation? :)

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Just finished a round of review.

@art-w
Copy link
Collaborator

art-w commented Sep 5, 2025

Thanks for the quick review! I've marked the simpler issues as resolved by the last commit, but I've left open the ones where I would appreciate your input :)

in
match argument with
| None -> []
| Some parameter -> [ "-as-argument-for"; Module_name.to_string parameter ])
Copy link
Member

Choose a reason for hiding this comment

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

Could you remind where we add a dependency on the cmi of the parameter? Is it added a library dependency somewhere?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the dependency to the parameter is added by the pre-existing code for vlibs:

dune/src/dune_rules/lib.ml

Lines 1025 to 1034 in 07d0a93

let* requires =
Memo.return
(let open Resolve.O in
let* requires = requires in
match implements with
| None -> Resolve.return requires
| Some impl ->
let+ impl = impl in
impl :: requires)
in

Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
This version works only in the singleton case at it aggressively
add the module implements to all the module. In the case of the
singleton it will break.

Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
This commit extends the support to find the root module from
the library name which must always exists locally because we
declare the implementation.

Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
maiste and others added 15 commits September 8, 2025 09:57
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: Etienne Marais <[email protected]>
Signed-off-by: ArthurW <[email protected]>
@art-w art-w force-pushed the maiste/library_param_impl branch from 3e40fdc to c9fa595 Compare September 8, 2025 11:15
open Import
open Memo.O

let setup_copy_rules_for_impl ~sctx ~dir vimpl =
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Library %s isn't virtual and cannot be implemented"
(Lib_name.to_string implements)
];
let+ vlib_modules, vlib_foreign_objects =
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shonfeder shonfeder requested a review from rgrinberg September 8, 2025 15:14
@art-w
Copy link
Collaborator

art-w commented Sep 8, 2025

I think this is ready for another review :) . I had to move large chunks of code in the last commit to clarify the implements field handling of virtual modules and library parameter, which makes this PR looks bigger than it really is -- I would be happy to submit that last commit as a follow-up PR if it's easier to review.

@shonfeder shonfeder enabled auto-merge (squash) September 9, 2025 14:54
@shonfeder shonfeder merged commit 2e0a649 into main Sep 9, 2025
1 of 2 checks passed
@shonfeder shonfeder deleted the maiste/library_param_impl branch September 9, 2025 14:54
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.

[OxCaml] Parameterized libraries: parameter implementation

5 participants