Commit Graph

321 Commits

Author SHA1 Message Date
Jordan Rose
d3edf7c9ff [SILGen] Always serialize witness tables in non-resilient modules (#20390)
...even if the conforming nominal type is resilient. It's the owner
of the conformance whose resilience matters.

I also factored this part out into a separate check at the AST level
so we can tweak it, and also so I can use it to (slightly) speed up
compiling a resilient swiftinterface.
2018-11-08 15:34:00 -08:00
Doug Gregor
637412c14d [Mangling] Consider overlays when determining retroactive conformances.
When determining whether a given normal protocol conformance is “retroactive”,
consider an overlay module to be equivalent to its underlying Clang module.
Therefore, don’t classify conformances within the overlay as “retroactive”,
simplifying some common manglings (e.g., NSObject’s Hashable conformance is
no longer considered retroactive) and better capturing the intent.
2018-11-03 21:38:17 -07:00
Doug Gregor
b5bc06e552 [ABI] Eliminate witness table accessors.
Witness table accessors return a witness table for a given type's
conformance to a protocol. They are called directly from IRGen
(when we need the witness table instance) and from runtime conformance
checking (swift_conformsToProtocol digs the access function out of the
protocol conformance record). They have two interesting functions:

1) For witness tables requiring instantiation, they call
swift_instantiateWitnessTable directly.
2) For synthesized witness tables that might not be unique, they call
swift_getForeignWitnessTable.

Extend swift_instantiateWitnessTable() to handle both runtime
uniquing (for #2) as well as handling witness tables that don't have
a "generic table", i.e., don't need any actual instantiation. Use it
as the universal entry point for "get a witness table given a specific
conformance descriptor and type", eliminating witness table accessors
entirely.

Make a few related simplifications:

* Drop the "pattern" from the generic witness table. Instead, store
  the pattern in the main part of the conformance descriptor, always.
* Drop the "conformance kind" from the protocol conformance
  descriptor, since it was only there to distinguish between witness
  table (pattern) vs. witness table accessor.
* Internalize swift_getForeignWitnessTable(); IRGen no longer needs to
  call it.

Reduces the code size of the standard library (+assertions build) by
~149k.

Addresses rdar://problem/45489388.
2018-10-25 20:35:27 -07:00
Slava Pestov
73f1990bc2 AST: Use getSelfInterfaceType() instead of getProtocolSelfType() where possible
The former appears in the code base a lot more frequently than the
latter, which returns a GenericTypeParamType *. Use it only in places
where the more specific type is intended.
2018-10-15 20:34:08 -07:00
Rintaro Ishizaki
c6017095c3 [AST] Use invalid conformance for unsatisfied requirement
There is an invariant that SignatureConformances should have the same
size as the number of conformance requirements in the signature.
Previously, since unsatisfied requirements weren't reflected in it,
that caused a crash.

rdar://problem/43625800
2018-10-10 21:03:25 +09:00
Slava Pestov
5d59a3f2f3 AST: Lazily compute conditional requirements in conditional conformance
In one test where we used to dump conditional requirements we now print
a message that they have not been computed yet. I couldn't come up with
a way to force them to be computed here, but for the most part this test
is just ensuring that we don't recurse forever when printing recursive
conformances.
2018-09-27 20:49:23 -07:00
Slava Pestov
8ddda4393c AST: More robust differenceAndStoreConditionalRequirements()
Make sure we handle invalid extensions here, since calling
resolveExtension() won't always give us a generic signature.

This fixes a regression exposed by the next patch.
2018-09-20 01:20:31 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
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