XIO

xWire

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

Swift Forums - Latest posts

Latest posts

SE-0564: Split Continuations

When originally designing withContinuation, I was imagining that the task would always resume immediately (well, after a hop) when resume was called on the continuation. That was a design that required the initialization of the continuation object to be tied to a single awaiting point. However, it created a disastrous semantic problem where the “body” closure of withContinuation could run concurrently with the continuation of the task. We then came up with the current behavior, where resume…

[Pitch #2] Called-once function types

Nickolas_Pohilets: IMO, that's redundant. Attempt to call the function will diagnose the error anyway. This error won't be applied to other ~Copyable or ~Deinitable types, right? I'd prefer to avoid introducing extra special cases for closure types: Unlike with other NC types, you know the only way to use the value is to consume it... I feel like it's fine to make it an error to write a function signature that cannot be used at all; @once is exactly once, so you must call a function you cannot…

SE-0564: Split Continuations

This enhancement solves actual problems I came across in the past. Great! One issue I have with the existing API remains, though. While I do understand the reasons for the scoped with-style APIs, both old and new, they introduce a potential suspension point before the continuation is passed to client code. Though it is documented that the closure in withCheckedContinuation is executed before any actual suspension occurs, this fact is not visible in code. In reviews it looks like a reentrancy…

Pitch: A vision for COM Interoperability in Swift

TwirlySeal: .NET assemblies are the standard for modern Windows development. This is not really true. There are plenty of native Windows programs still, and plenty of new ones, at that. .NET is just one part of the story on Windows, and while it's undeniably popular, it isn't the only way to write modern Windows software, and right now Swift doesn't have .NET back-end support anyway, so Swift programs on Windows will be native code, and for native code, the modern Windows API is all COM-based.…

SE-0564: Split Continuations

NotTheNHK: I’ve always found it curious that the Continuation APIs use with-style functions, unlike withTaskCancellationHandler, withTaskCancellationShield, etc. The scope itself isn’t relevant here (obviously, this proposal would change that somewhat): the body of a with*Continuation API provides the continuation handle, which is then, in most cases, stored somewhere immediately. There is no “special behavior” while the body closure is executing. In the current withContinuation functions the…

Pitch: A vision for COM Interoperability in Swift

compnerd: IMO no more strange than say ObjC interop. I have similar feelings about ObjC interop While I recognize it's a hard problem, better support for meta-programming could have allowed for "pluggable" object systems, where something like the ClangImporter is modeled as a "type provider" that interfaces with the rest of the frontend via a well-defined interface. It's unfortunate that today we have if (decl->isObjC()) { ... do this ... } else { ... do that ... } all over the codebase. We'd…

Pitch: A vision for COM Interoperability in Swift

TwirlySeal: A projection generator based on Windows Metadata is required for achieving idiomatic Swift bindings because headers and MIDL (when available) are missing a lot of important information that cannot be inferred (including [PreserveSig]), as I talked about in another thread. 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…

SE-0564: Split Continuations

Just another thought. I’ve always found it curious that the Continuation APIs use with-style functions, unlike withTaskCancellationHandler, withTaskCancellationShield, etc. The scope itself isn’t relevant here (obviously, this proposal would change that somewhat): the body of a with*Continuation API provides the continuation handle, which is then, in most cases, stored somewhere immediately. There is no “special behavior” while the body closure is executing.

[Pitch #2] Called-once function types

j-f1: Why not have the override rules match the protocol conformance rules? I’m thinking of a class as a bit like a protocol where all the requirements have a default implementation. The rules for matching witnesses against protocol requirements are even stricter than what we allow for class method overrides, basically you can’t have any variance at all except for a few special cases like Any vs any Sendable in preconcurrency contexts. This is because of associated type inference; you can’t…

[Pitch #2] Called-once function types

Nickolas_Pohilets: Why? Wouldn't allowing this help with source-compatibility? The existing rules for class method override variance are already a small subset of the function conversion rules allowed in expressions (and I believe the feature was originally motivated by Objective-C compatibility), so extending this behavior to allow more forms of variance does not help consistency, I think.

Understanding Iterable and Span's Escapable requirement

Span is itself ~Escapable. Why is it that a Span cannot hold ~Escapableelements? The current lifetimes model doesn't give us a way to talk about the lifetimes of ~Escapable elements of a container in the full generality that we need to be able to in order to build useful abstractions like this. With the existing lifetimes support in the language, most of the code that you would want to write would either have too-short lifetimes, or would have to use unsafe escape hatches much too often. John…

Throwing error in `init` is "conditional initialization" of noncopyable types?

I suspect it’s because delegating to self.init(...) initializes self all in one step. There are really two kinds of initializers: ones that initialize all stored properties one at a time, and ones that delegate to another initializer. You can’t mix them: init() { // this is invalid if condition { self.x = 3 } else { self.init(x: 4) } }

KeyPath to String: Efficient runtime conversion alternatives?

sliemeobn: because of all that swift-syntax build mumbo jumbo that frankly drives me bonkers as well. There are moves toward accelerating macros, some time ago a proof of concept for running macros via WASM was demonstrated on the forum. Additionally, Xcode has added the ability to use precompiled SwiftSyntax. However, specifically for my task, burdening users with a SwiftSyntax dependency just for the sake of a sugar API isn’t practical, so I decided to look into alternatives, if any exist.…

[Pitch #2] Called-once function types

Can we have this diagnostic specifically on the branch that exits without calling f? Maybe one error per function with a note per branch. func dropsConditionally(_ f: @once () -> Void, _ condition: Bool) { // error: 'f' is not called on all if condition { return // note: 'f' is not called on this path } f() } func borrowOnce(_ c: borrowing @once () -> Void) { } // error: '@once' cannot be used together with 'borrowing' IMO, that's redundant. Attempt to call the function will diagnose the error…

[Pitch #2] Called-once function types

tshortli: The choice to make Copyable refine Deinitable was an attempt to mitigate the type checking performance impact of introducing a third invertible protocol. The refinement is not designed to be load-bearing for anything and could be removed in the future with a corresponding update to the compiler Thanks for sharing the hierarchy here! It makes a lot of sense to me that Copyable refines Deinitable — if you’re able to create a new copy of a value out of thin air, it should follow that you…

[Pitch #2] Called-once function types

The latest iteration of this pitch looks great. Since calling a @once or @callable(once) function always consumes it, parameters with these function types are implicitly consuming and later This restriction could be lifted in the future if borrowing these function values becomes useful, such as to pass them to generic functions that inspect them without consuming them. Is it the right choice to default the implicit to consuming if we believe there might be value further down the road to lift…

Throwing error in `init` is "conditional initialization" of noncopyable types?

If you break the initialization into two steps, one of which only delegates to another init, and another which always initializes all properties, you can work around this issue: public struct Device: ~Copyable { public var device: USBDevice public var serialNumber: String? public init() throws { let devices = try? Self.usbGetDevices() guard var devices, let device = devices.popLast() else { throw DeviceError.deviceNotFound } try self.init(device: device) } private init(device: consuming…

[Pitch #2] Called-once function types

John_McCall: I am not aware of any kind of safety that depends on code running at an unspecified point in the future as long as it’s before process exit, and there had better not be one, because we absolutely do not make that promise on any level. Yeah, and it’s worth mentioning specifically that resource leaks, while potentially very inconvenient for the developer, do not violate what we think of as memory safety.

Units, conversions, and dimensional calculations in Swift Measures 3.0.0

Here’s another example showing dimensional composition in a calculation: kinetic energy using E = ½mv². import Measures let mass: Measure<Mass> = .init(80, .kilogram) let speed: Measure<Speed> = .init(36, .kilometersPerHour) let kineticEnergy: Measure<ComposedUnit> = mass * (speed ** 2) / 2 print(kineticEnergy) // 4000.0 kg·m²·s⁻² let energy: Measure<Energy> = kineticEnergy.converted(to: .joule) print(energy) // 4000.0 J The calculation handles the conversion from kilometres per hour, squares…

Measurement, Dimension, and Unit

Hi everyone, I wanted to follow up on this discussion from 2023: I’ve just released Measures 3.0.0. Several of the ideas discussed here are now implemented, including multiplying and dividing measures to produce derived units, converting those results to compatible defined units, and locale-aware formatting through Foundation’s FormatStyle APIs. The numeric representation behind a measure is still an area I’m exploring. I have an open issue researching decimal floating-point support, motivated…

Units, conversions, and dimensional calculations in Swift Measures 3.0.0

Hi everyone, I’ve just released version 3.0.0 of Measures, a Swift package for defining, converting, and composing units of measure. Some of you may remember this discussion from 2023, where I shared an earlier version and explored ideas around measurement APIs. The package has evolved since then, including support for dimensional composition and locale-aware formatting. Measures provides strongly typed values and units, with SI base and derived units, metric and binary prefixes, and commonly…