To allow for local functions that call themselves recursively, as well
as variable declarations that are (erroneously) referred to prior to
their first use, the Factory API needs to be adjusted so that it's
possible for a local function (or local variable) to be referred to
prior to its body (or initializer) being built.
The analyzer and the kernel have different ways of referring to local
functions and variables; in the kernel the reference
(e.g. VariableGet) points directly to the declaration
(VariableDeclaration). In the analyzer both the reference and the
declaration point to a FunctionElement (or LocalVariableElement). So
we want the Factory API to support both approaches.
This CL introduces the idea of a "lemma" (borrowed from linguistics).
In linguistics, a lemma is the mental binding site to which words and
meanings are attached. In the Factory API, a lemma is an object that
can be created before the function's body (or the variable's
initializer) is available. Thereafter, the declaration and the
references can be bound to the lemma in any order.
In the analyzer implementation, the lemma will be represented by a
FunctionElement or LocalVariableElement. (Note however that for the
moment we use a temporary object because the ResolutionStorer is not
yet creating elements and AST nodes). In the kernel implementation,
the VariableDeclaration node itself is used as the lemma, so the act
of "binding" the lemma to a declaration will do nothing more than
storing the body or initializer, and returning the same object.
Note that there are other syntactic constructs that can declare local
variables (closure parameters, for loops, and catch clauses). I'll
hook them up to the lemma mechanism in a future CL.
Also a future CL will introduce the same mechanism for labeled
statements (which have a similar need for references to be built
before the labeled statement is completed).
Change-Id: Ifa3b04dda7ce25d115ad58a471d164b4c24d539c
Reviewed-on: https://dart-review.googlesource.com/61720
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
We are pivoting our implementation of FE/Analyzer integration a little
bit, and so the BodyBuilder will not be parameterized in exactly the
same way. Remove the existing parameterization from it and all the
supporting classes. This requires specializing the BodyBuilder to the
front end's instantiation of it and deleting the corresponding code in
the Analyzer.
Fixes https://github.com/dart-lang/sdk/issues/33503
Change-Id: I3ddcd2c5f5ebd8f2ff95f2ec8d4c7b98b70a0b0a
Reviewed-on: https://dart-review.googlesource.com/61502
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Prior to this change we only had fileOffset which points to the name.
This CL adds a field - startFileOffset - that points to the start
(e.g. 'static', 'factory', the return type or any presiding annotation
(including '@')), as well as fixing `Function::GetSource` in the VM to
fix a crash when using mirrors to ask for the source of a function or
constructor.
The field is added to procedures, constructors and classes.
The latter changes the location of classes with annotations to be
the position of the annotation. This is on-par with --no-preview-dart-2.
The change in regards to procedures and constructors mean, that both
the location and the source (from .location and .source on a
MethodMirror) will change to include any annotations. This is a
different behavior than --no-preview-dart-2.
Closes#33271.
Change-Id: I90f1232c5ec2d01e60e0bab070d44c37232b2730
Reviewed-on: https://dart-review.googlesource.com/60560
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
This CL makes the following changes:
- Removes the type parameters from the ResolutionStorer interface;
they remain in the implementation (which is now called
_ResolutionStorer). In a follow-up CL I will add type parameters to
ResolutionStorer to match those expected by Factory. In the long
term, once the types have settled down, I'll fuse ResolutionStorer
and _ResolutionStorer back together and make the types more
concrete.
- Removes the "...Enter" calls from ResolutionStorer and
TypeInferenceListener. Now all the information needed by the
analyzer is passed in the "...Exit" methods (and the word "Exit" has
been dropped from the method names). As a consequence,
_ResolutionStorer no longer needs to use a stack of function
pointers to defer work from the "...Enter" to the "...Exit" calls.
- Removes the TypeInferenceBase class and moves the base class methods
into ResolutionStorer. This makes TypeInferenceListener a strictly
abstract interface class, which is easier to reason about.
- Adds a KernelTypeInferenceListener class, which implements
TypeInferenceListener and does nothing. This is used during top
level type inference, where we don't need to report resolution
information to the analyzer. Eventually this will be replaced with
ToplevelInferenceFactory.
In a follow-up CL I will add additional parameters to the
ResolutionStorer methods so that they match the Factory method
signatures exactly, and add an "implements" clause to keep them in
sync.
Change-Id: I908b643293d051474dfb4ff24430430bc1572672
Reviewed-on: https://dart-review.googlesource.com/61403
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This gets the tests running again. I'll follow this up with CLs that
reshape the ResolutionStorer API to match the Factory API we're
building, and then after that we can transition the code over to
calling the Factory API directly.
Fixes#33504Fixes#32258
Change-Id: I105841ed5b2ed1198ec5e3e7387f694c61d36ca7
Reviewed-on: https://dart-review.googlesource.com/61101
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Back in January we wanted to strip the call to unary- in the minimum
int64 literal. Now we have decided we want to keep it for the back
ends.
Change-Id: I06b3e20e63a59c84828eb5bdba4613f1c226ecbb
Reviewed-on: https://dart-review.googlesource.com/60444
Reviewed-by: Stephen Adams <sra@google.com>
Previously, the file offset pointed to the "@" token. Now it points
to the constructor name, which makes more sense, and will simplify
integration with the analyzer.
Change-Id: I949d092abebf6a9e99f1d59285ca0ebcbc3b86cc
Reviewed-on: https://dart-review.googlesource.com/60808
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>