Skip to content

feat(oxcaml): support parameter implementation#12002

Closed
maiste wants to merge 16 commits intoocaml:mainfrom
maiste:library_param_impl
Closed

feat(oxcaml): support parameter implementation#12002
maiste wants to merge 16 commits intoocaml:mainfrom
maiste:library_param_impl

Conversation

@maiste
Copy link
Copy Markdown
Collaborator

@maiste maiste commented Jul 8, 2025

Closes #12085

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

@maiste maiste added the oxcaml Related to the support to OxCaml functionnalities label Jul 8, 2025
@maiste maiste requested a review from art-w July 8, 2025 14:40
@maiste maiste force-pushed the library_param_impl branch from ec4d9c6 to 665cccd Compare July 8, 2025 14:43
Copy link
Copy Markdown
Collaborator

@art-w art-w left a comment

Choose a reason for hiding this comment

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

Great! Can we add a test with a library that implements a parameter that doesn't exist? (this should be caught by the existing virtual modules logic, but the error message may need an update)

@maiste maiste requested a review from rgrinberg July 10, 2025 12:59
@maiste maiste force-pushed the library_param_impl branch from a0027e4 to a1349eb Compare July 22, 2025 13:39
@maiste maiste force-pushed the library_param_impl branch from a1349eb to e6e5805 Compare July 31, 2025 12:51
@maiste maiste changed the base branch from library_parameter to main July 31, 2025 12:52
maiste and others added 16 commits July 31, 2025 14:52
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
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 <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
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 <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
Signed-off-by: Etienne Marais <self@maiste.fr>
@maiste maiste force-pushed the library_param_impl branch from e6e5805 to a45b410 Compare July 31, 2025 12:52
@maiste maiste marked this pull request as ready for review July 31, 2025 12:53
@maiste maiste requested a review from art-w July 31, 2025 14:26
(fun () -> build_shared ~native_archives ~sctx lib ~dir ~flags)
;;

let parameterize_root_module ~parameter ~root_module_name modules =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of storing this information in the module, how about just add a field to the compilation context designating which module is implementing a parameter. Should be easier to understand and more efficient.

| Ok None ->
(* The parameter must have a module name otherwise it can't exist. *)
assert false
| Error err -> Resolve.raise_error_with_stack_trace err
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This error needs to be delayed rather than forced.

@shonfeder shonfeder self-assigned this Aug 5, 2025

$ . ./helpers.sh

We create two parameters, on public, the other one local.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
We create two parameters, on public, the other one local.
We create two parameters, one public, the other one local.

Comment on lines +38 to +39
We implements a non parameter library (neither a virtual module). It should
fail with the correct error message.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
We implements a non parameter library (neither a virtual module). It should
fail with the correct error message.
Supplying a non-parameter, regular library (not a virtual module), as an implementation should
fail with the correct error message.

Comment on lines +49 to +52
3 | (implements missing_foo))
^^^^^^^^^^^
Error: Library "missing_foo" not found.
-> required by alias default
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Caveat that I am still getting up to speed here, but is this the right error message? I would rather expect something like parameter interface not found.

-> required by alias default
[1]

We implements the parameter using library calling a wrong parameter name.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
We implements the parameter using library calling a wrong parameter name.
We implement the parameter using library calling a wrong parameter name.

Comment on lines +57 to +69
$ rm -rf _build foo_impl
$ make_dir_with_dune "foo_impl" <<EOF
> (library
> (name foo_impl)
> (implements missing_foo))
> EOF
$ dune build
File "foo_impl/dune", line 3, characters 13-24:
3 | (implements missing_foo))
^^^^^^^^^^^
Error: Library "missing_foo" not found.
-> required by alias default
[1]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like the exact same test as the one on on lines 41 to 53. Perhaps a needed update to differentiate them was missed? Or am I missing something on my end?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As the user provides an element which doesn't exist, we can't differentiate if it is a virtual library or a parameter. We don't have the information to characterize the element.

Copy link
Copy Markdown
Member

@shonfeder shonfeder Aug 26, 2025

Choose a reason for hiding this comment

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

Ok, so we cannot differentiate these two cases, but then I supposed it doesn't help anything to test the same scenario twice?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Initially, it was to make sure we fail if the implements was fed, either with a non-existent parameter (or library) or a non parameterized library.

It depends if we go to a strict separation with Virtual or not. If we do, we might want to keep this test to make sure we are not using a library that shouldn't be used.

@shonfeder
Copy link
Copy Markdown
Member

shonfeder commented Aug 19, 2025

I've assigned myself here since I'll be taking this over from @maiste. My initial review comments here just notes to self (with the exception of #12002 (comment), which is a question for @rgrinberg).

@shonfeder
Copy link
Copy Markdown
Member

I don't seem to be able to push to this branch, so I am inclined to just replace this with a new PR. I'll copy the context over. I'll do it tomorrow, unless I get objections.

@maiste
Copy link
Copy Markdown
Collaborator Author

maiste commented Aug 26, 2025

I don't see a problem with opening a new PR. However, you should be able to push on the branch unless you don't have sufficient rights on the repository.
image

@shonfeder
Copy link
Copy Markdown
Member

I have a branch locally updating this on top of. #12253 I will push to this or replace it tomorrow. Just ran out of time.

@shonfeder
Copy link
Copy Markdown
Member

Thanks @maiste. I think I must not have maintainer perms, because I just get permission denied errors consistently.

@shonfeder
Copy link
Copy Markdown
Member

Superseded by #12392

@shonfeder shonfeder closed this Sep 4, 2025
@maiste maiste deleted the library_param_impl branch September 4, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oxcaml Related to the support to OxCaml functionnalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OxCaml] Parameterized libraries: parameter implementation

4 participants