caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] MetaOCaml error while running generated code that needs -rectypes
@ 2015-05-06 17:54 Ömer Sinan Ağacan
  2015-05-07 15:59 ` oleg
  0 siblings, 1 reply; 5+ messages in thread
From: Ömer Sinan Ağacan @ 2015-05-06 17:54 UTC (permalink / raw)
  To: OCaml Mailing List, oleg

I'm trying to generate some code that needs -rectypes. I'm compiling all
modules using -rectypes and things mostly work fine, except I can't run
MetaOCaml generated code, because it's failing with:

  File "_none_", line 1:
  Error: Unit  imports from UnlambdaFuns, which uses recursive types.
         The compilation flag -rectypes is required

  Fatal error: exception Failure("Error type-checking generated code:
scope extrusion?")

It's good that MetaOCaml is printing the original error message. I think this
is related with how MetaOCaml compiling/linking generated code. Is this a bug?
Are there any easy workarounds for that or do we need to patch MetaOCaml to fix
this?

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] MetaOCaml error while running generated code that needs -rectypes
  2015-05-06 17:54 [Caml-list] MetaOCaml error while running generated code that needs -rectypes Ömer Sinan Ağacan
@ 2015-05-07 15:59 ` oleg
  2015-05-07 21:49   ` Ömer Sinan Ağacan
  0 siblings, 1 reply; 5+ messages in thread
From: oleg @ 2015-05-07 15:59 UTC (permalink / raw)
  To: omeragacan; +Cc: caml-list


> I'm trying to generate some code that needs -rectypes. I'm compiling all
> modules using -rectypes and things mostly work fine, except I can't run
> MetaOCaml generated code, because it's failing with:
>
>   File "_none_", line 1:
>   Error: Unit  imports from UnlambdaFuns, which uses recursive types.
>          The compilation flag -rectypes is required

Is the code that contains the Runcode.run <your code> also compiled
with -rectypes?

Anyway, I think forcing recursive_types flag right before Runcode.run
may help. Here is how to do it, if ruiining at the top level:
 
#directory "INSTALLPREFIX/lib/ocaml/compiler-libs/";;
Clflags.recursive_types := true

If you compile the code first, then you need to add -I +compiler-libs
to the command line of the compiler. If the problem persists, it would
help to have a small test case.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] MetaOCaml error while running generated code that needs -rectypes
  2015-05-07 15:59 ` oleg
@ 2015-05-07 21:49   ` Ömer Sinan Ağacan
       [not found]     ` <20150510163426.EC8B1C38CA@www1.g3.pair.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Ömer Sinan Ağacan @ 2015-05-07 21:49 UTC (permalink / raw)
  To: oleg; +Cc: OCaml Mailing List

> Is the code that contains the Runcode.run <your code> also compiled
> with -rectypes?

Yes, otherwise I'm having a compile time error.

> Anyway, I think forcing recursive_types flag right before Runcode.run
> may help. Here is how to do it, if ruiining at the top level:
>
> #directory "INSTALLPREFIX/lib/ocaml/compiler-libs/";;
> Clflags.recursive_types := true

I'm not using REPL. I still tried to do this but (Meta)OCaml REPL is so
ridiculously bad I couldn't even manage to load all the dependencies of
my program...

> If you compile the code first, then you need to add -I +compiler-libs
> to the command line of the compiler. If the problem persists, it would
> help to have a small test case.

What do you mean by "compile the code first"?

My program is in a Github repo, here's how to reproduce:

  $ git clone https://github.com/osa1/int-proj.git
  $ cd int-proj
  $ make unlambda_metaocaml
  $ ./unlambda_metaocaml programs/Hello.unl -compile
  File "_none_", line 1:
  Error: Unit  imports from UnlambdaFuns, which uses recursive types.
         The compilation flag -rectypes is required

  Fatal error: exception Failure("Error type-checking generated code:
scope extrusion?")

Thanks.

2015-05-07 11:59 GMT-04:00  <oleg@okmij.org>:
>
>> I'm trying to generate some code that needs -rectypes. I'm compiling all
>> modules using -rectypes and things mostly work fine, except I can't run
>> MetaOCaml generated code, because it's failing with:
>>
>>   File "_none_", line 1:
>>   Error: Unit  imports from UnlambdaFuns, which uses recursive types.
>>          The compilation flag -rectypes is required
>
> Is the code that contains the Runcode.run <your code> also compiled
> with -rectypes?
>
> Anyway, I think forcing recursive_types flag right before Runcode.run
> may help. Here is how to do it, if ruiining at the top level:
>
> #directory "INSTALLPREFIX/lib/ocaml/compiler-libs/";;
> Clflags.recursive_types := true
>
> If you compile the code first, then you need to add -I +compiler-libs
> to the command line of the compiler. If the problem persists, it would
> help to have a small test case.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] MetaOCaml error while running generated code that
       [not found]     ` <20150510163426.EC8B1C38CA@www1.g3.pair.com>
@ 2015-05-12 21:01       ` Ömer Sinan Ağacan
  2015-05-14 11:43         ` oleg
  0 siblings, 1 reply; 5+ messages in thread
From: Ömer Sinan Ağacan @ 2015-05-12 21:01 UTC (permalink / raw)
  To: oleg; +Cc: OCaml Mailing List

> The fix that I have mentioned in the previous message seems to
> work. Before the line with Runcode.run in the file r2.ml, add this
> line
>
>   let () = Clflags.recursive_types := true
>
> When compiling the code, you have to add the flag -I +compiler-lib flag to the
> metacocamlc command line.

I just tried this on my program and now it's failing with this error:

  ➜  unlambda git:(master) ✗ ./unlambda_metaocaml programs/Hello.unl -compile
  Fatal error: exception Symtable.Error(_)

Does that look familiar?

Here's the diff of my changes:

  diff --git a/Makefile b/Makefile
  index 31ab193..4340429 100644
  --- a/Makefile
  +++ b/Makefile
  @@ -6,7 +6,7 @@ unlambda_idris: Unlambda.idr
      idris $< -o $@

   unlambda_metaocaml: Syntax.cmo UnlambdaInterp.cmo UnlambdaCont.cmo
Lift.cmo CmdArgs.cmo UnlambdaStaged.cmo UnlambdaCompiler.cmo
UnlambdaMain.ml
  - metaocamlc -rectypes $^ -o $@ -g
  + metaocamlc -rectypes -I +compiler-lib $^ -o $@ -g

   qbf_metaocaml: QBFSyntax.cmo QBFEval.cmo QBFMain.ml
      metaocamlc $^ -o $@ -g
  diff --git a/UnlambdaMain.ml b/UnlambdaMain.ml
  index 6a6f72f..8627283 100644
  --- a/UnlambdaMain.ml
  +++ b/UnlambdaMain.ml
  @@ -122,6 +122,7 @@ let _ =
         end
       end
     else if opts.compile then
  +    let _ = Clflags.recursive_types := true in
       let _ = Runcode.run (UnlambdaCompiler.compile exp_s) (fun x -> x) in
       ()
     else begin

2015-05-10 12:34 GMT-04:00  <oleg@okmij.org>:
>
> I was kind of hoping for a simpler example. So, I wrote one myself. It
> has two files:
>
> the file r1.ml
>   let auto'apply g = g g
>   let fix f = auto'apply (fun x n -> f (auto'apply x) n)
>
> the file r2.ml, first version
>   let c =
>    .<let fact self n = if n = 0 then 1 else n * self (n-1) in R1.fix fact 5>.
>   let r = Runcode.run c
>   let () = Printf.printf "The result is %d\n" r
>
> If we build the executable as
>       metaocamlc  -rectypes r1.ml r2.ml
>
> and run the result, we see the error you have reported:
>
> File "_none_", line 1:
> Error: Unit  imports from R1, which uses recursive types.
>        The compilation flag -rectypes is required
>
> Fatal error: exception Failure("Error type-checking generated code: scope extrusion?")
>
>
> The fix that I have mentioned in the previous message seems to
> work. Before the line with Runcode.run in the file r2.ml, add this
> line
>
>   let () = Clflags.recursive_types := true
>
> When compiling the code, you have to add the flag -I +compiler-lib flag to the
> metacocamlc command line.
>
> The resulting executable runs and prints the expected result.
>
>> I'm not using REPL. I still tried to do this but (Meta)OCaml REPL is so
>> ridiculously bad I couldn't even manage to load all the dependencies of
>> my program...
> I guess the mileage really varies: I do all my OCaml and MetaOCaml
> development using REPL.
>
> Well, MetaOCaml distribution includes the file to link your own REPL.
> I guess one can easily make MetaOCaml-enabled utop (by linking in the
> necessary libraries and the tiny object file that sets up the
> necessary environment and registers the code printers).
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] MetaOCaml error while running generated code that
  2015-05-12 21:01       ` [Caml-list] MetaOCaml error while running generated code that Ömer Sinan Ağacan
@ 2015-05-14 11:43         ` oleg
  0 siblings, 0 replies; 5+ messages in thread
From: oleg @ 2015-05-14 11:43 UTC (permalink / raw)
  To: omeragacan; +Cc: caml-list


[I have trouble posting on the caml-list at the moment. If you don't
see this message appearing on the Caml-list, could you forward it
please?]

> I just tried this on my program and now it's failing with this error:
>
>   ./unlambda_metaocaml programs/Hello.unl -compile
>   Fatal error: exception Symtable.Error(_)
>
> Does that look familiar?

Such errors usually indicate a linking problem: something was not
linked in or was not found. In fact, this specific error is emitted in
the following four cases:

  >   Undefined_global of string
  > | Unavailable_primitive of string
  > | Wrong_vm of string
  > | Uninitialized_global of string

I think the most likely problem was Undefined_global: that is, the
generated code you run depends on some .cmo file, which could not be
located. All needed .cmo files should either be in the current
directory, the standard library directory, or the directories you
specifically add to the search path of the evaluator. There is a
special function in the Runcode module that lets you set the search
path. For an example, please see the file
        metalib/test/test_path.ml
in the MetaOCaml distribution.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-14 23:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06 17:54 [Caml-list] MetaOCaml error while running generated code that needs -rectypes Ömer Sinan Ağacan
2015-05-07 15:59 ` oleg
2015-05-07 21:49   ` Ömer Sinan Ağacan
     [not found]     ` <20150510163426.EC8B1C38CA@www1.g3.pair.com>
2015-05-12 21:01       ` [Caml-list] MetaOCaml error while running generated code that Ömer Sinan Ağacan
2015-05-14 11:43         ` oleg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).