Skip to content

Conversation

@kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented Nov 21, 2023

Description

Based on the design doc, this PR introduces types to represent each of the special registers.

The Swift programming language has a different ABI, runtime environment, and object model. According to the calling convention, the self context has dedicated registers, and it is always passed through them since it's heavily used. Methods calling other methods on the same object can share the self context. Errors are also handled through registers, so the caller needs to check for errors and throw if necessary. Implementing P/Invoke thunks should simplify registers juggling by using predefined set of registers in these scenarios.

The Mono runtime currently does not compile native wrappers with the LLVM backend. However, support for LLVM is essential for handling scenarios involving UnmanagedCallersOnly, where Swift code calls into C#. The implementation of LLVM support will be addressed in a subsequent PRs.

We need approval for the #64215 before merging this PR.

Fixes #64215

@kotlarmilos kotlarmilos added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.InteropServices labels Nov 21, 2023
@kotlarmilos kotlarmilos added this to the 9.0.0 milestone Nov 21, 2023
@kotlarmilos kotlarmilos self-assigned this Nov 21, 2023
@ghost
Copy link

ghost commented Nov 21, 2023

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 21, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Based on the design doc, this PR introduces types to represent each of the special registers.

The Swift programming language has a different ABI, runtime environment, and object model. According to the calling convention, the self context has dedicated registers, and it is always passed through them since it's heavily used. Methods calling other methods on the same object can share the self context. Errors are also handled through registers, so the caller needs to check for errors and throw if necessary. Implementing P/Invoke thunks should simplify registers juggling by using predefined set of registers in these scenarios.

We need approval for the #64215 before merging this PR.

Author: kotlarmilos
Assignees: kotlarmilos
Labels:

api-suggestion, area-System.Runtime.InteropServices

Milestone: 9.0.0

@teo-tsirpanis teo-tsirpanis added api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Nov 21, 2023
kotlarmilos and others added 3 commits November 22, 2023 10:40
…erServices/CallingConventions.cs

Co-authored-by: Aaron Robinson <[email protected]>
…erServices/CallingConventions.cs

Co-authored-by: Aaron Robinson <[email protected]>
@kotlarmilos kotlarmilos added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Dec 4, 2023
@jkotas jkotas removed the api-ready-for-review API is ready for review, it is NOT ready for implementation label Dec 4, 2023
kotlarmilos and others added 2 commits January 9, 2024 15:25
…pServices/Swift/SwiftTypes.cs

Co-authored-by: Aaron Robinson <[email protected]>
…pServices/Swift/SwiftTypes.cs

Co-authored-by: Aaron Robinson <[email protected]>
@kotlarmilos
Copy link
Member Author

@AaronRobinsonMSFT please sign off on this from the Interop side.

@AaronRobinsonMSFT
Copy link
Member

@kotlarmilos Note that unless @jkoritzinsky specifically asks for my sign-off, his review is sufficient for any interop related PRs. I do appreciate your dilligence in getting all the stakeholders involved though. Thanks!

@kotlarmilos kotlarmilos merged commit adfae48 into dotnet:main Jan 10, 2024
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
…wift ABI calling convention (dotnet#95065)

* Add CallConvSwift attribute and introduce types to represent each of the special registers

---------

Co-authored-by: Aaron Robinson <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 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.

Introduce CallConvSwift to represent the Swift ABI calling convention

7 participants