-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: Distinguish "compatible convention" and "compatible representation" function conversions. #28541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
SIL: Distinguish "compatible convention" and "compatible representation" function conversions. #28541
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// RUN: %target-swift-frontend -emit-silgen -disable-availability-checking -module-name main -enable-subst-sil-function-types-for-function-values %s | %FileCheck %s | ||
|
||
func generic<T, U>(_ f: @escaping (T) -> U) -> (T) -> U { return f } | ||
|
||
// CHECK-LABEL: sil {{.*}}4main{{.*}}11sameGeneric | ||
func sameGeneric<X, Y, Z>(_: X, _: Y, _ f: @escaping (Z) -> Z) -> (Z) -> Z { | ||
// CHECK: bb0({{.*}}, [[F:%[0-9]+]] : @guaranteed $@callee_guaranteed <τ_0_0, τ_0_1> in (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Z, Z> | ||
// Similarly generic types should be directly substitutable | ||
// CHECK: [[GENERIC:%.*]] = function_ref @{{.*}}4main{{.*}}7generic | ||
// CHECK: [[RET:%.*]] = apply [[GENERIC]]<Z, Z>([[F]]) | ||
// CHECK: return [[RET]] | ||
return generic(f) | ||
} | ||
|
||
// CHECK-LABEL: sil {{.*}}4main{{.*}}16concreteIndirect | ||
func concreteIndirect(_ f: @escaping (Any) -> Any) -> (Any) -> Any { | ||
// CHECK: bb0([[F:%[0-9]+]] : @guaranteed $@callee_guaranteed (@in_guaranteed Any) -> @out Any) | ||
// Any is passed indirectly, but is a concrete type, so we need to convert | ||
// to the generic abstraction level | ||
// CHECK: [[F2:%.*]] = copy_value [[F]] | ||
// CHECK: [[GENERIC_F:%.*]] = convert_function [[F2]] : {{.*}} to $@callee_guaranteed <τ_0_0, τ_0_1> in (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Any, Any> | ||
// CHECK: [[GENERIC:%.*]] = function_ref @{{.*}}4main{{.*}}7generic | ||
// CHECK: [[GENERIC_RET:%.*]] = apply [[GENERIC]]<Any, Any>([[GENERIC_F]]) | ||
// CHECK: [[RET:%.*]] = convert_function [[GENERIC_RET]] : {{.*}} | ||
// CHECK: return [[RET]] | ||
return generic(f) | ||
} | ||
|
||
// CHECK-LABEL: sil {{.*}}4main{{.*}}14concreteDirect | ||
func concreteDirect(_ f: @escaping (Int) -> String) -> (Int) -> String { | ||
// CHECK: bb0([[F:%[0-9]+]] : @guaranteed $@callee_guaranteed (Int) -> @owned String): | ||
// Int and String are passed and returned directly, so we need both | ||
// thunking and conversion to the substituted form | ||
// CHECK: [[F2:%.*]] = copy_value [[F]] | ||
// CHECK: [[REABSTRACT_F:%.*]] = partial_apply {{.*}}([[F2]]) | ||
// CHECK: [[GENERIC_F:%.*]] = convert_function [[REABSTRACT_F]] : {{.*}} to $@callee_guaranteed <τ_0_0, τ_0_1> in (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Int, String> | ||
// CHECK: [[GENERIC:%.*]] = function_ref @{{.*}}4main{{.*}}7generic | ||
// CHECK: [[GENERIC_RET:%.*]] = apply [[GENERIC]]<Int, String>([[GENERIC_F]]) | ||
// CHECK: [[REABSTRACT_RET:%.*]] = convert_function [[GENERIC_RET]] : {{.*}} | ||
// CHECK: [[RET:%.*]] = partial_apply {{.*}}([[REABSTRACT_RET]]) | ||
// CHECK: return [[RET]] | ||
|
||
return generic(f) | ||
} | ||
|
||
func genericTakesFunction<T, U>( | ||
_ f: @escaping ((T) -> U) -> (T) -> U | ||
) -> ((T) -> U) -> (T) -> U { return f } | ||
|
||
func sameGenericTakesFunction<T>( | ||
_ f: @escaping ((T) -> T) -> (T) -> T | ||
) -> ((T) -> T) -> (T) -> T { | ||
return genericTakesFunction(f) | ||
} | ||
|
||
// CHECK-LABEL: sil {{.*}}4main29concreteIndirectTakesFunction | ||
func concreteIndirectTakesFunction( | ||
_ f: @escaping ((Any) -> Any) -> (Any) -> Any | ||
) -> ((Any) -> Any) -> (Any) -> Any { | ||
// CHECK: bb0([[F:%[0-9]+]] : @guaranteed $@callee_guaranteed | ||
|
||
// Calling convention matches callee, but the representation of the argument | ||
// to `f` needs to change, so we still have to thunk | ||
// CHECK: [[F2:%.*]] = copy_value [[F]] | ||
// CHECK: [[REABSTRACT_F:%.*]] = partial_apply {{.*}}([[F2]]) | ||
// CHECK: [[GENERIC_F:%.*]] = convert_function [[REABSTRACT_F]] | ||
// CHECK: [[GENERIC:%.*]] = function_ref @{{.*}}4main{{.*}}20genericTakesFunction | ||
// CHECK: [[GENERIC_RET:%.*]] = apply [[GENERIC]]<Any, Any>([[GENERIC_F]]) | ||
// CHECK: [[REABSTRACT_RET:%.*]] = convert_function [[GENERIC_RET]] : {{.*}} | ||
// CHECK: [[RET:%.*]] = partial_apply {{.*}}([[REABSTRACT_RET]]) | ||
// CHECK: return [[RET]] | ||
return genericTakesFunction(f) | ||
} | ||
|
||
func concreteDirectTakesFunction( | ||
_ f: @escaping ((Int) -> String) -> (Int) -> String | ||
) -> ((Int) -> String) -> (Int) -> String { | ||
// Int and String are passed and returned directly, so we need both | ||
// thunking and conversion to the substituted form | ||
return genericTakesFunction(f) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contrast between this and the cases below isn't clear. Maybe something like:
We don't need to be coy about using ptrauth as an example.
The comment about nested positions applies to all these cases except
CompatibleRepresentation
, so maybe it should just go there.Also you keep using
SameCallingConvention
in these comments, but it looks like you renamed that toCompatibleCallingConvention
.Longer-term question: should we just roll
thin_to_thick_function
intoconvert_function
, so that we have one instruction for doing superficial conversions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll clean up the comment in a follow up commit.