Commit Graph

276 Commits

Author SHA1 Message Date
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
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.
2022-09-13 10:35:29 +01:00
Hamish Knight
6804623a82 Fix some nullptr dereferences
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.
2022-09-13 10:35:28 +01:00
Alex Hoppen
a7dcd4604e [SourceKit] Add an operator syntax kind
This will allow us to do semantic highlighting for operators in SourceKit-LSP.
2022-07-25 07:19:49 +02:00
Pavel Yaskevich
b7860ea055 [TypeChecker] Split for-in sequence into parsed and type-checked versions 2022-05-30 23:17:41 -07:00
swift-ci
9fb0628010 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-01 04:13:53 -08:00
Ben Barham
3ceb0a30df [SourceKit] Use stack of argument mappings when walking the syntax model
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.
2021-12-01 14:02:53 +10:00
swift-ci
bc71cf7c54 Merge remote-tracking branch 'origin/main' into rebranch 2021-11-30 15:21:46 -08:00
Ben Barham
cb81c1a1aa [SourceKit] Add structure node for SubscriptExpr
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.
2021-11-30 19:56:48 +10:00
Ben Barham
e139a2f2ea [rebranch] Rename various functions to match new names in LLVM
llvm-project 601102d282d5e9a1429fea52ee17303aec8a7c10 renamed various
functions in `CharInfo.h` and `Lexer.h`. Rename uses in Swift.
2021-11-13 15:33:09 +10:00
swift_jenkins
aa6ae962c4 Merge remote-tracking branch 'origin/main' into next 2021-09-04 11:41:02 -07:00
swift-ci
cb32b553de Merge remote-tracking branch 'origin/main' into rebranch 2021-09-04 11:32:57 -07:00
Hamish Knight
488e91a0ae [SyntaxModel] Clear ArgumentInfo when outside of an argument list
Track the depth and clear out the map when it
reaches 0 to save memory.
2021-09-01 18:40:28 +01:00
Hamish Knight
78d8d09b99 [IDE] Adopt ArgumentList 2021-09-01 18:40:26 +01:00
swift_jenkins
e06e03926a Merge remote-tracking branch 'origin/main' into next 2021-08-13 17:01:35 -07:00
swift-ci
e5ab372616 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-13 16:55:57 -07:00
Ben Langmuir
c7c899ead8 Fix URL detection for "sip" and "service" schemes
We were concatenating these strings due to the missing comma. Found by
clang-tidy.
2021-08-13 12:20:11 -07:00
swift-ci
f9fa632ccf Merge remote-tracking branch 'origin/main' into rebranch 2021-07-27 09:53:29 -07:00
swift_jenkins
baca749839 Merge remote-tracking branch 'origin/main' into next 2021-07-27 09:41:29 -07:00
Hamish Knight
470cb261ef [SyntaxModel] Correctly annotate unlabelled unary args
Previously we would only handle TupleExpr argument
list exprs. Update the logic to handle ParenExpr
argument lists too.

rdar://81154978
2021-07-27 11:38:07 +01:00
Hamish Knight
e4b7e3104a [SyntaxModel] Remove some dead code
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.
2021-07-27 11:38:06 +01:00
Evan Wilde
42ff140171 llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.

(cherry picked from commit e21e70a6bf)
2021-07-02 10:55:17 -07:00
Evan Wilde
e21e70a6bf llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.
2021-06-30 10:57:47 -07:00
Hamish Knight
cc62c116f8 [ASTWalker] Don't visit capture list vars twice
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.
2021-06-08 22:56:05 +01:00
Rintaro Ishizaki
c991347160 [IDE] Explicitly specify 'SerializedOK=false' to 'getRawComment()'
This ensures that we don't try getRawComment() from serialized locations

rdar://problem/75010520
2021-03-18 17:30:36 -07:00
Minhyuk Kim
e924cf6104 Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key) 2021-02-04 00:42:04 +09:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Slava Pestov
fa4f7dd664 Parse: Don't create PatternBindingDecls with overlapping source ranges
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 }
2020-09-22 00:16:54 -04:00
Anthony Latsis
492156c10f Remove SubscriptDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Anthony Latsis
21faa48298 Remove FuncDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Dmitri Gribenko
b6d0ef5c81 Remove support for a broken std::regex in libstdc++ 4.8
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.
2020-05-19 17:20:55 +02:00
Nathan Hawes
fe9fc260fa Merge pull request #31465 from nathawes/doc-info-availability-catalyst
[IDE] Loosen assertion check in IDE/SyntaxModelWalker
2020-05-04 09:30:23 -07:00
Nathan Hawes
deecb58fe6 [IDE] Loosen assertion check in IDE/SyntaxModelWalker
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
2020-05-01 10:33:22 -07:00
Robert Widmann
1319b53528 Hide the TypeExpr in ClosureExpr 2020-04-29 13:40:39 -07:00
Robert Widmann
5b3060318e [NFC] Strip ClosureExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Nathan Hawes
7c0a17803d [Sema] Maintain the implicitness of call argument tuple/parens in coerceCallArguments
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
2020-04-23 18:54:46 -07:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
Nathan Hawes
5e1985c989 [SourceKit] Fix SyntaxModel assertion failures due to consuming tokens twice or prematurely
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
2020-02-12 13:44:04 -08:00
Argyrios Kyrtzidis
73c3e1c693 [IDE/SyntaxModel] For syntactic structure, make sure to not visit the captured list variables twice
rdar://59302427
2020-02-11 15:37:22 -08:00
Kita, Maksim
ea6a2dc094 SR-11889: Fixed code review issues
1. Updated Located field names with Pascal Case
2. Updated Located constuctor
3. Formatted lines with more than 80 symbols
2019-12-20 17:18:59 +03:00
Kita, Maksim
c1444dea18 SR-11889: Fixed code review issues 2019-12-20 17:18:59 +03:00
Brent Royal-Gordon
1df792ae9f [NFC] Convert TypeRepr to use DeclName(Loc)?
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
2019-12-11 00:45:08 -08:00
Nathan Hawes
11d20b8c92 [IDE] Avoid name binding in sourcekitd's syntactic requests
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
2019-11-16 13:41:20 -08:00
David Ungar
cd95ddb395 Don't do lookups into inactive clauses 2019-11-05 12:10:43 -08:00
Nathan Hawes
666a98cfd8 [syntax-coloring] Add fallback handling for coloring object literals when they don't appear in the AST
Resolves rdar://problem/55680999
2019-10-09 12:15:43 -07:00
Robert Widmann
2fe3ce8af8 Requestify the Raw Value Accessor
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.
2019-10-02 16:09:25 -07:00
David Ungar
ea81fdc7d8 Merge pull request #27313 from davidungar/generic-request-or-extended-nominal-assertion
Fail early if getExtendedNominal is called before extension has been bound.
2019-09-30 08:37:33 -07:00
David Ungar
4bc4030338 Catch failures earlier caused by premature requests for extended nominal 2019-09-28 15:19:32 -07:00