Commit Graph

719 Commits

Author SHA1 Message Date
Hamish Knight
3d3a2a5925 Remove redundant state from PersistentParserState
Now that we parse Swift decls in one pass, we no
longer need to track the parser's position across
multiple parser calls.
2020-02-04 13:04:50 -08:00
Hamish Knight
312f7ddc50 Parse Swift decls in one shot
Instead of interleaving typechecking and parsing
for SIL files, first parse the file for Swift
decls by skipping over any intermixed SIL decls.
Then we can perform type checking, and finally SIL
parsing where we now skip over Swift decls.

This is an intermediate step to requestifying the
parsing of a source file for its Swift decls.
2020-02-04 13:04:50 -08:00
Hamish Knight
dfeb482bf4 NFC: Rename isStartOfDecl -> isStartOfSwiftDecl
Make it clear that this function doesn't deal with
SIL decls.
2020-02-04 13:00:41 -08:00
David Ungar
d61f6f2f66 Changes to support per-type-body fingerprints. 2020-01-27 15:14:46 -08:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
Daniel Duan
0c6c5aa1a2 [Parse] Remove unnecessary conversion to SourceRange (#28926)
`SourceLoc`s are implicitly converted to `SourceRange`. Yay.

NFC, Gardening
2020-01-02 11:05:30 -08:00
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
ff97c06e8d [CodeCompletion] Use offsets in the buffer for second pass state
So that we can use the different the buffer for the second pass from the
first pass.
2019-12-18 21:52:20 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
4b9a219d4f [NFC] Add DeclNameRef type to the compiler
This type wraps a DeclName, indicating that it is a reference to a declaration that exists somewhere else and it requires slightly “fuzzy” comparison (i.e. if it’s not compound, only the base names should be compared). DeclName::matchesRef() and MemberLookupTable::find() both now take a DeclNameRef instead of a DeclName.

This commit temporarily allows implicit conversion from DeclName; I’ll flip the switch on that in a later commit.
2019-12-11 00:45:08 -08:00
Rintaro Ishizaki
6f201dbe54 [CodeCompletion] Don't restore the parser position after the second pass
This is just not necessary. This parser lives only for the single second
pass.
2019-11-22 17:36:39 +09:00
Rintaro Ishizaki
8fae0893e1 [CodeCompletion] Don't use temporary Lexer in the second pass
Since we only call one parsing function (i.e. parseAbstructFunctionBody,
parseDecl, or parseStmtOrExpr), the parser stops at the end of the node.
It's not necessary to limit the Lexer to set an ArtificialEOF.

To minimize the parsing range, modify the Parser to *not* parse the body
if the completion happens in the signature.
2019-11-22 17:18:32 +09:00
Slava Pestov
86f6570662 Stop using SharedTimer except to implement FrontendStatsTracer
Name binding can trigger swiftinterface compilation, which creates
a new ASTContext and runs a compilation job. If the compiler was
run with -stats-output-dir, this could trigger an assertion because
SharedTimer is not re-entrant.

Fix this by replacing all direct uses of SharedTimer in the frontend
with FrontendStatsTracer. SharedTimer is still used to _implement_
FrontendStatsTracer, however we can collapse some of the layers in
the implementation later. Many of the usages should also become
redundant over time once more code is converted over to requests.
2019-11-18 12:05:49 -05:00
Rintaro Ishizaki
63c1f847ae Merge pull request #28182 from rintaro/ide-completion-rdar56926367
[Parse/CodeCompletion] Cleanup code completion facilities in Parse
2019-11-13 11:06:07 +09:00
Rintaro Ishizaki
cd8ebe49bb [Parse/CodeCompletion] Cleanup code completion facilities in Parse
- Rename code completion related names in 'PersistentParserState' so
  it's clear when you are using.
- Refactor 'performCodeCompletionSecondPass()': Inline and consolidate
  'parse*Delayed()' because they used to share many code.

rdar://problem/56926367
2019-11-13 03:21:03 +09:00
Robert Widmann
48805b1d44 Give ASTContext TypeCheckerOptions
Strip TypeChecker of all of this state.
2019-11-12 09:56:01 -08:00
Gogul Balakrishnan
5accda22b2 [AutoDiff upstream] Introduce @differentiable attribute to mark functions as differentiable. (#27506)
This PR introduces `@differentiable` attribute to mark functions as differentiable. This PR only contains changes related to parsing the attribute. Type checking and other changes will be added in subsequent patches.

See https://github.com/apple/swift/pull/27506/files#diff-f3216f4188fd5ed34e1007e5a9c2490f for examples and tests for the new attribute.
2019-11-11 13:58:34 -08:00
Rintaro Ishizaki
4b01a973f3 [CodeCompleiton] Avoid walking the whole module to find the delayed func
Previously delayed parsing was performed by AST walker
'ParseDelayedFunctionBodies' by finding "delayed" function decl from the AST
of the whole module. This is not necessary. Optimize it by remembering the
"delayed" function decl in 'PersistentParserState'.

NOTE: 'SourceLoader' stopped using this delayed parsing mechanism in
d8b745db77

rdar://problem/56819166
2019-11-01 10:51:40 -07:00
Rintaro Ishizaki
aeec682c90 [SyntaxParse] Prevent memory leak in Syntax parsing
Essentially re-applying b09f87594a
2019-10-15 16:27:32 -07:00
Rintaro Ishizaki
8a03e08966 Revert "Merge pull request #26403 from rintaro/gsoc-2019-part1"
This reverts commit 1a211e6e5f, reversing
changes made to 482d0621a6.
2019-10-14 15:18:05 -07:00
Rintaro Ishizaki
570ed9361f Revert "Merge pull request #26883 from rintaro/revert-revert-26478-gsoc-2019-parser-types"
This reverts commit faaa3a859d, reversing
changes made to 62f947d6ba.
2019-10-14 15:18:05 -07:00
Rintaro Ishizaki
62408b0c78 Revert "Merge pull request #27046 from rintaro/syntaxparse-refactor-type"
This reverts commit a7d6612813, reversing
changes made to 111fb37f74.
2019-10-14 13:40:24 -07:00
Rintaro Ishizaki
cb00b8faf9 Revert "Merge pull request #27120 from rintaro/parser-rdar55267292"
This reverts commit e1b51f32aa, reversing
changes made to 086eb07ede.
2019-10-14 13:39:48 -07:00
Rintaro Ishizaki
00613db8db Revert "Merge pull request #27230 from rintaro/syntaxparsse-rdar55421369"
This reverts commit b09f87594a, reversing
changes made to d0b7ecab00.
2019-10-14 12:47:23 -07:00
Rintaro Ishizaki
8768832f24 Revert "Merge pull request #27281 from rintaro/reapply-syntaxparse-genericparam"
This reverts commit 5d3e8d6c83, reversing
changes made to 27e881d97e.
2019-10-14 12:46:31 -07:00
Rintaro Ishizaki
baa0ef70b3 Revert "Merge pull request #27286 from nathawes/r55280477-tuple-type-syntax-round-trip"
This reverts commit 8555d1b84a, reversing
changes made to e315b6ff6a.
2019-10-14 12:39:44 -07:00
Rintaro Ishizaki
cd1a2995ff Revert "Merge pull request #27531 from rintaro/syntaxparse-matchingtoken"
This reverts commit 2035658c57, reversing
changes made to 18f2b97641.
2019-10-14 12:17:45 -07:00
Rintaro Ishizaki
2f40f2493b Revert "Merge pull request #27565 from rintaro/syntaxparse-exprcollection"
This reverts commit 1724f5b704, reversing
changes made to bc1a3eaaa5.
2019-10-14 12:16:31 -07:00
Rintaro Ishizaki
0e8010d8b9 Revert "Merge pull request #27592 from rintaro/syntaxparse-exprtuple"
This reverts commit cdfd1ab2cf, reversing
changes made to eb02f20f99.
2019-10-14 12:15:48 -07:00
Rintaro Ishizaki
ebbc9c837f [SyntaxParse] Don't update PreviousLoc when ignoring token.
So that the last token in Syntax and PreviousLoc match.
2019-10-09 14:48:47 -07:00
Rintaro Ishizaki
0d4cf76ed0 [SyntaxParse] Renew parseListSyntax()
Optimize for libSyntax parsing.
The new 'parseListSyntax()' receives a vector storage, passes element
builder to the callback for populating the elements, then automatically
parses trailing commas. Also, it performs automatic recovery if the
element has an error (e.g. Skip until ',' or ')').
2019-10-08 23:11:08 -07:00
Rintaro Ishizaki
f42f60f233 [Syntax] Consolidate 'TupleElement' and 'FunctionCallArgument' kinds
into 'TupleExprElement'. They had exact the same layout.
2019-10-07 20:52:11 -07:00
Rintaro Ishizaki
9f26b5615f [SyntaxParse] Remove unused overload of parseMatchingTokenSyntax() 2019-10-03 14:52:55 -07:00
Rintaro Ishizaki
c022ff23e8 [SyntaxParse] Adjust parseMatchingToken() 2019-10-03 13:48:57 -07:00
Nathan Hawes
e89efa8f81 [parser] Fix tuple type round-tripping issue
`public init(a: (b || c))` became `public init(a: )(b || c)` after
round-tripping.

Resolves rdar://problem/55280477
2019-09-20 19:04:41 -07:00
Rintaro Ishizaki
f919b2ddd8 [SyntaxParse] Parse generic parameter clause and generic where clause 2019-09-19 23:09:58 -07:00
Rintaro Ishizaki
b09f87594a Merge pull request #27230 from rintaro/syntaxparsse-rdar55421369
[SyntaxParse] Re-apply move-only ParsedRawSyntaxNode
2019-09-19 07:36:14 +02: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
Rintaro Ishizaki
9f642f0bc1 Revert "Merge pull request #27203 from CodaFi/movin-on-up"
This reverts commit 387d2a9aee, reversing
changes made to bf1ab6c29d.
2019-09-17 16:42:44 -07:00
Robert Widmann
d8aaf29617 Revert "Merge pull request #27132 from rintaro/syntaxparse-parsedrawsyntax-moveonly"
This reverts commit e675c4947d, reversing
changes made to 73315ba01e.
2019-09-16 15:10:33 -07:00
Rintaro Ishizaki
80085e0d27 [SyntaxParse] Make ParsedRawSyntaxNode move-only
So that we can easily detect 'ParsedSyntaxNode' leaking. When it's
moved, the original node become "null" node. In the destructor of
'ParsedSyntaxNode', assert the node is not "recorded" node.
2019-09-11 16:33:49 -07:00
Rintaro Ishizaki
da95961de2 [SyntaxParse] Fix a crash in TokenReceiver
rdar://problem/55267292
2019-09-11 10:51:07 -07:00
Rintaro Ishizaki
a7d6612813 Merge pull request #27046 from rintaro/syntaxparse-refactor-type
[SyntaxParse] Refactor parsing facilities
2019-09-11 06:43:42 +02:00
Rintaro Ishizaki
a9af910664 [SyntaxParse] Add ignoreToken() function to ignore tokens 2019-09-10 10:29:02 -07:00
Rintaro Ishizaki
8edea315cd [Syntax] Abolish 'backtick' trivia
- Stop producing 'backtick' trivia for escaping identifier token. '`'s
  are now parts of the token text
- Adjust and simplify C++ libSyntax APIs
- Add 'is_deprecated' property to Trivia.py to attribute SwiftSyntax
  APIs

rdar://problem/54810608
2019-09-09 11:49:25 -07:00
Doug Gregor
6d390e44d9 Allow delayed body parsing in parseDelayedDecl().
When performing delayed decl parsing (e.g., for code completion),
allow other function bodies to be delayed.
2019-09-03 11:41:19 -07:00
Doug Gregor
d7f6768a9d Eliminate DelayedParsingCallbacks.
DelayedParsingCallbacks only had one implementation, for code
completion, which is only used to determine which bodies to skip and
which to delay. Inline that logic into the parser's delay logic and
remove DelayedParsingCallbacks entirely.
2019-09-02 19:03:07 -07:00
Doug Gregor
d8b745db77 Add a request to lazily parse function bodies.
Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
2019-08-31 16:23:08 -07:00
eeckstein
903eeb220b Revert "Add a request to lazily parse function bodies." 2019-08-31 12:29:01 +02:00