Skip to content

Commit e36b8ea

Browse files
Merge pull request #4780 from swiftwasm/main
[pull] swiftwasm from main
2 parents 51ecdf2 + 8366183 commit e36b8ea

37 files changed

+622
-145
lines changed

.dir-locals.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(add-to-list 'load-path
1212
(concat this-directory "utils")
1313
:append)
14+
(defvar swift-project-directory)
1415
(let ((swift-project-directory this-directory))
1516
(require 'swift-project-settings)))
1617
(set (make-local-variable 'swift-project-directory)

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:

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,10 @@ class Solution {
15451545
/// Retrieve the fixed score of this solution
15461546
Score &getFixedScore() { return FixedScore; }
15471547

1548+
/// Check whether this solution has a fixed binding for the given type
1549+
/// variable.
1550+
bool hasFixedType(TypeVariableType *typeVar) const;
1551+
15481552
/// Retrieve the fixed type for the given type variable.
15491553
Type getFixedType(TypeVariableType *typeVar) const;
15501554

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,10 +5307,9 @@ ASTContext::getOverrideGenericSignature(const NominalTypeDecl *baseNominal,
53075307
baseGenericSig, derivedParams);
53085308

53095309
for (auto reqt : baseGenericSig.getRequirements()) {
5310-
if (auto substReqt = reqt.subst(QueryOverrideSubs(info),
5311-
LookUpConformanceInOverrideSubs(info))) {
5312-
addedRequirements.push_back(*substReqt);
5313-
}
5310+
auto substReqt = reqt.subst(QueryOverrideSubs(info),
5311+
LookUpConformanceInOverrideSubs(info));
5312+
addedRequirements.push_back(substReqt);
53145313
}
53155314

53165315
auto genericSig = buildGenericSignature(*this, derivedNominalSig,

lib/AST/ExistentialGeneralization.cpp

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

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

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

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/ProtocolConformance.cpp

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

963963
SmallVector<Requirement, 4> newReqs;
964964
for (auto oldReq : *parentCondReqs) {
965-
if (auto newReq = oldReq.subst(QuerySubstitutionMap{subMap},
966-
LookUpConformanceInModule(module)))
967-
newReqs.push_back(*newReq);
965+
auto newReq = oldReq.subst(QuerySubstitutionMap{subMap},
966+
LookUpConformanceInModule(module));
967+
newReqs.push_back(newReq);
968968
}
969969
auto &ctxt = getProtocol()->getASTContext();
970970
ConditionalRequirements = ctxt.AllocateCopy(newReqs);
@@ -1163,7 +1163,7 @@ ProtocolConformance::subst(TypeSubstitutionFn subs,
11631163

11641164
SmallVector<Requirement, 2> requirements;
11651165
for (auto req : getConditionalRequirements()) {
1166-
requirements.push_back(*req.subst(subs, conformances, options));
1166+
requirements.push_back(req.subst(subs, conformances, options));
11671167
}
11681168

11691169
auto kind = cast<BuiltinProtocolConformance>(this)

lib/AST/RequirementEnvironment.cpp

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

180180
if (conformanceSig) {
181181
for (auto &rawReq : conformanceSig.getRequirements()) {
182-
if (auto req = rawReq.subst(conformanceToWitnessThunkTypeFn,
183-
conformanceToWitnessThunkConformanceFn))
184-
requirements.push_back(*req);
182+
auto req = rawReq.subst(conformanceToWitnessThunkTypeFn,
183+
conformanceToWitnessThunkConformanceFn);
184+
requirements.push_back(req);
185185
}
186186
}
187187

@@ -205,8 +205,8 @@ RequirementEnvironment::RequirementEnvironment(
205205
// Next, add each of the requirements (mapped from the requirement's
206206
// interface types into the abstract type parameters).
207207
for (auto &rawReq : reqSig.getRequirements()) {
208-
if (auto req = rawReq.subst(reqToWitnessThunkSigMap))
209-
requirements.push_back(*req);
208+
auto req = rawReq.subst(reqToWitnessThunkSigMap);
209+
requirements.push_back(req);
210210
}
211211

212212
witnessThunkSig = buildGenericSignature(ctx, GenericSignature(),

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;

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ AbstractGenericSignatureRequest::evaluate(
596596
},
597597
MakeAbstractConformanceForGenericType(),
598598
SubstFlags::AllowLoweredTypes);
599-
resugaredRequirements.push_back(*resugaredReq);
599+
resugaredRequirements.push_back(resugaredReq);
600600
}
601601

602602
return GenericSignatureWithError(

0 commit comments

Comments
 (0)