Skip to content

Commit aabe465

Browse files
committed
Disable compiler optimizations only in module body
1 parent ed2bbe5 commit aabe465

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/elixir/src/elixir_compiler.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% Elixir compiler front-end to the Erlang backend.
22
-module(elixir_compiler).
3-
-export([string/3, quoted/3, bootstrap/0, file/2, compile/3]).
3+
-export([string/3, quoted/3, bootstrap/0, file/2, compile/4]).
44
-include("elixir.hrl").
55

66
string(Contents, File, Callback) ->
@@ -36,30 +36,30 @@ maybe_fast_compile(Forms, Args, E) ->
3636
case (?key(E, module) == nil) andalso allows_fast_compilation(Forms) andalso
3737
(not elixir_config:is_bootstrap()) of
3838
true -> fast_compile(Forms, E);
39-
false -> compile(Forms, Args, E)
39+
false -> compile(Forms, Args, [], E)
4040
end,
4141
ok.
4242

43-
compile(Quoted, ArgsList, #{line := Line} = E) ->
43+
compile(Quoted, ArgsList, CompilerOpts, #{line := Line} = E) ->
4444
Block = no_tail_optimize([{line, Line}], Quoted),
4545
{Expanded, SE, EE} = elixir_expand:expand(Block, elixir_env:env_to_ex(E), E),
4646
elixir_env:check_unused_vars(SE, EE),
4747

4848
{Module, Fun, Purgeable} =
49-
elixir_erl_compiler:spawn(fun() -> spawned_compile(Expanded, E) end),
49+
elixir_erl_compiler:spawn(fun() -> spawned_compile(Expanded, CompilerOpts, E) end),
5050

5151
Args = list_to_tuple(ArgsList),
5252
{dispatch(Module, Fun, Args, Purgeable), SE, EE}.
5353

54-
spawned_compile(ExExprs, #{line := Line, file := File} = E) ->
54+
spawned_compile(ExExprs, CompilerOpts, #{line := Line, file := File} = E) ->
5555
{Vars, S} = elixir_erl_var:from_env(E),
5656
{ErlExprs, _} = elixir_erl_pass:translate(ExExprs, erl_anno:new(Line), S),
5757

5858
Module = retrieve_compiler_module(),
5959
Fun = code_fun(?key(E, module)),
6060
Forms = code_mod(Fun, ErlExprs, Line, File, Module, Vars),
6161

62-
{Module, Binary} = elixir_erl_compiler:noenv_forms(Forms, File, [nowarn_nomatch, no_bool_opt, no_ssa_opt]),
62+
{Module, Binary} = elixir_erl_compiler:noenv_forms(Forms, File, [nowarn_nomatch | CompilerOpts]),
6363
code:load_binary(Module, "", Binary),
6464
{Module, Fun, is_purgeable(Module, Binary)}.
6565

lib/elixir/src/elixir_module.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ build(Module, Line, File, E) ->
421421
%% Handles module and callback evaluations.
422422

423423
eval_form(Line, Module, DataBag, Block, Vars, Prune, E) ->
424-
{Value, ExS, EE} = elixir_compiler:compile(Block, Vars, E),
424+
%% Given Elixir modules can get very long to compile due to metaprogramming,
425+
%% we disable expansions that take linear time to code size.
426+
{Value, ExS, EE} = elixir_compiler:compile(Block, Vars, [no_bool_opt, no_ssa_opt], E),
425427
elixir_overridable:store_not_overridden(Module),
426428
EV = (elixir_env:reset_vars(EE))#{line := Line},
427429
EC = eval_callbacks(Line, DataBag, before_compile, [EV], EV),

0 commit comments

Comments
 (0)