Skip to content

Conversation

@art-w
Copy link
Collaborator

@art-w art-w commented Nov 10, 2025

Follow-up on the instantiation of parameterised libraries #12561 to support inline_tests (marking this PR as a draft since only the last commit is new).

To run the inline tests of a parameterised library, the user should specify with (arguments ...) which implementation of the parameters to use, as otherwise the test can't be ran.

Fix #12110

@Alizter
Copy link
Collaborator

Alizter commented Nov 10, 2025

Is ppx_expect building in oxcaml now?

@art-w
Copy link
Collaborator Author

art-w commented Nov 10, 2025

ppx_inline_test works yes, but I think the nix flake is using a more edgy version of OxCaml than the one published in their opam-repo... I'm looking into it.

Copy link
Member

@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.

Looks good! I have just a few questions and 2 small suggestions

Comment on lines +296 to +305
implementation of the parameters to use with the ``arguments`` field:

.. code:: ocaml
(library
(name foo)
(parameters a_param b_param)
(inline_tests
(arguments a_impl b_impl)))
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggstion, feel free to disregard:

I think it can help with readability to accompany examples with descriptions how how to map the example to the general concept:

Suggested change
implementation of the parameters to use with the ``arguments`` field:
.. code:: ocaml
(library
(name foo)
(parameters a_param b_param)
(inline_tests
(arguments a_impl b_impl)))
implementation of the parameters to use with the ``arguments`` field. E.g.,
if `foo` is a parameterised library, taking parameters `a_param` and
`b_param`, you can specify the implementations to use for the parameters for
inline tests as follows:
.. code:: ocaml
(library
(name foo)
(parameters a_param b_param)
(inline_tests
(arguments a_impl b_impl)))

IMO, this can leave the reader with less to puzzle out, tho it does come at the cost of redundancy.

Comment on lines +270 to +272
let open Memo.O in
let+ dep = Lib.DB.resolve lib_db (loc, dep) in
loc, dep)
Copy link
Member

Choose a reason for hiding this comment

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

On the one hand, I like that the local open of Memo.O makes clear where our binding ops are coming from. On the other hand, since we are also already in the context of a monadic bind, this made me assume we must be in some other binding context, so I went looking up the file. From line 2, it seems that Memo.O is just opened thought this file already. So this means the applicative bind on line 253 just above is also Memo.O.

My conclusion is that the extra local open here actually makes the code more confusing, given the pre-existing context. My suggestion is to stick with the surrounding convention for now

Suggested change
let open Memo.O in
let+ dep = Lib.DB.resolve lib_db (loc, dep) in
loc, dep)
let+ dep = Lib.DB.resolve lib_db (loc, dep) in
loc, dep)

and maybe do a followup to make the binding context more narrowly scoped throughout this file in a followup, if you think it is worth it.

Resolve.Memo.lift_memo
@@ Memo.List.map info.arguments ~f:(fun (loc, dep) ->
let open Memo.O in
let+ dep = Lib.DB.resolve lib_db (loc, dep) in
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not also use Library.best_name on the dep here?

Comment on lines +48 to +49
Hint: Pass an argument implementing param to the dependency, or add
(parameters param)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how to interpret

or add (parameters param)

Isn't (parameters param) already in the stanza? What does fixing using the second disjunct in the hint look like?

3 | (parameters param)
4 | (inline_tests)
5 | (preprocess (pps ppx_inline_test)))
Error: Parameter "param" is missing.
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this error more exact and point to the parameters field?

let pp_map =
Staged.unstage
@@ Pp_spec.pped_modules_map
(Dune_lang.Preprocess.Per_module.without_instrumentation preprocess)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this change just an unrelated bug fix?

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: support for applying library arguments in inline tests

4 participants