Commit Graph

305 Commits

Author SHA1 Message Date
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
Nathan Hawes
888529cf97 [IDE] Fix ModelASTWalker passing syntax nodes before the corresponding AST nodes had been visited
This was causing the tokens comprising image literals to be output separately,
rather than as a single object literal.

Resolves rdar://problem/55045797
2019-09-24 11:39:54 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Nathan Hawes
aa0305ee80 [Parse][IDE] Fix document structure request output for interpolated string literals
InterpolatedStringLiteralExpr has a TapExpr, which contains a BraceStmt
containing the builder CallExprs to the builder appendInterpolation /
appendStringLiteral methods used to construct the final string. This is all
implementation detail, but the BraceStmt wasn't marked implicit and had a valid
(but incorrect) SourceRange, so the document structure request treated it as
any other BraceStmt and made a structure node for it. The invalid range ended
up tripping an assertion in the document structure walker in swift-ide-test.

This patch corrects the BraceStmts produced by interpolated strings to be
marked implicit and have the correct range, and also updates ModelASTWalker to
skip over the internal details of interpolated strings when walking them (the
CallExprs were also being emitted).
2019-09-09 09:54:17 -07:00
Robert Widmann
8d22702a22 Use Integrated Caching
Replumb the TypeLoc for the extended type as a TypeRepr instead. Fixup
the myriad callsites this touches in the process.
2019-08-26 11:48:29 -07:00
Nathan Hawes
5d47b45991 [IDE][Parse] Change the source location of TypeAttributes to point to the @ like DeclAttributes 2019-08-05 11:36:32 -07:00
Nathan Hawes
87d17bfb4c [IDE] Fix ModelASTWalker's handling of type attributes
When looking for the SyntaxNode corresponding to a type attribute (like
@escaping), ModelASTWalker would look for one whose range *started* at the type
attribute's source location. It never found one, though, because the
SyntaxNode's range included the @, while the type attribute's source location
pointed to the name *after* the @.
2019-08-05 11:36:32 -07:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Nathan Hawes
218f49052a [IDE] Fix SyntaxModel crash due to out-of-order walking of EnumElementDecls
ModelASTWalker was previously constructing SyntaxNodes for EnumElementDecls
manually when visiting their associated EnumCaseDecl so that they would appear
as children rather than siblings. It wasn't actually walking these nodes
though, so missed handling some things, e.g. closures passed as default
argument values. These were also still being visited later, and because the
first visit consumed all the associated TokenNodes, this was triggering an
assertion due to the associated TokenNodes not matching expectations.
2019-07-23 09:34:25 -07:00
Gwen Mittertreiner
bfae01547f Sort DeclAttributeAndRanges Deterministically
Comparing the start and end of ranges doesn't work in all cases since
both a < b and b < a can be true if a = b. This behavior was causing an
assertion fail in the Windows standard library which while sorting,
asserts that if `a < b`, then  `!(b < a)` in debug mode.

Since ranges don't overlap otherwise, comparing just the starts of the
ranges will properly sort them.
2019-07-12 10:57:02 -07:00
Nathan Hawes
a565430239 [IDE][Index] Fix syntax coloring, index, and rename support for custom attributes
This fixes custom attribute syntax highlighting on parameters and functions
(where function builders can be applied). They weren't being walked in
the function position previously and were walked out of source order in the
parameter position.

It also fixes rename of the property wrapper and function builder type
names that can appear in custom attributes, as well as rename of property
wrapper constructors, that can appear after the type names, e.g.
`@Wrapper(initialValue: 10)`. The index now also records these constructor
occurrences, along with implicit occurrences whenever a constructor is
called via default value assignment, e.g. `@Wrapper var foo = 10`, so that
finding calls/references to the constructor includes these locations.

Resolves rdar://problem/49036613
Resolves rdar://problem/50073641
2019-06-26 18:37:47 -07:00
Argyrios Kyrtzidis
dbc35b4531 [IDE/SyntaxModel] Make sure to properly annotate comment markers in single-line comment blocks
rdar://51893731
2019-06-24 12:19:12 -07:00
Rintaro Ishizaki
fcc35c7012 [SyntaxModel] Don't mark custom attribute as attribute-builtin
rdar://problem/50074156
2019-05-31 11:10:04 -07:00
Xi Ge
d3a192f3c5 SourceKit/SyntaxMap: properly handle object literal syntax for highlighting
We should use parser to figure out the end position of object literal expression instead
of scanning through token stream, which crashes sourcekitd when the syntax is invalid.

Fixing: rdar://48390913
2019-05-22 14:29:57 -07:00
Argyrios Kyrtzidis
b76ac41aff Merge pull request #22090 from marcelofabri/enum-type-syntax-map
[SR-9740][SourceKit] Mark types inside enum case decl as typeidentifiers
2019-03-02 00:10:28 -08:00
Nathan Hawes
a1de792ae3 [IDE][syntax-coloring] Treat unterminated raw strings as strings for syntax coloring purposes
The existing check assumed unterminated strings started with " which is no
longer true now we have raw strings.

Resolves rdar://problem/48269826
2019-02-22 18:53:32 -08:00
Rintaro Ishizaki
d4c3ee6b49 [IDE] Handle '@unknown' attribute in syntax map
`@unknown` is so far the only attribute for statement. Handle it
specially in syntax-map.

rdar://problem/47855035 / https://bugs.swift.org/browse/SR-9873
2019-02-06 11:23:53 -08:00
Rintaro Ishizaki
e7700dc67f [IDE] Fix SyntaxModel to corretly walk sequence expression correctly
* Handle sequence expression at call argument position
* Set the sequence expression as the parent when walking into its sub
  expressions.
* Correctly call walkToExprPost() to the sequence expression.

rdar://problem/47603866 / https://bugs.swift.org/browse/SR-9776
2019-01-28 11:25:07 -08:00
Marcelo Fabri
cab4968da3 [SR-9740][SourceKit] Mark types inside enum case decl as typeidentifiers 2019-01-24 09:14:11 -08:00
Marcelo Fabri
d948823d89 [SR-9576][SourceKit] Fix syntax type when rethrows is present 2019-01-22 20:26:23 -08:00
Slava Pestov
fc8f122336 AST: Remove FuncDecl::getReturnTypeLoc() 2018-12-02 18:41:39 -05:00