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

toplevels built with ocamlmktop do not support opening files compiled with -rectypes #4460

Closed
vicuna opened this Issue Nov 30, 2007 · 9 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

commented Nov 30, 2007

Original bug ID: 4460
Reporter: herbelin
Assigned to: @garrigue
Status: closed (set by @garrigue on 2010-04-27T07:26:33Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.10.0
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @glondu

Bug description

This looks similar to bug report 4402 with ocamlmktop instead of ocamldebug.

The following script allows to reproduce the problem.
#touch foo.ml
#ocamlc -c -rectypes foo.ml
#ocamlmktop -o mytop
#mytop
open Foo
Unit Foo imports from , which uses recursive types.
The compilation flag -rectypes is required

Adding option -rectypes to ocamlmktop does not change anything (maybe should it? or has topmain.ml to systematically set Clflags.recursive_types to true?)

File attachments

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 30, 2007

Comment author: jm

Try to add -rectypes to your custom toplevel:

% ./mytop -rectypes
Objective Caml version 3.10.1+dev3 (2007-11-26)

open Foo;;

HTH

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 30, 2007

Comment author: herbelin

Adding -rectypes to the custom toplevel command line works for the simple problem mentioned above but not in the more general case (which is in fact our real case) where the custom toplevel has its own parser for the arguments of the command line .

Would it be possible though to do so that the custom toplevel has automatically the recursive_types flag set? I tried to add Clflags.recursive_types := true in foo.ml but I couldn't get the Clflags module visible when compiling foo.ml, even with toplevellib.cma loaded. Thanks in advance.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 30, 2007

Comment author: jm

Would it be possible though to do so that the custom toplevel
has automatically the recursive_types flag set?
I do not see anything that could help in topdirs.mli, topmain.mli or toploop.mli.
Neither any toplevel directive that would do the job.
And Sys.argv could not be extended.

So you may have to use a shell alias:
alias mytop='mytop -rectypes'
Or a shell script mytop.sh:
#!/bin/sh
mytop -rectypes

I tried to add Clflags.recursive_types := true in foo.ml
but I couldn't get the Clflags module visible
when compiling foo.ml, even with toplevellib.cma loaded.
That's because you need clflags.cmi which is not inside
the binaries of ocaml (in ocamlc -where I mean),
but if you have the sources of your ocaml
in /usr/local/src/ocaml for instance, then you can do:
% ocamlc -c -rectypes foo.ml
% cat set_rectypes.ml
let _ =
print_endline "Set rectypes.";
Clflags.recursive_types := true

% ocamlmktop -o mytop_rectypes -I /usr/local/src/ocaml/utils set_rectypes.ml
% ./mytop_rectypes
Set rectypes.
Objective Caml version 3.10.1+dev3 (2007-11-26)

open Foo;;

type t = t -> t;;

type t = t -> t

HTH

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 16, 2007

Comment author: @garrigue

I think that the original report is correct. Indeed,
ocamlmktop -rectypes should set the resulting toplevel to
use recursive types. This is because it is unsafe to use
an environment containing recursive types without the flag
correctly set. But I'm not sure of how it could be implemented.
One way to do it would be to put a "use_rectypes.cmo" file
in the library directory, and link it if the option was given,
but it looks a little hacky.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 14, 2008

Comment author: herbelin

Here is an update to the -rectypes issue with ocamlmktop that I submitted for ocaml 3.10.

For debugging purposes of the coq software, we do on-demand calls to the ocaml toplevel loop as in the following configuration:

% cat foo.ml
(* parsing command line and doing some job with them, eventually leading to *)
Toploop.loop Format.std_formatter
% ocamlmktop -o foo -rectypes foo.ml
% ./foo

type t = t -> t;;

which fails since 3.10. We know about the Cflags-linking workaround but it requires the ocaml sources. We know another hack which is to cheat with Sys.argv, setting all arguments to "-rectypes" and using a call to Topmain.main to activate the Cflags.recursive_types option, but this needs to have at least one true argument in Sys.argv. Will there be cleaner alternatives with 3.11?

Thanks in advance.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 18, 2008

Comment author: @glondu

Another possibility would be to add a new toplevel directive #rectypes. This seems to be a quite well-established way to alter command line options from within a toplevel. Attached is patch implementing this.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 19, 2008

Comment author: @garrigue

I've commited Stephane's patch (adding a #rectypes directive), since it seems a good thing
to have anyway. It is safe, since it only allows to set -rectypes, not to unset it.

Does it solve the problem for Coq?

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 19, 2008

Comment author: @glondu

Not exactly. But it is sufficient for our purposes.

Thank you.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 27, 2010

Comment author: @garrigue

The fix seems to be sufficient.

@vicuna vicuna closed this Apr 27, 2010

@vicuna vicuna added the bug label Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.