Skip to content

Commit

Permalink
Deprecate parse transforms, closes #5762
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Feb 19, 2017
1 parent 39c7115 commit c0c8472
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,13 @@ defmodule Kernel do
:elixir_errors.warn env.line, env.file,
"@behavior attribute is not supported, please use @behaviour instead"

# TODO: Remove :compile check once on 2.0 as we no longer
# need to warn on parse transforms in Module.put_attribute.
name == :compile ->
{stack, _} = :elixir_quote.escape(env_stacktrace(env), false)
quote do: Module.put_attribute(__MODULE__, unquote(name), unquote(arg),
unquote(stack), unquote(line))

:lists.member(name, [:moduledoc, :typedoc, :doc]) ->
{stack, _} = :elixir_quote.escape(env_stacktrace(env), false)
arg = {env.line, arg}
Expand Down
9 changes: 9 additions & 0 deletions lib/elixir/lib/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,15 @@ defmodule Module do
table = data_table_for(module)
value = preprocess_attribute(key, value)

# TODO: Remove on Elixir v2.0
case value do
{:parse_transform, _} when key == :compile and is_list(stack) ->
IO.warn "@compile {:parse_transform, _} is deprecated. " <>
"Elixir will no longer support Erlang-based transforms in future versions", stack
_ ->
:ok
end

case :ets.lookup(table, key) do
[{^key, {line, <<_::binary>>}, accumulated?, _unread_line}]
when key in [:doc, :typedoc, :moduledoc] and is_list(stack) ->
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/src/elixir_module.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ compile(Line, Module, Block, Vars, E) ->
{Result, NE} = eval_form(Line, Module, Data, Block, Vars, E),

PersistedAttrs = ets:lookup_element(Data, ?persisted_attr, 2),
CompileOpts = ets:lookup_element(Data, compile, 2),
CompileOpts = lists:flatten(ets:lookup_element(Data, compile, 2)),
OnLoad = ets:lookup_element(Data, 'on_load', 2),
[elixir_locals:record_local(Tuple, Module) || Tuple <- OnLoad],

Expand All @@ -94,7 +94,7 @@ compile(Line, Module, Block, Vars, E) ->
{attribute, Line, module, Module} | Forms3
],

Binary = load_form(Line, Data, Final, lists:flatten(CompileOpts), NE),
Binary = load_form(Line, Data, Final, CompileOpts, NE),
{module, Module, Binary, Result}
catch
error:undef ->
Expand Down

0 comments on commit c0c8472

Please sign in to comment.