11-module (elixir_module ).
22-export ([file /1 , data_tables /1 , is_open /1 , mode /1 , delete_definition_attributes /6 ,
33 compile /6 , expand_callback /6 , format_error /1 , compiler_modules /0 ,
4- write_cache /3 , read_cache /2 , next_counter /1 , taint /1 ]).
4+ write_cache /3 , read_cache /2 , next_counter /1 , taint /1 , cache_env / 1 , get_cached_env / 1 ]).
55-include (" elixir.hrl" ).
66-define (counter_attr , {elixir , counter }).
7+ -define (cache_key , {elixir , cache_env }).
78
89% % Stores modules currently being defined by the compiler
910
@@ -71,6 +72,29 @@ taint(Module) ->
7172 _ :_ -> false
7273 end .
7374
75+ cache_env (#{line := Line , module := Module } = E ) ->
76+ {Set , _ } = data_tables (Module ),
77+ Cache = elixir_env :reset_vars (E #{line := nil }),
78+ PrevKey = ets :lookup_element (Set , ? cache_key , 2 ),
79+
80+ Pos =
81+ case ets :lookup (Set , {cache_env , PrevKey }) of
82+ [{_ , Cache }] ->
83+ PrevKey ;
84+ _ ->
85+ NewKey = PrevKey + 1 ,
86+ ets :insert (Set , [{{cache_env , NewKey }, Cache }, {? cache_key , NewKey }]),
87+ NewKey
88+ end ,
89+
90+ {Module , {Line , Pos }}.
91+
92+ get_cached_env ({Module , {Line , Pos }}) ->
93+ {Set , _ } = data_tables (Module ),
94+ (ets :lookup_element (Set , {cache_env , Pos }, 2 ))#{line := Line };
95+ get_cached_env (Env ) ->
96+ Env .
97+
7498% % Compilation hook
7599
76100compile (Meta , Module , Block , Vars , Prune , Env ) ->
@@ -146,7 +170,7 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
146170
147171 NifsAttribute = lists :keyfind (nifs , 1 , Attributes ),
148172 validate_nifs_attribute (NifsAttribute , AllDefinitions , Line , E ),
149- elixir_locals : ensure_no_import_conflict (Module , AllDefinitions , E ),
173+ elixir_import : ensure_no_local_conflict (Module , AllDefinitions , E ),
150174
151175 make_readonly (Module ),
152176
@@ -330,7 +354,6 @@ build(Module, Line, File, E) ->
330354 % % * {{type, Tuple}, ...}, {{opaque, Tuple}, ...}
331355 % % * {{callback, Tuple}, ...}, {{macrocallback, Tuple}, ...}
332356 % % * {{def, Tuple}, ...} (from elixir_def)
333- % % * {{import, Tuple}, ...} (from elixir_locals)
334357 % % * {{overridable, Tuple}, ...} (from elixir_overridable)
335358 % %
336359 DataSet = ets :new (Module , [set , public ]),
@@ -346,8 +369,6 @@ build(Module, Line, File, E) ->
346369 % % * {overridables, ...} (from elixir_overridable)
347370 % % * {{default, Name}, ...} (from elixir_def)
348371 % % * {{clauses, Tuple}, ...} (from elixir_def)
349- % % * {reattach, ...} (from elixir_locals)
350- % % * {{local, Tuple}, ...} (from elixir_locals)
351372 % %
352373 DataBag = ets :new (Module , [duplicate_bag , public ]),
353374
@@ -374,6 +395,7 @@ build(Module, Line, File, E) ->
374395 {optional_callbacks , [], accumulate , []},
375396
376397 % Others
398+ {? cache_key , 0 },
377399 {? counter_attr , 0 }
378400 ]),
379401
@@ -390,7 +412,6 @@ build(Module, Line, File, E) ->
390412 % % Setup definition related modules
391413 Tables = {DataSet , DataBag },
392414 elixir_def :setup (Tables ),
393- elixir_locals :setup (Tables ),
394415 Tuple = {Module , Tables , Line , File , all },
395416
396417 Ref =
0 commit comments