Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

[SoM] Might be able to improve dispatch #73

Open
stephen-hawley opened this issue Apr 2, 2019 · 0 comments
Open

[SoM] Might be able to improve dispatch #73

stephen-hawley opened this issue Apr 2, 2019 · 0 comments
Milestone

Comments

@stephen-hawley
Copy link
Contributor

At present, we wrap any function in swift that (1) doesn't match the platform function call ABI and (2) calls a virtual method.

Quick rundown - on x64, the swift function call ABI follows these rules:
All value types are passed by value if they take 3 machine words or fewer.
If a value type is more than 3 words, a copy is made and it is passed by reference.
The instance/context pointer for a method is passed in R13.
If a function throws, it will set R12 to the exception

If we can implement in mono the ability to selectively match the function call ABI then we can eliminate most of the wrapper code that SoM generates.
This doesn't solve the issue of invoking virtual methods since, to date, we have no means of finding the correct vtable entry to call. Swift 5 has added a set of data structures and associated calls that let us do this.
For every major language element, there is an associated descriptor for it.
For example, there exists this new call:

void *
swift::swift_lookUpClassMethod(const ClassMetadata *metadata,
                               const MethodDescriptor *method,
                               const ClassDescriptor *description)

Which returns a method for a given method descriptor.
I suspect that this is in place for either:
writing a better debugger
calling code via reflection

Nonetheless, we should be able to (mis)use this to call virtual methods without wrapping them.

@stephen-hawley stephen-hawley transferred this issue from another repository Oct 29, 2019
@chamons chamons added this to the Future milestone Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants