Skip to content

Commit 4b25b67

Browse files
committed
Factor a transform visitor out of IsBindableVisitor.
For substituted function type lowering, we want to take every structural position where a concrete type matches the original generic type in an interface, and replace it with an independent generic parameter. The first bit, matching up structural positions to generic parameters, is more or less what `Type::isBindableTo` already does, so we can adapt its visitor to take a callback that optionally substitutes into the type being walked based on the generic argument and binding in the given pair of types.
1 parent 22ed240 commit 4b25b67

File tree

2 files changed

+306
-187
lines changed

2 files changed

+306
-187
lines changed

include/swift/AST/Types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,19 @@ class alignas(1 << TypeAlignInBits) TypeBase {
872872
/// True if this type contains archetypes that could be substituted with
873873
/// concrete types to form the argument type.
874874
bool isBindableTo(Type ty);
875+
876+
/// Visit this type and the argument type in parallel, invoking the callback
877+
/// function with each archetype-to-substituted-type binding. The callback
878+
/// may return a new type to substitute into the result type, or return
879+
/// CanType() to error out of the operation.
880+
///
881+
/// Returns the substituted type, or a null CanType() if this type
882+
/// is not bindable to the substituted type, or the callback returns
883+
/// CanType().
884+
CanType substituteBindingsTo(Type ty,
885+
llvm::function_ref<CanType(ArchetypeType*, CanType)> substFn);
875886

887+
876888
/// Determines whether this type is similar to \p other as defined by
877889
/// \p matchOptions.
878890
bool matches(Type other, TypeMatchOptions matchOptions);
@@ -4274,6 +4286,10 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
42744286
SILType substInterfaceType(SILModule &M,
42754287
SILType interfaceType) const;
42764288

4289+
/// Return the unsubstituted function type equivalent to this type; that is, the type that has the same
4290+
/// argument and result types as `this` type after substitutions, if any.
4291+
CanSILFunctionType getUnsubstitutedType(SILModule &M) const;
4292+
42774293
void Profile(llvm::FoldingSetNodeID &ID) {
42784294
Profile(ID, getSubstGenericSignature(), getExtInfo(), getCoroutineKind(),
42794295
getCalleeConvention(), getParameters(), getYields(), getResults(),

0 commit comments

Comments
 (0)