trifork / erjang

A JVM-based Erlang VM
http://www.erjang.org
Apache License 2.0
726 stars 62 forks source link

is_record/2 not supported? #83

Closed oubiwann closed 10 years ago

oubiwann commented 10 years ago

When trying to use the LFE library Exemplar (S-expressions for rendering HTML), an error is thrown (pasted below). When I remove the call to is_record/2 in a supporting library, the error goes away and the expected content is rendered (<p>here is my content</p>).

Are there plans to add is_record/2? I did notice in the docs that is_record/2 gets special treatment from the compiler ...

Here's most of the error I got (some bits elided):

> (slurp '"src/exemplar-html.lfe")
#(ok exemplar-html)
> (p '"here is my content")
Apr 06, 2014 4:42:30 PM erjang.m.erlang.ErlBif load_module
SEVERE: cannot load module 'lfe-utils'
java.lang.Error: no normal bif named erlang:'is_record'/2
    at erjang.beam.BIFUtil.getMethod(BIFUtil.java:408)
    at erjang.beam.BIFUtil.getMethod(BIFUtil.java:378)
    at erjang.beam.ModuleAnalyzer$1$1.visitInsn(ModuleAnalyzer.java:369)
    at erjang.beam.repr.FunctionRepr.accept(FunctionRepr.java:63)
    at erjang.beam.repr.FunctionRepr.accept(FunctionRepr.java:53)
    at erjang.beam.repr.ModuleRepr.accept(ModuleRepr.java:72)
    at erjang.beam.Compiler.compile(Compiler.java:86)
    at erjang.ErjangCodeCache.getModuleClassLoader(ErjangCodeCache.java:91)
    at erjang.EModuleLoader.load_module(EModuleLoader.java)
    at erjang.m.erlang.ErlBif.load_module(ErlBif.java)
    at erjang.m.erlang.ErlBif.load_module(ErlBif.java)
    at erjang.m.code_server.code_server.try_load_module_1__5(code_server.erl:1264)
    at erjang.m.code_server.code_server$FN_try_load_module_1__5.go(Unknown Source)
    at erjang.m.code_server.code_server.handle_call__3$call(code_server.erl)
    at erjang.m.code_server.code_server.loop__1(code_server.erl:154)
    at erjang.m.code_server.code_server$FN_loop__1.go(Unknown Source)
    at erjang.m.erlang.ErlBif.apply(ErlBif.java:140)
    at erjang.m.erlang.ErlBif$FN_apply__2.go(Unknown Source)
    at erjang.EProc.execute1(EProc.java:682)
    at erjang.EProc.execute0(EProc.java:607)
    at erjang.EProc.execute(EProc.java:590)
    at kilim.Task._runExecute(Task.java)
    at kilim.WorkerThread.run(WorkerThread.java:32)

exception error: undef
  in (: lfe-utils partition-list "here is my content")
  in (exemplar attrs? 1)
  in (exemplar-html make-html 2)

After a pause of about 5 seconds, a much longer error message is printed out, of which I will only paste part:

=ERROR REPORT==== 6-Apr-2014::16:42:30 ===
Loading of ...lab/erlang/exemplar/deps/lfe-utils/ebin/lfe-utils.beam failed:
    {badfile,
       [{erlang,
         load_module,
         ['lfe-utils',
          <<70,79,
            82,49,0,
            0,19,
            140,66,
            69,65,
            77,65,
            116,111,
            109,0,0,
            4,38,0,
            0,0,114,
            9,108,
            102,101,
...
            0,0,0,0,
            0,118,0,
            0,0,0,0,
            0,0,0...>>],
         []},
        {code_server,
         try_load_module_1,
         5,
         [{file,
           "code_server.erl"},
          {line,
           1264}]},
        {code_server,
         loop,
         1,
         [{file,
           "code_server.erl"},
          {line,
           154}]}]}
eriksoe commented 10 years ago

I believe this is indeed a bug. is_record/2 is in most cases (when the record is known) compiled to checks of a) tuplity, b) tuple_size and c) the first element of the tuple. But there are is_record/{2,3} BIFs to handle the fallback case, and apparently these are not presently implemented.

krestenkrab commented 10 years ago

Fixed in 6e8527bfa12448303c2eb48640acdeec5dadd774; @oubiwann please verify.

oubiwann commented 10 years ago

Wow! That was fast :-)

Nice...

oubiwann commented 10 years ago

Just confirmed -- works like a charm. Thanks!