Skip to content

gigun-dev/tryswift-student-hackathon-2026

 
 

Repository files navigation

tryswift-student-hackathon-2026

try! Swift 学生ハッカソン 2026 でチームで作った 学習用 Swift Macro 3 本 のリポジトリ。

「Swift 言語ハッカーの深淵を覗く」というハッカソンテーマに沿って、 自分たちで Swift Macro を書いて、Swift コンパイラに何ができるかを身体で覚える ことを目的としている。

含まれているマクロ

マクロ 種別 学べる概念
#trySwift("名前") freestanding expression ExpressionMacro の最小構成、引数パース、ExprSyntax の生成
#TODO(until: ..., ...) freestanding expression context.diagnose によるエラー発行、FixIt でのクイック修正、マクロ展開時の副作用
@MiniCodable attached extension ExtensionMacroDeclGroupSyntax の走査、Codable のボイラープレート自動生成

詳しい使い方・コードの読み方・学びのポイントは STUDY.md を参照。 発表台本は PRESENTATION.md を参照。

動かし方

ビルド

swift build

テスト

swift test

7 つの assertMacroExpansion ベースのテストが動く。

サンプル実行

swift run tryswift-student-hackathon-2026Client

3 つのマクロを実際に呼び出すサンプル (Sources/tryswift-student-hackathon-2026Client/main.swift) が走り、#trySwift の出力、@MiniCodable 経由の JSON encode / decode 結果が表示される。

#TODO の期限切れエラーを体感したい場合は、main.swift の中の #TODO(until: "2099-01-01", ...)"2020-01-01" のような過去日付に書き換えてから ビルドすると、Xcode / コンパイラからコンパイルエラーと FixIt が出る様子を観察できる。

ディレクトリ構成

.
├── Package.swift
├── README.md
├── STUDY.md            学びのポイント解説
├── PRESENTATION.md     発表台本
├── Sources
│   ├── tryswift-student-hackathon-2026Macros
│   │   ├── Plugin.swift              CompilerPlugin 登録
│   │   ├── TrySwiftMacro.swift       #trySwift 実装
│   │   ├── TODOMacro.swift           #TODO 実装
│   │   └── MiniCodableMacro.swift    @MiniCodable 実装
│   ├── tryswift-student-hackathon-2026
│   │   └── tryswift_student_hackathon_2026.swift   public macro 宣言
│   └── tryswift-student-hackathon-2026Client
│       └── main.swift                サンプル実行ファイル
└── Tests
    └── tryswift-student-hackathon-2026Tests
        └── tryswift_student_hackathon_2026Tests.swift   全マクロのテスト

必要な環境

  • Swift 6.0+ (リポジトリは swift-tools-version 6.2 を宣言)
  • swift-syntax 602.0.0+
  • macOS / Linux のいずれか (マクロのビルドはホスト側 toolchain で実行される)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 100.0%