Skip to content
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

feat: Add support for user-defined builtins with Dune plugins #214

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

bclement-ocp
Copy link
Contributor

This patch adds support for model extensions in Dolmen_loop using a similar mechanism to typing extensions.

Model extensions and typing extensions are now loaded by the binary through Dune's plugin mechanism, and the existing bvconv extension is moved to use the plugin mechanism.

Fixes #203

@bclement-ocp
Copy link
Contributor Author

the existing bvconv extension is moved to use the plugin mechanism

In retrospect, I am not 100% sure this is a good idea. I did this initially to have an example of usage of the plugin mechanism, but ended up writing two example plugins (abs_real, abs_real_split) which I think is better for that purpose since. I am open to reverting this part of the change.

@bclement-ocp
Copy link
Contributor Author

the existing bvconv extension is moved to use the plugin mechanism

This was causing build failures on the CI so no longer part of the PR. Instead there is support for builtin extensions when loading them at the CLI level.

@bclement-ocp
Copy link
Contributor Author

I did some late cleanup but this should be ready to review @Gbury

Copy link
Owner

@Gbury Gbury left a comment

Choose a reason for hiding this comment

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

Overall this looks good.

Note: you can rebase on current master to fix the CI bugs.

Result.map (fun ext -> (ext, kind)) (find_ext name)
in
let print ppf _p = Fmt.pf ppf "" in
Arg.conv (parse, print)
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is enough code to warrant it being mostly in a new file (extensions.ml ?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, will do.

add_plugin ok err e @@ parse_ext_opt e
) (builtin_extensions, []) (Dolmen.Sites.Plugins.Plugins.list ())
in
merge_extensions ok, List.fast_sort String.compare err
Copy link
Owner

Choose a reason for hiding this comment

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

Hm... I'm a bit worried by the cost of computing the list of all extensions systematically at startup (particularly since listing all dune plugins might involve a number of system calls).
Intuitively, we should only need that we want want to list all extensions, i.e. when a user asks for a list of extensions (or in error messages), but when loading an extension, we should be able to not need the lis tof all extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I did it this way because I initially wanted to preserve the behavior where the list of all available extensions is provided as an enum to Cmdliner. Since this is no longer the case (and there is --list-extensions instead), it makes sense to perform the listing lazily; will change.

src/loop/typer.ml Outdated Show resolved Hide resolved
This patch adds support for model extensions in `Dolmen_loop` using a
similar mechanism to typing extensions.

Model extensions and typing extensions are now loaded by the binary
through Dune's plugin mechanism, and the existing `bvconv` extension is
moved to use the plugin mechanism.

Fixes Gbury#203
 - Move code dealing with extensions out of the Options module and into
   a new Extensions module

 - Clean up examples (notably avoid an almost-empty plugin in
   abs_real_split by defining the builtin in the typing plugin; it does
   not make sense to use the model plugin without the typing plugin)

 - Load dune plugins lazily

 - Use a hash table to find binary extensions (but not typing
   extensions/model extensions)

 - Allow override of builtin extensions by dune plugins
@bclement-ocp
Copy link
Contributor Author

Made the requested changes + some others following (old) offline discussions:

  • Move code dealing with extensions out of the Options module and into
    a new Extensions module

  • Clean up examples (notably avoid an almost-empty plugin in
    abs_real_split by defining the builtin in the typing plugin; it does
    not make sense to use the model plugin without the typing plugin)

  • Load dune plugins lazily

  • Use a hash table to find binary extensions (but not typing
    extensions/model extensions)

  • Allow override of builtin extensions by dune plugins

@bclement-ocp
Copy link
Contributor Author

@Gbury ping

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.

Supporting evaluation for custom functions
2 participants