Skip to content

Commit 1859533

Browse files
committed
AST: Remove substGenericFunctionType()
1 parent fef485b commit 1859533

File tree

1 file changed

+2
-72
lines changed

1 file changed

+2
-72
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -152,73 +152,6 @@ operator()(CanType dependentType, Type conformingReplacementType,
152152
conformingReplacementType, conformedProtocol);
153153
}
154154

155-
static Type substGenericFunctionType(GenericFunctionType *genericFnType,
156-
InFlightSubstitution &IFS) {
157-
// Substitute into the function type (without generic signature).
158-
auto *bareFnType = FunctionType::get(genericFnType->getParams(),
159-
genericFnType->getResult(),
160-
genericFnType->getExtInfo());
161-
Type result = Type(bareFnType).subst(IFS);
162-
if (!result || result->is<ErrorType>()) return result;
163-
164-
auto *fnType = result->castTo<FunctionType>();
165-
// Substitute generic parameters.
166-
bool anySemanticChanges = false;
167-
SmallVector<GenericTypeParamType *, 2> genericParams;
168-
for (auto param : genericFnType->getGenericParams()) {
169-
Type paramTy = Type(param).subst(IFS);
170-
if (!paramTy)
171-
return Type();
172-
173-
if (auto newParam = paramTy->getAs<GenericTypeParamType>()) {
174-
if (!newParam->isEqual(param))
175-
anySemanticChanges = true;
176-
177-
genericParams.push_back(newParam);
178-
} else {
179-
anySemanticChanges = true;
180-
}
181-
}
182-
183-
// If no generic parameters remain, this is a non-generic function type.
184-
if (genericParams.empty())
185-
return result;
186-
187-
// Transform requirements.
188-
SmallVector<Requirement, 2> requirements;
189-
for (const auto &req : genericFnType->getRequirements()) {
190-
// Substitute into the requirement.
191-
auto substReqt = req.subst(IFS);
192-
193-
// Did anything change?
194-
if (!anySemanticChanges &&
195-
(!req.getFirstType()->isEqual(substReqt.getFirstType()) ||
196-
(req.getKind() != RequirementKind::Layout &&
197-
!req.getSecondType()->isEqual(substReqt.getSecondType())))) {
198-
anySemanticChanges = true;
199-
}
200-
201-
requirements.push_back(substReqt);
202-
}
203-
204-
GenericSignature genericSig;
205-
if (anySemanticChanges) {
206-
// If there were semantic changes, we need to build a new generic
207-
// signature.
208-
ASTContext &ctx = genericFnType->getASTContext();
209-
genericSig = buildGenericSignature(ctx, GenericSignature(),
210-
genericParams, requirements,
211-
/*allowInverses=*/false);
212-
} else {
213-
// Use the mapped generic signature.
214-
genericSig = GenericSignature::get(genericParams, requirements);
215-
}
216-
217-
// Produce the new generic function type.
218-
return GenericFunctionType::get(genericSig, fnType->getParams(),
219-
fnType->getResult(), fnType->getExtInfo());
220-
}
221-
222155
InFlightSubstitution::InFlightSubstitution(TypeSubstitutionFn substType,
223156
LookupConformanceFn lookupConformance,
224157
SubstOptions options)
@@ -540,11 +473,8 @@ Type Type::subst(TypeSubstitutionFn substitutions,
540473
}
541474

542475
Type Type::subst(InFlightSubstitution &IFS) const {
543-
// Handle substitutions into generic function types.
544-
// FIXME: This should be banned.
545-
if (auto genericFnType = getPointer()->getAs<GenericFunctionType>()) {
546-
return substGenericFunctionType(genericFnType, IFS);
547-
}
476+
ASSERT(!getPointer()->getAs<GenericFunctionType>() &&
477+
"Perhaps you want GenericFunctionType::substGenericArgs() instead");
548478

549479
if (IFS.isInvariant(*this))
550480
return *this;

0 commit comments

Comments
 (0)