Skip to content
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

Swift 5.7 support: Replace the AssociatedTypeRequirementsKit package with native casts #8

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"object": {
"pins": [
{
"package": "AssociatedTypeRequirementsKit",
"repositoryURL": "https://github.com/nerdsupremacist/AssociatedTypeRequirementsKit.git",
"state": {
"branch": null,
"revision": "2e4c49c21ffb2135f1c99fbfcf2119c9d24f5e8c",
"version": "0.3.2"
}
},
{
"package": "FineJSON",
"repositoryURL": "https://github.com/omochi/FineJSON.git",
Expand Down
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let package = Package(
.library(name: "MetadataSystem", targets: ["MetadataSystem"])
],
dependencies: [
.package(url: "https://github.com/nerdsupremacist/AssociatedTypeRequirementsKit.git", .upToNextMinor(from: "0.3.2")),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/norio-nomura/XCTAssertCrash.git", from: "0.2.0"),
.package(url: "https://github.com/omochi/FineJSON.git", from: "1.14.0")
Expand All @@ -36,8 +35,7 @@ let package = Package(
.target(
name: "MetadataSystem",
dependencies: [
.target(name: "ApodiniContext"),
.product(name: "AssociatedTypeRequirementsKit", package: "AssociatedTypeRequirementsKit")
.target(name: "ApodiniContext")
]
),
.target(
Expand Down
64 changes: 12 additions & 52 deletions Sources/MetadataSystem/MetadataParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import ApodiniContext
@_implementationOnly import AssociatedTypeRequirementsVisitor

/// An instance of this protocol is used to visit a ``AnyMetadata`` tree.
public protocol MetadataParser {
Expand Down Expand Up @@ -77,14 +76,18 @@ public extension MetadataParser {
extension MetadataParser {
// swiftlint:disable:next identifier_name
func _visit<Definition: MetadataDefinition>(definition: Definition) {
if StandardEmptyMetadataVisitor(parser: self)(definition) == nil {
if let emptyBlock = definition as? any EmptyMetadata {
lukaskollmer marked this conversation as resolved.
Show resolved Hide resolved
emptyBlock._accept(parser: self)
} else {
self.visit(definition: definition)
}
}

// swiftlint:disable:next identifier_name
func _visit<Block: AnyMetadataBlock>(block: Block) {
if StandardRestrictedMetadataBlockVisitor(parser: self)(block) == nil {
if let restrictedBlock = block as? any RestrictedMetadataBlock {
restrictedBlock._accept(parser: self)
} else {
self.visit(block: block)
}
}
Expand All @@ -106,58 +109,15 @@ public struct StandardMetadataParser: MetadataParser {
}


private protocol RestrictedMetadataBlockVisitor: AssociatedTypeRequirementsVisitor {
associatedtype Visitor = RestrictedMetadataBlockVisitor
associatedtype Input = RestrictedMetadataBlock
associatedtype Output

func callAsFunction<M: RestrictedMetadataBlock>(_ value: M) -> Output
}

private struct TestBlock: RestrictedMetadataBlock {
typealias RestrictedContent = TestBlock
var typeErasedContent: AnyMetadata {
fatalError("Not implemented!")
}
}

private extension RestrictedMetadataBlockVisitor {
@inline(never)
@_optimize(none)
func _test() {
_ = self(TestBlock())
}
}

private struct StandardRestrictedMetadataBlockVisitor: RestrictedMetadataBlockVisitor {
var parser: MetadataParser
func callAsFunction<M: RestrictedMetadataBlock>(_ value: M) {
parser.visit(restrictedBlock: value)
extension RestrictedMetadataBlock {
fileprivate func _accept(parser: MetadataParser) {
parser.visit(restrictedBlock: self)
}
}


private protocol EmptyMetadataVisitor: AssociatedTypeRequirementsVisitor {
associatedtype Visitor = EmptyMetadataVisitor
associatedtype Input = EmptyMetadata
associatedtype Output

func callAsFunction<M: EmptyMetadata>(_ value: M) -> Output
}

private struct TestEmpty: EmptyMetadata {}

private extension EmptyMetadataVisitor {
@inline(never)
@_optimize(none)
func _test() {
_ = self(TestEmpty())
}
}

private struct StandardEmptyMetadataVisitor: EmptyMetadataVisitor {
var parser: MetadataParser
func callAsFunction<M: EmptyMetadata>(_ value: M) {
parser.visit(empty: value)
extension EmptyMetadata {
fileprivate func _accept(parser: MetadataParser) {
parser.visit(empty: self)
}
}