734 Commits

Author SHA1 Message Date
Hamish Knight
b857b224c7 NFC: Rename shouldCollectToken -> shouldCollectTokens
And fix the name of the underlying vector.
2020-06-03 11:03:54 -07:00
Hamish Knight
49fed42d03 NFC: Remove SILParserState from Subsystems
Since SIL parsing has been requestified, this is
now redundant. Remove the type from Subsystems.h,
and rename SILParserTUState to take its place.
2020-05-21 14:39:57 -07:00
Argyrios Kyrtzidis
6bfde00934 [Parser/libSyntax] For accessor parsing only backtrack until the accessor introducer
Previously it was backtracking for the duration of the whole property body which was preventing re-use of previously parsed nodes for incremental re-parsing.
2020-05-09 20:23:41 -07:00
Slava Pestov
b81c0d63d1 AST: Remove SourceFileKind::REPL 2020-05-07 02:04:05 -04:00
Hamish Knight
7f8a0e8a6c Requestify implicit imports
Add ModuleImplicitImportsRequest, which computes
the modules that should be implicitly imported by
each file of a given module. Use this request in
import resolution to add all the necessary
implicit imports.

The request computes the implicit imports by
consulting the ImplicitImportInfo, which ModuleDecl
can now be created with. This allows us to remove
uses of `SourceFile::addImports` in favor of
adding modules needed to be implicitly imported to
the ImplicitImportInfo.
2020-04-20 13:20:35 -07:00
Robert Widmann
ee9bf600b3 [NFC] Requestify Code Completion's Second Pass
Code Completion operates on a CompilerInstance that passes a primary
file down for type checking. This means it creates and registers
dependencies in the referenced name trackers. Despite the fact that
those dependencty edges are unused,
because the would-be swiftdeps file is never written to disk,
it is still a dependency source that should participate in the
request-based dependency tracking refactor.
2020-03-19 23:25:38 -07:00
Nathan Hawes
1c729ca3e1 [Parse] Fix up a few places where we weren't propagating parse error status correctly.
We were always dropping the error status when returning from parseExprImpl. We
were also incorrectly keeping error status after recovering by finding the
right close token in parseList. This change fixes both, and also updates a few
callers of parseList that assumed when they reported a failure parsing an
element the list as a whole would get error status, which isn't true due to
recovery.
2020-03-10 21:04:22 -07:00
Hamish Knight
011f4f1584 Requestify SourceFile parsing
Add ParseSourceFileRequest that parses a SourceFile
for its top-level decls.
2020-03-03 15:53:18 -08:00
Hamish Knight
f56b061407 [Parse] Check the SourceFile for #if evaluation
Remove the `EvaluateConditionals` flags from the
parser, and instead query the source file.

This commit also changes ParserUnit such that it
doesn't evaluate #if conditions by default, as
none of its clients appear to require it. The
only client that wasn't explicitly disabling #if
evaluation and is processing the resulting AST is
swift-indent, so this commit also adds a test to
ensure it continues to work correctly with #if
decls.
2020-03-02 14:12:37 -08:00
Hamish Knight
2724cf6f65 [Parse] Check the SourceFile to see if bodies can be delayed
Remove the `DelayBodyParsing` flag from the parser
and instead query the source file.
2020-03-02 14:12:37 -08:00
Hamish Knight
2ec619caf7 [AST] Add a few parsing flags to SourceFile
Add flags for whether delayed body parsing or #if
condition evaluation is disabled, as well as
whether warnings should be suppressed. Then pass
down these flags from the frontend.

This is in preparation for the requestification of
source file parsing where the SourceFile will need
to be able to parse itself on demand.
2020-03-02 14:12:37 -08:00
Hamish Knight
d77cae6720 Move PersistentParserState onto SourceFile
Move the global PersistentParserState from
the CompilerInstance to the source file that code
completion is operating on, only hooking up the
state when it's needed. This will help make it
easier to requestify source file parsing.
2020-03-02 11:22:44 -08:00
Hamish Knight
0d5a5e12d5 Move #if evaluation flag out of PersistentParserState
Move this flag onto the parser instead. Now the
only client of PersistentParserState is code
completion.
2020-02-28 10:51:12 -08:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Rintaro Ishizaki
8936633451 [Parse] Consolidate AFD body parsing implemtations 2020-02-12 10:05:12 -08:00
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