Commit Graph

385 Commits

Author SHA1 Message Date
Doug Gregor
0c1b625773 Propagate error types out of specialized conformances.
Fixes rdar://problem/21598514.

Swift SVN r29809
2015-06-30 21:50:12 +00:00
Doug Gregor
fea40a4dd2 Rank conformances implied by synthesized conformances as "synthesized".
This means that we prefer conformances implied by explicit
conformances (ones that the user wrote) over conformances implied by
synthesized conformances (those that the compiler would
generate). This resolves the ambiguity causing rdar://problem/21007417.

Swift SVN r28880
2015-05-21 17:14:28 +00:00
Jordan Rose
2ad796627a Revert "Prefer compiler-provided conformances to those required by other protocols."
This may not be the right solution. Even if it is, there are SourceKit tests
that need updating.

This reverts commit r28849 / rdar://problem/21007417.

Swift SVN r28852
2015-05-20 21:32:56 +00:00
Jordan Rose
1ad7651e19 Prefer compiler-provided conformances to those required by other protocols.
Previously, we'd warn on this code:

  enum Suit { case Spades, Hearts, Clubs, Diamonds }
  extension Suit : Comparable {}
  func <(...) {...}

because both Comparable and the synthesized conformance to Hashable imply
a conformance to Equatable. However, that's silly: Suit already has a
synthesized conformance to Equatable associated with the main 'enum'
declaration, not the extension. These compiler-provided conformances are
part of the language and something people rely on, so rank them higher than
conformances implied by conforming to a refined protocol.

rdar://problem/21007417

Swift SVN r28849
2015-05-20 20:48:04 +00:00
Doug Gregor
74050648de Make @objc enums that conform to ErrorType also conform to _ObjectiveCBridgeableErrorType.
This allows @objc enum error types produced in Objective-C (e.g., via
+[NSError errorWithDomain:code:userInfo:]) to be bridged back to their
original enum types in Swift via pattern matching/catch blocks.

This finishes rdar://problem/20577517.

Swift SVN r28803
2015-05-20 00:16:39 +00:00
Joe Pamer
ca6e909808 Use a MapVector for the conformance tables we plan on iterating, instead of DenseMaps. Not having stable ordering of conformances results in non-deterministic type checker behavior, and causes all sorts of other mischief. (This unblocks rdar://problem/20824955, and also seems to address some other fishy things we've been seeing.)
Swift SVN r28374
2015-05-09 22:10:04 +00:00
Doug Gregor
d0282e0d62 Switch the AST printer over to getLocalProtocols().
Swift SVN r27968
2015-04-30 16:13:37 +00:00
Doug Gregor
8a8895de75 Populate the conformance lookup table for a deserialized protocol.
When deserializing a protocol, the conformance lookup table would not
contain entries for the inherited protocols of that protocol. They
were stashed in the "Protocols" array in TypeDecl (which will
eventually go away), but since there are no conformances for a
protocol, the conformance lookup table never got updated.

Nothing important seems to query this now; that will change soon.

Swift SVN r27967
2015-04-30 16:13:35 +00:00
Doug Gregor
f985ba6542 Conformance lookup table: delay parsed extensions when we have no resolver.
If we try to visit a parsed extension (to find its protocol
conformances) when we don't have a resolver, we would get no
information out of the extension and never revisit it. Queue up these
extensions to be processed later, when we do have a resolver.

I’ve only ever seen this happen when building the standard library,
where verifying imported modules after checking a source file can
cause otherwise-unused extensions to get skipped, although they would
be needed later. The following commit depends on this, but this issue
is separable.

Swift SVN r27945
2015-04-29 23:20:53 +00:00
Doug Gregor
02d25888c9 Clean up the interface to Type::subst(), NFC.
Replace the 'ignoreMissing' boolean flag with a new option set type,
SubstOptions, which is easier to extend. It is not an OptionSet<>
because a follow-on commit will introduce a non-trivial option that
will require more storage.

Also eliminate the LazyResolver parameter, which is no longer
needed. Eliminate the silly TypeChecker::substType(), whose only
purpose was to provide the resolver.

Swift SVN r27656
2015-04-23 23:36:18 +00:00
Doug Gregor
4ae7b13820 Stop trying to fully check a conformance when we query its existence.
This eliminates nonsensical recursion when working with protocol
conformances, and makes their checking more lazy. Start to improve
name lookup to deal with protocol witnesses more lazily, generalizing
the solution we had to all protocol conformances and making it more
directed. We're not done here, as the FIXMEs in the code completion
test imply: this replace-the-requirement-with-the-witness behavior
needs to be sunk down into the AST level so it also applies to
unqualified lookup, visible-decl lookup, etc.

Swift SVN r27639
2015-04-23 18:20:57 +00:00
Argyrios Kyrtzidis
707394aea8 [AST] Refactor implementation for ValueDecl::getSatisfiedProtocolRequirements().
Move the map that keeps track of conforming decl -> requirement from ASTContext
to a nominal type's ConformanceLookupTable, and populate it lazily.

This allows getSatisfiedProtocolRequirements() to work with declarations from module files.
Test on the SourceKit side.

Part of rdar://20526240.

Swift SVN r27353
2015-04-16 06:23:56 +00:00
Argyrios Kyrtzidis
5f6d091efc [AST] Keep track of the type decl that the type witness came from, for protocol conformances.
Swift SVN r27352
2015-04-16 06:23:54 +00:00
Doug Gregor
7c4823ec71 Convert PrintAsObjC over to conformance lookup table entrypoints.
Another step toward using the conformance lookup table for
everything. This uncovered a tricky little bug in the conformance
lookup table's filtering logic (when asking for only those
conformances explicitly specified within a particular context) that
would end up dropping non-explicit conformances from the table (rather
than just the result).

Ween a few tests off of -enable-source-import, because they'll break
otherwise.

Swift SVN r27021
2015-04-05 13:44:47 +00:00
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
Joe Groff
ebed0946fa Rename 'isSimpleEnum' to 'hasOnlyCasesWithoutAssociatedValues'.
Eliminate a bit of jargon that never caught on. This condition isn't used pervasively enough to need a short name.

Swift SVN r26781
2015-03-31 22:10:23 +00:00
Doug Gregor
557751ba7e Protocol extensions cannot have inheritance clauses.
Swift SVN r26770
2015-03-31 18:55:58 +00:00
Doug Gregor
75d0c16036 Perform substitution in ProtocolConformance::getInheritedConformance() properly
Fixes the regression in rdar://problem/20301648, which was triggered
by the separation of extension archetypes (r26483).

Swift SVN r26638
2015-03-27 18:30:10 +00:00
Doug Gregor
159ecf7b84 SILPrinter: print the name of protocol conformance using its generic signature.
When we print the name of a protocol conformance, we normally use the generic parameters as written. However, since some requirements may be inferred (particularly by an extension of a generic type), it's better for the SIL printer to use the generic signature, which is fully expanded and will also be correct, e.g., when working with a deserialized conformance.

Swift SVN r26437
2015-03-23 17:51:39 +00:00
Doug Gregor
9c7280c3d9 Use ProtocolConformance::subst() when digging out inherited conformances of specialized conformances.
Just blindly forming a specialized conformance is wrong here; I'm surprised we haven't tripped over this before.

Swift SVN r26419
2015-03-22 12:35:30 +00:00
Doug Gregor
7ee6f7b666 Conformance table: stop expanding deserialized conformances.
We (de-)serialize everything in the table already, so this is just useless work.

Swift SVN r26414
2015-03-22 12:35:24 +00:00
Doug Gregor
813df95fca Register protocol conformances more eagerly with the conformance lookup table during deserialization.
Swift SVN r26413
2015-03-22 12:35:23 +00:00
Doug Gregor
7708c5a65e Start moving away from (Nominal)?TypeDecl::getProtocols().
Instead, use other entry points, particularly those that use the conformance lookup table.

Swift SVN r26412
2015-03-22 12:35:21 +00:00
Doug Gregor
3f6a14ade6 Eliminate NominalTypeDecl::(get|set)Conformances.
We now access the conformances of a nominal type through the
conformance lookup table, so there is no reason to continue storing
conformances directly on the nominal type declaration, which was
error-prone regardless. This mirrors the change to ExtensionDecl from
my previous commit.

Swift SVN r26354
2015-03-20 16:32:25 +00:00
Doug Gregor
9bd774fd57 Eliminate ExtensionDecl::(get|set|)Conformances.
Stop storing a conformances array on ExtensionDecls. Instead, always use the conformance lookup table to retrieve conformances (which is lazy and supports multi-file, among other benefits).

As part of this, space-optimize ExtensionDecl's handling of conformance loaders. When one registers a conformance loader, it goes into a DenseMap on ASTContext and gets erased once we've loaded that data, so we get two words worth of space back in each ExtensionDecl.

Swift SVN r26353
2015-03-20 16:32:21 +00:00
Doug Gregor
a5a46752c2 Teach SILGen to use getAllConformances() when emitting witness tables we might need.
Sort the conformances here so we keep the order deterministic.

Swift SVN r26330
2015-03-19 22:10:11 +00:00
Doug Gregor
ad497366bd Eliminate useless scratch buffer from getAllProtocols/getAllConformances. NFC
Swift SVN r26323
2015-03-19 22:10:06 +00:00
Doug Gregor
b75e03b724 Eliminate the annoying scratch buffer from getLocalConformances(). NFC
Swift SVN r26322
2015-03-19 22:10:05 +00:00
Doug Gregor
7d57195508 Centralize the creation/lookup of normal protocol conformances further.
This simplifies and isolates the "deep conformance checking" behavior
of LazyResolver::checkConformance (renamed from
LazyResolver::resolveConformance). We actually don't want to be
triggering this from lookup, because it's exceedingly non-lazy, but
our lazy resolution of witnesses isn't good enough to support that
just yet. NFC

Swift SVN r26319
2015-03-19 22:10:03 +00:00
Doug Gregor
940ba832e5 Use the conformance lookup table to find protocol conformances.
Replace the loop over all known protocols with a query into the
actual conformance lookup table, which more properly deals with
out-of-order conformance queries, inheritance of protocol
conformances, and conformance queries in multi-file situtations.

The SILGen test change is because we're no longer emitting redundant
conformances, while the slight diagnostic regression in
circular-inheritance cases is because we handle circular inheritance
very poorly throughout the compiler.

While not the end, this is a major step toward finishing
rdar://problem/18448811.

Swift SVN r26299
2015-03-19 06:35:28 +00:00
Doug Gregor
dc27688eca Generalize the importer-only RawOptionSet attribute to a SynthesizedProtocol attribute.
This lets us tag imported declarations with arbitrary synthesized
protocols. Use it to handle imported raw option sets as well as the
RawRepresentable conformances of enums that come in as structs.

Swift SVN r26298
2015-03-19 06:35:25 +00:00
Doug Gregor
99ec43ca0d Start building conformances in the conformance lookup table.
We're still not using these generated conformances as our primary
source of conformances, but now we can create them here and it doesn't
break anything.

Swift SVN r26297
2015-03-19 06:35:22 +00:00
Doug Gregor
3e4632e4d6 Reinstate "Centralize the logic for synthesized conformances.""
This reinstates r26115 along with a small fix to the synthesization of
witnesses (an existing bug exposed by this change).

Swift SVN r26146
2015-03-15 04:15:36 +00:00
Erik Eckstein
fe84d94938 Revert "Centralize the logic for synthesized conformances."
It causes some fails in compiler_crashers:

    Swift :: compiler_crashers/0986-swift-unboundgenerictype-get.swift
    Swift :: compiler_crashers/1103-swift-unboundgenerictype-get.swift
    Swift :: compiler_crashers/1223-swift-lexer-leximpl.swift
    Swift :: compiler_crashers/1276-swift-metatypetype-get.swift
    Swift :: compiler_crashers/1287-swift-printingdiagnosticconsumer-handlediagnostic.swift



Swift SVN r26136
2015-03-14 13:00:13 +00:00
Doug Gregor
78892d78c0 Centralize the logic for synthesized conformances.
This is effectively NFC, but we had two implementations of "figure out
the protocols that this type should implicitly conform to". The one in
the conformance table is what will matter going forward.

Swift SVN r26115
2015-03-13 23:37:21 +00:00
Doug Gregor
b752f9b140 Remove the unused NominalTypeDecl::registerSynthesizedConformance().
The conformance lookup table should ask for registration, it should
*know* what the conformances will be based on the form of the AST. NFC

Swift SVN r26114
2015-03-13 23:37:13 +00:00
Doug Gregor
746141dc64 Introduce a __raw_option_set attribute that the Clang importer adds for option sets.
Effectively NFC; this is part of teaching the new conformance registry
about all synthesized conformances.

Swift SVN r26113
2015-03-13 23:37:12 +00:00
Doug Gregor
9271a24a92 Introduce a protocol conformance registry for nominal types.
(Note that this registry isn't fully enabled yet; it's built so that
we can test it, but has not yet taken over the primary task of
managing conformances from the existing system).

The conformance registry tracks all of the protocols to which a
particular nominal type conforms, including those for which
conformance was explicitly specified, implied by other explicit
conformances, inherited from a superclass, or synthesized by the
implementation.

The conformance registry is a lazily-built data structure designed for
multi-file support (which has been a problematic area for protocol
conformances). It allows one to query for the conformances of a type
to a particular protocol, enumerate all protocols to which a type
conforms, and enumerate all of the conformances that are associated
with a particular declaration context (important to eliminate
duplicated witness tables).

The conformance registry diagnoses conflicts and ambiguities among
different conformances of the same type to the same protocol. There
are three common cases where we'll see a diagnostic:

1) Redundant explicit conformance of a type to a protocol:

    protocol P { }
    struct X : P {  }
    extension X : P { } // error: redundant explicit conformance

2) Explicit conformance to a protocol that collides with an inherited
  conformance:

    protocol P { }
    class Super : P { }
    class Sub : Super, P { } // error: redundant explicit conformance

3) Ambiguous placement of an implied conformance:

    protocol P1 { }
    protocol P2 : P1 { }
    protocol P3 : P1 { }

    struct Y { }
    extension Y : P2 { }
    extension Y : P3 { } // error: ambiguous implied conformance to 'P1'

  This happens when two different explicit conformances (here, P2 and
  P3) placed on different declarations (e.g., two extensions, or the
  original definition and other extension) both imply the same
  conformance (P1), and neither of the explicit conformances imply
  each other. We require the user to explicitly specify the ambiguous
  conformance to break the ambiguity and associate the witness table
  with a specific context.

Swift SVN r26067
2015-03-12 21:11:23 +00:00
Doug Gregor
eb572e6a63 Simplify and improve our handling of generic parameters/signatures/interface types in ProtocolConformance.
This ends up being NFC right now because we're not really creating
inherited conformances consistently, so the cases where it might
matter (reshuffling generic parameters as we go up an inheritance
chain) either fail for other reasons or don't change.

Swift SVN r25993
2015-03-11 20:47:33 +00:00
Doug Gregor
bc799c3fbc Remove ProtocolConformance::getSubstitutedGenericParams().
It's unused and wrong. NFC

Swift SVN r25992
2015-03-11 20:42:47 +00:00
Chris Willmore
5b51620d1d Be more tolerant of invalid protocol conformances when applying constraint solution.
* Lift NormalProtocolConformance::hasTypeWitness() to
  ProtocolConformance. This method can be used to determine whether a
  potentially invalid conformance has a particular type witness.

* ProtocolConformance::getWitness() may return nullptr if the witness
  does not exist.

* In TypeChecker::getWitnessType(), don't complain that a builtin
  protocol is broken if it's the conformance that's broken.

* ConformanceChecker should only emit diagnostics from within calls to
  checkConformance().

* TypeChecker::conformsToProtocol() now returns true if the type
  has a declared conformance to the protocol, regardless of whether the
  conformance is valid. Clients must check the validity of the
  ProtocolConformance themselves if necessary.

<rdar://problem/19495341> Can't upcast to parent types of type constraints without forcing

Swift SVN r25326
2015-02-16 22:41:52 +00:00
Doug Gregor
4994d702b5 Clean up ProtocolConformance::getTypeWitnessByName(). NFC
Swift SVN r24876
2015-01-31 06:12:08 +00:00
Joe Groff
bf3c92c743 Sema: Move 'getBridgedToObjC' out of the type checker.
It is useful for other code to be able to query whether a type is bridged sharing the same logic as the type checker. NFC yet.

Swift SVN r24758
2015-01-27 21:20:39 +00:00
Doug Gregor
e98094859c Allow substitution into dependent types to resolve nested types.
Fixes the reduced forms of rdar://problem/19009056 and
rdar://problem/18475138.

Swift SVN r24352
2015-01-10 04:16:20 +00:00
Dmitri Hrybenko
8fdd6aca87 Fix warnings about falling off the end of a function without a return
Swift SVN r22317
2014-09-27 23:34:22 +00:00
Manman Ren
bc004b6b88 [Generic Specializer] handle specializing inherited conformance.
When we have a WitnessMethodInst in the original SILFunction and
self of the WitnessMethodInst will be replaced with the actual type
that has an inherited protocol conformance, we need to upcast the
lookup type of the WitnessMethodInst to make sure the lookup type
and the conformance type matches.

rdar://18068002


Swift SVN r21311
2014-08-20 18:36:56 +00:00
Doug Gregor
0184d9719b Partially revert “Maintain the DeclContext of a NormalProtocolConformance as the type declaration or extension.”
We now have this information during parsing and throw it away during deserialization. This half-baked state works because all non-generic-extension clients only care about the module context.

Swift SVN r20833
2014-07-31 17:30:08 +00:00
Doug Gregor
182e0b0d24 Revert "When determining the generic parameters used in a conformance, query the DeclContext."
This reverts commit r20794.

Swift SVN r20832
2014-07-31 17:30:07 +00:00
Doug Gregor
73d50e45ce Don't permit creating specialized conformances of specialized conformances...
... and stop doing it when we're separating the archetypes of
extensions from the types they extend. I wasn't able to isolate a
useful test case for this; it triggers when building the standard
library with extension archetypes separated.


Swift SVN r20814
2014-07-31 05:56:27 +00:00
Doug Gregor
37b354b693 When determining the generic parameters used in a conformance, query the DeclContext.
Swift SVN r20794
2014-07-31 01:00:31 +00:00