Skip to content

Commit 34a5e75

Browse files
authored
Merge pull request #8497 from slavapestov/subst-fixes
Fixing some questionable uses of Type::subst()
2 parents cc611de + 9319a53 commit 34a5e75

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ static Type substType(Type derivedType,
30493049
if (isa<GenericTypeParamType>(substOrig)) {
30503050
if (options.contains(SubstFlags::UseErrorType))
30513051
return ErrorType::get(type);
3052-
return Type(type);
3052+
return Type();
30533053
}
30543054

30553055
auto archetype = cast<ArchetypeType>(substOrig);
@@ -3065,7 +3065,7 @@ static Type substType(Type derivedType,
30653065
if (!parent) {
30663066
if (options.contains(SubstFlags::UseErrorType))
30673067
return ErrorType::get(type);
3068-
return Type(type);
3068+
return Type();
30693069
}
30703070

30713071
// Substitute into the parent type.

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ Serializer::writeConformance(ProtocolConformanceRef conformanceRef,
13941394
auto substitutions = conf->getGenericSubstitutions();
13951395
unsigned abbrCode = abbrCodes[SpecializedProtocolConformanceLayout::Code];
13961396
auto type = conf->getType();
1397-
if (genericEnv)
1397+
if (genericEnv && type->hasArchetype())
13981398
type = genericEnv->mapTypeOutOfContext(type);
13991399
SpecializedProtocolConformanceLayout::emitRecord(Out, ScratchRecord,
14001400
abbrCode,
@@ -1412,7 +1412,7 @@ Serializer::writeConformance(ProtocolConformanceRef conformanceRef,
14121412
= abbrCodes[InheritedProtocolConformanceLayout::Code];
14131413

14141414
auto type = conf->getType();
1415-
if (genericEnv)
1415+
if (genericEnv && type->hasArchetype())
14161416
type = genericEnv->mapTypeOutOfContext(type);
14171417

14181418
InheritedProtocolConformanceLayout::emitRecord(
@@ -1451,7 +1451,7 @@ Serializer::writeSubstitutions(SubstitutionList substitutions,
14511451

14521452
for (auto &sub : substitutions) {
14531453
auto replacementType = sub.getReplacement();
1454-
if (genericEnv) {
1454+
if (genericEnv && replacementType->hasArchetype()) {
14551455
replacementType =
14561456
genericEnv->mapTypeOutOfContext(replacementType);
14571457
}

validation-test/compiler_crashers/28732-type-hasarchetype-not-fully-substituted.swift renamed to validation-test/compiler_crashers_fixed/28732-type-hasarchetype-not-fully-substituted.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
{
1111
protocol A{
1212
struct A:P{

0 commit comments

Comments
 (0)