Skip to content

Swift 6 Language Mode #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:6.0

import PackageDescription

Expand All @@ -19,20 +19,33 @@ let package = Package(
.target(
name: "SwiftDraw",
dependencies: [],
path: "SwiftDraw"
path: "SwiftDraw",
swiftSettings: .upcomingFeatures
),
.executableTarget(
name: "CommandLine",
dependencies: ["SwiftDraw"],
path: "CommandLine"
path: "CommandLine",
swiftSettings: .upcomingFeatures
),
.testTarget(
name: "SwiftDrawTests",
dependencies: ["SwiftDraw"],
path: "SwiftDrawTests",
resources: [
.copy("Test.bundle")
]
],
swiftSettings: .upcomingFeatures
)
]
)

extension Array where Element == SwiftSetting {

static var upcomingFeatures: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
.swiftLanguageMode(.v6)
]
}
}
38 changes: 38 additions & 0 deletions Package@swift-5.8.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version:5.8

import PackageDescription

let package = Package(
name: "SwiftDraw",
platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.executable(name: "swiftdrawcli", targets: ["CommandLine"]),
.library(
name: "SwiftDraw",
targets: ["SwiftDraw"]),
],
dependencies: [],
targets: [
.target(
name: "SwiftDraw",
dependencies: [],
path: "SwiftDraw"
),
.executableTarget(
name: "CommandLine",
dependencies: ["SwiftDraw"],
path: "CommandLine"
),
.testTarget(
name: "SwiftDrawTests",
dependencies: ["SwiftDraw"],
path: "SwiftDrawTests",
resources: [
.copy("Test.bundle")
]
)
]
)
38 changes: 38 additions & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "SwiftDraw",
platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.executable(name: "swiftdrawcli", targets: ["CommandLine"]),
.library(
name: "SwiftDraw",
targets: ["SwiftDraw"]),
],
dependencies: [],
targets: [
.target(
name: "SwiftDraw",
dependencies: [],
path: "SwiftDraw"
),
.executableTarget(
name: "CommandLine",
dependencies: ["SwiftDraw"],
path: "CommandLine"
),
.testTarget(
name: "SwiftDrawTests",
dependencies: ["SwiftDraw"],
path: "SwiftDrawTests",
resources: [
.copy("Test.bundle")
]
)
]
)
4 changes: 2 additions & 2 deletions SwiftDraw/CommandLine.Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ private extension XMLParser.Scanner {
}

extension SVG.Options {
static let disableTransparencyLayers = Self(rawValue: 1 << 8)
static let commandLine = Self(rawValue: 1 << 9)
static var disableTransparencyLayers: SVG.Options { Self(rawValue: 1 << 8) }
static var commandLine: SVG.Options { Self(rawValue: 1 << 9) }
}

extension URL {
Expand Down
16 changes: 8 additions & 8 deletions SwiftDraw/DOM.Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ extension DOM {

class Element {}

class GraphicsElement: Element, ElementAttributes {
class GraphicsElement: Element, ElementAttributes, @unchecked Sendable {
var id: String?
var `class`: String?

var attributes = PresentationAttributes()
var style = PresentationAttributes()
}

final class Line: GraphicsElement {
final class Line: GraphicsElement, @unchecked Sendable {
var x1: Coordinate
var y1: Coordinate
var x2: Coordinate
Expand All @@ -67,7 +67,7 @@ extension DOM {
}
}

final class Circle: GraphicsElement {
final class Circle: GraphicsElement, @unchecked Sendable {
var cx: Coordinate?
var cy: Coordinate?
var r: Coordinate
Expand All @@ -80,7 +80,7 @@ extension DOM {
}
}

final class Ellipse: GraphicsElement {
final class Ellipse: GraphicsElement, @unchecked Sendable {
var cx: Coordinate?
var cy: Coordinate?
var rx: Coordinate
Expand All @@ -95,7 +95,7 @@ extension DOM {
}
}

final class Rect: GraphicsElement {
final class Rect: GraphicsElement, @unchecked Sendable {
var x: Coordinate?
var y: Coordinate?
var width: Coordinate
Expand All @@ -113,7 +113,7 @@ extension DOM {
}
}

final class Polyline: GraphicsElement {
final class Polyline: GraphicsElement, @unchecked Sendable {
var points: [Point]

init(points: [Point]) {
Expand All @@ -122,7 +122,7 @@ extension DOM {
}
}

final class Polygon: GraphicsElement {
final class Polygon: GraphicsElement, @unchecked Sendable {
var points: [Point]

init(points: [Point]) {
Expand All @@ -131,7 +131,7 @@ extension DOM {
}
}

final class Group: GraphicsElement, ContainerElement {
final class Group: GraphicsElement, ContainerElement, @unchecked Sendable {
var childElements = [GraphicsElement]()
}
}
2 changes: 1 addition & 1 deletion SwiftDraw/DOM.Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// 3. This notice may not be removed or altered from any source distribution.
//
extension DOM {
final class Image: GraphicsElement {
final class Image: GraphicsElement, @unchecked Sendable {
var href: URL
var width: Coordinate?
var height: Coordinate?
Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/DOM.Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Foundation

extension DOM {

final class Path: GraphicsElement {
final class Path: GraphicsElement, @unchecked Sendable {

// segments[0] should always be a .move
var segments: [Segment]
Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/DOM.SVG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//

extension DOM {
final class SVG: GraphicsElement, ContainerElement {
final class SVG: GraphicsElement, ContainerElement, @unchecked Sendable {
var x: Coordinate?
var y: Coordinate?
var width: Length
Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/DOM.Switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//

extension DOM {
final class Switch: GraphicsElement, ContainerElement {
final class Switch: GraphicsElement, ContainerElement, @unchecked Sendable {
var childElements = [DOM.GraphicsElement]()
}
}
4 changes: 2 additions & 2 deletions SwiftDraw/DOM.Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Foundation

extension DOM {

final class Text: GraphicsElement {
final class Text: GraphicsElement, @unchecked Sendable {
var x: Coordinate?
var y: Coordinate?
var value: String
Expand All @@ -45,7 +45,7 @@ extension DOM {
}
}

final class Anchor: GraphicsElement, ContainerElement {
final class Anchor: GraphicsElement, ContainerElement, @unchecked Sendable {
var href: URL?
var childElements = [GraphicsElement]()
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftDraw/DOM.Use.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//

extension DOM {
final class Use: GraphicsElement {
final class Use: GraphicsElement, @unchecked Sendable {
var x: Coordinate?
var y: Coordinate?

Expand Down Expand Up @@ -61,7 +61,7 @@ extension Array<DOM.GraphicsElement> {
if element.id == id {
return element
}
if let container = element as? ContainerElement {
if let container = element as? any ContainerElement {
return container.childElements.firstGraphicsElement(with: id)
}
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/LayerTree.Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extension LayerTree {

if let contents = makeContents(from: currentElement, with: newState) {
layer.appendContents(contents)
} else if let container = currentElement as? ContainerElement {
} else if let container = currentElement as? any ContainerElement {
// Push children in reverse so they are processed in the original order
for child in container.childElements.reversed() {
stack.append((child, newState, layer))
Expand Down
12 changes: 6 additions & 6 deletions SwiftDraw/LayerTree.CommandGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ extension LayerTree {
case layer(LayerTree.Layer)
}

func makeRenderContents(for contents: Layer.Contents, colorConverter: ColorConverter) -> RenderContents {
func makeRenderContents(for contents: Layer.Contents, colorConverter: any ColorConverter) -> RenderContents {
switch contents {
case .shape(let shape, let stroke, let fill):
return .simple(renderCommands(for: shape, stroke: stroke, fill: fill, colorConverter: colorConverter))
Expand All @@ -189,7 +189,7 @@ extension LayerTree {
func renderCommands(for shape: Shape,
stroke: StrokeAttributes,
fill: FillAttributes,
colorConverter: ColorConverter) -> [RendererCommand<P.Types>] {
colorConverter: any ColorConverter) -> [RendererCommand<P.Types>] {
var commands = [RendererCommand<P.Types>]()
let path = provider.createPath(from: shape)

Expand Down Expand Up @@ -330,7 +330,7 @@ extension LayerTree {
return frame
}

func renderCommands(for text: String, at point: Point, attributes: TextAttributes, colorConverter: ColorConverter = DefaultColorConverter()) -> [RendererCommand<P.Types>] {
func renderCommands(for text: String, at point: Point, attributes: TextAttributes, colorConverter: any ColorConverter = .default) -> [RendererCommand<P.Types>] {
guard let path = provider.createPath(from: text, at: point, with: attributes) else { return [] }

let converted = colorConverter.createColor(from: attributes.color)
Expand Down Expand Up @@ -430,7 +430,7 @@ extension LayerTree {
func renderCommands(forLinear gradient: LayerTree.LinearGradient,
endpoints: (start: LayerTree.Point, end: LayerTree.Point),
opacity: LayerTree.Float,
colorConverter: ColorConverter) -> [RendererCommand<P.Types>] {
colorConverter: any ColorConverter) -> [RendererCommand<P.Types>] {
let pathStart: LayerTree.Point
let pathEnd: LayerTree.Point
switch gradient.units {
Expand Down Expand Up @@ -464,7 +464,7 @@ extension LayerTree {
func renderCommands(forRadial gradient: RadialGradient,
in bounds: LayerTree.Rect,
opacity: LayerTree.Float,
colorConverter: ColorConverter) -> [RendererCommand<P.Types>] {
colorConverter: any ColorConverter) -> [RendererCommand<P.Types>] {
let startCenter: LayerTree.Point
let startRadius: LayerTree.Float
let endCenter: LayerTree.Point
Expand Down Expand Up @@ -560,7 +560,7 @@ private extension LayerTree.Rect {


private extension LayerTree.Gradient {
func convertColor(using converter: ColorConverter) -> LayerTree.Gradient {
func convertColor(using converter: any ColorConverter) -> LayerTree.Gradient {
let stops: [LayerTree.Gradient.Stop] = stops.map { stop in
var stop = stop
stop.color = converter.createColor(from: stop.color).withMultiplyingAlpha(stop.opacity)
Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/LayerTree.Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension LayerTree {
case linearGradient(LinearGradient)
case radialGradient(RadialGradient)

static let none = Fill.color(.none)
static var none: Fill { .color(.none) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftDraw/LayerTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension LayerTree {
typealias Filter = DOM.Filter.Effect

enum Error: Swift.Error {
case unsupported(Any)
case unsupported(any Sendable)
case invalid(String)
}

Expand Down
4 changes: 2 additions & 2 deletions SwiftDraw/Parser.XML.Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ extension XMLParser {
// attributes["fill"] == "red"
final class Attributes: AttributeParser {

let parser: AttributeValueParser
let parser: any AttributeValueParser
let options: XMLParser.Options

let element: [String: String]
let style: [String: String]

init(parser: AttributeValueParser,
init(parser: any AttributeValueParser,
options: XMLParser.Options = [],
element: [String: String],
style: [String: String]) {
Expand Down
Loading