Skip to content

Commit

Permalink
Disable compiler optimizations only in module body
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 9, 2023
1 parent ed2bbe5 commit aabe465
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/elixir/src/elixir_compiler.erl
@@ -1,6 +1,6 @@
%% Elixir compiler front-end to the Erlang backend.
-module(elixir_compiler).
-export([string/3, quoted/3, bootstrap/0, file/2, compile/3]).
-export([string/3, quoted/3, bootstrap/0, file/2, compile/4]).
-include("elixir.hrl").

string(Contents, File, Callback) ->
Expand Down Expand Up @@ -36,30 +36,30 @@ maybe_fast_compile(Forms, Args, E) ->
case (?key(E, module) == nil) andalso allows_fast_compilation(Forms) andalso
(not elixir_config:is_bootstrap()) of
true -> fast_compile(Forms, E);
false -> compile(Forms, Args, E)
false -> compile(Forms, Args, [], E)
end,
ok.

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

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

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

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

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

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

Expand Down
4 changes: 3 additions & 1 deletion lib/elixir/src/elixir_module.erl
Expand Up @@ -421,7 +421,9 @@ build(Module, Line, File, E) ->
%% Handles module and callback evaluations.

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

0 comments on commit aabe465

Please sign in to comment.