-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add support for SwiftSelf<T> in Mono JIT and Interpreter
#104171
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
kotlarmilos
merged 15 commits into
dotnet:main
from
kotlarmilos:feature/swift-self-generic
Jul 19, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0647f6a
Add support for SwiftSelf<T>
kotlarmilos 3008c6c
Add constraints
kotlarmilos 240c1b3
Enable runtime tests
kotlarmilos 5bcb0a5
Add swift_self_t instead of strcmp check
kotlarmilos 630e6a9
Use int_class instead of typed_reference
kotlarmilos a2c1d78
Remove redundant branch for SwiftSelf<T>
kotlarmilos e375636
Merge branch 'main' into feature/swift-self-generic
kotlarmilos 692aacc
Update src/mono/mono/mini/mini-amd64.c
kotlarmilos 5756236
Update src/mono/mono/mini/mini-arm64.c
kotlarmilos 04eee19
Use sizeof(MonoObject) offset for swift_self_t
kotlarmilos 0b05920
Merge branch 'main' into feature/swift-self-generic
kotlarmilos 110534a
Use MONO_ABI_SIZEOF to load boxed struct as an argument
kotlarmilos b902f1d
Load the address of the struct with 0 offset from SwiftSelf<T>
kotlarmilos 30c14b0
Resolve conflicts
kotlarmilos 21f7fc7
Update NEW_ARGLOADA to the pointer-like type
kotlarmilos 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7533,6 +7533,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b | |
| GArray *new_params = g_array_sized_new (FALSE, FALSE, sizeof (MonoType*), n); | ||
| uint32_t new_param_count = 0; | ||
| MonoClass *swift_self = mono_class_try_get_swift_self_class (); | ||
| MonoClass *swift_self_t = mono_class_try_get_swift_self_t_class (); | ||
| MonoClass *swift_error = mono_class_try_get_swift_error_class (); | ||
| MonoClass *swift_indirect_result = mono_class_try_get_swift_indirect_result_class (); | ||
| /* | ||
|
|
@@ -7543,6 +7544,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b | |
| for (int idx_param = 0; idx_param < n; ++idx_param) { | ||
| MonoType *ptype = fsig->params [idx_param]; | ||
| MonoClass *klass = mono_class_from_mono_type_internal (ptype); | ||
| MonoGenericClass *gklass = mono_class_try_get_generic_class (klass); | ||
|
|
||
| // SwiftSelf, SwiftError, and SwiftIndirectResult are special cases where we need to preserve the class information for the codegen to handle them correctly. | ||
| if (mono_type_is_struct (ptype) && !(klass == swift_self || klass == swift_error || klass == swift_indirect_result)) { | ||
|
|
@@ -7562,9 +7564,17 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b | |
| ++new_param_count; | ||
| } | ||
| } else { | ||
| // For structs that cannot be lowered, we change the argument to byref type | ||
| // For structs that cannot be lowered, we change the argument to a pointer-like argument type. | ||
| // If SwiftSelf<T> can't be lowered, it should be passed in the same manner as SwiftSelf, via the context register. | ||
| if (gklass && (gklass->container_class == swift_self_t)) { | ||
| ptype = mono_class_get_byref_type (swift_self); | ||
| // The ARGLOADA should be a pointer-like type. | ||
| struct_base_address->klass = mono_defaults.int_class; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed. Is it leading to failures, maybe it was just failing with previous wrong code ? It seems to me in other places the klass information holds the type that we get the ref for and not really the ref type. |
||
| } else { | ||
| ptype = mono_class_get_byref_type (klass); | ||
| } | ||
|
|
||
| *sp++ = struct_base_address; | ||
| ptype = mono_class_get_byref_type (klass); | ||
|
|
||
| g_array_append_val (new_params, ptype); | ||
| ++new_param_count; | ||
|
|
||
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
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.
Does this lower as
SwiftSelf<T>instead of as the inner element type? That might be problematic since the layout ofSwiftSelf<T>may not match the layout ofTdue to potentially added padding at the end.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.
I think you are right, it seems we are lowering the generic, not the inner type. Could you share more details about when padding would be added?
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.
Are you referring that it should first retrieve the inner type if
klassisSwiftSelf<T>, and then perform the lowering?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.
For example, the Swift struct
corresponds to the C# struct
But we have
Foo- size 5SwiftSelf<Foo>- size 8Does this actually matter for the final lowering and ABI? Not totally sure when "self" is the last argument, actually. I wouldn't be surprised if there are cases where lowering
SwiftSelf<Foo>instead ofFooends up with some different register assignments.Right.