[Typed throws] IR generation and runtime support for function type metadata

Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
This commit is contained in:
Doug Gregor
2023-10-29 07:33:04 -07:00
parent e82854d860
commit 40e07cf900
18 changed files with 369 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-stdlib %s -module-name main -o %t/a.out
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-stdlib -enable-experimental-feature TypedThrows %s -module-name main -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test
@@ -522,5 +522,18 @@ if #available(SwiftStdlib 5.1, *) {
}
}
enum MyBigError: Error {
case epicFail
}
if #available(SwiftStdlib 5.11, *) {
DemangleToMetadataTests.test("typed throws") {
typealias Fn = (Int) throws(MyBigError) -> Void
expectEqual("ySi4main10MyBigErrorOYKc", _mangledTypeName(Fn.self)!)
print("Looking up the typed throws... \(_typeByName("ySi4main10MyBigErrorOYKc"))")
expectEqual(Fn.self, _typeByName("ySi4main10MyBigErrorOYKc")!)
}
}
runAllTests()