Skip to content

Commit bf418eb

Browse files
authored
Merge pull request swiftlang#24979 from aschwaighofer/document_dynamic_function_ref
Document dynamic_function_ref and prev_dynamic_function_ref
2 parents 729a955 + 56924d4 commit bf418eb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

docs/SIL.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,73 @@ function_ref
30533053

30543054
Creates a reference to a SIL function.
30553055

3056+
dynamic_function_ref
3057+
````````````
3058+
::
3059+
3060+
sil-instruction ::= 'dynamic_function_ref' sil-function-name ':' sil-type
3061+
3062+
%1 = dynamic_function_ref @function : $@convention(thin) T -> U
3063+
// $@convention(thin) T -> U must be a thin function type
3064+
// %1 has type $T -> U
3065+
3066+
Creates a reference to a `dynamically_replacable` SIL function. A
3067+
`dynamically_replacable` SIL function can be replaced at runtime.
3068+
3069+
For the following Swift code::
3070+
3071+
dynamic func test_dynamically_replaceable() {}
3072+
3073+
func test_dynamic_call() {
3074+
test_dynamically_replaceable()
3075+
}
3076+
3077+
We will generate::
3078+
3079+
sil [dynamically_replacable] @test_dynamically_replaceable : $@convention(thin) () -> () {
3080+
bb0:
3081+
%0 = tuple ()
3082+
return %0 : $()
3083+
}
3084+
3085+
sil @test_dynamic_call : $@convention(thin) () -> () {
3086+
bb0:
3087+
%0 = dynamic_function_ref @test_dynamically_replaceable : $@convention(thin) () -> ()
3088+
%1 = apply %0() : $@convention(thin) () -> ()
3089+
%2 = tuple ()
3090+
return %2 : $()
3091+
}
3092+
3093+
prev_dynamic_function_ref
3094+
````````````
3095+
::
3096+
3097+
sil-instruction ::= 'prev_dynamic_function_ref' sil-function-name ':' sil-type
3098+
3099+
%1 = prev_dynamic_function_ref @function : $@convention(thin) T -> U
3100+
// $@convention(thin) T -> U must be a thin function type
3101+
// %1 has type $T -> U
3102+
3103+
Creates a reference to a previous implemenation of a `dynamic_replacement` SIL
3104+
function.
3105+
3106+
For the following Swift code::
3107+
3108+
@_dynamicReplacement(for: test_dynamically_replaceable())
3109+
func test_replacement() {
3110+
test_dynamically_replaceable() // calls previous implementation
3111+
}
3112+
3113+
We will generate::
3114+
3115+
sil [dynamic_replacement_for "test_dynamically_replaceable"] @test_replacement : $@convention(thin) () -> () {
3116+
bb0:
3117+
%0 = prev_dynamic_function_ref @test_replacement : $@convention(thin) () -> ()
3118+
%1 = apply %0() : $@convention(thin) () -> ()
3119+
%2 = tuple ()
3120+
return %2 : $()
3121+
}
3122+
30563123
global_addr
30573124
```````````
30583125

0 commit comments

Comments
 (0)