Commit Graph

435 Commits

Author SHA1 Message Date
Doug Gregor
bd75425b0e Remove the notion of non-inheritable conformances entirely <rdar://problem/16880016>.
Swift SVN r20627
2014-07-28 16:29:05 +00:00
Doug Gregor
1cc28d4f80 An initializer requirement can only be satisfied by a required class initializer in a non-final class.
This is part of eliminating the notion of non-inheritable
conformances. Fixes <rdar://problem/17408284>.

Swift SVN r20430
2014-07-23 22:16:38 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Doug Gregor
f6ff2977f3 Tighten up the semantics of inherited conformances.
'Self' can be used within parameters whenever the corresponding
parameter in a subclass will be contravariant, and in result types
when the method returns dynamic Self. This also applies to subscript
indices. More of <rdar://problem/16996872>.

Swift SVN r18788
2014-06-10 23:13:17 +00:00
Doug Gregor
2af6e0800b An operator requirement whose input type involves Self does not make a a conformance noninheritable.
Addresses <rdar://problem/16996872>. making NSObject's Equatable
conformance inheritable.

Swift SVN r18783
2014-06-10 22:01:00 +00:00
Michael Gottesman
c1bd3560af [devirtualization] Make ProtocolConformance::getGenericParams() more
sane and ad ProtocolConformance::getSubstitutedGenericParams() for
returning the generic params that were substituted into by a specialized
protocol conformance.

I am going to use this to handle inherited specialized inherited
conformance devirtualization.

Swift SVN r16907
2014-04-27 02:47:44 +00:00
Michael Gottesman
e2cde3c7f4 [devirtualization] Properly substitute in types for upcast when handling
a specialized inherited conformance.

Swift SVN r16900
2014-04-27 00:06:46 +00:00
Michael Gottesman
0676121334 Fix what looks like a copy-pasto error in the protocol conformance code.
This code is supposed to check that each subclass of ProtocolConformance
implements the invoked method. The copy-pasto was that when we were
supposed to be checking if SpecializedProtocolConformance overrode a
method, we were instead checking if InheritedProtocolConformance did so.
Luckily when I fixed this it looks like we are implementing all the
appropriate methods. But still a nice catch I feel.

Swift SVN r15273
2014-03-20 18:30:12 +00:00
Ted Kremenek
c87ac8167a Use SWIFT_FALLTHROUGH instead of [[clang::fallthrough]].
Swift SVN r15028
2014-03-14 05:15:05 +00:00
Ted Kremenek
39a368f0ec Add [[clang::fallthrough]] in obvious cases to satisfy -Wimplicit-fallthrough.
Swift SVN r15018
2014-03-14 00:34:25 +00:00
Joe Groff
205d286211 Knock off some bogus Substitution::Archetype uses.
Swift SVN r14967
2014-03-12 20:46:13 +00:00
Joe Groff
a404b0cd49 Rework Substitution::subst not to depend on the meaningless 'Archetype' field of Substitutions.
Pass in the context generic parameters that correspond to the substitution vector in Substitution::subst. When we build the type substitution map, also collect the conformances from the substitutions into a map we can use to fill in those conformances in substituted substitutions where necessary, without relying on the '.Archetype' field.

Swift SVN r14964
2014-03-12 20:29:46 +00:00
Joe Pamer
3684658771 When resolving generic type aliases within protocols, the type aliases themselves may be modeled as substitutions, and not strictly as type variables. Not accounting for this lead to rdar://problem/16228026 and rdar://problem/16228058, wherein the compiler could crash if the open type alias was referenced from within a generic type instantiation.
Swift SVN r14746
2014-03-06 19:47:41 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Jordan Rose
37c1d8cdbd Don't assert when using a type variable as a specialized conformance witness.
Previously, we would try to generate a conformance for the type variable
(to the witness's requirement), fail, and then assert that we should have
succeeded. Now, we just let the type variable pass through with a null
conformance.

<rdar://problem/16078944>

Swift SVN r14617
2014-03-03 22:47:42 +00:00
Adrian Prantl
4b2ca8bd34 Silence warning.
Swift SVN r14422
2014-02-26 22:52:33 +00:00
Doug Gregor
4af20816a6 Make the interface type for an initializer in a protocol return 'Self'.
Swift SVN r14352
2014-02-25 21:54:31 +00:00
Doug Gregor
9c860f1b22 A conformance is non-inheritable if it has a non-abstract initializer witness.
Swift SVN r14323
2014-02-24 23:28:46 +00:00
Doug Gregor
926e3711d0 Only permit inheritance of protocol conformance when it is semantically valid.
A protocol conformance of a class A to a protocol P can be inherited
by a subclass B of A unless
  - A requirement of P refers to Self (not an associated type thereof)
  in its signature, 
    + *except* when Self is the result type of the method in P and the
    corresponding witness for A's conformance to B is a DynamicSelf
    method.

Remove the uses of DynamicSelf from the literal protocols, going back
to Self. The fact that the conformances of NSDictionary, NSArray,
NSString, etc. to the corresponding literal protocols use witnesses
that return DynamicSelf makes NSMutableDictionary, NSMutableArray,
NSMutableString, and other subclasses still conform to the
protocol. We also correctly reject attempts to (for example) create an
NSDecimalNumber from a numeric literal, because NSNumber doesn't
provide a suitable factory method by which any subclass can be literal
convertible.



Swift SVN r14204
2014-02-21 07:48:28 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Joe Groff
8cecd9fcf7 AST: ProtocolConformance::getInheritedConformance() should preserve specialization.
When applying getInheritedConformance to a specialized conformance, reapply the specialization to the found inherited conformance so we get a conformance for the same type we put in, making the specializer's job easier when finding conformances to insert into archetype_methods. To expose the problems this fixes, add a check in the SIL verifier that ArchetypeMethodInsts carry a ProtocolConformance that actually matches their lookup type.

Swift SVN r12988
2014-01-27 07:18:43 +00:00
Joe Groff
92f7b5512d AST: Add a "Substitution::subst" API.
Substitute a...um...substitution by remapping its Replacement mapping and recursively remapping any ProtocolConformances it has. Modify the Specializer to use Substitution::subst when specializing the substitutions of ArchetypeMethod and Apply instructions.

Swift SVN r12900
2014-01-24 04:35:49 +00:00
Doug Gregor
e9fdec95fe Put specialized and inherited conformances into an appropriate arena.
This is infrastructure toward allowing us to construct conformances
where there are type variables <rdar://problem/15168483>, which keeps
tripping up library work.

Swift SVN r12899
2014-01-24 04:13:17 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +00:00
Doug Gregor
df4d42ec47 Scaffolding for lazy witness resolution.
No functionality change yet.

Swift SVN r11676
2013-12-27 21:26:16 +00:00
Joe Groff
1690f5265c IRGen: Emit witness tables as exported symbols in -emit-sil-protocol-witness-tables mode.
SILGen eagerly produces witness tables for all of the conformances defined in the module, which is what we want in order to make them runtime-unique. Have IRGen follow suit. This should address a ton of radars about breakage with non-unique conformances once SIL witnesses are turned on. We will need some runtime machinery to handle witness tables with dependent fields, but since we currently ignore the associated type fields of witnesses, we can get away with emitting direct references to all witness tables for now.

Swift SVN r11608
2013-12-23 20:31:49 +00:00
Joe Groff
41276a6d04 AST: Make ProtocolConformance::getGenericParams handle generic params from a generic parent of a nongeneric local nominal type.
Swift SVN r11574
2013-12-22 22:37:50 +00:00
Doug Gregor
be3463f32d Store a file-level DeclContext* in protocol conformances rather than a module.
We'll need to perform name lookup based on the file-level
DeclContext*, so the module no longer suffices. No functionality
change here yet.


Swift SVN r11523
2013-12-20 22:53:21 +00:00
Doug Gregor
b9696e1c01 Create protocol conformances and then, separately, fill in the witnesses.
This is a structural baby step toward lazily filling in protocol
conformances. We always build a ProtocolConformance, then mark it
either "complete" (when it's well-formed) or "invalid" (when it's
ill-formed). At present, the only benefit to this is that it slows
diagnostic cascades from invalid conformances.


Swift SVN r11492
2013-12-20 00:29:00 +00:00
Doug Gregor
2d75ca2adf Add a LazyResolver to ProtocolConformance::getWitness().
Swift SVN r11331
2013-12-15 19:40:49 +00:00
Doug Gregor
07c0793e30 Construct the type witnesses of SpecializedProtocolConformance lazily.
A SpecializedProtocolConformance intentionally contains all of the
information we need to synthesize the type witnesses from the
underlying (generic) conformance. Do so lazily rather than eagerly,
because we won't always need all of them.

As a nice side effect, we no longer need to serialize the witnesses of
these specialized protocol conformances, so we can save some space in
the Swift module file.


Swift SVN r11303
2013-12-14 06:20:44 +00:00
Doug Gregor
1b161ff043 Eliminate ProtocolConformance::getTypeWitnesses().
Swift SVN r11301
2013-12-14 05:19:18 +00:00
Doug Gregor
8aa7eaa150 Remove ProtocolConformance::getWitnesses().
Swift SVN r11278
2013-12-13 23:55:37 +00:00
Joe Groff
1f3c29b86c Give ProtocolConformance a getGenericParams() method.
It's useful to know what the open type variables in a generic protocol conformance are. For now, make the somewhat shaky assumptions that a NormalProtocolConformance for a bound generic type is for the DeclaredTypeInContext of its originating nominal type, that all type variables of the nominal type are open, and that specialized and inherited conformances bind all of the generic parameters.

Swift SVN r11274
2013-12-13 22:59:34 +00:00
Doug Gregor
82a2cc19fe Add missing file from prior commit.
Swift SVN r6866
2013-08-02 23:14:54 +00:00