Skip to content

Conversation

@jkurdek
Copy link
Contributor

@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
Contributor 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
Contributor 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
@jkurdek
Copy link
Contributor Author

jkurdek commented May 15, 2024

/azp run runtime-extra-platforms

@azure-pipelines
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
Contributor Author

jkurdek commented May 16, 2024

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkurdek
Copy link
Contributor 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!

@jkurdek jkurdek merged commit 4185f94 into dotnet:main May 17, 2024
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