XIO

xWire

Posts from every feed QUEST has found across the web — blogs, news, podcasts, channels and more.

Swift Forums - Latest posts

Latest posts

Why isn't UserDefaults Sendable?

How would a type conform to Sendable if it has non-Sendable subclasses? You can always upcast the subclass and get a magic, incorrect, Sendable conformance. You can even cast it back to the subclass after sending! I don't know what a good solution looks like here, besides source breaking those non-Sendable subclasses.

Sendable subclassing

I just invented a trick that I wanted to share. So, normally you cannot subclass checked Sendable classes: class Base: Sendable { // error: Non-final class `Base` cannot conform to the `Sendable` protocol. let id: Int = 0 } class Derived: Base { let name: String = "" } But GAI-classes are Sendable and allow subclassing: @MainActor class Base {} class Derived: Base {} func needSendable(_: some Sendable) {} needSendable(Base()) // ok needSendable(Derived()) // ok So, if add a dummy global-actor…

Conform Never to CustomStringConvertible

Dmitriy_Ignatyev: Whether a developer uses where T: CustomStringConvertible in a custom appendInterpolation overload or elsewhere, Right, the point I'm making is that the guidance has always been explicitly that a developer should not do this. Again, it's meant to provide a customization point for the standard library itself to call. Dmitriy_Ignatyev: Stepping back from the API design debate, the core issue here is simply type-system consistency. Never is the universal bottom type in Swift.…

Pitch: A vision for COM Interoperability in Swift

al45tair: Since we can't add the Clang attribute to Microsoft's headers, that means using API Notes (which, as I pointed out, could be generated from the winmd data; they don't need to be manually maintained). I generate my own headers rather than annotating the Windows headers with API Notes for a few reasons: The Windows headers are hostile to modularity and pollute the global namespace. Including a single Windows header in C and C++ often pulls in the entire Windows API surface from…

[Pitch] Add Issue Capturing & Test-Utility-specific module to Swift Testing

Naming withExpectedIssue With the behavior I described earlier, where withExpectedIssue will record an issue if no issues were recorded while executing the body closure, I think that withExpectedIssue is a pretty good name, with only 1 drawback: the existing XCTExpectFailure API in XCTest. XCTExpectFailure is XCTest's version of the Testing Library's withKnownIssue, and I would loath to cause confusion for test authors by having these APIs which behave differently yet share a very similar name.…

[Pitch] Add Issue Capturing & Test-Utility-specific module to Swift Testing

Separate Libraries The Testing Workgroup has had a desire to add a secondary module to the Testing Library for quite some time. Polling Confirmations was in consideration to drive out this secondary module for a while (because polling confirmations, especially as initially proposed, inherently introduced some amount of instability into your tests). For this pitch, the reason to put it in a secondary module is because it can prevent otherwise valid issues from being recorded (though, you can…

[Pitch] Add Issue Capturing & Test-Utility-specific module to Swift Testing

I really appreciate the feedback so far. There's several points to address, and I have a lot to say. So, I'll break this up into multiple comments. Behavior This pitch has 2 separate audiences, and while I thought they were fairly related, I didn't fully appreciate the differences between their desires. Put more plainly: this pitch largely served the second audience, not so much the first. Despite the fact that the first audience is a lot larger than the second. The first audience is people who…

Pitch: A vision for COM Interoperability in Swift

Yes, and that equivalence is by design in COM. Clang on Windows uses the MSVC C++ ABI, which is how I achieved interop with Swift. GCC and Clang on other platforms (and MinGW-w64) use other ABIs like Itanium. I think the vtable layout for Itanium is actually equivalent for the Windows COM interfaces, and GCC and Clang in MinGW-w64 are able to use them, but the MSVC ABI is needed for C++ libraries on Windows that use it. This isn't an important detail though.

Embedded Swift toolchain for Xtensa (ESP32, ESP32-S2, ESP32-S3)

Hello I’ve been working on an Xtensa toolchain for Embedded Swift, and I have a first (experimental) release that supports the original ESP32 (LX6) and the ESP32-S2 and ESP32-S3 (LX7). If you’d like to try it, there are prebuilt binaries for macOS arm64 and Linux x86_64. There are two downloads for each host. Thin is the standalone toolchain with patched Swift, LLVM, and LLDB, plus matching Embedded Swift runtime resources. It’s the one I’d pick for bare-metal work or an existing project with a…

Qt for Swift

There were two things I wanted to see imported with C++ interop when it was announced, LLVM and Qt. I just showed this to a Qt programmer in the team, and he was sold on the widget example, which was much easier to parse in his head compared to an equivalent rust binding. Really awesome.

SE-0556: Cell, ConstCell, and Volatile

Andrew_Trick: The result of constCell() can be "safely" passed to C++. The compiler can, however, continue to assume that the original borrowed value is unaliased and immutable after it has escaped to C++. It's not just Span.constCells() that has this problem. It's also possible for C++ code to return a Span<ConstCell>/std::span<const T> pointing to a C++ array that was originally declared as const (such as const int a[10]), which is also memory that the compiler can assume is really immutable.

Pitch: A vision for COM Interoperability in Swift

I opened "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\Unknwn.h" on my Windows machine, and this is the definition of the IUnknown interface in the Windows SDK. It uses a C++ struct like I described when __cplusplus is defined and a C struct otherwise; they are ABI compatible. #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("00000000-0000-0000-C000-000000000046") IUnknown { public: BEGIN_INTERFACE virtual HRESULT STDMETHODCALLTYPE QueryInterface( /* [in] */…

Pitch: A vision for COM Interoperability in Swift

TwirlySeal: Processing the Windows headers in C++ mode works for Windows development in C++ so I don't see why it wouldn't work for Swift. Because of clang modules. clang modules are built in a single mode which fixes it. We cannot have different build modes for the WinSDK module, so if you have a module that is using the clang module in C++ mode, the entire build graph locks into C++ mode. With Windows C++ development, you can do this on a per translation unit basis. TwirlySeal: The…

Pitch: A vision for COM Interoperability in Swift

compnerd: I think that you are misunderstanding the vision. The projection generator is still required: GitHub - compnerd/swift-winmd: Windows Metadata Parser in Swift · GitHub is precisely that. The projections are language specific representations. I think we are on the same page for this point; I recognise projections are part of the vision, I was only establishing in this thread that they are needed before making other points. compnerd: All of this is already in user space. More than that,…

[Pitch #2] Called-once function types

aviva: Is there a conversation to be had about how necessary withoutActuallyDeiniting is at all? I suspect we will add it, but unlike withoutActuallyEscaping we are introducing both types of ~Copyable function types at the same time, so there should not exist APIs which choose the "wrong" annotation. In what case does the programmer know more than the api author about if a function will be called that should not have been encoded into a different api instead? This is a good analogy, but not in…

[Pitch #2] Called-once function types

aviva: I don't believe this is the case. Consider a span which takes a borrowing access of an array; there are many reachable points where we can prove the span is dead and the array may be mutated again. This would have to be a non-escaping function to express this safety property, though. Even putting the array invalidation aside, it's capturing a non-escapable value (the span). I think my original statement holds up. There are no safety properties that rely on rules like "X must happen, but…

Optimizing task scheduling and memory allocations in high-concurrency Swift Server applications

softuvo: Copy-on-Write (CoW) Triggers: Deeply nested value types modified within async contexts occasionally triggered unexpected full-struct copies under concurrent access. Are you sure this was caused by async functions? The rules around exclusivity and isolation ensure that only one task can “see” a value type at a time, so any copying should be deterministic and observable with a single thread of execution. Perhaps the overhead of atomics and cache line bouncing make this more noticeable in…

[Pitch #2] Called-once function types

aviva: Is there a conversation to be had about how necessary withoutActuallyDeiniting is at all? I suspect we will add it, but unlike withoutActuallyEscaping we are introducing both types of ~Copyable function types at the same time, so there should not exist APIs which choose the "wrong" annotation. In what case does the programmer know more than the api author about if a function will be called that should not have been encoded into a different api instead? There are still a large number of…

Improve the performance of `a = b` on imported C++ types

Swift implements a = b on an imported C++ type as: destroy a, copy-construct it from b (see assignWithCopy). This is slower than calling operator= especially for STL types. For example, std::vector::operator= does not allocate a new buffer if b fits inside a, see this example: C++ Swift vector: b.size() <= a.capacity() operator=: 0 allocs destroy+copy: 1 allocs vector: b.size() > a.capacity() operator=: 1 allocs destroy+copy: 1 allocs This is more pronounced in containers like std::map where…

[Pitch #2] Called-once function types

aviva: An example would be an exactly once function which is used to restore memory to an initialized / defined state before the programmer can access it again. In this case any sound static analysis would prevent you from ever accessing the value again, because there would be no reachable point in the program where the value is subsequently known to be initialized.

[Pitch #2] Called-once function types

Lovely and extremely thorough proposal, I'm excited about the expressivity this will provide and the performance it can unlock. j-f1: In theory, on an @isolated(any) closure, you could access .isolation without consuming it. While I don't know why one does this, point taken, we should have some specialized diagnostics for attempting to call borrowing @callable(once) if we don't forbid this. borrowing @once would still be an error. Since a borrowed function value cannot be called, explicitly…

Introducing the Embedded Swift Platform Abstraction Layer

gark: For the armv7em-none-none-eabi target, both: libswiftEmbeddedPlatformPOSIX.a libswiftEmbeddedPlatformSingleThreaded.a are 88-byte archives containing only empty BSD symbol indices, with no object members or implementations. This looks to have been a CMake issue that we had missed. @al45tair has a fix at [Build][Embedded] Fix building cross-compiled libraries on macOS. by al45tair · Pull Request #94067 · swiftlang/swift · GitHub that we'll get into a nightly as soon as we can. Sorry about…