Commit Graph

463 Commits

Author SHA1 Message Date
Doug Gregor
c7152f3576 [SIL] Don’t create witness table entries for overriding requirements.
SIL will not generate calls to protocol requirements that override
other protocol requirements, so all of the witness table entries for
the overriding arguments are dynamically dead. Remove them from the
witness tables entirely.

Implements rdar://problem/43870489, reducing the size of the standard
library binary by 196k.
2018-09-05 13:51:26 -07:00
Slava Pestov
e78f16fb69 AST: ProtocolConformance::subst() doesn't need to take substType 2018-08-25 00:31:07 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
d1a43617cc [Conformance lookup table] Drop unnecessary LazyResolver parameters.
There is no point in threading LazyResolver parameters through this
data structure; we can recover the resolver in the one place it is 
needed.
2018-08-14 01:05:42 -07:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00
Doug Gregor
b07dd059a6 [Type Checker] Remove TypeChecker/LazyResolver parameters from name lookup.
Make the TypeChecker’s name-lookup routines static, so they don’t depend
on the TypeCheck instance… except for one pesky place where we jump back
into protocol conformance checking. This is part of teasing apart the type
checker.
2018-07-18 14:50:38 -07:00
Slava Pestov
fc80f75273 AST: Create new 'invalid' state for ProtocolConformanceRef 2018-07-16 16:44:27 -07:00
Slava Pestov
0c0ecba756 AST: Add new overload of ProtocolConformance{,Ref}::subst() taking a SubstitutionMap 2018-07-16 16:44:27 -07:00
Doug Gregor
8dbdf7feb1 [Type checker] Handle literals based on superclass constraints.
When we form a literal whose type is a type parameter where the literal
conformance comes from a superclass constraint of that type parameter,
make sure we can property extract the type witness we need.

Fixes SR-7551 / rdar://problem/39860617.
2018-06-28 16:53:06 -07:00
Huon Wilson
d4df4b3e71 [AST] "Simple case" of specialized conditional requirements should be an optional with an empty array. 2018-06-26 12:45:02 +10:00
Huon Wilson
10b30fef78 [GSB] Explicit error on unsupported conditional conformance recursion.
This doesn't fix the fundamental problem of correctly handling such cases, but
it is better than the "error message" that occurred previously:

    Assertion failed: ((bool)typeSig == (bool)extensionSig && "unexpected generic-ness mismatch on conformance").

Fixes the crash rdar://problem/41281406 (that in
https://bugs.swift.org/browse/SR-6569 (rdar://problem/36068136)),
https://bugs.swift.org/browse/SR-8019 (rdar://problem/41216423) and
https://bugs.swift.org/browse/SR-7989 (rdar://problem/41126254).
2018-06-21 10:53:30 +10:00
Doug Gregor
99e540f588 [Evaluator] Add an “enum raw type” request and use it consistently.
Similar to get “superclass of class” request, introduce an “enum raw type”
request that is accessed via EnumDecl::getRawType().
2018-06-14 15:29:57 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00
Doug Gregor
ef020c74aa Eliminate all vestiges of Substitution and SubstitutionList.
Introduced during the bring-up of the generics system in July, 2012,
Substitution (and SubstitutionList) has been completely superseded by
SubstitutionMap. R.I.P.
2018-05-11 21:43:40 -07:00
Doug Gregor
e13fd4cb00 [AST] Eliminate Substitution::getCanonicalSubstitution().
It's one client can canonicalize via the SubstitutionMap instead.
2018-05-03 08:48:54 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
e09c152f1d [AST] Eliminate Substitution::getCanonicalSubstitution().
It's one client can canonicalize via the SubstitutionMap instead.
2018-05-03 00:05:20 -07:00
Doug Gregor
ebf9cdcc44 [AST] Collapse storage for ConcreteDeclRef.
Rather than ASTContext-allocating ConcreteDeclRef’s storage when there is a
non-empty substitution map, put the SubstitutionMap directly in the
ConcreteDeclRef. Simplify the various interfaces along the way.
2018-05-02 13:39:21 -07:00
Doug Gregor
bc5bbe8b64 [AST] Use SubstitutionMap, not SubstitutionList, in SILBoxType.
Eliminate the last place in the AST proper that stores
SubstitutionLists rather than SubstitutionMaps. Randomly fixes a
crasher, too.
2018-05-02 13:39:21 -07:00
Doug Gregor
3e2bed119b [AST] Switch SpecializedProtocolConformance over to SubstitutionMap.
Eliminate another common use of SubstitutionList from the AST.
2018-05-02 13:38:15 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Pavel Yaskevich
f5db1df5dc [AST] Unify witness construction logic
Avoid storing more information than necessary in witnesses
and establishing the invariant that we only use out-of-line
storage when we require substitutions.
2018-04-19 18:00:04 -07:00
Slava Pestov
75db43b978 AST: Replace ProtocolType::compareProtocols() with TypeDecl::compare() 2018-04-06 15:41:07 -07:00
Huon Wilson
48a06be73d [AST] Implied conformances store which conformance implied them. 2018-04-04 10:34:33 +10:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
Graydon Hoare
5f01c19d8e [Stats] Add support for tracing protocol conformances. 2018-02-21 14:49:24 -08:00
Huon Wilson
715ca9d27d [AST] Store sugared requirements in NormalProtocolConformances.
No point in getting rid of the sugar so early.
2018-02-13 01:30:42 +11:00
Doug Gregor
28c489c16d [ABI] Mangle retroactive conformances as part of bound generic types.
A "retroactive" protocol conformance is a conformance that is provided
by a module that is neither the module that defines the protocol nor
the module that defines the conforming type. It is possible for such
conformances to conflict at runtime, if defined in different modules
that were not both visible to the compiler at the same time.

When mangling a bound generic type, also mangle retroactive protocol
conformances that were needed to satisfy the generic requirements of
the generic type. This prevents name collisions between (e.g.) types
formed using retroactive conformances from different modules. The
impact on the size of the mangling is expected to be relatively small,
because most conformances are not retroactive.

Fixes the ABI part of rdar://problem/14375889.
2018-01-31 09:53:38 -08:00
Doug Gregor
597c955948 [Associated type inference] Find tentative type witnesses across protocol hierarchy.
As a minor step toward more global associated type inference,
allow tentative type witnesses to be found across a protocol
hierarchy, eliminating some recursion through associated type
inference. Fixes a recent regression in validation-test/stdlib/CollectionTypes.swift, as well as rdar://problem/36453271.
2018-01-24 23:01:21 -08:00
Doug Gregor
24aa030f0c [Associated type inference] Break recursive inference and fail predictably.
There was a path through associated type inference where we would end
up recording a type witness that contained an error, but for which we
had not reported that error, which would lead to downstream
crashes. Make sure that we reject such inferences.

And because it triggers once we fix this issue... make sure break
recursion when trying to resolve type witnesses lazily.

Fixes the crash in SR-6609 / rdar://problem/36038033, but we're still
failing to infer in those cases.
2018-01-24 15:58:26 -08:00
Doug Gregor
663d6af063 [ABI] Factor out the protocol conformance flags (again).
Protocol conformance records are becoming richer and more interesting;
separate out the "flags" word and add the various other fields that we
want there (is-retroactive, is-synthesized-nonunique, # of conditional
requirements).
2018-01-17 10:06:07 -08:00
Doug Gregor
d9095b1079 [Conformance checking] Don't suppress substitution failures during checking.
When checking whether a particular protocol conformance satisfies all of
the protocol's requirements, we were suppressing substitution failures.
In some cases, this would mean that we marked a conformance "invalid"
without ever emitting a diagnostic, which would lead to downstream crashes.

Instead, treat substitution failures somewhat more lazily. If we encounter
one while performing the checking, put the conformance into a "delayed" list
rather than failing immediately. Teach the top-level type checking
loop to re-check these conformances, emitting a diagnostic if they
fail the second time around.

Fixes rdar://problem/35082483 and likely other issues that slipped
through the type checker or blew up in unpredictable ways.
2017-12-18 16:43:59 -08:00
Doug Gregor
59ee97f4af [SE-0143] Try harder to substitute conditional requirements fully.
When forming a specialized protocol conformance, we substitute into the
conditional requirements. Allow this substitution to look into the module
to find conformances, which might be required to accurately represented
the requirements. Otherwise, we can silently end up dropping them.

We should rethink this notion of eagerly substituting conditional
requirements, and consider whether clients should always handle this
substitution. For now, fixes rdar://problem/35837054.

Allow conformance lookup in module context for conditional
2017-12-04 15:02:56 -08:00
Tony Allevato
c92a08df2d Remove unused NominalDecl args from ConformanceLookupTable 2017-11-28 17:42:35 -08:00
swift-ci
2f48ba5587 Merge pull request #13041 from DougGregor/conformance-micro-opts 2017-11-20 22:03:50 -08:00
Slava Pestov
b394ddf1b7 AST: Fix ProtocolConformance::subst() for interface-typed normal conformances 2017-11-20 12:59:03 -05:00
Doug Gregor
af083791e8 [AST] Enable commented-out optimization for associated-type access.
A while ago, we commented-out an obvious optimization when accessing the
associated types of a protocol conformance to get better coverage of the
general substitution path. Bring that code back, avoiding the creation of
substitution maps in a few cases.
2017-11-19 22:44:56 -08:00
Doug Gregor
a2c05130ef [AST] Use getSuperclassForDecl() appropriately.
Thank you to @slavapestov for noticing that I hard-coded an existing
utility function. DRY indeed!
2017-11-19 22:23:56 -08:00
Doug Gregor
41e0648336 [AST] Properly adjust substitution type for inherited conformances.
When we substitute into an inherited conformance, make sure that we
follow the superclass chain from the new conforming type up to the
matching superclass *before* doing the substitution.

Fixes rdar://problem/35632543.
2017-11-19 21:50:24 -08:00
Doug Gregor
b0760e149e [AST] Substitute into conditional requirements of a specialized conformance.
Substitute the type arguments of the conforming type into the conditional
requirements of the specialized conformance, so they reflect the specific
requirements of the specialized conformance.

Fixes rdar://problem/34944286.
2017-11-17 22:57:41 -08:00
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