Swift 6.3がAndroid SDKを安定化、C言語相互運用性を拡張
本文の状態
日本語全文を表示中
詳細モードで約3分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
InfoQ
Swift開発チームがSwift 6.3をリリースし、公式Androidサポートによるクロスプラットフォーム対応を強化、新しい@c属性によるC言語相互運用性を大幅に改善、組み込みプログラミングサポートを拡張した。
Continue in AI NEW LAB
このニュースを、実務の判断につなげる
AI NEW LABで、試したことや先に確認したい条件を共有できます。まずはログインなしで読めます。
AI NEW LABで論点を見るSource Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
Swift 6.3 は、公式の Android サポートと大幅に改善された新しい @c 属性による C 言語との相互運用性、そして組み込みプログラミング サポートの継続的な拡張により、Swift のクロスプラットフォームにおける取り組みを前進させます。さらに、統一されたビルドシステムへの方向性を示すことでエコシステムを強化し、開発者により多くの低レベルのパフォーマンス制御を提供します。
C 言語との相互運用性を拡張するために、Swift 6.3 では @c および @implementation という 2 つの新しい属性が導入されました。@c で注釈付けされた Swift 関数は、生成される C/C++ ヘッダーに自動的に対応する宣言を取得するため、C/C++ コードからそれを呼び出すことができます。既存の C 宣言に対して Swift の実装を提供したい場合、@c と @implementation を組み合わせることができます。この場合、コンパイラは C 宣言が既に存在することを保証します。
Swift 6.3 ではまた、モジュール セレクタも導入されました。これは、異なるモジュールに同じシンボルが存在する場合に関数呼び出しの曖昧さを解消し、意図した実装を明示的に参照しやすくします。例えば:
import ModuleA
import ModuleB
let x = ModuleA::getValue() // 'ModuleA' の 'getValue' を呼び出す
let y = ModuleB::getValue() // 'ModuleB' の 'getValue' を呼び出す
新しい weak let 宣言は、並行コンテキストにおいてクラスやクロージャが弱参照を使用する際の長年の制限を解消します。実際、以前のバージョンでは weak 修飾子は weak var を使用してオブジェクト参照に対してのみ適用可能であり、それらの参照は可変であったため sendable ではありませんでした。weak let を使用することで、並行処理に安全な方法でクロージャ内に非参照かつ不変のシンボルをキャプチャすることが可能になります。
言語へのその他の拡張機能には、@specialize を使用したジェネリック API の特殊化実装や @inline(always) による保証されたメソッドのインライン展開など、コンパイラの最適化をより細かく制御する機能が含まれています。
前述の通り、Swift 6.3 では Swift SDK for Android が安定化しました。これは以前はナイトリービルドでのプレビュー版としてのみ利用可能でしたが、開発者が Swift パッケージを Android にポートするのを支援するために設計されています。
この SDK を使用することで、Swift でネイティブな Android プログラムの開発を開始し、Swift パッケージを更新して Android でのビルドをサポートさせ、Swift Java および Swift Java JNI Core を使用して Kotlin/Java で記述された既存の Android アプリケーションに Swift コードを統合することができます。
最後に、Embedded Swift は、埋め込みおよび非埋め込み Swift 向けの統一されたリンクモデルへの移行、デバッグ機能の改善、@section や @used 属性によるリンクに関するより細かな制御の提供、Swift SMMIO を介したメモリマップド I/O のサポート追加など、大きな進展を遂げました。
セルジオ・デ・シモーネ
セルジオ・デ・シモーネはソフトウェアエンジニアです。セルジオは、シーメンス、HP、そして小規模なスタートアップ企業など、多様なプロジェクトや会社で25年以上にわたりソフトウェアエンジニアとして活動してきました。過去10年以上は、モバイルプラットフォームおよび関連技術の開発に注力しています。現在は大規模機械学習プラットフォームのBigML, Inc.で勤務し、iOSおよびmacOS開発をリードしています。
詳細表示非表示
原文を表示
Swift 6.3 advances the Swift cross-platform story with official Android support, improves significantly C interoperability through the new @c attribute, and continues extending embedded programming support. It also strengthens the ecosystem with a unified build system direction and gives developers more low-level performance control.
To extend interoperability with the C language, Swift 6.3 introduces two new attributes, @c and @implementation. A Swift function annotated with @c will automatically get a corresponding declaration in the generated C/C++ header so you can call it from C/C++ code. In case you want to provide a Swift implementation for an existing C declaration, you can combine @c with @implementation, in which case the compiler will ensure the C declaration already exists.
Swift 6.3 also introduces module selectors, which let you disambiguate function calls when the same symbol exists in distinct modules, making it easier to explicitly reference the intended implementation. For example:
import ModuleA
import ModuleB
let x = ModuleA::getValue() // Call 'getValue' from ModuleA
let y = ModuleB::getValue() // Call 'getValue' from ModuleB
The new weak let declaration removes a long-standing limitation with classes and closures using weak references in concurrent contexts. In previous versions, in fact, the weak modifier could be used only with object references, using weak var, which made those references mutable and thus not sendable. weak let allows to capture a non-reference, immutable symbol inside a closure in a concurrency-safe way.
Other extensions to the language provide finer-grained control over compiler optimizations, including specialized implementations of generic APIs using @specialize, guaranteed method inlining using @inline(always), and more.
As mentioned, Swift 6.3 stabilizes the Swift SDK for Android, previously available only as a preview in nightly builds, which is designed to help developers port their Swift packages to Android.
With this SDK, you can start developing native Android programs in Swift, update your Swift packages to support building for Android, and use Swift Java and Swift Java JNI Core to integrate Swift code into existing Android applications written in Kotlin/Java.
As a final note, Embedded Swift has made significant progress by moving toward a unified linking model for embedded and non-embedded Swift, improving debugging facilities, and providing more control over linking with the @section and @used attributes, adding support for memory-mapped I/O with Swift SMMIO, and more.
About the Author
Sergio De Simone
Sergio De Simone is a software engineer. Sergio has been working as a software engineer for over twenty five years across a range of different projects and companies, including such different work environments as Siemens, HP, and small startups. For the last 10+ years, his focus has been on development for mobile platforms and related technologies. He is currently working for BigML, Inc., where he leads iOS and macOS development.
Show moreShow less
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み