Swift: Extract whether a function type is throwing or async.

This commit is contained in:
Mathias Vorreiter Pedersen
2022-05-27 11:48:01 +01:00
parent 55513e0dbb
commit 45bbd24355
6 changed files with 25 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ AnyFunctionType:
param_types: Type* param_types: Type*
param_labels: string* param_labels: string*
is_throwing: predicate is_throwing: predicate
is_async: predicate
AnyGenericType: AnyGenericType:
_extends: Type _extends: Type

View File

@@ -211,6 +211,14 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
} }
++i; ++i;
} }
if (type->isThrowing()) {
dispatcher_.emit(AnyFunctionTypeIsThrowingTrap{label});
}
if (type->isAsync()) {
dispatcher_.emit(AnyFunctionTypeIsAsyncTrap{label});
}
} }
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label) { void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label) {

View File

@@ -27,4 +27,6 @@ class AnyFunctionTypeBase extends @any_function_type, Type {
int getNumberOfParamLabels() { result = count(getAParamLabel()) } int getNumberOfParamLabels() { result = count(getAParamLabel()) }
predicate isThrowing() { any_function_type_is_throwing(this) } predicate isThrowing() { any_function_type_is_throwing(this) }
predicate isAsync() { any_function_type_is_async(this) }
} }

View File

@@ -176,6 +176,11 @@ any_function_type_is_throwing(
int id: @any_function_type ref int id: @any_function_type ref
); );
#keyset[id]
any_function_type_is_async(
int id: @any_function_type ref
);
@any_generic_type = @any_generic_type =
@nominal_or_bound_generic_nominal_type @nominal_or_bound_generic_nominal_type
| @unbound_generic_type | @unbound_generic_type

View File

@@ -38,3 +38,4 @@
| types.swift:21:10:21:10 | f | (Int) -> Int | | types.swift:21:10:21:10 | f | (Int) -> Int |
| types.swift:21:10:21:13 | call to ... | Int | | types.swift:21:10:21:13 | call to ... | Int |
| types.swift:21:12:21:12 | x | Int | | types.swift:21:12:21:12 | x | Int |
| types.swift:25:10:25:10 | 42 | Int |

View File

@@ -20,3 +20,11 @@ func f(x: Int, y: Int) -> Int {
func g(_ f: (Int) -> Int, _ x: Int) -> Int { func g(_ f: (Int) -> Int, _ x: Int) -> Int {
return f(x) return f(x)
} }
func throwingFunc() throws -> Int {
return 42
}
func asyncFunction(x: Int) async { }
func throwingAndAsyncFunction(x: Int) async throws { }