Commit Graph

1224 Commits

Author SHA1 Message Date
Robert Widmann
92c8a65f09 Drop references to name binding as a phase
A lot of places appear to mean "name lookup".  A few places meant "import resolution".
2020-03-29 18:51:09 -07:00
Rintaro Ishizaki
7b7599a28d [CodeCompletion] Don't run second pass for decls in closures
For instance:
--
let globalVar = {
    func something(arg: Int) -> Int {
        #^HERE^#
    }
    return something(12)
}()
--
We want to consider this as a top-level completion, not a function body
completion.

rdar://problem/60838686
2020-03-26 00:42:39 -07:00
Argyrios Kyrtzidis
791309155d [Parse] Fix issue with incremental re-parsing for SwiftSyntax emitting bogus parsing error
rdar://60232712
2020-03-18 16:00:04 -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
Nathan Hawes
a368434432 [SourceKit/CodeFormat] Re-work and improve the indentation implementation.
This restructures the indentation logic around producing a single IndentContext
for the line being indented. An IndentContext has:
- a ContextLoc, which points to a source location to indent relative to,
- a Kind, indicating whether we should align with that location exactly, or
  with the start of the content on its containing line, and
- an IndentLevel with the relative number of levels to indent by.

It also improves the handling of:
- chained and nested parens, braces, square brackets and angle brackets, and
  how those interact with the exact alignment of parameters, call arguments,
  and tuple, array and dictionary elements.
- Indenting to the correct level after an incomplete expression, statement or
  decl.

Resolves:
rdar://problem/59135010
rdar://problem/25519439
rdar://problem/50137394
rdar://problem/48410444
rdar://problem/48643521
rdar://problem/42171947
rdar://problem/40130724
rdar://problem/41405163
rdar://problem/39367027
rdar://problem/36332430
rdar://problem/34464828
rdar://problem/33113738
rdar://problem/32314354
rdar://problem/30106520
rdar://problem/29773848
rdar://problem/27301544
rdar://problem/27776466
rdar://problem/27230819
rdar://problem/25490868
rdar://problem/23482354
rdar://problem/20193017
rdar://problem/47117735
rdar://problem/55950781
rdar://problem/55939440
rdar://problem/53247352
rdar://problem/54326612
rdar://problem/53131527
rdar://problem/48399673
rdar://problem/51361639
rdar://problem/58285950
rdar://problem/58286076
rdar://problem/53828204
rdar://problem/58286182
rdar://problem/58504167
rdar://problem/58286327
rdar://problem/53828026
rdar://problem/57623821
rdar://problem/56965360
rdar://problem/54470937
rdar://problem/55580761
rdar://problem/46928002
rdar://problem/35807378
rdar://problem/39397252
rdar://problem/26692035
rdar://problem/33760223
rdar://problem/48934744
rdar://problem/43315903
rdar://problem/24630624
2020-03-10 21:04:21 -07:00
Holly Borla
3634b4366c [Parse] Mark closure parameters as definitively not destructured in
parseClosureSignatureIfPresent.

Otherwise, closure parameters that were parsed as "potentially destructured"
will fail constraint generation, even after the parser has decided
they are not destructured.
2020-03-05 13:45:37 -08:00
Brent Royal-Gordon
222c459fb2 [SE-0274] Stage in #filePath (#29944)
* Stage in #filePath

To give users of #file time to transition, we are first adding #filePath without changing #file’s behavior. This commit makes that change.

Fixes <rdar://problem/58586626>.

* Correct swiftinterface test line
2020-02-27 00:03:13 -06:00
Argyrios Kyrtzidis
bbdada475b [Parse] Try to preserve the invariant that anything that contains KeyPathDotExpr must be wrapped in KeyPathExpr
Even in the presence of invalid code. Fixes typechecker crash in rdar://50666427
2020-02-20 15:07:00 -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
Rintaro Ishizaki
1e8c644a4a [CodeCompletion] Don't discard parsed expression in incomplete ternary
If we are code-completion, we need to keep the parsed expression in the
AST. Don't discard the parsed expression if the middle expression in a
ternary expression has code-completion token. This improves the
completions for:

    let _: MyEnum = condition ? .<HERE>
    let _: MyEnum = condition ? .<HERE> :

rdar://problem/54132682
2020-01-21 15:29:55 -08:00
Rintaro Ishizaki
9d44c455db [CodeCompletion] Use CodeCompletionExpr as a value of dictionary literal
When a completion happens in a key position and the value expression
is missing. This allows type checker to use TypeVariable so it increases
the chance to type check them successfully.
2020-01-16 15:52:56 -08:00
Rintaro Ishizaki
95f12afb7c [CodeCompletion] Improve context type analysis for dictionary literal
- Analyze the type of the literal in the context
- If ':' is missing in the literal, treat the expression as a key
  expression
- If the parent expression is TupleExpr, analyze the context type of the
  tuple first, then return the element type of the position

rdar://problem/57096392
2020-01-16 15:52:48 -08:00
Varun Gandhi
022314a640 Merge pull request #28643 from kitaisreal/using-located-instead-of-pair
[Compiler]: Using Located<T> instead of std::pair<SourceLoc, T>
2020-01-06 14:22:29 -08:00
Daniel Rodríguez Troitiño
fb30e9ec74 [MSVC] Evaluate parameters in the right order.
Parameter evaluation order is unspecified, and MSVC happens to do it in
the opposite order than Clang.

Move the evaluation of the parameters outside the invocation, so the
order is clear, and the token consuming happens in the right order.
2019-12-20 12:10:31 -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
Frederick Kellison-Linn
71697c37ca Allow implicit self in escaping closures when self usage is unlikely to cause cycle (#23934)
* WIP implementation

* Cleanup implementation

* Install backedge rather than storing array reference

* Add diagnostics

* Add missing parameter to ResultFinderForTypeContext constructor

* Fix tests for correct fix-it language

* Change to solution without backedge, change lookup behavior

* Improve diagnostics for weak captures and captures under different names

* Remove ghosts of implementations past

* Address review comments

* Reorder member variable initialization

* Fix typos

* Exclude value types from explicit self requirements

* Add tests

* Add implementation for AST lookup

* Add tests

* Begin addressing review comments

* Re-enable AST scope lookup

* Add fixme

* Pull fix-its into a separate function

* Remove capturedSelfContext tracking from type property initializers

* Add const specifiers to arguments

* Address review comments

* Fix string literals

* Refactor implicit self diagnostics

* Add comment

* Remove trailing whitespace

* Add tests for capture list across multiple lines

* Add additional test

* Fix typo

* Remove use of ?: to fix linux build

* Remove second use of ?:

* Rework logic for finding nested self contexts
2019-12-20 02:38:41 +00:00
Brent Royal-Gordon
bed2ce4ac5 [NFC] Improve wording and usage of subscript/deinit flag 2019-12-15 23:46:42 -08:00
Brent Royal-Gordon
b5f02c3d0c [NFC] Remove unused Parser::parseUnqualifiedDeclName methods 2019-12-15 23:46:42 -08:00
Brent Royal-Gordon
9fa4303dd4 [NFC] Switch uses over to parseDeclNameRef() 2019-12-15 23:46:42 -08:00
Brent Royal-Gordon
c5747c3d96 [NFC] Refactor name parsing into Parser::parseDeclNameRef()
Gives this functionality a more self-documenting interface.
2019-12-15 23:46:42 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08: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
Brent Royal-Gordon
850583aceb [NFC] Extract Parser::parseUnqualifiedDeclBaseName 2019-12-11 00:45:07 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Owen Voorhees
a3946cdb50 Revert "Revert "[Diagnostic] Improve diagnostic for trailing closures in statement conditions (#25165)""
This reverts commit e3a6b67c63.
2019-11-19 13:24:20 -08:00
Robert Widmann
dd1b15775d Partially Revert #27862
When SE-110 was being implemented, we accidentally began to accept
closure parameter declarations that had no associated parameter names,
e.g.

foo { ([Int]) in /**/ }

This syntax has never been sanctioned by any version of Swift and should
be banned.  However, the change was made long enough ago and there are
enough clients relying on this, that we cannot accept the source break
at the moment.  For now, add a bit to ParamDecl that marks a parameter
as destructured, and back out setting the invalid bit on the type repr
for these kinds of declarations.

To prevent further spread of this syntax, stub in a warning that offers
to insert an anonymous parameter.

Resolves part of rdar://56673657 and improves QoI for errors like
rdar://56911630
2019-11-10 22:10:53 -08:00
David Zarzycki
49276074fd [Parser] Track missing right brace correctly
Fixed compiler crasher 28651 now exits in milliseconds rather than seconds
because the constraint solver is no longer trying to solve a large
number of nested closures with missing right braces.
2019-11-05 15:27:14 +02:00
Robert Widmann
6dc3f4aad9 Fixup the destructuring diagnostics
Use the isInvalid() bit on the TypeRepr to signal that a closure
parameter is potentially a tuple destructure.  This has two benefits
1) Parse is no longer using the isInvalid() bit on Decl
2) Invalidating the type repr itself means that we no longer spuriously
diagnose variable patterns in destructures as missing types.
2019-10-24 16:03:41 -07:00
Nathan Hawes
05ef088859 Revert "Remove The Last Vestiges of isInvalid from Parse" 2019-10-22 11:31:07 -07:00
swift-ci
4edefa8e14 Merge pull request #27820 from CodaFi/valid-the-impaler 2019-10-21 16:35:00 -07:00
Robert Widmann
961a1cf0a4 Clean up invalidation in Parse
Clean up uses of setInvalid() and remove uses of isInvalid() in preparation for that being a semantic accessor.
2019-10-21 15:17:07 -07:00
Rintaro Ishizaki
7c43083718 [SyntaxParse] Sink element layout check to right before node creations
ParsedRawSyntaxRecorder::recordRawSyntax() and
ParsedRawSyntaxNode::makeDeferred()
2019-10-18 17:46:17 -07:00
Nathan Hawes
97757e4c2a [Parse] Assert that the children of syntax tree nodes have contiguous source ranges
This should help us catch syntax tree round-tripping issues.
2019-10-18 17:22:01 -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
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
9fa176051d Revert "Merge pull request #27406 from nathawes/add-syntax-range-assertions"
This reverts commit 325204bd0d, reversing
changes made to 066bb61e8f.
2019-10-14 12:38:46 -07:00
Rintaro Ishizaki
4eadbaa9f6 Revert "Merge pull request #27466 from rintaro/syntaxparse-type"
This reverts commit a4fcd26b38, reversing
changes made to 88ecae4b9a.
2019-10-14 12:19:04 -07:00
Rintaro Ishizaki
e53ad15b10 Revert "Merge pull request #27508 from rintaro/syntaxparse-expridentifier"
This reverts commit dfe962f19a, reversing
changes made to 04ce7bf779.
2019-10-14 12:18:26 -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
b56c543f0d Revert "Merge pull request #27607 from rintaro/syntaxparse-exprunresolvedmember"
This reverts commit 5e1f790b3b, reversing
changes made to 1846a5957e.
2019-10-14 12:15:12 -07:00
Rintaro Ishizaki
572cfe26a9 Revert "[SyntaxParse] Parse ObjC keypath expression syntax"
This reverts commit 1036d2a2bf.
2019-10-14 12:11:40 -07:00
Robert Widmann
7770564f1a Merge pull request #27624 from CodaFi/in-locale-parentis
Downgrade The TypeLoc in VarDecl to a TypeRepr
2019-10-11 14:53:10 -07:00
Rintaro Ishizaki
1036d2a2bf [SyntaxParse] Parse ObjC keypath expression syntax 2019-10-11 11:55:22 -07:00
Robert Widmann
060cbb293f [NFC] Downgrade The TypeLoc in VarDecl to a TypeRepr
TypeCheckPattern used to splat the interface type into this, and
different parts of the compiler would check one or the other.   There is
now one source of truth: The interface type.  The type repr is now just
a signal that the user has written an explicit type annotation on
a parameter.  For variables, we will eventually be able to just grab
this information from the parent pattern.
2019-10-11 11:15:51 -07:00
Rintaro Ishizaki
5e1f790b3b Merge pull request #27607 from rintaro/syntaxparse-exprunresolvedmember
[SyntaxParse] Parse object literal and unresolved member expressions
2019-10-11 18:59:10 +02:00