mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Implement typed throws support in _openExistential.
This commit is contained in:
@@ -3145,11 +3145,14 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
|
||||
auto result = CS.createTypeVariable(
|
||||
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
|
||||
TVO_CanBindToNoEscape);
|
||||
auto thrownError = CS.createTypeVariable(
|
||||
CS.getConstraintLocator(locator, ConstraintLocator::ThrownErrorType),
|
||||
0);
|
||||
FunctionType::Param bodyArgs[] = {FunctionType::Param(openedTy)};
|
||||
auto bodyClosure = FunctionType::get(bodyArgs, result,
|
||||
FunctionType::ExtInfoBuilder()
|
||||
.withNoEscape(true)
|
||||
.withThrows(true, /*FIXME:*/Type())
|
||||
.withThrows(true, thrownError)
|
||||
.withAsync(true)
|
||||
.build());
|
||||
FunctionType::Param args[] = {
|
||||
@@ -3159,7 +3162,7 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
|
||||
auto refType = FunctionType::get(args, result,
|
||||
FunctionType::ExtInfoBuilder()
|
||||
.withNoEscape(false)
|
||||
.withThrows(true, /*FIXME:*/Type())
|
||||
.withThrows(true, thrownError)
|
||||
.withAsync(true)
|
||||
.build());
|
||||
return {refType, refType, refType, refType, Type()};
|
||||
|
||||
@@ -1053,12 +1053,28 @@ func __abi_withoutActuallyEscaping<ClosureType, ResultType>(
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@_semantics("typechecker._openExistential(_:do:)")
|
||||
public func _openExistential<ExistentialType, ContainedType, ResultType>(
|
||||
public func _openExistential<ExistentialType, ContainedType, ResultType, Failure>(
|
||||
_ existential: ExistentialType,
|
||||
do body: (_ escapingClosure: ContainedType) throws(Failure) -> ResultType
|
||||
) throws(Failure) -> ResultType {
|
||||
// This implementation is never used, since calls to
|
||||
// `Swift._openExistential(_:do:)` are resolved as a special case by
|
||||
// the type checker.
|
||||
Builtin.staticReport(_trueAfterDiagnostics(), true._value,
|
||||
("internal consistency error: '_openExistential(_:do:)' operation failed to resolve"
|
||||
as StaticString).utf8Start._rawValue)
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
@_silgen_name("$ss16_openExistential_2doq0_x_q0_q_KXEtKr1_lF")
|
||||
func __abi_openExistential<ExistentialType, ContainedType, ResultType>(
|
||||
_ existential: ExistentialType,
|
||||
do body: (_ escapingClosure: ContainedType) throws -> ResultType
|
||||
) rethrows -> ResultType {
|
||||
) throws -> ResultType {
|
||||
// This implementation is never used, since calls to
|
||||
// `Swift._openExistential(_:do:)` are resolved as a special case by
|
||||
// the type checker.
|
||||
|
||||
@@ -11,3 +11,13 @@ func open(existential: P, mutExistential: inout P) {
|
||||
_openExistential(mutExistential, do: foo)
|
||||
_openExistential(type(of: mutExistential), do: bar)
|
||||
}
|
||||
|
||||
enum HomeworkError: Error {
|
||||
case dogAteIt
|
||||
}
|
||||
|
||||
func fooThrowing<T: P>(_: T) throws(HomeworkError) {}
|
||||
|
||||
func openMaybeThrow(existential: P) throws(HomeworkError) {
|
||||
try _openExistential(existential, do: fooThrowing)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,9 @@ Func Result.get() has mangled name changing from 'Swift.Result.get() throws -> A
|
||||
Func withoutActuallyEscaping(_:do:) has been renamed to Func __abi_withoutActuallyEscaping(_:do:)
|
||||
Func withoutActuallyEscaping(_:do:) has mangled name changing from 'Swift.withoutActuallyEscaping<A, B>(_: A, do: (A) throws -> B) throws -> B' to 'Swift.__abi_withoutActuallyEscaping<A, B>(_: A, do: (A) throws -> B) throws -> B'
|
||||
Func withoutActuallyEscaping(_:do:) is now without @rethrows
|
||||
|
||||
Func _openExistential(_:do:) has been renamed to Func __abi_openExistential(_:do:)
|
||||
Func _openExistential(_:do:) has mangled name changing from 'Swift._openExistential<A, B, C>(_: A, do: (B) throws -> C) throws -> C' to 'Swift.__abi_openExistential<A, B, C>(_: A, do: (B) throws -> C) throws -> C'
|
||||
Func _openExistential(_:do:) is now without @rethrows
|
||||
|
||||
// These haven't actually been removed; they are simply marked unavailable.
|
||||
// This seems to be a false positive in the ABI checker. This is not an ABI
|
||||
|
||||
Reference in New Issue
Block a user