mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema/CS] Convenience function for adding a Requirement as a constraint.
This commit is contained in:
@@ -1044,55 +1044,33 @@ void ConstraintSystem::openGeneric(
|
||||
|
||||
// Add the requirements as constraints.
|
||||
for (auto req : sig->getRequirements()) {
|
||||
switch (req.getKind()) {
|
||||
Optional<Requirement> openedReq;
|
||||
auto openedFirst = openType(req.getFirstType(), replacements);
|
||||
|
||||
auto kind = req.getKind();
|
||||
switch (kind) {
|
||||
case RequirementKind::Conformance: {
|
||||
auto subjectTy = openType(req.getFirstType(), replacements);
|
||||
auto proto = req.getSecondType()->castTo<ProtocolType>();
|
||||
auto protoDecl = proto->getDecl();
|
||||
|
||||
// Determine whether this is the protocol 'Self' constraint we should
|
||||
// skip.
|
||||
if (skipProtocolSelfConstraint &&
|
||||
protoDecl == outerDC &&
|
||||
protoDecl->getSelfInterfaceType()->isEqual(req.getFirstType()))
|
||||
break;
|
||||
|
||||
addConstraint(ConstraintKind::ConformsTo, subjectTy, proto,
|
||||
locatorPtr);
|
||||
continue;
|
||||
openedReq = Requirement(kind, openedFirst, proto);
|
||||
break;
|
||||
}
|
||||
|
||||
case RequirementKind::Layout: {
|
||||
auto subjectTy = openType(req.getFirstType(), replacements);
|
||||
auto layoutConstraint = req.getLayoutConstraint();
|
||||
|
||||
if (layoutConstraint->isClass())
|
||||
addConstraint(ConstraintKind::ConformsTo, subjectTy,
|
||||
TC.Context.getAnyObjectType(),
|
||||
locatorPtr);
|
||||
|
||||
// Nothing else can appear outside of @_specialize yet, and Sema
|
||||
// doesn't know how to check.
|
||||
case RequirementKind::Superclass:
|
||||
case RequirementKind::SameType:
|
||||
openedReq = Requirement(kind, openedFirst,
|
||||
openType(req.getSecondType(), replacements));
|
||||
break;
|
||||
case RequirementKind::Layout:
|
||||
openedReq = Requirement(kind, openedFirst, req.getLayoutConstraint());
|
||||
break;
|
||||
}
|
||||
|
||||
case RequirementKind::Superclass: {
|
||||
auto subjectTy = openType(req.getFirstType(), replacements);
|
||||
auto boundTy = openType(req.getSecondType(), replacements);
|
||||
addConstraint(ConstraintKind::Subtype, subjectTy, boundTy, locatorPtr);
|
||||
addConstraint(ConstraintKind::ConformsTo, subjectTy,
|
||||
TC.Context.getAnyObjectType(),
|
||||
locatorPtr);
|
||||
break;
|
||||
}
|
||||
|
||||
case RequirementKind::SameType: {
|
||||
auto firstTy = openType(req.getFirstType(), replacements);
|
||||
auto secondTy = openType(req.getSecondType(), replacements);
|
||||
addConstraint(ConstraintKind::Bind, firstTy, secondTy, locatorPtr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
addConstraint(*openedReq, locatorPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user