@@ -254,21 +254,22 @@ defmodule Protocol do
254
254
{ :error , :not_a_protocol } |
255
255
{ :error , :no_beam_info }
256
256
def consolidate ( protocol , types ) when is_atom ( protocol ) do
257
- with { :ok , info } <- beam_protocol ( protocol ) ,
258
- { :ok , code , docs } <- change_debug_info ( info , types ) ,
259
- do: compile ( code , docs )
257
+ with { :ok , ast_info , chunks_info } <- beam_protocol ( protocol ) ,
258
+ { :ok , code } <- change_debug_info ( ast_info , types ) ,
259
+ do: compile ( protocol , code , chunks_info )
260
260
end
261
261
262
262
defp beam_protocol ( protocol ) do
263
- chunk_ids = [ :abstract_code , :attributes , 'ExDc' ]
263
+ chunk_ids = [ :abstract_code , :attributes , :compile_info , 'ExDc' ]
264
264
opts = [ :allow_missing_chunks ]
265
265
case :beam_lib . chunks ( beam_file ( protocol ) , chunk_ids , opts ) do
266
266
{ :ok , { ^ protocol , [ { :abstract_code , { _raw , abstract_code } } ,
267
267
{ :attributes , attributes } ,
268
+ { :compile_info , compile_info } ,
268
269
{ 'ExDc' , docs } ] } } ->
269
270
case attributes [ :protocol ] do
270
271
[ fallback_to_any: any ] ->
271
- { :ok , { protocol , any , abstract_code , docs } }
272
+ { :ok , { protocol , any , abstract_code } , { compile_info , docs } }
272
273
_ ->
273
274
{ :error , :not_a_protocol }
274
275
end
@@ -286,12 +287,12 @@ defmodule Protocol do
286
287
287
288
# Change the debug information to the optimized
288
289
# impl_for/1 dispatch version.
289
- defp change_debug_info ( { protocol , any , code , docs } , types ) do
290
+ defp change_debug_info ( { protocol , any , code } , types ) do
290
291
types = if any , do: types , else: List . delete ( types , Any )
291
292
all = [ Any ] ++ for { _guard , mod } <- __builtin__ ( ) , do: mod
292
293
structs = types -- all
293
294
case change_impl_for ( code , protocol , types , structs , false , [ ] ) do
294
- { :ok , ret } -> { :ok , ret , docs }
295
+ { :ok , ret } -> { :ok , ret }
295
296
other -> other
296
297
end
297
298
end
@@ -358,9 +359,9 @@ defmodule Protocol do
358
359
change_impl_for ( tail , protocol , info , types , protocol? , [ head | acc ] )
359
360
end
360
361
361
- defp change_impl_for ( [ ] , protocol , _info , _types , protocol? , acc ) do
362
+ defp change_impl_for ( [ ] , _protocol , _info , _types , protocol? , acc ) do
362
363
if protocol? do
363
- { :ok , { protocol , Enum . reverse ( acc ) } }
364
+ { :ok , Enum . reverse ( acc ) }
364
365
else
365
366
{ :error , :not_a_protocol }
366
367
end
@@ -405,8 +406,9 @@ defmodule Protocol do
405
406
end
406
407
407
408
# Finally compile the module and emit its bytecode.
408
- defp compile ( { protocol , code } , docs ) do
409
- opts = if Code . compiler_options [ :debug_info ] , do: [ :debug_info ] , else: [ ]
409
+ defp compile ( protocol , code , { compile_info , docs } ) do
410
+ opts = Keyword . take ( compile_info , [ :source ] )
411
+ opts = if Code . compiler_options [ :debug_info ] , do: [ :debug_info | opts ] , else: opts
410
412
{ :ok , ^ protocol , binary , _warnings } = :compile . forms ( code , [ :return | opts ] )
411
413
{ :ok ,
412
414
case docs do
0 commit comments