Skip to content

Commit 0cc0df9

Browse files
authored
Merge pull request #69474 from slavapestov/typed-throws-wip-2
A couple more typed throws fixes
2 parents 8e2c95a + d430d12 commit 0cc0df9

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

include/swift/AST/TypeMatcher.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,10 @@ class TypeMatcher {
397397
return false;
398398
}
399399

400-
// If requested, compare the thrown error types.
400+
// Compare the thrown error types.
401401
Type thrownError1 = firstFunc->getEffectiveThrownErrorTypeOrNever();
402402
Type thrownError2 = secondFunc->getEffectiveThrownErrorTypeOrNever();
403-
if (Matcher.asDerived().considerThrownErrorTypes(thrownError1,
404-
thrownError2) &&
405-
!this->visit(thrownError1->getCanonicalType(),
403+
if (!this->visit(thrownError1->getCanonicalType(),
406404
thrownError2, thrownError1))
407405
return false;
408406

@@ -567,10 +565,6 @@ class TypeMatcher {
567565
return MatchVisitor(*this).visit(first->getCanonicalType(), second,
568566
first);
569567
}
570-
571-
bool considerThrownErrorTypes(Type errorType1, Type errorType2) const {
572-
return false;
573-
}
574568
};
575569

576570
} // end namespace swift

lib/AST/RequirementMachine/TypeDifference.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ swift::rewriting::buildTypeDifference(
348348
auto resultSymbol = [&]() {
349349
switch (symbol.getKind()) {
350350
case Symbol::Kind::Superclass:
351-
return Symbol::forSuperclass(CanType(resultType),
351+
return Symbol::forSuperclass(resultType->getCanonicalType(),
352352
resultSubstitutions, ctx);
353353
case Symbol::Kind::ConcreteType:
354-
return Symbol::forConcreteType(CanType(resultType),
354+
return Symbol::forConcreteType(resultType->getCanonicalType(),
355355
resultSubstitutions, ctx);
356356
case Symbol::Kind::ConcreteConformance:
357-
return Symbol::forConcreteConformance(CanType(resultType),
357+
return Symbol::forConcreteConformance(resultType->getCanonicalType(),
358358
resultSubstitutions,
359359
symbol.getProtocol(),
360360
ctx);

lib/SIL/IR/AbstractionPattern.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -2044,15 +2044,21 @@ AbstractionPattern::getParameterConvention(TypeConverter &TC) const {
20442044

20452045
AbstractionPattern::CallingConventionKind
20462046
AbstractionPattern::getErrorConvention(TypeConverter &TC) const {
2047-
// Tuples should be destructured.
2048-
if (isTuple()) {
2049-
return Destructured;
2050-
}
20512047
switch (getKind()) {
20522048
case Kind::Opaque:
20532049
// Maximally abstracted values are always thrown indirectly.
20542050
return Indirect;
20552051

2052+
case Kind::ClangType:
2053+
case Kind::Type:
2054+
case Kind::Discard:
2055+
// Pass according to the formal type.
2056+
return SILType::isFormallyThrownIndirectly(getType(),
2057+
TC,
2058+
getGenericSignatureOrNull())
2059+
? Indirect : Direct;
2060+
2061+
case Kind::Tuple:
20562062
case Kind::OpaqueFunction:
20572063
case Kind::OpaqueDerivativeFunction:
20582064
case Kind::PartialCurriedObjCMethodType:
@@ -2064,20 +2070,7 @@ AbstractionPattern::getErrorConvention(TypeConverter &TC) const {
20642070
case Kind::CXXMethodType:
20652071
case Kind::CurriedCXXMethodType:
20662072
case Kind::PartialCurriedCXXMethodType:
2067-
// Function types are always thrown directly
2068-
return Direct;
2069-
2070-
case Kind::ClangType:
2071-
case Kind::Type:
2072-
case Kind::Discard:
2073-
// Pass according to the formal type.
2074-
return SILType::isFormallyThrownIndirectly(getType(),
2075-
TC,
2076-
getGenericSignatureOrNull())
2077-
? Indirect : Direct;
2078-
20792073
case Kind::Invalid:
2080-
case Kind::Tuple:
20812074
case Kind::ObjCCompletionHandlerArgumentsType:
20822075
llvm_unreachable("should not get here");
20832076
}

lib/Sema/TypeCheckProtocolInference.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,6 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitness(ValueDecl *req,
752752
TypeBase *secondType, Type sugaredFirstType) {
753753
return true;
754754
}
755-
756-
bool considerThrownErrorTypes(Type errorType1, Type errorType2) const {
757-
return errorType1->hasTypeParameter();
758-
}
759755
};
760756

761757
// Match a requirement and witness type.

test/Generics/typed_throws.swift

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -enable-experimental-feature TypedThrows 2>&1 | %FileCheck %s
2+
3+
protocol P1 {
4+
associatedtype A
5+
}
6+
7+
// CHECK-LABEL: typed_throws.(file).f1@
8+
// CHECK-NEXT: Generic signature: <T where T : P1, T.[P1]A == Never>
9+
func f1<T: P1>(_: T) where () throws(T.A) -> () == () -> () {}
10+
11+
// CHECK-LABEL: typed_throws.(file).f2@
12+
// CHECK-NEXT: Generic signature: <T where T : P1, T.[P1]A == any Error>
13+
func f2<T: P1>(_: T) where () throws(T.A) -> () == () throws -> () {}
14+
15+
protocol P2 {
16+
associatedtype A where A == () throws(E) -> ()
17+
associatedtype E
18+
}
19+
20+
// CHECK-LABEL: typed_throws.(file).f3@
21+
// CHECK-NEXT: Generic signature: <T where T : P2, T.[P2]E == Never>
22+
func f3<T: P2>(_: T) where T.A == () -> () {}
23+
24+
// CHECK-LABEL: typed_throws.(file).f4@
25+
// CHECK-NEXT: Generic signature: <T where T : P2, T.[P2]E == any Error>
26+
func f4<T: P2>(_: T) where T.A == () throws -> () {}

0 commit comments

Comments
 (0)