Skip to content

Commit 89cbe93

Browse files
author
José Valim
committed
The AST now allows metadata to be attached to each node
This means the second item in the AST is no longer an integer (representing the line), but a keywords list. Code that relies on the line information from AST or that manually generate AST nodes need to be properly updated.
1 parent 4633c64 commit 89cbe93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1010
-905
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* [String] `String.rstrip` and `String.lstrip` now verify if argument is a binary
2626
* [Typespec] Support `...` inside typespec's lists
2727

28+
* backwards incompatible changes
29+
* [Kernel] The AST now allows metadata to be attached to each node. This means the second item in the AST is no longer an integer (representing the line), but a keywords list. Code that relies on the line information from AST or that manually generate AST nodes need to be properly updated
30+
2831
* deprecations
2932
* [Dict] Deprecate `Binary.Dict` and `OrdDict` in favor of `HashDict` and `List.Dict`
3033
* [File] Deprecate path related functions in favor of the module `Path`

lib/eex/lib/eex.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ defmodule EEx do
189189

190190
@doc false
191191
def function_from_quoted(module, kind, name, args, source, info) do
192-
args = Enum.map args, fn arg -> { arg, 0, nil } end
192+
args = Enum.map args, fn arg -> { arg, [], nil } end
193193
quote = quote do
194194
unquote(kind).(unquote(name).(unquote_splicing(args)), do: unquote(source))
195195
end

lib/eex/lib/eex/compiler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ defmodule EEx.Compiler do
9090

9191
defp maybe_block([]), do: nil
9292
defp maybe_block([h]), do: h
93-
defp maybe_block(other), do: { :__block__, 0, other }
93+
defp maybe_block(other), do: { :__block__, [], other }
9494

9595
# Changes placeholder to real expression
9696

lib/elixir/include/elixir.hrl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
-define(ELIXIR_WRAP_CALL(Line, Module, Function, Args),
1+
-define(wrap_call(Line, Module, Function, Args),
22
{ call, Line,
33
{ remote, Line, { atom, Line, Module }, { atom, Line, Function } },
44
Args
55
}).
66

7-
-define(ELIXIR_ATOM_CONCAT(Atoms), list_to_atom(lists:concat(Atoms))).
8-
-define(ELIXIR_MACRO(Macro), list_to_atom(lists:concat(['MACRO-',Macro]))).
7+
-define(atom_concat(Atoms), list_to_atom(lists:concat(Atoms))).
8+
-define(elixir_macro(Macro), list_to_atom(lists:concat(['MACRO-',Macro]))).
9+
-define(line(Opts), elixir_tree_helpers:get_line(Opts)).
910

1011
-record(elixir_scope, {
1112
context=nil, %% can be assign, guards or nil
@@ -37,7 +38,7 @@
3738
unquote=true
3839
}).
3940

40-
%% used in tokinization and interpolation
41+
%% Used in tokenization and interpolation
4142

4243
-define(is_digit(S), S >= $0 andalso S =< $9).
4344
-define(is_hex(S), ?is_digit(S) orelse (S >= $A andalso S =< $F) orelse (S >= $a andalso S =< $f)).

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ defmodule Code do
182182

183183
defp unpack_ast(_line, []), do: nil
184184
defp unpack_ast(_line, [forms]) when not is_list(forms), do: forms
185-
defp unpack_ast(line, forms), do: { :__block__, line, forms }
185+
defp unpack_ast(line, forms), do: { :__block__, [line: line], forms }
186186

187187
@doc """
188188
Loads the given `file`. Accepts `relative_to` as an argument

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,7 +2584,7 @@ defmodule Kernel do
25842584
25852585
"""
25862586
defmacro left <> right do
2587-
concats = extract_concatenations({ :<>, 0, [left, right] })
2587+
concats = extract_concatenations({ :<>, [], [left, right] })
25882588
quote do: << unquote_splicing(concats) >>
25892589
end
25902590

@@ -2601,7 +2601,7 @@ defmodule Kernel do
26012601
26022602
"""
26032603
defmacro first .. last do
2604-
{ :{}, 0, [Elixir.Range, first, last] }
2604+
{ :{}, [], [Elixir.Range, first, last] }
26052605
end
26062606

26072607
@doc """
@@ -2759,7 +2759,7 @@ defmodule Kernel do
27592759
end
27602760

27612761
defp pipeline_op(left, atom) when is_atom(atom) do
2762-
{ { :., 0, [left, atom] }, 0, [] }
2762+
{ { :., [], [left, atom] }, [], [] }
27632763
end
27642764

27652765
defp pipeline_op(_, other) do
@@ -3180,7 +3180,7 @@ defmodule Kernel do
31803180
end
31813181

31823182
defp wrap_concatenation(other) do
3183-
{ :::, 0, [other, { :binary, 0, nil }] }
3183+
{ :::, [], [other, { :binary, [], nil }] }
31843184
end
31853185

31863186
# Builds cond clauses by nesting them recursively.

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ defmodule Kernel.SpecialForms do
326326
## Examples
327327
328328
quote do: sum(1, 2, 3)
329-
#=> { :sum, 0, [1, 2, 3] }
329+
#=> { :sum, [], [1, 2, 3] }
330330
331331
## Explanation
332332
@@ -486,8 +486,8 @@ defmodule Kernel.SpecialForms do
486486
487487
One of Elixir goals is to provide proper stacktrace whenever there is an
488488
exception. In order to work properly with macros, the default behavior
489-
in quote is to set the line to 0. When a macro is invoked and the quoted
490-
expressions is expanded, 0 is replaced by the line of the call site.
489+
in quote is to not set a line. When a macro is invoked and the quoted
490+
expressions is expanded, the call site line is inserted.
491491
492492
This is a good behavior for the majority of the cases, except if the macro
493493
is defining new functions. Consider this example:
@@ -549,13 +549,13 @@ defmodule Kernel.SpecialForms do
549549
550550
Which would then return:
551551
552-
{ :sum, 0, [1, { :value, 0, quoted }, 3] }
552+
{ :sum, [], [1, { :value, [], quoted }, 3] }
553553
554554
Which is not the expected result. For this, we use unquote:
555555
556556
value = 13
557557
quote do: sum(1, unquote(value), 3)
558-
#=> { :sum, 0, [1, 13, 3] }
558+
#=> { :sum, [], [1, 13, 3] }
559559
560560
"""
561561
defmacro unquote(expr)
@@ -568,7 +568,7 @@ defmodule Kernel.SpecialForms do
568568
569569
values = [2,3,4]
570570
quote do: sum(1, unquote_splicing(values), 5)
571-
#=> { :sum, 0, [1, 2, 3, 4, 5] }
571+
#=> { :sum, [], [1, 2, 3, 4, 5] }
572572
573573
"""
574574
defmacro unquote_splicing(expr)
@@ -634,7 +634,7 @@ defmodule Kernel.SpecialForms do
634634
and should not be invoked directly:
635635
636636
quote do: (1; 2; 3)
637-
#=> { :__block__, 0, [1,2,3] }
637+
#=> { :__block__, [], [1,2,3] }
638638
639639
"""
640640
defmacro __block__(args)
@@ -657,13 +657,13 @@ defmodule Kernel.SpecialForms do
657657
It is usually compiled to an atom:
658658
659659
quote do: Foo.Bar
660-
{ :__aliases__, 0, [:Foo,:Bar] }
660+
{ :__aliases__, [], [:Foo,:Bar] }
661661
662662
Elixir represents `Foo.Bar` as `__aliases__` so calls can be
663663
unambiguously identified by the operator `:.`. For example:
664664
665665
quote do: Foo.bar
666-
{{:.,0,[{:__aliases__,0,[:Foo]},:bar]},0,[]}
666+
{{:.,[],[{:__aliases__,[],[:Foo]},:bar]},[],[]}
667667
668668
Whenever an expression iterator sees a `:.` as the tuple key,
669669
it can be sure that it represents a call and the second argument
@@ -680,7 +680,7 @@ defmodule Kernel.SpecialForms do
680680
4) When the head element of aliases is not an atom, it is expanded at runtime:
681681
682682
quote do: some_var.Foo
683-
{:__aliases__,0,[{:some_var,0,:quoted},:Bar]}
683+
{:__aliases__,[],[{:some_var,[],:quoted},:Bar]}
684684
685685
Since `some_var` is not available at compilation time, the compiler
686686
expands such expression to:

0 commit comments

Comments
 (0)