Skip to content

Commit f5fe7c1

Browse files
committed
Add an API to map substitution map into a type expansion context.
1 parent d9a575c commit f5fe7c1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/GenericSignature.h"
2121
#include "swift/AST/ProtocolConformanceRef.h"
2222
#include "swift/AST/Type.h"
23+
#include "swift/AST/TypeExpansionContext.h"
2324
#include "swift/Basic/Debug.h"
2425
#include "llvm/ADT/ArrayRef.h"
2526
#include "llvm/ADT/DenseMapInfo.h"
@@ -176,7 +177,13 @@ class SubstitutionMap {
176177
SubstitutionMap subst(TypeSubstitutionFn subs,
177178
LookupConformanceFn conformances,
178179
SubstOptions options=None) const;
179-
180+
181+
/// Apply type expansion lowering to all types in the substitution map. Opaque
182+
/// archetypes will be lowered to their underlying types if the type expansion
183+
/// context allows.
184+
SubstitutionMap mapIntoTypeExpansionContext(
185+
TypeExpansionContext context) const;
186+
180187
/// Create a substitution map for a protocol conformance.
181188
static SubstitutionMap
182189
getProtocolSubstitutions(ProtocolDecl *protocol,

lib/AST/SubstitutionMap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,11 @@ bool SubstitutionMap::isIdentity() const {
715715

716716
return !hasNonIdentityReplacement;
717717
}
718+
719+
SubstitutionMap SubstitutionMap::mapIntoTypeExpansionContext(
720+
TypeExpansionContext context) const {
721+
ReplaceOpaqueTypesWithUnderlyingTypes replacer(
722+
context.getContext(), context.getResilienceExpansion(),
723+
context.isWholeModuleContext());
724+
return this->subst(replacer, replacer, SubstFlags::SubstituteOpaqueArchetypes);
725+
}

0 commit comments

Comments
 (0)