Comments (4)
Associated type doesn't have direct mapping in C# and could be represented with generics:
The prevalent opinion in previous discussions has been that mapping of protocols and associated types to C# is going to be hard. Where is the catch?
Nit:
public struct Never
{
private Never() {}
}
This fails to compile with "The parameterless struct constructor must be 'public'.".
from runtimelab.
This issue has been updated with a better-defined goal -- feel free to provide feedback on the general direction or identified projections.
from runtimelab.
The prevalent opinion in previous discussions has been that mapping of protocols and associated types to C# is going to be hard. Where is the catch?
My understanding is that some scenarios would be harder to implement than others. Let's start with simple scenarios first.
Generic methods are used in the CryptoKit
and SwiftUI
dev templates. For these, we need to pass an implicit metadata pointer for the concrete type that can be located and exposed as PInvoke during binding process.
Generic methods with protocol constraints require an implicit protocol witness table parameter for conformance. There are two ways to retrieve them: statically and dynamically. Protocol conformance records are emitted in __TEXT.__swift5_proto
binary section and each record contains a pointer to protocol descriptor and protocol witness table. One option is to scan it and map them to a hash table during the binding process. Alternatively, they can be retrieved at runtime using swift_conformsToProtocol
. Here is an interesting article on performance of protocol conformances scanning during app startup: https://medium.com/geekculture/the-surprising-cost-of-protocol-conformances-in-swift-dfa5db15ac0c.
Methods with protocols used as types - instead of passing C# interface pointers within the projection tooling, we need to pass a boxed existential container. We need to implement their construction within the projection tooling, probably at runtime, which will depend on protocol witness tables retrieval.
An addition to above-mentioned scenarios could be types with generics, which require passing concrete type metadata and calling swift_instantiateConcreteTypeFromMangledName
to create a concrete type.
For protocols with associated types, I haven't yet encountered differences in public API and underlying calling convention. I may be missing something here. This is a brief overview of these scenarios, and I will initiate the design on protocols while keeping this issue open for further requirements collection.
from runtimelab.
I agree that we should be always able to setup the right arguments and call the method. I am more worried about the projected API surface that we expose to user when protocols and generics are in the mix. Is the C# code that people end up writing against the projected API surface going to look reasonable?
from runtimelab.
Related Issues (20)
- Review Swift projections tooling UX and functionality
- [Discussion] Generate C# bindings for CryptoKit framework
- [Discussion] Generate C# bindings for Foundation framework
- Performance benchmarking framework for Swift projection tooling
- Can I create NativeLibrary for x86? HOT 1
- [NativeAOT-LLVM]: SIMD support
- [NativeAOT-LLVM] avaliable in .Net 9? HOT 1
- [NativeAOT-LLVM] Remove WASI-SDK pthread.h hack
- [NativeAOT-LLVM] LLVM version synchronization and verification
- [NativeAOT-LLVM] Use clang from EMSDK directly to compile bitcode
- [NativeAOT-LLVM] [Question]: Should GCPointerMap have a provision for adding optional fields to GCStaticEETypeNode HOT 3
- [Question] [NativeAOT-LLVM] What defines if jobs has a `Initialize containers` step? HOT 4
- [Question] [NativeAOT-LLVM] Is there a docker image with `as` ? HOT 2
- [NativeAOT-LLVM] [Question]: why is c++ 11 not installed in the root fs on the linux distros? HOT 25
- [NativeAOT-LLVM] Delegates marshalling is broken in some scenarios HOT 8
- [NativeAOT-LLVM] DotnetJS exception on marshalled c#-objects finalizer call HOT 2
- [NativeAOT-LLVM] DotnetJS JSExport fails, when function was defined in a Browser class library HOT 4
- [NativeAOT-LLVM] DotnetJS Minor incompatibilities with WASM SDK on Mono runtime
- [NativeAOT-LLVM] Enable bulk memory by default and as a baseline
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from runtimelab.