[erlang-questions] Compile Question

Michael Schmidt Michael.K.Schmidt@REDACTED
Tue Dec 4 20:38:48 CET 2018


Just to close the loop, this was the fix:
https://github.com/absinthe-graphql/absinthe/pull/645

Thanks again Michał and Fred for the help


From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Michael Schmidt
Sent: Tuesday, December 4, 2018 1:24 PM
To: Michał Muskała <michal@REDACTED>; erlang-questions@REDACTED
Subject: Re: [erlang-questions] Compile Question


[External email: Use caution with links and attachments]

________________________________


Thanks! That makes sense that the issue is not the lists:foreach(), but a layer deeper

I am open on how to address this—I need to test Fred’s hypothesis real quick.

In the mean time, this is as deep as I got:
def build_types(types) do
    IO.puts "build_types #{types |> length() |> inspect}"
    for type <- types do
      if !type.definition,
        do:
          raise("""
          No definition set!
          #{inspect(type)}
          """)

      ast = Macro.escape(type, unquote: true)

      quote do
        def __absinthe_type__(unquote(type.identifier)) do
          unquote(ast)
        end

        def __absinthe_type__(unquote(type.name)) do
          unquote(ast)
        end
      end
    end
    |> Enum.concat([
      quote do
        def __absinthe_type__(_type) do
          nil
       end
      end
    ])
  end


The types list is 776 long.  If I comment out the 2 “def __absinthe_type()” clauses the issue does not occur, so I assume this is the list referenced in the error message.


From: Michał Muskała [mailto:michal@REDACTED]
Sent: Tuesday, December 4, 2018 1:14 PM
To: erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>; Michael Schmidt <Michael.K.Schmidt@REDACTED<mailto:Michael.K.Schmidt@REDACTED>>
Subject: Re: [erlang-questions] Compile Question


[External email: Use caution with links and attachments]

________________________________


The issue seems to be that the compile-time function created by the module is huge and tries to allocate a compile-time list with 1555 elements. The lists:foreach call is probably misleading - that's just somewhere on the compiler stack. The good thing is that it's probably just a matter of refactoring  macros in the Absinthe.Phase.Schema.Compile module. It shouldn't need to build such huge lists (I've reviewed the module briefly).

Michał.
On 4 Dec 2018, 19:44 +0100, Michael Schmidt <Michael.K.Schmidt@REDACTED<mailto:Michael.K.Schmidt@REDACTED>>, wrote:
I have been chasing a compile error:
** (CompileError) elixir_compiler_1: function '__MODULE__'/1+17:
  An implementation limit was reached.
  Try reducing the complexity of this function.

  Instruction: {move,{x,0},{y,1555}}

    (stdlib) lists.erl:1338: :lists.foreach/2
    lib/absinthe/phase/schema/compile.ex:51: Absinthe.Phase.Schema.Compile.run/2
    lib/absinthe/pipeline.ex:283: Absinthe.Pipeline.run_phase/3
    lib/absinthe/schema.ex:214: Absinthe.Schema.__after_compile__/2
    (stdlib) lists.erl:1263: :lists.foldl/3
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

I realize this is an Elixir / Absinthe issue, but my question is this:  How is lists:foreach() able to trigger this?
https://github.com/erlang/otp/blob/master/lib/stdlib/src/lists.erl#L1332<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ferlang%2Fotp%2Fblob%2Fmaster%2Flib%2Fstdlib%2Fsrc%2Flists.erl%23L1332&data=02%7C01%7Cmichael.k.schmidt%40schneider-electric.com%7C87fe5b9077a346e957f808d65a1e1689%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636795482608459451&sdata=WR3VT%2BAIRrgX1eJUX9h6BvRuHGe7hDnKFJ9yJZ0odew%3D&reserved=0>

Poking around, there is indeed a list of 776 items that generates 2 function defs each, which gives us a final AST list of approx 1552.  I assume this is related to the {y,1555} in Error.

Can lists:each() not handle lists longer than 1024?  What am I missing?

Thanks!
Mike






_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>
http://erlang.org/mailman/listinfo/erlang-questions<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions&data=02%7C01%7Cmichael.k.schmidt%40schneider-electric.com%7C87fe5b9077a346e957f808d65a1e1689%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636795482608469447&sdata=0qpbd9aGavX%2BBD%2BfX9J9gLA9KvcwPRRDSRcRMmJqF2Y%3D&reserved=0>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181204/d17ac4cb/attachment.htm>


More information about the erlang-questions mailing list