@@ -16,7 +16,7 @@ quoted(Forms, File, Callback) ->
1616
1717 elixir_lexical :run (
1818 Env ,
19- fun (LexicalEnv ) -> eval_or_compile (Forms , [], LexicalEnv ) end ,
19+ fun (LexicalEnv ) -> maybe_fast_compile (Forms , [], LexicalEnv ) end ,
2020 fun (#{lexical_tracker := Pid }) -> Callback (File , Pid ) end
2121 ),
2222
@@ -32,16 +32,17 @@ file(File, Callback) ->
3232% % Evaluates the given code through the Erlang compiler.
3333% % It may end-up evaluating the code if it is deemed a
3434% % more efficient strategy depending on the code snippet.
35- eval_or_compile (Forms , Args , E ) ->
35+ 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 );
3939 false -> compile (Forms , Args , E )
4040 end ,
4141 ok .
4242
43- compile (Quoted , ArgsList , E ) ->
44- {Expanded , SE , EE } = elixir_expand :expand (Quoted , elixir_env :env_to_ex (E ), E ),
43+ compile (Quoted , ArgsList , #{line := Line } = E ) ->
44+ Block = no_tail_optimize ([{line , Line }], Quoted ),
45+ {Expanded , SE , EE } = elixir_expand :expand (Block , elixir_env :env_to_ex (E ), E ),
4546 elixir_env :check_unused_vars (SE , EE ),
4647
4748 {Module , Fun , Purgeable } =
@@ -55,7 +56,7 @@ spawned_compile(ExExprs, #{line := Line, file := File} = E) ->
5556 {ErlExprs , _ } = elixir_erl_pass :translate (ExExprs , erl_anno :new (Line ), S ),
5657
5758 Module = retrieve_compiler_module (),
58- Fun = code_fun (? key (E , module )),
59+ Fun = code_fun (? key (E , module )),
5960 Forms = code_mod (Fun , ErlExprs , Line , File , Module , Vars ),
6061
6162 {Module , Binary } = elixir_erl_compiler :noenv_forms (Forms , File , [nowarn_nomatch , no_bool_opt , no_ssa_opt ]),
@@ -106,15 +107,9 @@ allows_fast_compilation(_) ->
106107
107108fast_compile ({'__block__' , _ , Exprs }, E ) ->
108109 lists :foldl (fun (Expr , _ ) -> fast_compile (Expr , E ) end , nil , Exprs );
109- fast_compile ({defmodule , Meta , [Mod , [{do , TailBlock }]]}, NoLineE ) ->
110+ fast_compile ({defmodule , Meta , [Mod , [{do , Block }]]}, NoLineE ) ->
110111 E = NoLineE #{line := ? line (Meta )},
111112
112- Block = {'__block__' , Meta , [
113- {'=' , Meta , [{result , Meta , ? MODULE }, TailBlock ]},
114- {{'.' , Meta , [elixir_utils , noop ]}, Meta , []},
115- {result , Meta , ? MODULE }
116- ]},
117-
118113 Expanded = case Mod of
119114 {'__aliases__' , _ , _ } ->
120115 case elixir_aliases :expand_or_concat (Mod , E ) of
@@ -129,6 +124,13 @@ fast_compile({defmodule, Meta, [Mod, [{do, TailBlock}]]}, NoLineE) ->
129124 ContextModules = [Expanded | ? key (E , context_modules )],
130125 elixir_module :compile (Expanded , Block , [], false , E #{context_modules := ContextModules }).
131126
127+ no_tail_optimize (Meta , Block ) ->
128+ {'__block__' , Meta , [
129+ {'=' , Meta , [{result , Meta , ? MODULE }, Block ]},
130+ {{'.' , Meta , [elixir_utils , noop ]}, Meta , []},
131+ {result , Meta , ? MODULE }
132+ ]}.
133+
132134% % Bootstrapper
133135
134136bootstrap () ->
0 commit comments