Skip to content

Commit 1ee954a

Browse files
committed
doc and NEWS updates for IR changes
1 parent e6400ab commit 1ee954a

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ Compiler/Runtime improvements
4747
Breaking changes
4848
----------------
4949

50+
* Local variables and arguments are represented in lowered code as numbered `Slot`
51+
objects instead of as symbols ([#15609]).
52+
53+
* The information that used to be in the `ast` field of the `LambdaStaticData` type
54+
is now divided among the fields `code`, `slotnames`, `slottypes`, `slotflags`,
55+
`gensymtypes`, `rettype`, `nargs`, and `isva` in the `LambdaInfo` type ([#15609]).
56+
5057
Library improvements
5158
--------------------
5259

@@ -173,3 +180,4 @@ Deprecated or removed
173180
[#15242]: https://github.com/JuliaLang/julia/issues/15242
174181
[#15258]: https://github.com/JuliaLang/julia/issues/15258
175182
[#15550]: https://github.com/JuliaLang/julia/issues/15550
183+
[#15609]: https://github.com/JuliaLang/julia/issues/15609

doc/devdocs/ast.rst

+20-30
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Julia ASTs
44

55
.. currentmodule:: Base
66

7-
Julia has two AST representations. First there is a surface syntax AST returned
7+
Julia has two representations of code. First there is a surface syntax AST returned
88
by the parser (e.g. the :func:`parse` function), and manipulated by macros.
99
It is a structured representation of code as it is written,
1010
constructed by ``julia-parser.scm`` from a character stream.
11-
Next there is a lowered AST which is used by type inference and code generation.
12-
In the lowered form, there are generally fewer types of nodes, all macros
11+
Next there is a lowered form, or IR (intermediate representation), which is used by
12+
type inference and code generation.
13+
In the lowered form there are fewer types of nodes, all macros
1314
are expanded, and all control flow is converted to explicit branches and sequences
1415
of statements. The lowered form is constructed by ``julia-syntax.scm``.
1516

@@ -21,17 +22,17 @@ significant rearrangement of the input syntax.
2122
Lowered form
2223
------------
2324

24-
The following data types exist in lowered ASTs:
25+
The following data types exist in lowered form:
2526

2627
``Expr``
2728
has a node type indicated by the ``head`` field, and an ``args`` field
2829
which is a ``Vector{Any}`` of subexpressions.
2930

30-
``Symbol``
31-
used to name local variables and static parameters within a function.
31+
``Slot``
32+
identifies arguments and local variables by consecutive numbering.
3233

3334
``LambdaInfo``
34-
wraps the AST of each method.
35+
wraps the IR of each method.
3536

3637
``LineNumberNode``
3738
line number metadata
@@ -54,9 +55,6 @@ The following data types exist in lowered ASTs:
5455
forces a name to be resolved as a global in Base. This is now mostly
5556
redundant with ``GlobalRef(Base, :x)``.
5657

57-
``SymbolNode``
58-
used to annotate a local variable with a type
59-
6058
``GenSym``
6159
refers to a consecutively-numbered (starting at 0) static single assignment
6260
(SSA) variable inserted by the compiler.
@@ -75,6 +73,9 @@ These symbols appear in the ``head`` field of ``Expr``\s in lowered form.
7573
function call. ``args[1]`` is the function to call, ``args[2:end]`` are the
7674
arguments.
7775

76+
``static_parameter``
77+
reference a static parameter by index.
78+
7879
``line``
7980
line number and file name metadata. Unlike a ``LineNumberNode``, can also
8081
contain a file name.
@@ -181,38 +182,27 @@ LambdaInfo
181182

182183
``sparam_vals`` - The values of the static parameters (once known), indexed by ``sparam_syms``.
183184

184-
Has an ``->ast`` field pointing to an ``Expr`` with head ``lambda``. This
185-
``Expr`` has the following layout:
185+
``code`` - An ``Any`` array of statements, or a UInt8 array with a compressed representation of the code.
186186

187-
``args[1]``
188-
``Vector{Any}`` of argument name symbols. For varargs functions, the last
189-
element is actually an ``Expr`` with head ``...``. The argument of this
190-
``Expr`` is an ``Expr`` with head ``::``. The first argument of ``::`` is a
191-
symbol (the argument name), and the second argument is a type declaration.
187+
``slotnames`` - An array of symbols giving the name of each slot (argument or local variable).
192188

193-
``args[2]``
194-
A ``Vector{Any}`` with variable information:
189+
``slottypes`` - An array of types for the slots.
195190

196-
``args[2][1]`` - An array of 3-element ``varinfo`` arrays, one for each
197-
argument or local variable. A ``varinfo`` array has the form ``Any[:name,
198-
type, bits]``. The ``bits`` field is an integer
199-
describing variable properties as follows:
191+
``slotflags`` - A UInt8 array of slot properties, represented as bit flags:
200192
- 1 - captured (closed over)
201193
- 2 - assigned (only false if there are *no* assignment statements with this var on the left)
202194
- 4 - assigned by an inner function
203195
- 8 - const (currently unused for local variables)
204196
- 16 - statically assigned once
205197
- 32 - might be used before assigned. This flag is only valid after type inference.
206198

207-
``args[2][2]`` - An array of ``varinfo`` triples for each outer variable
208-
this function captures.
199+
``gensymtypes`` - Either an array or an Int giving the number of compiler-inserted
200+
temporary locations in the function. If an array, specifies a type for each location.
209201

210-
``args[2][3]`` - The types of variables represented by ``GenSym`` objects.
211-
Given ``GenSym`` ``g``, its type will be at ``args[2][3][g.id+1]``.
202+
``nargs`` - The number of argument slots. The first ``nargs`` entries of the slots
203+
arrays refer to arguments.
212204

213-
``args[3]``
214-
an ``Expr`` with head ``body`` whose arguments are the statements
215-
comprising the function body.
205+
``isva`` - A boolean indicating whether the function is variadic.
216206

217207

218208
Surface syntax AST

0 commit comments

Comments
 (0)