-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunctionTypes.swift
More file actions
84 lines (67 loc) · 2.62 KB
/
FunctionTypes.swift
File metadata and controls
84 lines (67 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public struct FunctionType<System: TypeSystem> {
/// The calling convention used for a function.
public enum Convention {
/// The normal Swift calling convention.
///
/// This is the default calling convention for Swift functions, which is
/// able to handle all Swift types and capture state.
case swift
/// The C calling convention, which can only use types expressible in
/// (Objective-)C and cannot capture any state.
case c
/// The block calling convention, supporting the C "blocks" extension.
///
/// These functions can only use types expressible in (Objective-)C, and
/// can capture state.
case block
/// The normal Swift calling convention but without a context pointer.
///
/// Thin functions can handle all Swift types, but are represented as a
/// single function pointer and cannot capture state.
case thin
}
/// Attributes provided for a function.
public struct Attributes {
/// Whether this function is asynchronous.
public var `async`: Bool
/// Whether this function can throw.
public var `throws`: Bool
/// Whether this function is escaping.
public var `escaping`: Bool
/// Whether this function is `@Sendable`.
public var `sendable`: Bool
/// The calling convention for the function.
public var convention: Convention = .swift
/// The global actor, such as `@MainActor`, on which this function runs.
public var globalActor: System.Type?
}
/// The convention used to pass a parameter.
public enum ParameterConvention {
/// An `inout` parameter, which is passed indirectly and can be modified
/// by the callee.
case `inout`
/// A borrowing parameter, which the callee cannot mutate.
case borrowing
/// A consuming parameter, which the callee can locally mutate and is
/// responsible for destroying.
case consuming
}
/// A parameter within a function type.
public struct Parameter {
/// The argument label used when calling the function.
///
/// Note: this is in the language grammar, but must either be omitted or
/// be `_`. We might not want to model this at all.
public var argumentName: Identifier?
/// The parameter name.
///
/// Note: this is in the language grammar, but has no effect on anything.
/// We might not want to model this at all.
public var parameterName: Identifier?
/// The parameter-passing convention, if specified.
public var convention: ParameterConvention?
/// Whether the parameter is variadic, i.e., `indices: Int...`.
public var variadic: Bool
// TODO: There are more bits here
}
}