Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.
There is still more work that can be done here, in
particular:
- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.
But I'm leaving those as future work for now as
this patch is already large enough.
Turns out we were getting away with dereferencing
`nullptr` in a few cases as `walk` would use
`nullptr` to indicate that the walk should be
stopped, and luckily Clang didn't optimize it to
something broken.
This commit is fairly defensive and sprinkles
some null checks for calls to `walk` directly
on a body of a function or top-level code decl.
A single map of arguments allows an argument to be added to an incorrect
node, eg. when the parent node isn't handled but the argument is mapped.
Use a stack of (parent, mappings) instead and check that the parent
matches to ensure this cannot happen.
Arguments in `SubscriptExpr` are visited since the recent `ArgumentList`
refactoring, but were being added to the containing `CallExpr`. Add a
node for the `SubscriptExpr` itself so that its argument is added there
instead of the `CallExpr`.
Also remove `key.nameoffset` and `key.namelength` from the response when
both are 0 to match the rest of the offsets and lengths.
Resolves rdar://85412164.
This code doesn't quite do what it says it does,
and appears to be dead as we should never form an
argument list TupleExpr with an OptionalEvaluationExpr
parent. Given the test case that was added with it
still passes, let's remove it.
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.
Ran git clang-format.
(cherry picked from commit e21e70a6bf)
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.
Ran git clang-format.
Previously we were walking them once when visiting
the capture list, and then again as a part of the
pattern binding decl. Change the logic to only
visit them as a part of their pattern binding decl.
This was happening in the error recovery path when parsing accessors
on a pattern binding declaration that does not bind any variables, eg
let _: Int { 0 }
Out of all operating systems ever supported by Swift, only Ubuntu 14.04
had libstdc++ 4.8, and Swift has sunset support for Ubuntu 14.04 for a
while now.
We were asserting that the attribute range recorded in the AST started at the
same location as the fist unconsumed SyntaxNode in the file. This should be
true in most cases, but isn't for mispelled attributes, corrected in the AST
but not recognised or present in the list of SyntaxNodes. E.g.
@availability(...) comes through as if @available(...) was specified, but
there's no SyntaxNode for it because we don't highlight invalid attributes
(to indicate they're invalid).
Resolves rdar://problem/62201594
Resolves https://bugs.swift.org/browse/SR-12500
If any arguments were defaulted the tuple/paren was made implicit, even though
the original tuple/paren was present in the source.
This prevented some sourcekit ASTWalkers from considering them, making
refactorings, documentation info, jump-to-definition and other features
unavailable when queried via their argument labels.
Resolves rdar://problem/62118957
The SyntaxModel walker would end up visiting the attributes attached to a
PatternBindingDecl twice if it contained more than one VarDecl, hitting the
below assertion on the second visit because the tokens corresponding to the
attribute had already been consumed the first time around:
```
Assertion failed: (0 && "Attribute's TokenNodes already consumed?"), function
handleSpecialDeclAttribute
```
It would also hit the same assertion for attributes on an EnumCaseDecl, but even
when it only had a single child EnumElementDecl. This because when we visited
the EnumCaseDecl and pushed its structure node, we'd consume and emit any tokens
before it's start position. This meant that when we tried to process the
attributes attached to the child EnumElementDecl its tokens had already been
consumed, triggering the assertion.
In both cases the attributes syntactically attach to the parent
PatternBindingDecl or EnumCaseDecl, but in the AST they're accessed via their
child VarDecls or EnumElementDecls.
Resolves rdar://problem/53747546
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
It looks like we recently started binding extensions to their nominals in order
to continue to compute access levels via ValueDecl::getFormalAccess() after an
assertion was added to enforce that bindExtensions had been called before
anything tried to call ExtensionDecl::getBoundNominal() - which
getFormalAccess() depends on. Sourcekitd's syntactic requests are made on every
keypress in the editor though, so we shouldn't do any name binding (which may
require module loading) to keep them as fast as possible.
This patch restores the old inferAccessLevel() functions we used prior to the
switch to ValueDecl::getFormalAccess() (plus a few fixes) that does as much as
it can syntactically, without any name binding, and simply doesn't report the
access level in cases where it couldn't be computed without name-binding.
This also fixes an assertion hit we were getting trying to bind extensions in
inactive ifconfig clauses, which ASTScope doesn't support.
Resolves rdar://problem/57202584
Make getRawValueExpr() return a checked value.
This entails a strange kind of request that effectively acts like
a cache warmer. In order to properly check the raw value expression for
a single case, we actually need all the other cases for the
autoincrementing synthesis logic. The strategy is therefore to have the
request act at the level of the parent EnumDecl and check all the values
at once. We also cache at the level of the EnumDecl so the cache
"warms" for all enum elements simultaneously.
The request also abuses TypeResolutionStage to act as an indicator for
how much information to compute. In the minimal case, we will return
a complete accounting of (auto-incremented) raw values. In the maximal
case we will also check and record types and emit diagnostics. The
minimal case is uncached to support repeated evaluation.
Note that computing the interface type of an @objc enum decl *must*
force this request. The enum's raw values are part of the ABI, and we
should not get all the way to IRGen before discovering that we cannot
possibly lay out the enum. In the future, we might want to consider
moving this check earlier or have IRGen tolerate broken cases but for
now we will maintain the status quo and not have IRGen emit
diagnostics.