@@ -69,8 +69,9 @@ handle_call(retrieve_compiler_module, _From, Config) ->
6969
7070handle_call (purge_compiler_modules , _From , Config ) ->
7171 {Used , Unused , Counter } = Config # elixir_code_server .mod_pool ,
72- _ = [code :purge (Module ) || Module <- Used ],
73- ModPool = {[], Used ++ Unused , Counter },
72+ purge_used (Used ),
73+ Mods = lists :map (fun ({Mod , _ }) -> Mod end , Used ),
74+ ModPool = {[], Mods ++ Unused , Counter },
7475 {reply , {ok , length (Used )}, Config # elixir_code_server {mod_pool = ModPool }};
7576
7677handle_call (Request , _From , Config ) ->
@@ -95,9 +96,9 @@ handle_cast({unrequire_files, Files}, Config) ->
9596 Unrequired = maps :without (Files , Current ),
9697 {noreply , Config # elixir_code_server {required = Unrequired }};
9798
98- handle_cast ({return_compiler_module , Module }, Config ) ->
99+ handle_cast ({return_compiler_module , Module , Purgeable }, Config ) ->
99100 {Used , Unused , Counter } = Config # elixir_code_server .mod_pool ,
100- ModPool = {[Module | Used ], Unused , Counter },
101+ ModPool = {[{ Module , Purgeable } | Used ], Unused , Counter },
101102 {noreply , Config # elixir_code_server {mod_pool = ModPool }};
102103
103104handle_cast (purge_compiler_modules , Config ) ->
@@ -111,11 +112,9 @@ handle_cast(purge_compiler_modules, Config) ->
111112 % % purge them asynchronously, especially because they can
112113 % % block the code server. Ideally we would purge them in
113114 % % batches, but that's not supported at the moment.
114- Opts = [{monitor , [{tag , {purged , Used }}]}],
115- erlang :spawn_opt (fun () ->
116- [code :purge (Module ) || Module <- Used ],
117- ok
118- end , Opts )
115+ Mods = lists :map (fun ({Mod , _ }) -> Mod end , Used ),
116+ Opts = [{monitor , [{tag , {purged , Mods }}]}],
117+ erlang :spawn_opt (fun () -> purge_used (Used ) end , Opts )
119118 end ,
120119
121120 ModPool = {[], Unused , Counter },
@@ -144,6 +143,13 @@ code_change(_Old, Config, _Extra) ->
144143compiler_module (I ) ->
145144 list_to_atom (" elixir_compiler_" ++ integer_to_list (I )).
146145
146+ purge_used (Used ) ->
147+ [begin
148+ code :delete (Module ),
149+ Purgeable andalso code :purge (Module )
150+ end || {Module , Purgeable } <- Used ],
151+ ok .
152+
147153defmodule (Pid , Tuple , # elixir_code_server {mod_ets = ModEts } = Config ) ->
148154 ets :insert (elixir_modules , Tuple ),
149155 Ref = erlang :monitor (process , Pid ),
0 commit comments