Commit Graph

321 Commits

Author SHA1 Message Date
Huon Wilson
5f70f68c0d [AST] Store only interface types in NormalProtocolConformances.
Rather than storing contextual types in the type witnesses and associated
conformances of NormalProtocolConformance, store only interface types.

@huonw did most of the work here, and @DougGregor patched things up to
complete the change.
2017-11-16 11:45:18 -08:00
Huon Wilson
6dd8bec47e [AST] Unify computation of 'has arguments?' for witness table accessors. 2017-11-09 17:51:48 -08:00
Huon Wilson
901bd35e5a [IRGen] Pass witness tables for conditional conformances to witness table accessor.
When calling an accessor, one has to pull the witness tables for each
conditional conformance requirement into a(n appropriately ordered) buffer that
is passed to the accessor. This is simple enough, if the appropriate
specialization of the relevant conformances are known, which the compiler didn't
track deep enough until now.
2017-11-08 17:02:50 -08:00
Huon Wilson
ae54ac0444 [AST] Allow retrieving substitutions from an arbitrary ProtocolConformance. 2017-11-08 17:02:50 -08:00
Huon Wilson
b5eb418ef1 [AST] Handle classes properly in ProtocolConformanceRef::subst.
Previously ProtocolConformance::subst would crash because it was receiving
things with an unexpected relationship between the conformance's type and the
substituted self type. The compiler doesn't quite properly model "abstract"
inherited conformances, so we end up using normal conformances instead, and we
need to work around this in some cases.
2017-11-01 11:33:27 -07:00
Doug Gregor
6db9cc8c54 [AST] Consolidate the generic signature "diff" algorithm used in two places.
Introduce GenericSignature::requirementsNotSatisfiedBy(otherSig) to
compute the set of requirements in a generic signature that aren't satisfied
by some other generic signature. This is used both for conditional
conformances (the conditional requirements) and for name mangling of
constrained extensions/protocol conformances.
2017-10-12 14:23:46 -07:00
Slava Pestov
c480c38ccb AST: Fix a warning 2017-10-10 22:40:11 -07:00
Huon Wilson
8e50a1666f [AST&Sema] Add assertions for conditional conformances.
These are just places that may need updating for conditional
conformances, and so having them flag eagerly will help in future.
2017-10-10 20:17:41 -07:00
Huon Wilson
945f723d59 [AST] Compute conditional requirements in a conformance.
This allows determining which requirements make a conformance conditional; as
in, which requirements aren't known as part of the type itself.

Additionally, use this to assert that a few builtin protocols aren't
conditionally-conformed-to, something we won't support for now.
2017-10-10 20:17:39 -07:00
Huon Wilson
fd07426743 [AST] NFC: factor out getting a SpecializedProtocolConformance's substitution map. 2017-10-10 19:17:31 -07:00
Doug Gregor
0f30f5e7de [AST] Don't try to compute substitutions for a missing generic signature.
Eliminates the crash in rdar://problem/34184392, but we still don't handle
this pattern.
2017-10-02 13:30:43 -07:00
Slava Pestov
2ad1d3a6e6 Merge pull request #11909 from slavapestov/divorce-clang-importer-from-sema-part-6
ClangImporter: Don't record redundant inheritance clause entries
2017-09-14 10:45:24 -07:00
Doug Gregor
cc1a2e99a6 [Conformance checking] Progressively populate signature conformances.
When setting the signature conformances in a NormalProtocolConformance,
do so progressively rather than waiting until all of them are computed.
This allows later requirements to refer to earlier conformances.
2017-09-14 09:16:13 -07:00
Slava Pestov
052ff42fd3 AST: Don't add duplicate synthesized conformances
If an enum has a raw type, and a SynthesizedProtocolAttr, don't add
two duplicate conformances, since that triggers an assertion.

Instead, make sure to only add each conformance once. We cannot just
drop the SynthesizedProtocolAttr in this case, because we need to
pull the LazyConformanceLoader out of it.
2017-09-13 23:11:25 -07:00
Slava Pestov
e26949d3fd ClangImporter: Find type witnesses in finishNormalConformance() 2017-09-12 22:31:25 -07:00
Slava Pestov
c7aa831363 AST: Push conformance state change down into implementations of finishNormalConformance() 2017-09-12 16:22:35 -07:00
Slava Pestov
62d71d99e0 AST: Rename NormalProtocolConformance::Resolver to Loader
In almost all other places, 'resolver' means the ASTContext's LazyResolver,
which is just an abstract base class for the TypeChecker instance to break
circularity.

But here it is something totally different, used to lazily populate
imported and deserialized conformances, not parsed conformances.
2017-09-11 22:34:43 -07:00
Slava Pestov
a2e7f363f3 AST: Split off LazyConformanceLoader from LazyMemberLoader 2017-09-11 22:34:43 -07:00
Slava Pestov
747bb56b7e AST: All imported RawRepresentable types have a RawValue typealias now 2017-09-11 22:06:45 -07:00
Slava Pestov
c3f2f2b567 AST: Small cleanups 2017-09-11 21:48:01 -07:00
Slava Pestov
defb9cd5b6 AST: Add ASTContext::Id_ArrayLiteralElement 2017-09-11 21:48:01 -07:00
Slava Pestov
091da16929 AST: Teach resolveKnownTypeWitness() about ExpressibleByArrayLiteral.ArrayLiteralElement 2017-09-11 21:47:55 -07:00
Slava Pestov
414a7bf4ed AST: Remove ProtocolConformanceRef::getInherited() now that all usages are gone 2017-09-01 00:46:18 -07:00
Jordan Rose
124f7d2fac Add a counter for the number of conformance lookup tables built.
I didn't end up using this in the previous commit, but it seems
reasonable to have.
2017-07-05 11:27:27 -07:00
Doug Gregor
623d72db3c [AST] Make the "requirement signature" of a protocol a flat array.
Rather than pretend that the requirement signature of a protocol is a
full, well-formed generic signature that one can meaningfully query,
treat it as a flat set of requirements. Nearly all clients already did
this, but make it official. NFC
2017-06-29 14:01:49 -07:00
John McCall
faa9713cf1 Add a ProtocolConformance::getWitnessDeclRef that includes the
substitutions for calling a specialized declaration.

For full generality, this really ought to be a Witness, but the current
use cases where we're constructing calls to specialized witnesses never
need to call a generic requirement, and I'm not sure how to apply
substitutions to a Witness with a synthetic environment.
2017-06-11 01:39:50 -04:00
Slava Pestov
ba82fab4b2 AST: Remove last usages of getEffectiveAccess() from AST 2017-06-08 22:32:04 -07:00
practicalswift
8c40c65c80 [gardening] Fix typos. 2017-05-09 21:50:04 +02:00
Doug Gregor
6c8dd3959f [AST] Dodge an annoying libc++ std::function quirk requiring complete result types 2017-05-04 08:51:47 -07:00
Doug Gregor
dbb973aab4 [AST] Allow tentative type witnesses to be plumbed through SubstOptions.
Extend SubstOptions, which controls how substitution is performed, to
allow the caller to subst() to provide a callback function that may
provide a type witness for a normal protocol conformance that is
undergoing type witness inference. In effect, it's allowing us to
provide tentative bindings for type witnesses so we can see the
effects of substitution.
2017-05-03 22:38:53 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Roman Levenstein
0aff7c0c78 Produce specialized conformances to AnyObject for bound generic types.
Fixes rdar://31910351 (SR-4750)
2017-05-01 18:12:52 -07:00
practicalswift
4ef5c6d840 [gardening] Remove unused variables 2017-04-25 21:03:41 +02:00
Michael Gottesman
a89752f77a [gardening] Eliminate unused variable warnings from non-asserts build. 2017-04-24 16:08:06 -07:00
Slava Pestov
0290c2d5d8 AST: Make GenericSignature and GenericEnvironment SubstitutionMaps interchangable
SubstitutionMap::lookupConformance() would map archetypes out
of context to compute a conformance path. Do the same thing
in SubstitutionMap::lookupSubstitution().

The DenseMap of replacement types in a SubstitutionMap now
always has GenericTypeParamTypes as keys.

This simplifies some code and brings us one step closer to
a more efficient representation of SubstitutionMaps.
2017-04-24 14:12:36 -07:00
Jordan Rose
e575d2d5ba [ClangImporter] Error structs from enums are not imported decls.
Enums with the ns_error_domain attribute represent codes for NSError,
which means Swift developers will expect to interact with them in
terms of Error. SE-0112 improved bridging for these enums to generate
a struct with the following form:

    struct MyError: Error {
      @objc enum Code: RawRepresentable {
        case outOfMemory
        case fileNotFound
      }
      var userInfo: [NSObject: AnyObject] { get }
      static var outOfMemory: Code { get }
      static var fileNotFound: Code { get }
    }

where MyError.Code corresponds to the original MyError enum defined in
Objective-C. Until recently, both the enum and the synthesized struct
were marked as having the original enum as their "Clang node", but
that leads to problems: the struct isn't really ObjC-compatible, and
the two decls have the same USR. (The latter had already been worked
around.)

This commit changes the struct to be merely considered a synthesized
"external definition", with no associated Clang node. This meant
auditing everywhere that's looking for a Clang node and seeing which
ones applied to external definitions in general.

There is one regression in quality here: the generated struct is no
longer printed as part of the Swift interface for a header file, since
it's not actually a decl with a corresponding Clang node. The previous
change to AST printing mitigates this a little by at least indicating
that the enum has become a nested "Code" type.
2017-04-24 09:57:41 -07:00
Slava Pestov
620db5f74c AST: Narrower workaround for "concrete conformance under abstract conformance" bug
Instead of just falling back to module lookup any time conformance
substitution fails, only do it in the case we know doesn't work.

This should shake out some more bugs, hopefully without causing
too much pain.
2017-04-23 01:49:01 -07:00
Slava Pestov
c89ebec356 AST: Fix ProtocolConformanceRef::subst() with self-conforming existentials 2017-04-23 01:49:01 -07:00
Slava Pestov
a8452b4076 AST: Fix crash in ProtocolConformance::subst() when specializing with dynamic Self
Looking up the conformance @dynamic_self C<T> : P simply returns
the normal conformance C<T> : P.

If we later apply a substitution map to the conformance to
specialize T, we would call isSpecialized() on the substituted
type, which would return false. We would then hit an assertion
because the type type @dynamic_self C<Int> is not equal to the
(erroneously unsubstituted) conformance type C<T>.

Tweak the logic slightly to avoid this.
2017-04-23 01:49:00 -07:00
practicalswift
797c2d8118 [gardening] Fix end of namespace comments 2017-04-20 22:01:01 +02:00
practicalswift
5b9267b8b4 [gardening] Use override as appropriate 2017-04-20 13:47:10 +02:00
Doug Gregor
8584e97408 [AST] Sink ProtocolConformance::getWitness() down into NormalProtocolConformance.
NormalProtocolConformance has the only correct implementation of this
functionality. Instead, providing a safer getWitnessDecl() that
doesn't promise substitutions that are incorrect (and not actually
used by any clients).
2017-04-18 23:35:24 -07:00
Doug Gregor
ebdd56a1f0 [AST] Eliminate the "interface type" from protocol conformances.
We don't need this notion.
2017-04-18 17:15:15 -07:00
Roman Levenstein
07d779058a Address review comments
- Avoid unnecessary memory allocation
- Fix spelling errors
- Some further minor fixes
2017-04-17 11:44:57 -07:00
Roman Levenstein
049ba39da4 Address review comments 2017-04-14 22:17:55 -07:00
Roman Levenstein
6b466c5e1f Add a functionality to produce canonical conformances and substitutions
A canonical conformance is defined as a conformance which:
- does not contain any non-canonical types.
- Its type and interface type should be canonical.
- Any referenced conformances should be canonical.
- Any used substitutions should be canonical as well.

A substitution is canonical if:
- its replacement type is canonical
- all of its conformances are canonical
2017-04-14 19:53:51 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Doug Gregor
c8b435757d [AST] Teach NormalProtocolConformance to resolve known, synthesized witnesses.
There are a number of type witnesses that are introduced by the Clang
importer. Immediately resolve those witnesses *without* going through
the type checker, because there are cases (i.e., deserialized SIL)
where the conformance is created but there is no type checker around.

Fixes rdar://problem/30364905, rdar://problem/31053701,
rdar://problem/31565413 / SR-4565.
2017-04-13 15:49:34 -07:00
Doug Gregor
25290bd537 [AST] Add PrettyStackTrace entries for lazy resolution of witnesses.
This is an area where we have existing bugs and would benefit from
better backtraces.
2017-04-13 15:49:34 -07:00
Robert Widmann
5b3c4b6844 [NFC] Use the presence of an argument type to check for associated values (#8679)
* Use the presence of an argument type to check for associated values

hasOnlyCasesWithoutAssociatedValues returns true for any serialized
enum declaration whether or not it has cases.  This never really came
up because it's mostly relevant to Sema's proto-deriving mechanism.  Fix
this by using the presence of the case's argument type instead.

* Separate checks for presence of cases and enum simplicity

Necessary because the old behavior was an artifact of the
implementation.
2017-04-11 20:13:17 -04:00