Commit Graph

9116 Commits

Author SHA1 Message Date
Huon Wilson
041b14175c [Sema] Remove restriction on conditional conformances. 2017-10-10 19:17:31 -07:00
Slava Pestov
124251cf2c Merge pull request #9619 from allevato/synthesize-equatable-hashable
Synthesize Equatable/Hashable for complex enums, structs
2017-10-10 18:22:40 -07:00
Doug Gregor
27239469ea [GSB] Mark conformances used by the GenericSignatureBuilder as “used”.
Prior to the removal of the “lookup conformance function”, whenever
the type checker created a GenericSignatureBuilder, its lookup conformance
function would mark any referenced conformance as “used”. Do so now via
a LazyResolver callback, which fixes a regression in multi-file type
checking scenarios.
2017-10-10 10:01:40 -07:00
Doug Gregor
a11f9c36a0 [AST] Remove ModuleDecl from TypeBase::getCanonicalType(). 2017-10-10 10:01:39 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
ef542ffd8a [GSB] Eliminate the stored LookupConformanceFn to the GSB.
Implement a module-agnostic conformance lookup operation within the GSB
itself, so it does not need to be supplied by the code constructing the
generic signature builder. This makes the generic signature builder
(closer to) being module-agnostic.
2017-10-10 09:41:23 -07:00
Doug Gregor
05b9e82b48 Always use LookUpConformanceInModule for the GenericSignatureBuilder. 2017-10-10 09:41:23 -07:00
Tony Allevato
ddaa390a62 Merge branch 'master' into synthesize-equatable-hashable 2017-10-10 01:39:48 -07:00
Slava Pestov
d866ebf8f4 Merge pull request #11744 from gspiers/bugfix/SR-479-ownership-in-protocols
[SE implementation] Ownership keyword removal in protocols
2017-10-10 00:08:57 -07:00
Slava Pestov
a3c4882bec Sema: Temporary workaround for recently-introduced GSB bug 2017-10-09 19:53:51 -07:00
Slava Pestov
7cbd0c0b37 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 19:53:51 -07:00
Slava Pestov
d7dbc23337 Sema: ConformanceChecker::Adoptee is always nominal 2017-10-09 19:53:51 -07:00
Slava Pestov
7bc5ac1248 Sema: Factor out ConformanceChecker::checkNonFinalClassWitness() from resolveWitnessViaLookup() 2017-10-09 19:53:50 -07:00
Slava Pestov
5afaadfbc8 Sema: Requirement environments for protocol extension members in class conformances have an abstract 'Self'
Consider the following code:

protocol P {
  func foo<A>(_: A)
}

extension P {
  func foo<A>(_: A) {}
}

class C<T> : P {}

Before, the witness thunk for [C : P].foo() had the generic signature
<T, A>, and the witness P.foo() was called with a substitution
Self := C<T>.

This is incorrect because the caller might be using a subclass of C
as the 'Self' type, but this was being erased.

Now, the witness thunk for [C : P].foo() has the generic signature
<X : C<T>, T, A>, and the witness P.foo() is called with the
substitution Self := X.

Fixes <rdar://problem/33690383>, <https://bugs.swift.org/browse/SR-617>.
2017-10-09 19:53:50 -07:00
Slava Pestov
861c46c218 Sema: Track if the protocol witness for a class conformance is in a protocol extension 2017-10-09 19:53:50 -07:00
Slava Pestov
717a7f52f8 Sema: Compute RequirementEnvironment when we are matching a witness
At this point, we already have a witness, so the requirement
environment can depend on the witness as well as the requirement.

Then, store the RequirementEnvironment inside the RequirementMatch.
2017-10-09 19:53:50 -07:00
Tony Allevato
715ba632dd Merge branch 'master' into synthesize-equatable-hashable 2017-10-09 15:57:36 -07:00
Doug Gregor
d3de4f2321 Merge pull request #12321 from DougGregor/assoc-type-overrides
Track "overrides" of associated types
2017-10-09 12:59:21 -07:00
Doug Gregor
f51d5b6aec [Conformance checking] Allow generic parameter when inferring type witnesses.
As part of type witness inference, allow us to infer a generic parameter
as the type witness for an associated type, when the associated type has
the same name as the generic parameter.

We likely want the more-general rule that generic parameters are always
visible as members of their enclosing type, but I'll tackle that separately.
This works around an order dependency that affected the source
compatibility suite.
2017-10-09 10:20:22 -07:00
Jordan Rose
192b523a8e Revert "Fix issue with 'Self' metadata when class conforms to protocol with default implementations" (#12344)
It broke the 32-bit iOS simulator, and possibly the 64-bit simulator as well. Reverts 5618553.
2017-10-09 10:02:48 -07:00
Slava Pestov
80ada27707 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 00:53:03 -07:00
Slava Pestov
216011437e Sema: ConformanceChecker::Adoptee is always nominal 2017-10-09 00:53:02 -07:00
Slava Pestov
21868c17ca Sema: Factor out ConformanceChecker::checkNonFinalClassWitness() from resolveWitnessViaLookup() 2017-10-08 23:27:39 -07:00
Slava Pestov
b145d40329 Sema: Requirement environments for protocol extension members in class conformances have an abstract 'Self'
Consider the following code:

protocol P {
  func foo<A>(_: A)
}

extension P {
  func foo<A>(_: A) {}
}

class C<T> : P {}

Before, the witness thunk for [C : P].foo() had the generic signature
<T, A>, and the witness P.foo() was called with a substitution
Self := C<T>.

This is incorrect because the caller might be using a subclass of C
as the 'Self' type, but this was being erased.

Now, the witness thunk for [C : P].foo() has the generic signature
<X : C<T>, T, A>, and the witness P.foo() is called with the
substitution Self := X.

Fixes <rdar://problem/33690383>, <https://bugs.swift.org/browse/SR-617>.
2017-10-08 23:01:18 -07:00
Slava Pestov
b5f231dfb0 Sema: Track if the protocol witness for a class conformance is in a protocol extension 2017-10-08 18:58:01 -07:00
Slava Pestov
3a8d484a77 Sema: Compute RequirementEnvironment when we are matching a witness
At this point, we already have a witness, so the requirement
environment can depend on the witness as well as the requirement.

Then, store the RequirementEnvironment inside the RequirementMatch.
2017-10-08 18:58:00 -07:00
Slava Pestov
6111a6a964 Sema: Replace a few mapTypeOutOfContext() calls with ArchetypeType::getInterfaceType() 2017-10-07 05:44:58 -07:00
Slava Pestov
6def545696 AST: Remove GenericEnvironment::containsPrimaryArchetype()
This is no longer necessary now that archetypes refer back to a
GenericEnvironment.
2017-10-07 04:46:37 -07:00
Slava Pestov
5e5b626622 Sema: Fix whitespace 2017-10-06 22:44:50 -07:00
Graydon Hoare
b156fbe354 Merge pull request #12305 from graydon/clang-importees-have-no-associated-type-members
[AST] Avoid getMembers() calls in contexts that only need associated types.
2017-10-06 10:07:10 -07:00
Graydon Hoare
51d759e0f1 [AST] Add dedicated lazier-path to getting protocol associated types. 2017-10-06 01:55:47 -04:00
Joe Groff
5caa51ce62 Merge pull request #12301 from jckarter/keypath-subscript-coerce-index
Sema: Coerce the type of the index expression in a key path component to match the subscript decl's index type.
2017-10-05 18:03:09 -07:00
Joe Groff
d3a2a0ff82 Sema: Coerce the type of the index expression in a key path component to match the subscript decl's index type.
Fixes SR-6062 | rdar://problem/34835322.
2017-10-05 14:33:21 -07:00
David Zarzycki
61980167ef [ASTVerifier] Better DeferStmt checking 2017-10-05 14:38:36 -04:00
David Zarzycki
1958b8f4bf [AST] NFC: Simplify AnyFunctionRef::isKnownNoEscape()
This removes a defer body hack and an assumption that non-defer functions are always escaping.
2017-10-05 10:24:11 -04:00
Doug Gregor
c02ffaf176 Merge pull request #12286 from DougGregor/subst-inout-param-type
[Type checker] Drop parameter 'inout' types in a few more places.
2017-10-05 00:48:04 -07:00
Doug Gregor
b4acc38730 [Type checker] Drop parameter 'inout' types in a few more places.
Follow-up to my earlier changes to drop 'inout' types when cloning parameter
lists, we also need to deal with substitutions into those parameter types.
This is an artifact of us having mostly---but not entirely---removed
InOutType from the AST. Fixes rdar://problem/34818336.
2017-10-04 21:18:05 -07:00
swift-ci
7679e9fb85 Merge pull request #12278 from DougGregor/sr-4486 2017-10-04 18:26:03 -07:00
Doug Gregor
7f6a71c173 [Conformance checking] Check 'inout' when matching witnesses.
Associated type inference was inferring an associated type to be an inout
type, causing crashing surprisingly late in IRGen. Fixes SR-4486.
2017-10-04 17:22:45 -07:00
Pavel Yaskevich
c0dbec055a Merge pull request #12276 from xedin/add-failed-constriant-logging
[ConstraintSolver] Add debug logging of failed constraints while solving
2017-10-04 16:17:49 -07:00
Doug Gregor
6b7732f861 Merge pull request #12273 from DougGregor/resolve-type-null-check
[Type checker] When type resolution fails, don't check bridgeable conformances
2017-10-04 13:06:34 -07:00
Doug Gregor
f0e244ccdd [Type checker] When type resolution fails, don't check bridgeable conformances.
Should address rdar://problem/34760012, although there isn't enough detail
there to be certain.
2017-10-04 12:36:27 -07:00
Pavel Yaskevich
03a39337a5 [ConstraintSolver] Add debug logging of failed constraints while solving 2017-10-04 12:13:38 -07:00
Pavel Yaskevich
c69469780f Merge pull request #12252 from xedin/remove-bindparam-hack
[ConstraintSolver] Remove hack related to single parameter handling
2017-10-04 11:32:18 -07:00
swift-ci
419b6f0227 Merge pull request #12262 from DougGregor/assoc-type-crashes 2017-10-03 22:32:58 -07:00
Doug Gregor
d12dbf99ea [Type checker] Diagnose failed attempts to resolve associated type witnesses.
If unqualified name lookup finds an associated type, but resolution to
the type witness fails, produce a diagnostic rather than silently
failing. Fixes the crash in SR-5825, SR-5881, and SR-5905.

It's conceivable that we could resolve this with suitably global
associated type inference... but that's far off and it's best not to
crash until then.
2017-10-03 21:59:14 -07:00
Pavel Yaskevich
f95c979cbf [ConstraintSolver] Remove hack related to single parameter handling 2017-10-03 15:15:57 -07:00
Pavel Yaskevich
4317074a9a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-10-03 10:41:35 -07:00
Pavel Yaskevich
9642ff0ba6 Merge pull request #12235 from xedin/fix-subtype-revert
Revert "[ConstraintSolver] Prioritize certain type variables while lo…
2017-10-02 18:43:36 -07:00