Skip to content

Commit f0899e3

Browse files
committed
RequirementMachine: Make some entry points in RequirementLowering.cpp public
1 parent 28c1178 commit f0899e3

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,24 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
210210
result.push_back({req, loc, wasInferred});
211211
}
212212

213-
static void inferRequirements(Type type, SourceLoc loc,
214-
SmallVectorImpl<StructuralRequirement> &result) {
213+
/// Infer requirements from applications of BoundGenericTypes to type
214+
/// parameters. For example, given a function declaration
215+
///
216+
/// func union<T>(_ x: Set<T>, _ y: Set<T>)
217+
///
218+
/// We automatically infer 'T : Hashable' from the fact that 'struct Set'
219+
/// declares a Hashable requirement on its generic parameter.
220+
void swift::rewriting::inferRequirements(
221+
Type type, SourceLoc loc,
222+
SmallVectorImpl<StructuralRequirement> &result) {
215223
// FIXME: Implement
216224
}
217225

218-
static void realizeRequirement(Requirement req, RequirementRepr *reqRepr, bool infer,
219-
SmallVectorImpl<StructuralRequirement> &result) {
226+
/// Desugar a requirement and perform requirement inference if requested
227+
/// to obtain zero or more structural requirements.
228+
void swift::rewriting::realizeRequirement(
229+
Requirement req, RequirementRepr *reqRepr, bool infer,
230+
SmallVectorImpl<StructuralRequirement> &result) {
220231
auto firstType = req.getFirstType();
221232
if (infer) {
222233
auto firstLoc = (reqRepr ? reqRepr->getFirstTypeRepr()->getStartLoc()
@@ -269,8 +280,11 @@ static void realizeRequirement(Requirement req, RequirementRepr *reqRepr, bool i
269280
}
270281
}
271282

272-
static void realizeInheritedRequirements(TypeDecl *decl, Type type, bool infer,
273-
SmallVectorImpl<StructuralRequirement> &result) {
283+
/// Collect structural requirements written in the inheritance clause of an
284+
/// AssociatedTypeDecl or GenericTypeParamDecl.
285+
void swift::rewriting::realizeInheritedRequirements(
286+
TypeDecl *decl, Type type, bool infer,
287+
SmallVectorImpl<StructuralRequirement> &result) {
274288
auto &ctx = decl->getASTContext();
275289
auto inheritedTypes = decl->getInherited();
276290

lib/AST/RequirementMachine/RequirementLowering.h

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

3535
namespace rewriting {
3636

37-
void
38-
desugarRequirement(Requirement req, SmallVectorImpl<Requirement> &result);
37+
// Entry points used by AbstractGenericSignatureRequest and
38+
// InferredGenericSignatureRequest; see RequiremetnLowering.cpp for
39+
// documentation
40+
// comments.
41+
42+
void desugarRequirement(Requirement req, SmallVectorImpl<Requirement> &result);
43+
44+
void inferRequirements(Type type, SourceLoc loc,
45+
SmallVectorImpl<StructuralRequirement> &result);
46+
47+
void realizeRequirement(Requirement req, RequirementRepr *reqRepr, bool infer,
48+
SmallVectorImpl<StructuralRequirement> &result);
49+
50+
void realizeInheritedRequirements(TypeDecl *decl, Type type, bool infer,
51+
SmallVectorImpl<StructuralRequirement> &result);
3952

4053
/// A utility class for bulding rewrite rules from the top-level requirements
4154
/// of a generic signature.

0 commit comments

Comments
 (0)