ocaml-community / utop

Universal toplevel for OCaml
Other
838 stars 110 forks source link

Topfind ignores Sys.interactive in utop #253

Open Maelan opened 6 years ago

Maelan commented 6 years ago

In utop, by contrast with ocaml, Topfind apparently ignores the value of Sys.interactive and prints its greeting message anyway.

Tested with OCaml 4.07.0, ocamlfind 1.8.0, utop 2.2.0.

In ocaml, Topfind apparently honours Sys.interactive when it is first loaded (however, when loaded again, as can be seen in the output below, it repeats the same behaviour even if Sys.interactive has since changed; not sure if it is a bug, nor if it is related to this issue).

$ ocaml
        OCaml version 4.07.0

# Sys.interactive := false ;;
- : unit = ()
# #use "topfind" ;;
- : unit = ()
- : unit = ()
# Sys.interactive := true ;;
- : unit = ()
# #use "topfind" ;;
- : unit = ()
- : unit = ()
# ^D

$ ocaml
        OCaml version 4.07.0

Unknown directive `fail'.
# Sys.interactive := true ;;
- : unit = ()
# #use "topfind" ;;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# Sys.interactive := false ;;
- : unit = ()
# #use "topfind" ;;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# ^D

In utop, Topfind always prints its greeting message.

$ utop
────────────────┬─────────────────────────────────────────────────────────────┬─────────────────
                │ Welcome to utop version 2.2.0 (using OCaml version 4.07.0)! │                 
                └─────────────────────────────────────────────────────────────┘                 
Unknown directive `fail'.

Type #utop_help for help about using utop.

─( 23:10:29 )─< command 0 >──────────────────────────────────────────────────────{ counter: 0 }─
utop # Sys.interactive := false ;;
- : unit = ()
─( 23:10:29 )─< command 1 >──────────────────────────────────────────────────────{ counter: 0 }─
utop # #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
─( 23:10:38 )─< command 2 >──────────────────────────────────────────────────────{ counter: 0 }─
utop # ^D

This is especially annoying when chaining several init scripts, which all load topfind because they need it and cannot assume it has been done by someone else.

whitequark commented 6 years ago

This is probably caused by toplevel expunging.

Maelan commented 5 years ago

How to fix it? Using utop-full instead of utop does not appear to change anything.

ghost commented 5 years ago

@Maelan when you build a toplevel, by default all the modules that are linked in this toplevel are visible and accessible to code evaluated inside this toplevel. This can be an issue because:

For instance, this means that you cannot load a library with a toplevel module called Path inside the toplevel. To workaround this issue, there is an expunge step that hides all these modules. They are still linked in, but they cannot be accessed from code evaluated inside the toplevel.

To check whether the issue you are seeing is related to expunging, you can try to reproduce it with utop-full, which is non-expunged version of utop.

pmetzger commented 5 years ago

Perhaps some documentation improvements would be in order here.

Maelan commented 1 month ago

Any news on this issue? It is still there as of utop 2.13.1 and ocamlfind 1.9.6.

pmetzger commented 1 month ago

@Maelan What would you see as an appropriate resolution?

Maelan commented 1 month ago

Sorry I don’t know, because I don’t know the internals of utop, and because I didn’t get how the reported behavior was related to module expunging as mentioned in previous messages. Using utop-full instead of utop did not make a difference. The only thing I can tell is that the currently observed behavior (Topfind printing its welcome message regardless of Sys.interactive) looks like a bug and that, unless utop devs say it is a feature, it should instead exhibit the same behavior as the vanilla ocaml toplevel (printing the welcome message is conditioned upon the value of Sys.interactive).