$ the-wire · showcase
Swift reworks extension macros, foreign reference types, and noncopyable `is`
By RepoJournal · Filed · About Mobile platforms · Composed from the cited sources · methodology
Swift's compiler landed a cluster of type-system and codegen changes: extension macros now land in the same IRGenModule as the type they extend, `@c` declarations accept foreign reference types, and `is` gets a new runtime entry point for noncopyable existentials.
Extension macros no longer get placed in a synthesized file unit. Swift now tracks them separately via `getTopLevelDeclsWithAuxiliaryDecls`, which puts them in the same `IRGenModule` as the nominal being extended [1]. The same helper now drives `IID` synthesis in Sema, letting the compiler remove the synthesized-file check in SILGen entirely [2]. The change required introducing `shouldWalkTopLevelAuxiliaryDecls` on ASTWalker, which the PR describes as "an unfortunate hack" owed to misconfigured macro handling in many existing walkers [1].
C and C++ interop broadens `@c` to cover foreign reference types, which are represented as pointers in C and C++ but were previously rejected in `@c` declarations, including `@c @implementation` [3]. All foreign reference types are now usable in `@c` functions, not just some CoreFoundation types, and `Unmanaged<_>` of a foreign reference type is enabled for cases where convention information is absent [3].
On noncopyable existentials, Swift added a new `is` runtime entry. It has the same arguments as `swift_dynamicCast` minus the `destination` argument, so neither the source nor the contained value is taken or copied [4]. The implementation is described as rudimentary for now; the PR is the first in a series converting `is` to be non-destructive [4].
Separately, Sema now always diagnoses custom availability domain restrictions for protocols [5], tightening a source-compatibility concession that previously let protocols appear in inheritance clauses before their target platform introduced them. Flutter's day was all autorolls: the Dart SDK moved from 7863887acbfb to 7253dff72c96 over two revisions [6], the Fuchsia Linux SDK advanced [7], and Skia rolled from e5e96533b732 to 6f85503e50b4 across five revisions [8].
Action items
- → Revert the Dart SDK autoroll to 3.14.0-226.0.dev if the roll caused breakage and set the roller to dry run flutter/flutter [monitor]
- → Audit `@c @implementation` declarations that currently bridge foreign reference types through workarounds apple/swift [plan]
- → Review code relying on the `swift_dynamicCast` destination argument before `is` becomes non-destructive apple/swift [plan]
References
- [1] [AST] Handle extension macros in `getTopLevelDeclsWithAuxiliaryDecls` ↗ apple/swift
- [2] [Sema] Use `getTopLevelDeclsWithAuxiliaryDecls` for `IID` synthesis ↗ apple/swift
- [3] [C/C++ interop] Allow foreign reference types in @c declarations ↗ apple/swift
- [4] [any ~Copyable] New `is` runtime entry ↗ apple/swift
- [5] Sema: Always diagnose custom availability domain restrictions for protocols ↗ apple/swift
- [6] Roll Dart SDK from 7863887acbfb to 7253dff72c96 (2 revisions) (#192706) ↗ flutter/flutter
- [7] Roll Fuchsia Linux SDK from m69nfK-wnHaMTe8P9... to AQu85JoTHCMET3Q8G... (#192703) ↗ flutter/flutter
- [8] Roll Skia from e5e96533b732 to 6f85503e50b4 (5 revisions) (#192702) ↗ flutter/flutter