Commit Graph

1583 Commits

Author SHA1 Message Date
Hamish Knight
4fa8fb6c08 substituteInputSugarTypeForResult can be static 2019-10-30 07:56:32 -07:00
Anthony Latsis
6325915b4b NFC: Solidify and tidy up the BraceStmt interface 2019-10-30 16:43:59 +03:00
Robert Widmann
e7006a92b1 Clean up some trivially true condition clauses
ProtocolConformanceRef::isConcrete checks the invalid bit for us.
2019-10-29 16:56:22 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Hamish Knight
c95ef110d5 [CS] Make resolveLocatorToDecl simpler and more robust (#27836)
[CS] Make resolveLocatorToDecl simpler and more robust
2019-10-23 15:11:23 -07:00
Hamish Knight
19fe19e972 Address review feedback 2019-10-23 13:22:03 -07:00
Slava Pestov
362488b867 Sema: Fix substitutions of generic caller-side default arguments
Using mapTypeIntoContext() is incorrect here, because we might not
be calling the default argument from the callee's context. Instead,
use the substitutions from the ConcreteDeclRef.

Fixes <rdar://problem/55739617>.
2019-10-22 16:38:45 -04:00
Hamish Knight
a5e375a770 Cache resolved concrete decl refs in ExprRewriter
This ensures we don't have to compute the substitutions
multiple times when, for example, rewriting an
apply of generic function.
2019-10-22 12:36:59 -07:00
Hamish Knight
9d80a82939 Make resolveLocatorToDecl simpler and more robust
Rather than attempting to pull out a concrete decl
ref from the rewritten function expr, retrieve the
callee from the solution using a callee locator
computed before the apply is rewritten, and then
pass this callee down through `finishApply` and
`coerceCallArguments`.

Resolves SR-11648.
2019-10-22 11:54:04 -07:00
Hamish Knight
e3df69a2b5 Add Solution::resolveConcreteDeclRef
This is a convenience member for computing the
contextual substitutions for a decl reference at
a given locator.
2019-10-22 11:54:03 -07:00
Hamish Knight
37c42f6203 [Sema] NFC: Remove an unnecessary parameter 2019-10-21 13:44:15 -07:00
Brent Royal-Gordon
ecf76c8fdf Merge pull request #27586 from brentdax/everything-evil
Fix keypath-as-function crasher
2019-10-15 17:54:13 -07:00
Brent Royal-Gordon
ca25640cc3 Merge branch 'master' into everything-evil 2019-10-14 13:24:03 -07:00
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
swift-ci
7d437ec4a8 Merge pull request #27629 from DougGregor/builder-refactoring-prelude 2019-10-11 15:35:11 -07:00
Doug Gregor
87b5df7333 [Constraint system] Abstract the record of an applied function builder.
std::pair and std::tuple are a bad, bad drug. NFC, but helps with
future refactoring.
2019-10-11 10:31:27 -07:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
Slava Pestov
d8b61ff24b Sema: Peel off typeCheckParameterList()'s specifier computation into a request
Since getSpecifier() now kicks off a request instead of always
returning what was previously set, we can't pass a ParamSpecifier
to the ParamDecl constructor anymore. Instead, callers either
call setSpecifier() if the ParamDecl is synthesized, or they
rely on the request, which can compute the specifier in three
specific cases:

- Ordinary parsed parameters get their specifier from the TypeRepr.

- The 'self' parameter's specifier is based on the self access kind.

- Accessor parameters are either the 'newValue' parameter of a
  setter, or a cloned subscript parameter.

For closure parameters with inferred types, we still end up
calling setSpecifier() twice, once to set the initial defalut
value and a second time when applying the solution in the
case that we inferred an 'inout' specifier. In practice this
should not be a big problem because expression type checking
walks the AST in a pre-determined order anyway.
2019-10-10 15:00:07 -04:00
Brent Royal-Gordon
eca51d4d53 Fix keypath-as-function crasher
The autoclosures generated for the keypath-as-function feature were not added to the list of closures that needed captures computed. In top-level code, this caused a crash. Fixes rdar://problem/56055600.
2019-10-08 18:11:41 -07:00
Jordan Rose
5f2695808d Merge pull request #26830 from owenv/diag_child_notes_refactor
[Diagnostics][NFC] Optionally add notes as explicit children of an error/warning
2019-10-02 14:34:33 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Suyash Srijan
ad4d623818 Merge pull request #27382 from theblixguy/fix/SR-11522
[CSApply] Don't diagnose a 'static let none' as ambiguous none unless its an enum type
2019-09-28 11:14:52 +01:00
Suyash Srijan
2de4755564 [CSApply] Filtering 'none' results should filter out any other decl (such as typealiases, structs, etc) by default 2019-09-27 23:09:50 +01:00
Suyash Srijan
0a39e7dbeb [CSApply] Move the variable type check into the lookup filter call 2019-09-27 02:12:02 +01:00
Suyash Srijan
aa565f550c [CSApply] Compare variable's type with the base type of the enum we're assigning to 2019-09-26 20:49:25 +01:00
Suyash Srijan
25e1bb5ac1 [CSApply] Filter out functions and instance members before the ambiguous none check 2019-09-26 20:10:50 +01:00
Suyash Srijan
8d869e6f23 [CSApply] Don't diagnose a 'static let none' as ambiguous none unless its type matches the enum 2019-09-26 19:02:37 +01:00
Robert Widmann
62266447f2 Drop the TypeChecker dependency from some helpers 2019-09-24 17:48:42 -07:00
Robert Widmann
50d9ab6694 [NFC] Drop some unnecesary interface type forcing 2019-09-24 10:12:16 -07:00
Robert Widmann
3e48f71b27 Merge pull request #27314 from CodaFi/an-interface-to-the-interface
Requestify getInterfaceType() in Name Only
2019-09-23 22:35:24 -07:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Pavel Yaskevich
96598d8ebf Merge pull request #26207 from owenv/new-vararg-conversion-diag
[Diagnostics] Improve diagnostic when attempting to pass an Array to a variadic argument
2019-09-23 12:57:44 -07:00
Owen Voorhees
6c5185f2e3 Improve diagnostic when attempting to pass an Array to a variadic argument
- Give a more specific diagnostic which indicates the parameter is variadic
- If the argument is an Array literal, offer to drop the brackets
2019-09-20 17:30:23 -07:00
Owen Voorhees
6e1e768dda Add diagnoseWithNotes helper so CompoundDiagnosticTransation doesn't need to be used manually in simple cases 2019-09-17 13:42:10 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
Owen Voorhees
000294f5b1 [Diagnostics][NFC] Optionally add notes as explicit children of an error/warning
Add a new type of diagnostic transaction, CompoundDiagnosticTransaction.
The first diagnostic emitted inside the transaction will become the parent of the subsequent notes.
DiagnosticConsumers may opt in to consuming these child notes alongside the parent
diagnostic, or they can continue to consider them seperately.

Moved PrintingDiagnosticConsumer and a couple of diagnostics to the new
system as a proof of concept.
2019-09-16 17:33:40 -07:00
Doug Gregor
187647de62 [Type checker] Don't replace function builder closures with their bodies.
When diagnosing failures in a function builder closure, we were
unnecessarily replacing the closure expression with its body,
destroying the AST and resulting in assertions due to DeclContext
mismatches. Fixes SR-11350 / rdar://problem/54590425.
2019-09-11 18:19:08 -07:00
Hamish Knight
c745c17c38 Revert naming changes to getCalleeLocator & getChoiceFor
In addition, add a document comment to `getCalleeLocator` to clarify
its semantics.
2019-09-09 22:08:52 +01:00
Hamish Knight
67ee821123 [CS] Allow getCalleeLocator to find key path component callees
In order to do this we need it to take a ConstraintLocator argument so
we can tell which component we want the callee for. To make it clear
that we're looking for a callee at the anchor, also rename the member
to getAnchormostCalleeLocator.
2019-09-09 14:14:35 +01:00
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
Pavel Yaskevich
5210e9b7c2 Revert "[AST] Paren'd reference to an IUO function crashes the compiler in SILGen" 2019-09-02 11:02:01 -07:00
Suyash Srijan
532498bae5 [CSApply] Use the choiceLocator, not locator when checking if a disjunction choice exists
Obviously we won't have a disjunction choice for the locator, it's only possible if the locator is extended with ImplicitlyUnwrappedDisjunctionChoice path element
2019-08-28 23:57:35 +01:00
Suyash Srijan
a2daa11109 Merge branch 'master' into fix/SR-10492 2019-08-28 23:48:08 +01:00
Suyash Srijan
28d0c089bc [CSApply] shouldForceUnwrapResult() should return false when we don't have an disjunction choice
This will only be false if we have an IUO method call wrapped in parens (like '(s.foo)()'), so assert that the type is a function type as well
2019-08-28 23:24:32 +01:00
Dan Zheng
f44064cbbc [SE-0253] Introduce callables. (#24299)
Introduce callables: values of types that declare `func callAsFunction`
methods can be called like functions. The call syntax is shorthand for
applying `func callAsFunction` methods.

```swift
struct Adder {
  var base: Int
  func callAsFunction(_ x: Int) -> Int {
    return x + base
  }
}
var adder = Adder(base: 3)
adder(10) // desugars to `adder.callAsFunction(10)`
```

`func callAsFunction` argument labels are required at call sites.
Multiple `func callAsFunction` methods on a single type are supported.
`mutating func callAsFunction` is supported.

SR-11378 tracks improving `callAsFunction` diagnostics.
2019-08-26 23:56:36 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Pavel Yaskevich
98a54a1e73 Merge pull request #26297 from hamishknight/pass-by-value-by-name
[CS] Add specific accessors for path element info
2019-08-20 01:04:59 -07:00
Greg Titus
604852d82d Merge pull request #26712 from gregomni/sr-11234
[CSGen] Coerce key path index expr to handle upcast correctly.
2019-08-19 14:34:19 -07:00
Hamish Knight
6e45ef1347 [CS] Add locator find[First/Last] members
These members provide a convenient way of getting the first or last
occurrence of a given kind of element in a locator's path.
2019-08-19 11:58:50 +01:00