Open Whirlwind opened 1 year ago
This looks like correct behavior, by telling that core_runCommander
is a dynamic replacement for runCommander
calling runCommander
means calling core_runCommander
which make this function a recursive call.
This looks like correct behavior, by telling that
core_runCommander
is a dynamic replacement forrunCommander
callingrunCommander
means callingcore_runCommander
which make this function a recursive call.
I don't think so. If I remove the async
, call the runCommander
will call the origin method:
dynamic
public func runCommander() {
printf("1")
}
@_dynamicReplacement(for: runCommander())
public func core_runCommander() {
runCommander()
}
It will print the 1
.
If you are right, what should I do when calling the origin method?
I found a test: https://github.com/apple/swift/blob/7123d2614b5f222d03b3762cb110d27a9dd98e24/test/Interpreter/Inputs/dynamic_replacement_chaining_B.swift It will call the origin method by origin name.
Ok, looks like I misunderstood the feature behavior
Yeah this looks indeed a bug
Any process?
cc @aschwaighofer
Any process?
Still reproducible with swift 5.9 swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
The following sample code:
dynamic func original() {
print("original")
}
@_dynamicReplacement(for: original)
func replacement() {
print("replacement")
original()
}
original()
correctly prints:
replacement
original
But adding async
to the original
method forces the use of await
in the replacement in order to call it, this produces a call to the replacement instead of the original implementation, ending with an infinte loop
dynamic func original() async {
print("original")
}
@_dynamicReplacement(for: original)
func replacement() async {
print("replacement")
await original()
}
await original()
replacement
replacement
replacement
replacement
replacement
replacement
replacement
replacement
replacement
replacement
...
Also reproducible for non-async objc methods: https://github.com/apple/swift/issues/53916
Any process?
Still reproducible with Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx15.0
Xcode 14.1, swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
I get a deadloop:
I try other methods, same wrong.