Commit Graph

461 Commits

Author SHA1 Message Date
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
Doug Gregor
5e7a63f69d [ProtocolConformanceRef] Propagate concrete-lookup hack yet further.
Fixes rdar://problem/31482855.
2017-04-06 15:31:40 -07:00
Huon Wilson
31b92b1b46 Merge pull request #8473 from huonw/symbol-list-2
Remove dependency on IRGenModule of some linkage computations
2017-04-05 16:39:04 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Huon Wilson
65c6bdca90 [IRGen] Remove IGM argument, factor out conformance fragility logic. 2017-04-05 09:54:19 -07:00
Doug Gregor
30ef37cb83 [AST] Eliminate "inherited conformances" from NormalProtocolConformance.
All of this information is recoverable from the more-general,
more-sane signature conformances, so stop
recording/serializing/deserializing all of this extra stuff.
2017-04-04 22:20:50 -07:00
Doug Gregor
dafbf47319 [AST] Reimplement ProtocolConformance::getInheritedConformance().
Use getAssociatedConformance() instead, which is far simpler and more correct.
2017-04-04 22:03:06 -07:00
Doug Gregor
4a5eede18e Handle substitution in InheritedProtocolConformance::getAssociatedConformance.
Fixes a regression introduced when we switched SubstitutionMap::lookupConformance() to conformance access paths.
2017-04-04 17:03:10 -07:00
Doug Gregor
6bf4c461aa [SubstitutionMap] Use conformance access paths to find conformances.
When looking up a particular conformance in a SubstitutionMap, use the
associated generic signature to determine how to find that conformance
(via a conformance access path). Follow that conformance access path
to retrieve the desired conformance.

FIXME: There is still one failure, here

  Constraints/generic_overload.swift

which appears to be because we either have the wrong generic signature
for the override case or we are looking in the wrong map.
2017-04-04 10:58:01 -07:00
John McCall
22382f7e15 Reimplement associated conformance IRGen using Doug's conformance
access path work.

Having done so, simplify archetype TypeInfos by removing a now-
unnecessary layer of abstraction.
2017-03-14 03:48:10 -04:00
Slava Pestov
b41888acdf AST: Add SubstitutionMap::subst()
This will replace Substitution::subst().
2017-03-07 16:04:46 -08:00