Commit Graph

233 Commits

Author SHA1 Message Date
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
Rintaro Ishizaki
fedc36e4fb [IDE] Don't walk to ExplicitCast expr twice in ModelASTWalker
Explict cast expressions (i.e. 'as', 'as!`, 'as?', and 'is') appear twice in
'SequenceExpr'. For instance, 'a as B' is parsed as:
  (sequence_expr
    (unresolved_declref_expr name='a')
    (coerce_expr writtenType='B')
    (coerce_expr writtenType='B'))
This patch prevents ModelASTWalker from walking into them twice.

rdar://problem/43135727
2018-08-14 08:19:48 +09:00
Rintaro Ishizaki
49f6a28637 [IDE] Use collected token to retrieve range of type identifier
Previously, it used to use length from AST. Because AST doesn't necessarily
holds actual source information, it may emits inacculate syntax info
which cause mis-coloring or compiler crash in the worst case. Instead, use
collected token info which contains actual token length.

https://bugs.swift.org/browse/SR-8378
rdar://problem/42653982
2018-08-02 10:02:58 +09:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Alex Hoppen
9149cb61c5 Merge pull request #16474 from ahoppen/namelength
[SourceKit] Make the NameLength of EnumElements take argument labels into account
2018-05-10 12:14:11 -07:00
Alex Hoppen
4f43c8e93c [SourceKit] Make the NameLength of EnumElements take argument labels into account 2018-05-10 11:27:49 -07:00
Rintaro Ishizaki
1fa04208e0 [IDE] Fix visiting DeferStmt
* Call balanced walkToStmtPost() for DeferStmt.
* In walkToStmtPre(), return DeferStmt itself instead of the body.

rdar://problem/39948168
2018-05-08 16:32:52 +09:00
Sho Ikeda
976c7f9c27 [gardening][IDE] Replace typedef with using 2018-03-26 13:45:36 +09:00
Rintaro Ishizaki
bdcd87754d [Parse] Eliminate POUND_OLD_OBJECT_LITERAL tokens
We don't want to handle them in libSyntax
2018-03-14 21:50:53 +09:00
John Fairhurst
677491fc9b [SourceKit] Add syntaxtype for #error/#warning (#14742) 2018-02-21 14:48:18 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Marcelo Fabri
94465a38c0 [SourceKit] Add GenericTypeParam to structure (SR-5474) (#13616) 2018-01-09 17:28:52 -08:00
Marcelo Fabri
b6ecf9c6d4 [SourceKit] Introduce "source.lang.swift.expr.closure" in structure (SR-6116) (#13617) 2018-01-04 10:45:29 -08:00
Marcelo Fabri
95383df793 [SourceKit] Introduce "source.lang.swift.expr.tuple" (SR-5977) (#12089) 2017-09-27 10:08:27 -07:00
Nathan Hawes
90cc29bb2c [syntax-coloring] Highlight unterminated regular and multi-line strings as strings
Also add tests for syntax map deltas when editing multi-line strings
2017-09-14 21:34:21 -07:00
Xi Ge
2ba1ca2d8f IDE: simplify some code. NFC (#11935)
* IDE: simplify some code. NFC

* add assert.
2017-09-14 18:19:48 -07:00
Xi Ge
6970b692e1 SyntaxModel: remove more unnecessary code. NFC 2017-09-08 13:23:48 -07:00
Xi Ge
0cfa094e75 SyntaxModel: remove unnecessary code. NFC (#11820) 2017-09-08 13:13:01 -07:00
Xi Ge
560b08c171 SyntaxModel: simplify the collecting of contextual keywords in PrecedenceGroup.NFC (#11819) 2017-09-08 12:38:44 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Marcelo Fabri
5c65887fd0 [SourceKit] Add function argument when optional chaining is used (SR-5717) (#11542) 2017-08-29 12:59:43 -07:00
Marcelo Fabri
8b9b49fdf3 [SourceKit] Add associatedtype to doc structure (SR-5700) 2017-08-16 23:40:36 +02:00
Marcelo Fabri
c639147f02 [SourceKit] Include function return type in function kinds structure (SR-5613) 2017-08-14 20:53:00 +02:00