Skip to content

Commit b318a9a

Browse files
Merge pull request #4796 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 9e6933b + c254623 commit b318a9a

31 files changed

+221
-122
lines changed

include/swift/AST/GenericEnvironment.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class QueryInterfaceTypeSubstitutions {
5454
/// Extra data in a generic environment for an opened existentiak.
5555
struct OpenedGenericEnvironmentData {
5656
Type existential;
57+
GenericSignature parentSig;
5758
UUID uuid;
5859
};
5960

@@ -110,7 +111,8 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
110111

111112
explicit GenericEnvironment(GenericSignature signature);
112113
explicit GenericEnvironment(
113-
GenericSignature signature, Type existential, UUID uuid);
114+
GenericSignature signature,
115+
Type existential, GenericSignature parentSig, UUID uuid);
114116
explicit GenericEnvironment(
115117
GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);
116118

@@ -143,6 +145,9 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
143145
/// Retrieve the UUID for an opened existential environment.
144146
UUID getOpenedExistentialUUID() const;
145147

148+
/// Retrieve the parent signature for an opened existential environment.
149+
GenericSignature getOpenedExistentialParentSignature() const;
150+
146151
/// Retrieve the opaque type declaration for a generic environment describing
147152
/// opaque types.
148153
OpaqueTypeDecl *getOpaqueTypeDecl() const;
@@ -158,29 +163,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
158163

159164
/// Create a new generic environment for an opened existential.
160165
///
161-
/// This function uses the provided parent signature to construct a new
162-
/// signature suitable for use with an opened archetype. If you have an
163-
/// existing generic signature from e.g. deserialization use
164-
/// \c GenericEnvironment::forOpenedArchetypeSignature instead.
165-
///
166166
/// \param existential The subject existential type
167167
/// \param parentSig The signature of the context where this existential type is being opened
168168
/// \param uuid The unique identifier for this opened existential
169169
static GenericEnvironment *
170170
forOpenedExistential(Type existential, GenericSignature parentSig, UUID uuid);
171171

172-
/// Create a new generic environment for an opened existential.
173-
///
174-
/// It is unlikely you want to use this function.
175-
/// Call \c GenericEnvironment::forOpenedExistential instead.
176-
///
177-
/// \param existential The subject existential type
178-
/// \param signature The signature of the opened archetype
179-
/// \param uuid The unique identifier for this opened existential
180-
static GenericEnvironment *
181-
forOpenedArchetypeSignature(Type existential,
182-
GenericSignature signature, UUID uuid);
183-
184172
/// Create a new generic environment for an opaque type with the given set of
185173
/// outer substitutions.
186174
static GenericEnvironment *forOpaqueType(

include/swift/AST/Requirement.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ class Requirement
5353

5454
/// Subst the types involved in this requirement.
5555
///
56-
/// The \c args arguments are passed through to Type::subst. This doesn't
57-
/// touch the superclasses, protocols or layout constraints.
56+
/// The \c args arguments are passed through to Type::subst.
5857
template <typename ...Args>
59-
llvm::Optional<Requirement> subst(Args &&...args) const {
58+
Requirement subst(Args &&...args) const {
6059
auto newFirst = getFirstType().subst(std::forward<Args>(args)...);
61-
if (newFirst->hasError())
62-
return None;
63-
6460
switch (getKind()) {
6561
case RequirementKind::Conformance:
6662
case RequirementKind::Superclass:
6763
case RequirementKind::SameType: {
6864
auto newSecond = getSecondType().subst(std::forward<Args>(args)...);
69-
if (newSecond->hasError())
70-
return None;
7165
return Requirement(getKind(), newFirst, newSecond);
7266
}
7367
case RequirementKind::Layout:

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,19 +4679,14 @@ GenericEnvironment::forOpenedExistential(
46794679
Type existential, GenericSignature parentSig, UUID uuid) {
46804680
auto &ctx = existential->getASTContext();
46814681
auto signature = ctx.getOpenedArchetypeSignature(existential, parentSig);
4682-
return GenericEnvironment::forOpenedArchetypeSignature(existential, signature, uuid);
4683-
}
46844682

4685-
GenericEnvironment *GenericEnvironment::forOpenedArchetypeSignature(
4686-
Type existential, GenericSignature signature, UUID uuid) {
46874683
// Allocate and construct the new environment.
4688-
auto &ctx = existential->getASTContext();
46894684
unsigned numGenericParams = signature.getGenericParams().size();
46904685
size_t bytes = totalSizeToAlloc<OpaqueTypeDecl *, SubstitutionMap,
46914686
OpenedGenericEnvironmentData, Type>(
46924687
0, 0, 1, numGenericParams);
46934688
void *mem = ctx.Allocate(bytes, alignof(GenericEnvironment));
4694-
return new (mem) GenericEnvironment(signature, existential, uuid);
4689+
return new (mem) GenericEnvironment(signature, existential, parentSig, uuid);
46954690
}
46964691

46974692
/// Create a new generic environment for an opaque type with the given set of
@@ -5340,9 +5335,8 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
53405335
};
53415336

53425337
for (auto reqt : baseGenericSig.getRequirements()) {
5343-
if (auto substReqt = reqt.subst(substFn, lookupConformanceFn)) {
5344-
addedRequirements.push_back(*substReqt);
5345-
}
5338+
auto substReqt = reqt.subst(substFn, lookupConformanceFn);
5339+
addedRequirements.push_back(substReqt);
53465340
}
53475341
}
53485342

lib/AST/ExistentialGeneralization.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
212212
if (origReq.getKind() != RequirementKind::Conformance) continue;
213213
auto origConformance = origConformances[i++];
214214

215-
auto optNewReq = origReq.subst(newSubs);
216-
assert(optNewReq && "generalization substitution failed");
217-
auto &newReq = *optNewReq;
218-
215+
auto newReq = origReq.subst(newSubs);
219216
addedRequirements.push_back(newReq);
220217

221218
substConformances.insert({{newReq.getFirstType()->getCanonicalType(),

lib/AST/GenericEnvironment.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ UUID GenericEnvironment::getOpenedExistentialUUID() const {
104104
return getTrailingObjects<OpenedGenericEnvironmentData>()->uuid;
105105
}
106106

107+
GenericSignature
108+
GenericEnvironment::getOpenedExistentialParentSignature() const {
109+
assert(getKind() == Kind::OpenedExistential);
110+
return getTrailingObjects<OpenedGenericEnvironmentData>()->parentSig;
111+
}
112+
107113
GenericEnvironment::GenericEnvironment(GenericSignature signature)
108114
: SignatureAndKind(signature, Kind::Normal)
109115
{
@@ -113,11 +119,12 @@ GenericEnvironment::GenericEnvironment(GenericSignature signature)
113119
}
114120

115121
GenericEnvironment::GenericEnvironment(
116-
GenericSignature signature, Type existential, UUID uuid)
122+
GenericSignature signature,
123+
Type existential, GenericSignature parentSig, UUID uuid)
117124
: SignatureAndKind(signature, Kind::OpenedExistential)
118125
{
119126
new (getTrailingObjects<OpenedGenericEnvironmentData>())
120-
OpenedGenericEnvironmentData{ existential, uuid };
127+
OpenedGenericEnvironmentData{ existential, parentSig, uuid };
121128

122129
// Clear out the memory that holds the context types.
123130
std::uninitialized_fill(getContextTypes().begin(), getContextTypes().end(),

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,14 @@ bool GenericSignatureImpl::isRequirementSatisfied(
373373
if (requirement.getFirstType()->hasTypeParameter()) {
374374
auto *genericEnv = getGenericEnvironment();
375375

376-
auto substituted = requirement.subst(
376+
requirement = requirement.subst(
377377
[&](SubstitutableType *type) -> Type {
378378
if (auto *paramType = type->getAs<GenericTypeParamType>())
379379
return genericEnv->mapTypeIntoContext(paramType);
380380

381381
return type;
382382
},
383383
LookUpConformanceInSignature(this));
384-
385-
if (!substituted)
386-
return false;
387-
388-
requirement = *substituted;
389384
}
390385

391386
// FIXME: Need to check conditional requirements here.

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5169,8 +5169,8 @@ class GenericSignatureBuilder::InferRequirementsWalker : public TypeWalker {
51695169
auto decl = TypeAlias->getDecl();
51705170
auto subMap = TypeAlias->getSubstitutionMap();
51715171
for (const auto &rawReq : decl->getGenericSignature().getRequirements()) {
5172-
if (auto req = rawReq.subst(subMap))
5173-
Builder.addRequirement(*req, source, nullptr);
5172+
auto req = rawReq.subst(subMap);
5173+
Builder.addRequirement(req, source, nullptr);
51745174
}
51755175

51765176
return Action::Continue;
@@ -5237,8 +5237,8 @@ class GenericSignatureBuilder::InferRequirementsWalker : public TypeWalker {
52375237
// Handle the requirements.
52385238
// FIXME: Inaccurate TypeReprs.
52395239
for (const auto &rawReq : genericSig.getRequirements()) {
5240-
if (auto req = rawReq.subst(subMap))
5241-
Builder.addRequirement(*req, source, nullptr);
5240+
auto req = rawReq.subst(subMap);
5241+
Builder.addRequirement(req, source, nullptr);
52425242
}
52435243

52445244
return Action::Continue;
@@ -8402,7 +8402,7 @@ AbstractGenericSignatureRequestGSB::evaluate(
84028402
},
84038403
MakeAbstractConformanceForGenericType(),
84048404
SubstFlags::AllowLoweredTypes);
8405-
resugaredRequirements.push_back(*resugaredReq);
8405+
resugaredRequirements.push_back(resugaredReq);
84068406
}
84078407

84088408
return GenericSignatureWithError(

lib/AST/ProtocolConformance.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@ void SpecializedProtocolConformance::computeConditionalRequirements() const {
992992

993993
SmallVector<Requirement, 4> newReqs;
994994
for (auto oldReq : *parentCondReqs) {
995-
if (auto newReq = oldReq.subst(QuerySubstitutionMap{subMap},
996-
LookUpConformanceInModule(module)))
997-
newReqs.push_back(*newReq);
995+
auto newReq = oldReq.subst(QuerySubstitutionMap{subMap},
996+
LookUpConformanceInModule(module));
997+
newReqs.push_back(newReq);
998998
}
999999
auto &ctxt = getProtocol()->getASTContext();
10001000
ConditionalRequirements = ctxt.AllocateCopy(newReqs);
@@ -1201,7 +1201,7 @@ ProtocolConformance::subst(TypeSubstitutionFn subs,
12011201

12021202
SmallVector<Requirement, 2> requirements;
12031203
for (auto req : getConditionalRequirements()) {
1204-
requirements.push_back(*req.subst(subs, conformances, options));
1204+
requirements.push_back(req.subst(subs, conformances, options));
12051205
}
12061206

12071207
auto kind = cast<BuiltinProtocolConformance>(this)

lib/AST/RequirementEnvironment.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ RequirementEnvironment::RequirementEnvironment(
181181

182182
if (conformanceSig) {
183183
for (auto &rawReq : conformanceSig.getRequirements()) {
184-
if (auto req = rawReq.subst(conformanceToSyntheticTypeFn,
185-
conformanceToSyntheticConformanceFn))
186-
requirements.push_back(*req);
184+
auto req = rawReq.subst(conformanceToSyntheticTypeFn,
185+
conformanceToSyntheticConformanceFn);
186+
requirements.push_back(req);
187187
}
188188
}
189189

@@ -207,8 +207,8 @@ RequirementEnvironment::RequirementEnvironment(
207207
// Next, add each of the requirements (mapped from the requirement's
208208
// interface types into the abstract type parameters).
209209
for (auto &rawReq : reqSig.getRequirements()) {
210-
if (auto req = rawReq.subst(reqToSyntheticEnvMap))
211-
requirements.push_back(*req);
210+
auto req = rawReq.subst(reqToSyntheticEnvMap);
211+
requirements.push_back(req);
212212
}
213213

214214
// Produce the generic signature and environment.

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ struct InferRequirementsWalker : public TypeWalker {
465465
auto decl = typeAlias->getDecl();
466466
auto subMap = typeAlias->getSubstitutionMap();
467467
for (const auto &rawReq : decl->getGenericSignature().getRequirements()) {
468-
if (auto req = rawReq.subst(subMap))
469-
desugarRequirement(*req, SourceLoc(), reqs, errors);
468+
desugarRequirement(rawReq.subst(subMap), SourceLoc(), reqs, errors);
470469
}
471470

472471
return Action::Continue;
@@ -532,8 +531,8 @@ struct InferRequirementsWalker : public TypeWalker {
532531
// Handle the requirements.
533532
// FIXME: Inaccurate TypeReprs.
534533
for (const auto &rawReq : genericSig.getRequirements()) {
535-
if (auto req = rawReq.subst(subMap))
536-
desugarRequirement(*req, SourceLoc(), reqs, errors);
534+
auto req = rawReq.subst(subMap);
535+
desugarRequirement(req, SourceLoc(), reqs, errors);
537536
}
538537

539538
return Action::Continue;

0 commit comments

Comments
 (0)