Skip to content

Commit 8ac2d65

Browse files
authored
Merge pull request #25986 from slavapestov/partially-checked-conformances
Remove PartiallyCheckedConformances list
2 parents 7da25d7 + 4c499fd commit 8ac2d65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+306
-552
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ namespace swift {
7070
class GenericSignature;
7171
class GenericTypeParamDecl;
7272
class GenericTypeParamType;
73-
class LazyResolver;
7473
class ModuleDecl;
7574
class EnumCaseDecl;
7675
class EnumElementDecl;
@@ -3956,10 +3955,7 @@ class ClassDecl final : public NominalTypeDecl {
39563955

39573956
/// Determine whether this class inherits the convenience initializers
39583957
/// from its superclass.
3959-
///
3960-
/// \param resolver Used to resolve the signatures of initializers, which is
3961-
/// required for name lookup.
3962-
bool inheritsSuperclassInitializers(LazyResolver *resolver);
3958+
bool inheritsSuperclassInitializers();
39633959

39643960
/// Marks that this class inherits convenience initializers from its
39653961
/// superclass.
@@ -4143,7 +4139,7 @@ class ProtocolDecl final : public NominalTypeDecl {
41434139

41444140
bool existentialConformsToSelfSlow();
41454141

4146-
bool existentialTypeSupportedSlow(LazyResolver *resolver);
4142+
bool existentialTypeSupportedSlow();
41474143

41484144
ArrayRef<ProtocolDecl *> getInheritedProtocolsSlow();
41494145

@@ -4269,12 +4265,12 @@ class ProtocolDecl final : public NominalTypeDecl {
42694265
/// conforming to this protocol. This is only permitted if the types of
42704266
/// all the members do not contain any associated types, and do not
42714267
/// contain 'Self' in 'parameter' or 'other' position.
4272-
bool existentialTypeSupported(LazyResolver *resolver) const {
4268+
bool existentialTypeSupported() const {
42734269
if (Bits.ProtocolDecl.ExistentialTypeSupportedValid)
42744270
return Bits.ProtocolDecl.ExistentialTypeSupported;
42754271

42764272
return const_cast<ProtocolDecl *>(this)
4277-
->existentialTypeSupportedSlow(resolver);
4273+
->existentialTypeSupportedSlow();
42784274
}
42794275

42804276
/// Explicitly set the existentialTypeSupported flag, without computing

include/swift/AST/ProtocolConformance.h

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,16 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
148148

149149
/// Return true if the conformance has a witness for the given associated
150150
/// type.
151-
bool hasTypeWitness(AssociatedTypeDecl *assocType,
152-
LazyResolver *resolver = nullptr) const;
151+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const;
153152

154153
/// Retrieve the type witness for the given associated type.
155154
Type getTypeWitness(AssociatedTypeDecl *assocType,
156-
LazyResolver *resolver,
157155
SubstOptions options = None) const;
158156

159157
/// Retrieve the type witness and type decl (if one exists)
160158
/// for the given associated type.
161159
std::pair<Type, TypeDecl *>
162160
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
163-
LazyResolver *resolver,
164161
SubstOptions options = None) const;
165162

166163
/// Apply the given function object to each type witness within this
@@ -173,17 +170,17 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
173170
///
174171
/// \returns true if the function ever returned true
175172
template<typename F>
176-
bool forEachTypeWitness(LazyResolver *resolver, F f) const {
173+
bool forEachTypeWitness(F f, bool useResolver=false) const {
177174
const ProtocolDecl *protocol = getProtocol();
178175
for (auto assocTypeReq : protocol->getAssociatedTypeMembers()) {
179176
if (assocTypeReq->isInvalid())
180177
continue;
181178

182179
// If we don't have and cannot resolve witnesses, skip it.
183-
if (!resolver && !hasTypeWitness(assocTypeReq))
180+
if (!useResolver && !hasTypeWitness(assocTypeReq))
184181
continue;
185182

186-
const auto &TWInfo = getTypeWitnessAndDecl(assocTypeReq, resolver);
183+
const auto &TWInfo = getTypeWitnessAndDecl(assocTypeReq);
187184
if (f(assocTypeReq, TWInfo.first, TWInfo.second))
188185
return true;
189186
}
@@ -193,13 +190,11 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
193190

194191
/// Retrieve the value witness declaration corresponding to the given
195192
/// requirement.
196-
ValueDecl *getWitnessDecl(ValueDecl *requirement,
197-
LazyResolver *resolver) const;
193+
ValueDecl *getWitnessDecl(ValueDecl *requirement) const;
198194

199195
/// Retrieve the witness corresponding to the given value requirement.
200196
/// TODO: maybe this should return a Witness?
201-
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement,
202-
LazyResolver *resolver) const;
197+
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const;
203198

204199
private:
205200
/// Determine whether we have a witness for the given requirement.
@@ -211,7 +206,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
211206
///
212207
/// The function object should accept a \c ValueDecl* for the requirement.
213208
template<typename F>
214-
void forEachNonWitnessedRequirement(LazyResolver *Resolver, F f) const {
209+
void forEachNonWitnessedRequirement(F f) const {
215210
const ProtocolDecl *protocol = getProtocol();
216211
for (auto req : protocol->getMembers()) {
217212
auto valueReq = dyn_cast<ValueDecl>(req);
@@ -220,7 +215,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
220215

221216
if (auto assocTypeReq = dyn_cast<AssociatedTypeDecl>(req)) {
222217
// If we don't have witness for the associated type, apply the function.
223-
if (getTypeWitness(assocTypeReq, Resolver)->hasError()) {
218+
if (getTypeWitness(assocTypeReq)->hasError()) {
224219
f(valueReq);
225220
}
226221
continue;
@@ -241,15 +236,13 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
241236

242237
/// Given a dependent type expressed in terms of the self parameter,
243238
/// map it into the context of this conformance.
244-
Type getAssociatedType(Type assocType,
245-
LazyResolver *resolver = nullptr) const;
239+
Type getAssociatedType(Type assocType) const;
246240

247241
/// Given that the requirement signature of the protocol directly states
248242
/// that the given dependent type must conform to the given protocol,
249243
/// return its associated conformance.
250244
ProtocolConformanceRef
251-
getAssociatedConformance(Type assocType, ProtocolDecl *protocol,
252-
LazyResolver *resolver = nullptr) const;
245+
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const;
253246

254247
/// Get the generic parameters open on the conforming type.
255248
GenericEnvironment *getGenericEnvironment() const;
@@ -353,12 +346,11 @@ class RootProtocolConformance : public ProtocolConformance {
353346
AvailabilityContext fromContext) const;
354347

355348
bool hasWitness(ValueDecl *requirement) const;
356-
Witness getWitness(ValueDecl *requirement, LazyResolver *resolver) const;
349+
Witness getWitness(ValueDecl *requirement) const;
357350

358351
/// Retrieve the witness corresponding to the given value requirement.
359352
/// TODO: maybe this should return a Witness?
360-
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement,
361-
LazyResolver *resolver) const;
353+
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const;
362354

363355
/// Apply the given function object to each value witness within this
364356
/// protocol conformance.
@@ -368,7 +360,7 @@ class RootProtocolConformance : public ProtocolConformance {
368360
/// witness will only be specialized if the conformance came from the current
369361
/// file.
370362
template<typename F>
371-
void forEachValueWitness(LazyResolver *resolver, F f) const {
363+
void forEachValueWitness(F f, bool useResolver=false) const {
372364
const ProtocolDecl *protocol = getProtocol();
373365
for (auto req : protocol->getMembers()) {
374366
auto valueReq = dyn_cast<ValueDecl>(req);
@@ -380,10 +372,10 @@ class RootProtocolConformance : public ProtocolConformance {
380372
continue;
381373

382374
// If we don't have and cannot resolve witnesses, skip it.
383-
if (!resolver && !hasWitness(valueReq))
375+
if (!useResolver && !hasWitness(valueReq))
384376
continue;
385377

386-
f(valueReq, getWitness(valueReq, resolver));
378+
f(valueReq, getWitness(valueReq));
387379
}
388380
}
389381

@@ -597,13 +589,11 @@ class NormalProtocolConformance : public RootProtocolConformance,
597589
/// for the given associated type.
598590
std::pair<Type, TypeDecl *>
599591
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
600-
LazyResolver *resolver,
601592
SubstOptions options = None) const;
602593

603594
/// Determine whether the protocol conformance has a type witness for the
604595
/// given associated type.
605-
bool hasTypeWitness(AssociatedTypeDecl *assocType,
606-
LazyResolver *resolver = nullptr) const;
596+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const;
607597

608598
/// Set the type witness for the given associated type.
609599
/// \param typeDecl the type decl the witness type came from, if one exists.
@@ -614,11 +604,10 @@ class NormalProtocolConformance : public RootProtocolConformance,
614604
/// that the given dependent type must conform to the given protocol,
615605
/// return its associated conformance.
616606
ProtocolConformanceRef
617-
getAssociatedConformance(Type assocType, ProtocolDecl *protocol,
618-
LazyResolver *resolver = nullptr) const;
607+
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const;
619608

620609
/// Retrieve the value witness corresponding to the given requirement.
621-
Witness getWitness(ValueDecl *requirement, LazyResolver *resolver) const;
610+
Witness getWitness(ValueDecl *requirement) const;
622611

623612
/// Determine whether the protocol conformance has a witness for the given
624613
/// requirement.
@@ -644,20 +633,14 @@ class NormalProtocolConformance : public RootProtocolConformance,
644633
/// the normal conformance.
645634
void setSignatureConformances(ArrayRef<ProtocolConformanceRef> conformances);
646635

647-
/// Retrieves a function object that should be called with each of the
648-
/// conformances required by the requirement signature.
649-
///
650-
/// This can be used to iteratively build up the signature conformances in
651-
/// the type checker (rather than emitting them in a batch via
652-
/// \c setSignatureConformances). The callee is responsible for calling
653-
/// the returned function object with protocol conformances that line up
654-
/// with the conformance requirements in the requirement signature (in order).
655-
std::function<void(ProtocolConformanceRef)> populateSignatureConformances();
636+
/// Populate the signature conformances without checking if they satisfy
637+
/// requirements. Can only be used with parsed or imported conformances.
638+
void finishSignatureConformances();
656639

657640
/// Determine whether the witness for the given type requirement
658641
/// is the default definition.
659642
bool usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
660-
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement, nullptr).second;
643+
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement).second;
661644
if (witnessDecl)
662645
return witnessDecl->isImplicit();
663646
// Conservatively assume it does not.
@@ -725,20 +708,17 @@ class SelfProtocolConformance : public RootProtocolConformance {
725708
llvm_unreachable("never an implied conformance");
726709
}
727710

728-
bool hasTypeWitness(AssociatedTypeDecl *assocType,
729-
LazyResolver *resolver) const {
711+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const {
730712
llvm_unreachable("self-conformances never have associated types");
731713
}
732714

733715
std::pair<Type, TypeDecl *>
734716
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
735-
LazyResolver *resolver,
736717
SubstOptions options) const {
737718
llvm_unreachable("self-conformances never have associated types");
738719
}
739720

740721
Type getTypeWitness(AssociatedTypeDecl *assocType,
741-
LazyResolver *resolver,
742722
SubstOptions options) const {
743723
llvm_unreachable("self-conformances never have associated types");
744724
}
@@ -748,15 +728,14 @@ class SelfProtocolConformance : public RootProtocolConformance {
748728
}
749729

750730
ProtocolConformanceRef getAssociatedConformance(Type assocType,
751-
ProtocolDecl *protocol,
752-
LazyResolver *resolver) const{
731+
ProtocolDecl *protocol) const{
753732
llvm_unreachable("self-conformances never have associated types");
754733
}
755734

756735
bool hasWitness(ValueDecl *requirement) const {
757736
return true;
758737
}
759-
Witness getWitness(ValueDecl *requirement, LazyResolver *resolver) const;
738+
Witness getWitness(ValueDecl *requirement) const;
760739

761740
Optional<ArrayRef<Requirement>> getConditionalRequirementsIfAvailable() const{
762741
return ArrayRef<Requirement>();
@@ -875,26 +854,22 @@ class SpecializedProtocolConformance : public ProtocolConformance,
875854
return GenericConformance->getImplyingConformance();
876855
}
877856

878-
bool hasTypeWitness(AssociatedTypeDecl *assocType,
879-
LazyResolver *resolver = nullptr) const;
857+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const;
880858

881859
/// Retrieve the type witness and type decl (if one exists)
882860
/// for the given associated type.
883861
std::pair<Type, TypeDecl *>
884862
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
885-
LazyResolver *resolver,
886863
SubstOptions options = None) const;
887864

888865
/// Given that the requirement signature of the protocol directly states
889866
/// that the given dependent type must conform to the given protocol,
890867
/// return its associated conformance.
891868
ProtocolConformanceRef
892-
getAssociatedConformance(Type assocType, ProtocolDecl *protocol,
893-
LazyResolver *resolver = nullptr) const;
869+
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const;
894870

895871
/// Retrieve the witness corresponding to the given value requirement.
896-
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement,
897-
LazyResolver *resolver) const;
872+
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const;
898873

899874
/// Determine whether the witness for the given requirement
900875
/// is either the default definition or was otherwise deduced.
@@ -989,31 +964,26 @@ class InheritedProtocolConformance : public ProtocolConformance,
989964
/// Get the protocol conformance which implied this implied conformance.
990965
NormalProtocolConformance *getImplyingConformance() const { return nullptr; }
991966

992-
bool hasTypeWitness(AssociatedTypeDecl *assocType,
993-
LazyResolver *resolver = nullptr) const {
994-
return InheritedConformance->hasTypeWitness(assocType, resolver);
967+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const {
968+
return InheritedConformance->hasTypeWitness(assocType);
995969
}
996970

997971
/// Retrieve the type witness and type decl (if one exists)
998972
/// for the given associated type.
999973
std::pair<Type, TypeDecl *>
1000974
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
1001-
LazyResolver *resolver,
1002975
SubstOptions options = None) const {
1003-
return InheritedConformance->getTypeWitnessAndDecl(assocType, resolver,
1004-
options);
976+
return InheritedConformance->getTypeWitnessAndDecl(assocType, options);
1005977
}
1006978

1007979
/// Given that the requirement signature of the protocol directly states
1008980
/// that the given dependent type must conform to the given protocol,
1009981
/// return its associated conformance.
1010982
ProtocolConformanceRef
1011-
getAssociatedConformance(Type assocType, ProtocolDecl *protocol,
1012-
LazyResolver *resolver = nullptr) const;
983+
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const;
1013984

1014985
/// Retrieve the witness corresponding to the given value requirement.
1015-
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement,
1016-
LazyResolver *resolver) const;
986+
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const;
1017987

1018988
/// Determine whether the witness for the given requirement
1019989
/// is either the default definition or was otherwise deduced.

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,18 @@ class ProtocolConformanceRef {
110110
LookupConformanceFn conformances,
111111
SubstOptions options = None) const;
112112

113+
/// Map contextual types to interface types in the conformance.
114+
ProtocolConformanceRef mapConformanceOutOfContext() const;
115+
113116
/// Given a dependent type (expressed in terms of this conformance's
114117
/// protocol), follow it from the conforming type.
115-
Type getAssociatedType(Type origType, Type dependentType,
116-
LazyResolver *resolver = nullptr) const;
118+
Type getAssociatedType(Type origType, Type dependentType) const;
117119

118120
/// Given a dependent type (expressed in terms of this conformance's
119121
/// protocol) and conformance, follow it from the conforming type.
120122
ProtocolConformanceRef
121123
getAssociatedConformance(Type origType, Type dependentType,
122-
ProtocolDecl *requirement,
123-
LazyResolver *resolver = nullptr) const;
124+
ProtocolDecl *requirement) const;
124125

125126
void dump() const;
126127
void dump(llvm::raw_ostream &out, unsigned indent = 0) const;

include/swift/AST/Type.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class ClassDecl;
3838
class CanType;
3939
class EnumDecl;
4040
class GenericSignature;
41-
class LazyResolver;
4241
class ModuleDecl;
4342
class NominalTypeDecl;
4443
class GenericTypeDecl;

include/swift/AST/Types.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,9 +5112,7 @@ class DependentMemberType : public TypeBase {
51125112
/// Substitute the base type, looking up our associated type in it if it is
51135113
/// non-dependent. Returns null if the member could not be found in the new
51145114
/// base.
5115-
Type substBaseType(ModuleDecl *M,
5116-
Type base,
5117-
LazyResolver *resolver = nullptr);
5115+
Type substBaseType(ModuleDecl *M, Type base);
51185116

51195117
/// Substitute the base type, looking up our associated type in it if it is
51205118
/// non-dependent. Returns null if the member could not be found in the new

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace swift {
2727
class AbstractFunctionDecl;
2828
class Decl;
2929
class Expr;
30-
class LazyResolver;
3130
class ExtensionDecl;
3231
class ProtocolDecl;
3332
class Type;

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
namespace swift {
2121
class ModuleFile;
22+
class LazyResolver;
2223

2324
/// Spceifies how to load modules when both a parseable interface and serialized
2425
/// AST are present, or whether to disallow one format or the other altogether.

0 commit comments

Comments
 (0)