eirproject / eir

Erlang ecosystem common IR
Apache License 2.0
252 stars 8 forks source link

Graph simplification generates invalid IR when block capture uses other value from same chain #24

Closed hansihe closed 4 years ago

hansihe commented 4 years ago

When a block capture is part of a chain, and the captured block uses any other value from the same chain, the graph simplification pass may generate invalid IR.

Invalid IR is caught by the graph validation pass.

This issue presents itself when compiling Elixir.Enum. It is high priority.

hansihe commented 4 years ago

This triggers when blocks are used in static value chains.

Workaround

In a case like this

-module(init).
-export([start/0]).
-import(erlang, [print/1]).
start() ->
    Name = <<"Paul">>,
    Callback = 
        fun(Greeting) ->
            print(Greeting),
            print(Name)
        end,
    greet(Callback).

greet(Greeter) -> 
    Greeter(<<"Hello">>).

Workaround:

-module(init).
-export([start/0]).
-import(erlang, [print/1]).
start() ->
    Name = void_map(<<"Name">>),
    void(),
    Callback = 
        fun(Greeting) ->
            print(Greeting),
            print(Name)
        end,
    greet(Callback).

greet(Greeter) ->
    Greeter(<<"Hello">>).

void() -> ok.
void_map(A) -> A.
hansihe commented 4 years ago

This was fixed by the graph simplification pass rewrite.