Skip to content
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

[Mono] added simple reverse pinvoke support to interpreter #102185

Merged
merged 12 commits into from
May 17, 2024

Conversation

jkurdek
Copy link
Member

@jkurdek jkurdek commented May 14, 2024

Adds simple (no structs) Swift reverse pinvoke support to mono interpreter.

Comment on lines 4423 to 4435
imethod->swift_error_offset = -1;

MonoClass *swift_error = mono_class_try_get_swift_error_class ();
MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error));

int swift_error_index = -1;
for (int i = 0; i < sig->param_count; i++) {
MonoClass *klass = mono_class_from_mono_type_internal (sig->params [i]);
if (klass == swift_error_ptr) {
swift_error_index = i;
break;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably hardcode type and allocate this variable without checking whether SwiftError* exists on signature

Copy link
Member

@kotlarmilos kotlarmilos May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. It can allocate a variable for SwiftError* if a signature is CallConvSwift.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got rid of the loop as you suggested. I don't think there is a significant benefit of hardcoding it now. What you think?

@jkurdek jkurdek force-pushed the swift-reverse-pinvokes-interpreter branch from a135604 to 232d512 Compare May 14, 2024 09:58
@jkurdek jkurdek requested a review from matouskozak May 14, 2024 10:00
src/mono/mono/mini/interp/transform.c Outdated Show resolved Hide resolved
src/mono/mono/mini/mini-arm64.c Outdated Show resolved Hide resolved
@jkurdek
Copy link
Member Author

jkurdek commented May 15, 2024

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkurdek jkurdek marked this pull request as ready for review May 16, 2024 13:04
@jkurdek
Copy link
Member Author

jkurdek commented May 16, 2024

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkurdek
Copy link
Member Author

jkurdek commented May 16, 2024

Verified that using SwiftSelf in reverse pinvokes works with this changes.

Copy link
Member

@kotlarmilos kotlarmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

src/mono/mono/mini/interp/interp.c Outdated Show resolved Hide resolved
src/mono/mono/mini/interp/interp.c Outdated Show resolved Hide resolved
@jkurdek jkurdek merged commit 4185f94 into dotnet:main May 17, 2024
124 of 126 checks passed
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mono] Implement UnmanagedCallersOnly support for Swift calling convention
3 participants