Commit Graph

12650 Commits

Author SHA1 Message Date
Doug Gregor
90859ad6aa [Type checker] Fix assertion/spin with ill-formed property delegate initialization
Fixes rdar://problem/50822051.
2019-05-15 16:42:38 -07:00
Doug Gregor
165133e3dd Merge pull request #24799 from DougGregor/disfavored-overload-attr
Add @_disfavoredOverload attribute to affect overload resolution.
2019-05-15 16:03:28 -07:00
Pavel Yaskevich
d5c561b44e [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-15 15:37:36 -07:00
Pavel Yaskevich
577e6291a6 [ConstraintSystem] Use missing conformance fix to diagnose contextual failures
Extend use of `missing protocol conformance` fix to cover contextual
failures, such as:

- Assignment mismatches, where destination requires source to conform
  to certain protocol (or protocol composition);
- Incorrect returns where returned type doesn't conform to the
  protocol specified in the signature.
2019-05-15 14:49:17 -07:00
Suyash Srijan
935128cd3b Merge branch 'master' into fix/duplicate-tuple-labels 2019-05-15 22:38:52 +01:00
Pavel Yaskevich
1cc6f774a1 [ConstraintSystem] Improve contextual mismatch diagnostics for for ... in <expr> loop 2019-05-15 14:34:24 -07:00
Slava Pestov
e39d236b29 Sema: Simplify for ... in ... type checking 2019-05-15 14:34:18 -07:00
Slava Pestov
744850749b Sema: Fix 'for ... in ...' over a sequence of DynamicSelfType 2019-05-15 14:34:10 -07:00
Pavel Yaskevich
a23bc3e189 [ConstraintSystem] Switch "missing conformance" fix/diagnostic to use protocol type
Switch type allows "missing conformance" diagnostic to be
used not only for protocols by for protocol compositions as well.
2019-05-15 14:21:37 -07:00
Pavel Yaskevich
2ee371b03a Merge pull request #24791 from xedin/diag-collection-element-conversions
[ConstraintSystem] Detect and diagnose conversion failures related to…
2019-05-15 12:58:04 -07:00
Joe Groff
cec9e9e33a Opaque types require a newer Swift runtime.
Check the availability of decls that declare an opaque return type to ensure they deploy to a
runtime that supports opaque types.

rdar://problem/50731151
2019-05-15 11:39:53 -07:00
Doug Gregor
5aea1315cd Add @_disfavoredOverload attribute to affect overload resolution.
Introduce an attribute @_disfavoredOverload that can be used to state
that a particular declaration should be avoided if there is a
successful type-check for a non-@_disfavoredOverload. It's a way to
nudge overload resolution away from particular solutions.
2019-05-14 23:07:26 -07:00
Slava Pestov
c141c4807d Merge pull request #24797 from slavapestov/more-type-checked-accessors
More type checked accessors
2019-05-15 00:49:15 -04:00
Suyash Srijan
a332eb6b4d [Typechecker] Don't add empty identifiers to the set 2019-05-15 02:26:04 +01:00
Slava Pestov
86f9ca7245 AST: Add ProtocolConformanceRef::getWitnessByName() 2019-05-14 21:18:06 -04:00
Brent Royal-Gordon
82928fd821 Merge pull request #24464 from brentdax/charmed-interpolations
[Parse][Sema] Improve interpolation parsing and construction
2019-05-14 17:49:46 -07:00
Pavel Yaskevich
b9a0ca6afb [ConstraintSystem] Detect and diagnose conversion failures related to collection element types
Detect and diagnose a contextual mismatch between expected
collection element type and the one provided (e.g. source
of the assignment or argument to a call) e.g.:

```swift
let _: [Int] = ["hello"]

func foo(_: [Int]) {}
foo(["hello"])
```
2019-05-14 17:33:11 -07:00
Slava Pestov
6e3609dc22 AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method 2019-05-14 19:28:55 -04:00
Slava Pestov
d93695f999 Sema: Remove support code for building non-type checked accessors 2019-05-14 19:19:24 -04:00
Slava Pestov
e65161ea2e Sema: Build type checked bodies for lazy getters 2019-05-14 19:18:58 -04:00
Slava Pestov
548e292ad9 Sema: Fold Solution::convertOptionalToBool() into its only remaining caller 2019-05-14 19:18:57 -04:00
Slava Pestov
7e15c21dac Sema: Use an 'if let' instead of a hasValue/! in lazy property getter
We used to generate this:

  let tmp1 = storage
  if tmp1.hasValue {
    return tmp1!
  }

Instead we now generate this:

  if let tmp1 = storage {
    return tmp1
  }
2019-05-14 19:18:57 -04:00
Slava Pestov
d29d017fce Sema: Build type checked bodies for observer setters 2019-05-14 19:18:57 -04:00
Alexis Laferrière
d4e6b58214 Merge pull request #24741 from xymus/default-definition-request
Request to lazily compute the default definition type of associated types
2019-05-14 14:17:30 -07:00
Ben Langmuir
e9384bb351 Merge pull request #24540 from benlangmuir/cc-nested-keypath
[code-completion] Handle nested keypath dynamic lookup correctly
2019-05-14 13:30:48 -07:00
Suyash Srijan
71fee96093 [Typechecker] Ban tuples with duplicate labels 2019-05-14 19:43:46 +01:00
Alexis Laferrière
547ba1cbef Intro a request to lazily compute default definition types
The new request, DefaultDefinitionTypeRequest, is triggered
by calling AssociatedTypeDecl::getDefaultDefinitionType.
2019-05-14 10:54:19 -07:00
Slava Pestov
b9f42b31dc Merge pull request #24665 from slavapestov/fully-checked-trivial-accessors
Build type checked bodies for more synthesized declarations
2019-05-13 21:05:54 -04:00
Gwen Mittertreiner
a6d5830f79 Merge pull request #24659 from gmittert/StackConstraints
Reduce the Stack Size of ConstraintSystem
2019-05-13 16:50:10 -07:00
Ben Langmuir
d65254c054 Add doc comments to the new lookupVisible* functions 2019-05-13 16:41:32 -07:00
Ben Langmuir
636d63e609 [code-completion] Handle nested keypath dynamic lookup correctly
If the root type of the KeyPath also has dynamic member lookup, we need
to look through it.

rdar://problem/50450037
2019-05-13 14:32:33 -07:00
Slava Pestov
a18c32ae06 Sema: Build type checked bodies for designated init overrides
Similarly to trivial accessors, the body of a synthesized
designated initializer override is simple enough that we can
build it directly without involving the constraint solver.
2019-05-13 17:25:49 -04:00
Slava Pestov
0bab515f66 Sema: Build type checked bodies for trivial accessors
This includes all synthesized accessors except for lazy getters
and observer setters.

Building checked AST has certain advantages:

- It is faster, avoiding the need to create and solve ConstraintSystems
  or performing various diagnostic and semantic walks over the AST.

- It allows us to postpone delayed body synthesis until needed in SILGen,
  instead of having to walk a list of "external declarations" in Sema.

It also unblocks lazier conformance checking. Now that SILGen can
trigger conformance checking on its own, we need to be able to
synthesize bodies of accessors that witness protocol requirements.
This will allow us to eventually remove Sema's "used conformances"
list.

Note that for now, various utility functions in CodeSynthesis.cpp are
used for both checked and unchecked function bodies, so they take a
'typeChecked' boolean parameter that complicates some logic more than
necessary. Once the remaining body synthesizers are refactored to
build type-checked AST, the 'typeChecked' flag will go away.
2019-05-13 17:25:49 -04:00
Slava Pestov
d22b3a7b0b Sema: Move the Optional-typed nil peephole to SILGen
When applying a solution to a nil literal of Optional type, we would
build a direct reference to Optional<T>.none instead of leaving the
NilLiteralExpr in place, because this would generate more efficient
SIL that avoided the call to the Optional(nilLiteral: ()) witness.

However, a few places in the type checker build type-checked AST, and
they build NilLiteralExpr directly. Moving the peephole to SILGen's
lowering of NilLiteralExpr allows us to simplify generated SIL even
further by eliding an unnecessary metatype value. Furthermore, it
allows SILGen to accept NilLiteralExprs that do not have a
ConcreteDeclRef set, which makes type-checked AST easier to build.
2019-05-13 17:25:49 -04:00
Gwen Mittertreiner
e51b72b3e0 Reduce the Stack Size of ConstraintSystem
The ConstraintSystem class is on the order of 1000s of bytes in size on
the stacka nd is causing issues with dispatch's 64k stack limit.

This changes most Small data types which store data on the stack to non
small heap based data types.
2019-05-13 11:40:43 -07:00
swift-ci
00af9c9d9a Merge pull request #22156 from Azoy/cache-money 2019-05-10 19:07:49 -07:00
Slava Pestov
d0c7eb67ba Merge pull request #24694 from slavapestov/random-ast-cleanups
More preliminary cleanups for 'Used Conformances' removal
2019-05-10 18:27:06 -04:00
Alexis Laferrière
245481520a Merge pull request #24682 from xymus/delayed-req-sig
Remove DelayedRequirementSignatures and rely on laziness instead
2019-05-10 14:03:22 -07:00
Slava Pestov
37412c2de2 AST: Add ParamDecl::toFunctionParam() 2019-05-10 15:00:49 -04:00
Slava Pestov
644b6adcd2 AST: Simplify ProtocolConformanceRef::getTypeWitnessByName() 2019-05-10 15:00:48 -04:00
Slava Pestov
4643cbd8e9 GSB: Remove another call to resolveDeclSignature()
The GSB should avoid triggering declaration validation where
possible, to avoid problems resulting from circularity and as
a general performance rule-of-thumb.

This last call was there to catch self-recursive protocol
typealiases. However, we can diagnose this problem elsewhere,
which allows us to emit a more accurate diagnostic as well.
2019-05-10 15:00:48 -04:00
Alexis Laferrière
8b8736402b Remove DelayedRequirementSignatures and rely on laziness instead
Because we create requirement signatures lazily, we don't need
to force a full validateDecl of ProtocolDecls in this way anymore.
2019-05-10 10:04:28 -07:00
Alexis Laferrière
9c4c30413b Merge pull request #24591 from xymus/req-sig-request
GSB: Lazy requirement signature
2019-05-10 08:47:27 -07:00
Sam Lazarus
3d432fea65 Sema / Test: Fix misplaced fix-it for .init calls on instances 2019-05-09 19:17:39 -04:00
Brent Royal-Gordon
a4e5bcea6a Move strange interpolation fix to PreCheckExpression
This defers diagnosis until a stage where #if conditions have definitely been evaluated, at the cost of a slightly more complex implementation. We’ll gain some of that complexity back in a subsequent refactoring. Fixes SR-9937.
2019-05-09 15:29:21 -07:00
Sam Lazarus
2309ee580a Merge pull request #24617 from sl/sl/sr-10297
Add a Diagnostic for .init calls which should be transformed into assignments (SR-10297)
2019-05-09 18:05:38 -04:00
Alexis Laferrière
be4ac2cf68 Don’t use isRequirementSignatureComputed because it is lazy 2019-05-09 10:45:29 -07:00
Sam Lazarus
8ad51b298e Sema: Get constraint locator for TupleExpr inside ApplyExpr branch
Additionally has some other minor cleanup.
2019-05-09 11:58:28 -04:00
Pavel Yaskevich
ce406fca04 Merge pull request #24615 from xedin/fix-autoclj-returning-fn-type
[ConstraintSystem] Allow arguments to be passed by value to `@autoclo…
2019-05-09 00:48:53 -07:00
Sam Lazarus
743d8fb0ee Sema: Change isImmutable to isMutable (thanks De Morgan) and negated call 2019-05-08 23:49:58 -04:00