@@ -16,7 +16,7 @@ quoted(Forms, File, Callback) ->
16
16
17
17
elixir_lexical :run (
18
18
Env ,
19
- fun (LexicalEnv ) -> eval_or_compile (Forms , [], LexicalEnv ) end ,
19
+ fun (LexicalEnv ) -> maybe_fast_compile (Forms , [], LexicalEnv ) end ,
20
20
fun (#{lexical_tracker := Pid }) -> Callback (File , Pid ) end
21
21
),
22
22
@@ -32,16 +32,17 @@ file(File, Callback) ->
32
32
% % Evaluates the given code through the Erlang compiler.
33
33
% % It may end-up evaluating the code if it is deemed a
34
34
% % more efficient strategy depending on the code snippet.
35
- eval_or_compile (Forms , Args , E ) ->
35
+ maybe_fast_compile (Forms , Args , E ) ->
36
36
case (? key (E , module ) == nil ) andalso allows_fast_compilation (Forms ) andalso
37
37
(not elixir_config :is_bootstrap ()) of
38
38
true -> fast_compile (Forms , E );
39
39
false -> compile (Forms , Args , E )
40
40
end ,
41
41
ok .
42
42
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 ),
45
46
elixir_env :check_unused_vars (SE , EE ),
46
47
47
48
{Module , Fun , Purgeable } =
@@ -55,7 +56,7 @@ spawned_compile(ExExprs, #{line := Line, file := File} = E) ->
55
56
{ErlExprs , _ } = elixir_erl_pass :translate (ExExprs , erl_anno :new (Line ), S ),
56
57
57
58
Module = retrieve_compiler_module (),
58
- Fun = code_fun (? key (E , module )),
59
+ Fun = code_fun (? key (E , module )),
59
60
Forms = code_mod (Fun , ErlExprs , Line , File , Module , Vars ),
60
61
61
62
{Module , Binary } = elixir_erl_compiler :noenv_forms (Forms , File , [nowarn_nomatch , no_bool_opt , no_ssa_opt ]),
@@ -106,15 +107,9 @@ allows_fast_compilation(_) ->
106
107
107
108
fast_compile ({'__block__' , _ , Exprs }, E ) ->
108
109
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 ) ->
110
111
E = NoLineE #{line := ? line (Meta )},
111
112
112
- Block = {'__block__' , Meta , [
113
- {'=' , Meta , [{result , Meta , ? MODULE }, TailBlock ]},
114
- {{'.' , Meta , [elixir_utils , noop ]}, Meta , []},
115
- {result , Meta , ? MODULE }
116
- ]},
117
-
118
113
Expanded = case Mod of
119
114
{'__aliases__' , _ , _ } ->
120
115
case elixir_aliases :expand_or_concat (Mod , E ) of
@@ -129,6 +124,13 @@ fast_compile({defmodule, Meta, [Mod, [{do, TailBlock}]]}, NoLineE) ->
129
124
ContextModules = [Expanded | ? key (E , context_modules )],
130
125
elixir_module :compile (Expanded , Block , [], false , E #{context_modules := ContextModules }).
131
126
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
+
132
134
% % Bootstrapper
133
135
134
136
bootstrap () ->
0 commit comments