Skip to content

Commit

Permalink
Merge pull request #401 from tayloraswift/custom-conditions
Browse files Browse the repository at this point in the history
implement a way to pass custom defines from SSGC.CompileCommand down to SSGC.Linker.Tables
  • Loading branch information
tayloraswift authored Jan 18, 2025
2 parents 9765cfd + 4c1040a commit ab0a161
Show file tree
Hide file tree
Showing 33 changed files with 664 additions and 197 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "e1e5bc4097a648e30bd54ed58c2183ece694fa7de97d79d6e3ac430b8877cf50",
"originHash" : "ac889a2138081f33b7082197e1abaad3a29c5bd9bfc43d6642472e675a7b8fdc",
"pins" : [
{
"identity" : "indexstore-db",
Expand Down Expand Up @@ -186,8 +186,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tayloraswift/swift-ucf",
"state" : {
"revision" : "b9e4a2d860a47877c0ee71c56f2381587609e086",
"version" : "0.1.0"
"revision" : "f3f9ed12bad3915fefb5653fd0eda8555b586c97",
"version" : "0.2.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let package:Package = .init(
.package(url: "https://github.com/tayloraswift/swift-png", .upToNextMinor(
from: "4.4.9")),
.package(url: "https://github.com/tayloraswift/swift-ucf", .upToNextMinor(
from: "0.1.0")),
from: "0.2.0")),
.package(url: "https://github.com/tayloraswift/swift-unixtime", .upToNextMinor(
from: "0.2.0")),

Expand Down
40 changes: 0 additions & 40 deletions Sources/LinkResolution/Codelinks/UCF.ConditionFilter (ext).swift

This file was deleted.

25 changes: 25 additions & 0 deletions Sources/LinkResolution/UCF.ConditionError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import UCF

extension UCF
{
@frozen @usableFromInline
enum ConditionError:Error
{
case value(Condition, String)
case valueExpected(Condition)
}
}
extension UCF.ConditionError:CustomStringConvertible
{
@usableFromInline
var description:String
{
switch self
{
case .value(let condition, let value):
"value '\(value)' is invalid for condition '\(condition)'"
case .valueExpected(let condition):
"value expected for condition '\(condition)'"
}
}
}
44 changes: 44 additions & 0 deletions Sources/LinkResolution/UCF.ConditionFilter (ext).swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import UCF

extension UCF.ConditionFilter
{
@inlinable public
func value<T>(as _:T.Type = T.self) throws -> T where T:LosslessStringConvertible
{
guard
let value:String = self.value
else
{
throw UCF.ConditionError.valueExpected(self.label)
}

guard
let result:T = .init(value)
else
{
throw UCF.ConditionError.value(self.label, value)
}

return result
}

func callAsFunction<T>(as _:T.Type = T.self,
default:T) throws -> (UCF.Condition, T) where T:LosslessStringConvertible
{
guard
let value:String = self.value
else
{
return (self.label, `default`)
}

guard
let result:T = .init(value)
else
{
throw UCF.ConditionError.value(self.label, value)
}

return (self.label, result)
}
}
97 changes: 4 additions & 93 deletions Sources/LinkResolution/UCF.DisambiguationTraits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,111 +14,22 @@ extension UCF
public
let kinks:Phylum.Decl.Kinks
public
let async:Bool
public
let hash:FNV24

@inlinable public
init(autograph:Autograph?,
phylum:Phylum.Decl,
kinks:Phylum.Decl.Kinks,
async:Bool,
hash:FNV24)
{
self.autograph = autograph
self.phylum = phylum
self.kinks = kinks
self.async = async
self.hash = hash
}
}
}
extension UCF.DisambiguationTraits
{
static func ~= (predicate:UCF.Predicate, self:Self) -> Bool
{
if case nil = predicate.seal
{
// Macros are currently the only kind of declaration that *must* be spelled with
// trailing parentheses.
switch self.phylum
{
case .actor: break
case .associatedtype: break
case .case: break
case .class: break
case .deinitializer: break
case .enum: break
case .func: break
case .initializer: break
case .macro: return false
case .operator: break
case .protocol: break
case .struct: break
case .subscript: break
case .typealias: break
case .var: break
}
}
else
{
switch self.phylum
{
case .actor: return false
case .associatedtype: return false
case .case: break
case .class: return false
case .deinitializer: return false
case .enum: return false
case .func: break
case .initializer: break
case .macro: break
case .operator: break
case .protocol: return false
case .struct: return false
case .subscript: break
case .typealias: return false
case .var: return false
}
}

guard
let suffix:UCF.Selector.Suffix = predicate.suffix
else
{
return true
}

switch suffix
{
case .unidoc(let filter):
if let signature:UCF.SignatureFilter = filter.signature
{
// If a signature filter is present, the declaration must have an autograph.
guard
let autograph:UCF.Autograph = self.autograph, signature ~= autograph
else
{
return false
}
}

let decl:(Phylum.Decl, Phylum.Decl.Kinks) = (self.phylum, self.kinks)
for condition:UCF.ConditionFilter in filter.conditions
{
guard condition ~= decl
else
{
return false
}
}

return true

case .legacy(let filter, nil):
return filter ~= self.phylum

case .legacy(_, let hash?):
return hash == self.hash

case .hash(let hash):
return hash == self.hash
}
}
}
Loading

0 comments on commit ab0a161

Please sign in to comment.