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

feature: load modules in the repl #5940

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

rgrinberg
Copy link
Member

@rgrinberg rgrinberg commented Jun 30, 2022

This PR introduces the $ dune ocaml top-level src/module.ml command. The purpose of this command is to load a particular module for interactive development. The way it differs from the other toplevel commands is that it only build the minimal amount needed to load a particular module and then it evaluates the module's source with #use. The point of this is to avoid sealing the module with the mli and thereby allowing interactive development with all the private parts of the module.

@ulugbekna this should work nicely for vscode

@nojb
Copy link
Collaborator

nojb commented Jun 30, 2022

What's the relation between this PR and dune top ?

@rgrinberg
Copy link
Member Author

rgrinberg commented Jun 30, 2022

What's the relation between this PR and dune top ?

Just updated the PR description.

@rgrinberg rgrinberg requested review from nojb, emillon and Alizter June 30, 2022 17:05
@rgrinberg rgrinberg added this to the 3.4.0 milestone Jun 30, 2022
@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch 11 times, most recently from 4228460 to c6c0096 Compare July 1, 2022 22:18
@ejgallego
Copy link
Collaborator

I guess this needs documentation, right?

@rgrinberg
Copy link
Member Author

I guess this needs documentation, right?

Do you think we need something in the online manual or is the man page enough?

@ejgallego
Copy link
Collaborator

I guess this needs documentation, right?

Do you think we need something in the online manual or is the man page enough?

Leaving this to doc experts, but I see dune utop appears in usage.rst , so maybe worth mentioning it too?

@emillon
Copy link
Collaborator

emillon commented Jul 4, 2022

Sidenote, dune ocaml subcommands are not very discoverable. So I agree that a quick mention would be useful:

% dune ocaml       
dune ocaml: is a command group and requires a command argument.
Usage: dune ocaml [OPTION]... 
Try `dune ocaml --help' or `dune --help' for more information.
 % dune ocaml --help=plain
NAME
       dune-ocaml

SYNOPSIS
       dune ocaml [OPTION]... 

OPTIONS
       --help[=FMT] (default=auto)
           Show this help in format FMT. The value FMT must be one of `auto',
           `pager', `groff' or `plain'. With `auto', the format is `pager` or
           `plain' whenever the TERM env var is `dumb' or undefined.

       --version
           Show version information.

@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch 3 times, most recently from 0e86fb6 to fe8b0f7 Compare July 4, 2022 22:58
@rgrinberg rgrinberg requested a review from christinerose as a code owner July 4, 2022 22:58
Copy link
Contributor

@christinerose christinerose left a comment

Choose a reason for hiding this comment

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

Two minor capitalisations.

doc/toplevel-integration.rst Show resolved Hide resolved
bin/top.ml Outdated Show resolved Hide resolved
res
in
let* dir_contents =
drop_rules @@ fun () -> Dune_rules.Dir_contents.get sctx ~dir
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is drop_rules doing here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The function returns the rules in addition, but we don't need the rules since they've already been setup.

Copy link
Collaborator

@ejgallego ejgallego left a comment

Choose a reason for hiding this comment

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

LGTM

@rgrinberg
Copy link
Member Author

Does the work with dialects?

Let me give this a try. Although I would say that this issue isn't blocking the PR.

Does it make sense to consider a utop version of the command which would launch utop directly, in the same way as dune utop does?

We could add this if there's demand for it. I personally preferred the approach of building the toplevel binary ourself, but Jeremie liked doing everything through directives more.

Also in the same direction, if indeed we have both "top" and "utop" variations of the command, does it make sense to extend those commands, intead of dune ocaml?

I would say that we should deprecate dune top and dune utop and stick to the dune ocaml subcommand for all this stuff.

There's still a few issues with this PR btw:

  • It doesn't evaluate -open Alias__module__ in the toplevel
  • It doesn't load the warnings flags from the stanza.
  • This is the biggest problem: #directory $stanza/obj_dir contains stale artifacts that lead to some inconsistent assumptions issues.

The first two problems can be fixed with additional directives. Although if we went for the approach of building the toplevel (like dune utop) we wouldn't even this stuff :/

To solve the 3rd problem, we must prepare an object directory free of stale artifacts. The simplest way to do that is just to copy the objects into some temp dir and use that. A more clever way is to introduce rules for each modules that will setup the subdirectory with only the relevant artifacts.

@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch from fe8b0f7 to e04fd0d Compare July 19, 2022 18:03
bin/top.ml Show resolved Hide resolved
bin/top.ml Outdated Show resolved Hide resolved
bin/top.ml Outdated Show resolved Hide resolved
bin/top.ml Show resolved Hide resolved
@emillon emillon force-pushed the ps/rr/feature__load_modules_in_the_repl branch 5 times, most recently from 7279d02 to ab352d4 Compare July 20, 2022 13:47
@rgrinberg rgrinberg modified the milestones: 3.4.0, 3.5.0 Jul 20, 2022
@emillon
Copy link
Collaborator

emillon commented Jul 20, 2022

@rgrinberg I was about to include it into 3.4 even with the limitations you mentioned but happy to postpone to 3.5.

@rgrinberg
Copy link
Member Author

The issue with the stale artifacts makes this feature not very ergonomic at the moment unfortunately. I'd rather solve this issue first

@rgrinberg
Copy link
Member Author

Sidenote, dune ocaml subcommands are not very discoverable. So I agree that a quick mention would be useful:

That's actually due to a bug with our fork of cmdliner. Once we update our version of cmdliner, the per command docs should appear.

@rgrinberg rgrinberg modified the milestones: 3.5.0, 3.6.0 Oct 5, 2022
@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch from ab352d4 to 371d15a Compare November 3, 2022 17:35
[ `Library of Dune_file.Library.t
| `Executables of Dune_file.Executables.t
]
Module_name.Map.t
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

ftr: Merged into 8b1d684

@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch 6 times, most recently from 8c3d5cb to d0aaeae Compare November 3, 2022 21:56
introduce a $ dune ocaml top-module command to load modules directly

Signed-off-by: Rudi Grinberg <[email protected]>

ps-id: 79f4ac2d-0e7b-4983-9bee-c410d534bc8e
@rgrinberg rgrinberg force-pushed the ps/rr/feature__load_modules_in_the_repl branch from d0aaeae to 1bc4e91 Compare November 3, 2022 22:16
@rgrinberg rgrinberg merged commit 8a59adf into main Nov 3, 2022
@Alizter Alizter deleted the ps/rr/feature__load_modules_in_the_repl branch November 12, 2022 15:11
emillon added a commit to emillon/opam-repository that referenced this pull request Nov 14, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.6.0)

CHANGES:

- Forbid multiple instances of dune running concurrently in the same workspace.
  (ocaml/dune#6360, fixes ocaml/dune#236, @rgrinberg)

- Allow promoting into source directories specified by `subdir` (ocaml/dune#6404, fixes
  ocaml/dune#3502, @rgrinberg)

- Make dune describe workspace return the correct root path
  (ocaml/dune#6380, fixes ocaml/dune#6379, @esope)

- Introduce a `$ dune ocaml top-module` subcommand to load modules directly
  without sealing them behind the signature. (ocaml/dune#5940, @rgrinberg)

- [ctypes] do not mangle user written names in the ctypes stanza (ocaml/dune#6374, fixes
  ocaml/dune#5561, @rgrinberg)

- Support `CLICOLOR` and `CLICOLOR_FORCE` to enable/disable/force ANSI
  colors. (ocaml/dune#6340, fixes ocaml/dune#6323, @MisterDA).

- Forbid private libraries with `(package ..)` set from depending on private
  libraries that don't belong to a package (ocaml/dune#6385, fixes ocaml/dune#6153, @rgrinberg)

- Allow `Byte_complete` binaries to be installable (ocaml/dune#4873, @AltGr, @rgrinberg)

- Revive `$ dune external-lib-deps` under `$ dune describe external-lib-deps`.
  (ocaml/dune#6045, @moyodiallo)

- Fix running inline tests in bytecode mode (ocaml/dune#5622, fixes ocaml/dune#5515, @dariusf)

- [ctypes] always re-run `pkg-config` because we aren't tracking its external
  dependencies (ocaml/dune#6052, @rgrinberg)

- [ctypes] remove dependency on configurator in the generated rules (ocaml/dune#6052,
  @rgrinberg)

- Build progress status now shows number of failed jobs (ocaml/dune#6242, @Alizter)

- Allow absolute build directories to find public executables. For example,
  those specified with `(deps %{bin:...})` (ocaml/dune#6326, @anmonteiro)

- Create a fake socket file `_build/.rpc/dune` on windows to allow rpc clients
  to connect using the build directory. (ocaml/dune#6329, @rgrinberg)

- Prevent crash if absolute paths are used in the install stanza and in
  recursive globs. These cases now result in a user error. (ocaml/dune#6331, @gridbugs)

- Add `(glob_files <glob>)` and `(glob_files_rec <glob>)` terms to the `files`
  field of the `install` stanza (ocaml/dune#6250, closes ocaml/dune#6018, @gridbugs)

- Allow `:standard` in the `(modules)` field of the `coq.pp` stanza (ocaml/dune#6229,
  fixes ocaml/dune#2414, @Alizter)

- Fix passing of flags to dune coq top (ocaml/dune#6369, fixes ocaml/dune#6366, @Alizter)

- Extend the promotion CLI to a `dune promotion` group: `dune promote` is moved
  to `dune promotion apply` (the former still works) and the new `dune promotion
  diff` command can be used to just display the promotion without applying it.
  (ocaml/dune#6160, fixes ocaml/dune#5368, @emillon)
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.

7 participants