utop icon indicating copy to clipboard operation
utop copied to clipboard

#info directive

Open kandu opened this issue 6 years ago • 29 comments
trafficstars

This PR adds a depopt, ocp-index to utop. If utop is built when ocp-index is installed, a new directive, #infoof, will present.

This directive works similarly to #typeof. The symbol resolving and completion mechanism is based on the current Env of the Toploop. That is, if we type open String;; in utop, #infoof "concat" will still find out the very infomation of String.concat

Click to expand

image

kandu avatar Jul 26 '19 07:07 kandu

I have to say that as an English speaker I find "#infoof" amazingly hard to read. (I also wouldn't guess what it does from the name, the first parse that comes to mind is "in foof" and that's pretty incomprehensible...)

pmetzger avatar Jul 26 '19 23:07 pmetzger

Yeah this isn't a great name. #info is fine; #doc is fine; #info_of could work.

bluddy avatar Jul 26 '19 23:07 bluddy

I'd say "#info" or "#doc".

pmetzger avatar Jul 26 '19 23:07 pmetzger

Ha, at the first glance. I feel that the name is very funny. foof ʕoٹoʔ ʕ•̀ω•́ʔ

kandu avatar Jul 27 '19 00:07 kandu

I think #info is fine.

kandu avatar Jul 27 '19 00:07 kandu

I've renamed the pull request btw.

pmetzger avatar Jul 28 '19 20:07 pmetzger

That's a nice feature :) BTW, I would make the dependency on ocp-index be a required one rather than an optional one. Optional dependencies always end up being annoying in the long run.

ghost avatar Jul 30 '19 12:07 ghost

The implementation of ocp-index seems not stable for now(we have to fork a clean room for it). I'd like to keep it as an optional dependency to observe for a period of time. When everything is stable enough, we then make it as a required dependency. Is this ok?

kandu avatar Jul 31 '19 08:07 kandu

I have no opinion on the optional vs. required dependency issue.

How do we decide when this is okay to merge?

pmetzger avatar Jul 31 '19 16:07 pmetzger

@diml I've seen negative opinions about optional dependencies, but what is the main objection against them?

bluddy avatar Jul 31 '19 16:07 bluddy

@kandu that seems reasonable yeah.

@pmetzger I'd suggest that someone test it on its machine, just to make sure nothing obvious was missed, and eyeball the code to make sure things seem reasonable. For instance that no unwanted dependency was added by accident or a rootkit was slipped in (just joking here, though we should definitely do it for new contributors).

Then I'd say it's good to merge. This looks like a feature that is worth having.

@bluddy the main source of pain is recompilation. When you install a new package, you have to recompile all already installed packages that have a depopts on this package plus all their reverse dependencies. For utop I guess it's probably not too bad as it doesn't have many reverse dependencies.

But in this case there is also something else: whenever you setup a new switch, you now have to remember to install both utop and ocp-index if you want all the features of utop.

ghost avatar Aug 01 '19 10:08 ghost

It seems to me that requiring ocp-index as mandatory has only one defect, which is that sometimes it is broken when a new release comes out.

pmetzger avatar Aug 01 '19 13:08 pmetzger

yeah, considering about this, to keep it as an optional dependency is a good option since what you've just said implies we are confident that zed, lambda-term and utop will keep the pace with new ocaml releases better than ocp-index will do :) And once that happens, utop will be still installable without the presenting of #info directive temporarily.

kandu avatar Aug 01 '19 13:08 kandu

This feature is disabled on Windows since Unix.fork is not available on it.

By the way, are there any easy expressions in dune which I can use to define required libraries more flexibly? like:

(libraries
  ((and (= %{os_type} Unix) (= (system "opam var ocp-index:installed") "true"))
    ocp-index))

Only requires ocp-index as dependency when we are on Unix and ocp-index is installed.

kandu avatar Aug 04 '19 10:08 kandu

@kandu Good question. I don't know. Perhaps you should ask the Dune maintainers?

pmetzger avatar Aug 04 '19 12:08 pmetzger

Not really, though there is a ticket about this.

What about using spawn? It's a portable and more efficient way of spawning sub-processes. Note that it's under the janestreet org, however it is developed on github as a normal open source project, so you can expect the API to be stable.

ghost avatar Aug 05 '19 08:08 ghost

There are two ways to use ocp-index.

  1. to invoke the ocp-index excutable every time when user types #info "something". So we can call Unix.create_process or spawn to invoke it. This works on all OSes, including Windows. But we'll always tolerate the lag, especially when inquiring from a big library like core_kernel.

  2. to use the LibIndex library, create and keep the index data permanently in a process memory. Module info is cached in the lazy-evaluation data structure when user re-inquire some info of the same library. But because of the implementation issuse, we have to workaround it, to fork a clean room for it or the CPU will hang. But since Unix.fork is not implemented on Windows, we have to disable this feature on Windows or we have to either create a standalone executable wrapping LibIndex or we add a new cmd-opt to utop to tell it to work in "ocp-index-server" mode and then spawn a child utop to inquire info. We now just simply disable it on Windows.

I think the second way is preferable, ocp-index developers will eventually fix the bug and we will not need to fork a clean room for it and thus it will work on all OSes. The lack of Windows support is temporary.

kandu avatar Aug 05 '19 15:08 kandu

Hi, @AltGr @Drup The step-to-reproduce is quite obvious, Should I create a new issue in https://github.com/OCamlPro/ocp-index/ ?

kandu avatar Aug 05 '19 15:08 kandu

I see. Personally, I would recommend to fix ocp-index first. It means that we have to wait before making this feature available to users, but on the other hand when we release it both utop and ocp-index will be in a better state.

ghost avatar Aug 06 '19 07:08 ghost

Wow, this looks great, thanks! @kandu, if you could open an issue as you proposed, that'd be very helpful and I'll look into it. :)

AltGr avatar Aug 06 '19 08:08 AltGr

Ah, thanks! here is the issue report https://github.com/OCamlPro/ocp-index/issues/136

kandu avatar Aug 06 '19 11:08 kandu

Great feature! Method 2 is clearly preferable, and libindex should be fairly easy to use. Let's try to beat ocp-index into shape so that everything works fine :p

Drup avatar Aug 15 '19 11:08 Drup

btw, why not show the doc information in the suggestion bar on the bottom? This is what bpython does for example.

mimoo avatar May 11 '21 21:05 mimoo

BTW, I note this has been stalled out for a long time. What do we need to do to get it moving?

pmetzger avatar May 12 '21 00:05 pmetzger

@pmetzger I guess someone has to fix https://github.com/OCamlPro/ocp-index/issues/136

bbatsov avatar Jul 19 '22 12:07 bbatsov

What do we need to do to get this merged?

pmetzger avatar Sep 08 '22 15:09 pmetzger

I'm not familiar with the implementation of this PR, but if it just adds a new directive, I don't think it has to be maintained as part as utop. It can be implemented as something that when #require'd, will add the directive. Users can call utop -require ocpindex.top or add this to their dotfiles to do it automatically. Would that work for you?

emillon avatar Sep 08 '22 15:09 emillon

Up to @kandu.

pmetzger avatar Sep 08 '22 15:09 pmetzger

I note that this is still hanging around; @kandu you should finish it.

pmetzger avatar May 07 '23 13:05 pmetzger