Exploring Swift and .NET

A couple of blog posts about my exploration of Swift and .NET:

https://ericsink.com/entries/dotnet_swift.html

https://ericsink.com/entries/swift_closures_llama.html

TLDR: Based on a thing that converts LLVM bitcode to target the .NET runtime. Use that to compile the Swift runtime and Swift code for .NET. Proof of concept.

16 Likes

This is cool! Since this is at the LLVM level, is Swift still using refcounting, at least for native Swift classes? That seems pretty necessary given how much Swift depends on copy-on-write.

1 Like

Thanks!

Yes. Whenever Swift (or its runtime, or whatever) allocates memory, it comes out of what .NET calls the unmanaged heap, equivalent to a regular malloc.

Generally speaking, the primary goal is to simply compile Swift for a different platform, with no semantic changes. Integration with other .NET stuff is the second step.

6 Likes

And BTW, @jrose, I've spent a LOT of time reading your blog series on implementing the Swift runtime. Excellent stuff.

It sure seems like my task should be easier. I'm not implementing the runtime, I'm just trying to compile it into a form that isn't broken. But I've been through quite a few iterations, each time believing that I finally got it right, only to discover another problem. Like decoding a symbolic reference is broken. Or some piece of metadata can't be found. Or a relative pointer calculation failed. And so on. :grinning:

1 Like

Cool!

1 Like

Excellent job @ericsink , I've been eyeing this since you first posted it and have been thinking a lot about it.

I feel like we should be encouraging / exploring this more as a community. With increased interest from Microsoft's side to interop with swift in future dotnet releases, as well as the wide availability of platforms dotnet targets, swift would be the perfect candidate to integrate with this ecosystem more.

It could increase adoption of the language as well as make programming in certain environments (games, back end) more feasible.

Thanks @hggz -- I am always grateful to see someone interested in my work.

I have another preview in progress, which I plan to post next week. My recent focus has been on improving Swift integration with .NET class libraries and packages. I continue to find that there is potential for Swift/.NET integration to have a reasonably natural "feel", in most places anyway.

4 Likes

My latest blog entry is a demo of a simple web API, using ASP.NET Core, written in Swift:

https://ericsink.com/entries/swift_aspnetcore_llama_demo.html

Includes a few musings about the possible usefulness of this as an alternate approach for server-side Swift.

4 Likes

I know there was suppose to be efforts to make Swift interop with C# better in dotnet core 5+. I wondering if the path taken by LLAMA can be used for dotnet core.

C# - .NET Reunified: Microsoft’s Plans for .NET 5 | Microsoft Docs

Terms of Service

Privacy Policy

Cookie Policy