Skip to content

Commit

Permalink
Merge pull request #137 from orchetect/hotfix
Browse files Browse the repository at this point in the history
Fussy Swift compiler hotfix
  • Loading branch information
orchetect authored Sep 2, 2022
2 parents 829c183 + 80589ad commit 80baa7a
Show file tree
Hide file tree
Showing 11 changed files with 1,145 additions and 231 deletions.
70 changes: 70 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/MIDIKit-CI.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,76 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MIDIKitCore"
BuildableName = "MIDIKitCore"
BlueprintName = "MIDIKitCore"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MIDIKitIO"
BuildableName = "MIDIKitIO"
BlueprintName = "MIDIKitIO"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MIDIKitControlSurfaces"
BuildableName = "MIDIKitControlSurfaces"
BlueprintName = "MIDIKitControlSurfaces"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MIDIKitSync"
BuildableName = "MIDIKitSync"
BlueprintName = "MIDIKitSync"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MIDIKitSMF"
BuildableName = "MIDIKitSMF"
BlueprintName = "MIDIKitSMF"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ extension HUIParameter {
/// Construct from a HUI zone and port pair.
/// Returns `nil` if the pair is undefined.
public init?(
zone: UInt8,
port: UInt4
zone: HUIZone,
port: HUIPort
) {
guard let parameter = HUIParameter.allCases
.first(where: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public enum HUICoreEvent: Hashable {
)

case `switch`(
zone: UInt8,
port: UInt4,
zone: HUIZone,
port: HUIPort,
state: Bool
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ extension HUISurface {

/// Unhandled/unrecognized switch.
case unhandledSwitch(
zone: UInt8,
port: UInt4,
zone: HUIZone,
port: HUIPort,
state: Bool
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ extension HUISurface.State {
}

private mutating func updateState_Switch(
zone: UInt8,
port: UInt4,
zone: HUIZone,
port: HUIPort,
state: Bool
) -> HUISurface.Event? {
guard let param = HUIParameter(zone: zone, port: port)
Expand Down
225 changes: 7 additions & 218 deletions Sources/MIDIKitCore/Types/MIDIUnsignedInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ where Magnitude == Storage.Magnitude,

// FixedWidthInteger types declared without conforming to FixedWidthInteger
static var bitWidth: Int { get }

// FixedWidthInteger types declared without conforming to FixedWidthInteger
static var min: Self { get }

// FixedWidthInteger types declared without conforming to FixedWidthInteger
static var max: Self { get }
}

protocol _MIDIUnsignedInteger: MIDIUnsignedInteger {
internal protocol _MIDIUnsignedInteger: MIDIUnsignedInteger {
/// Internal: Type name for use in debugging and exceptions.
static var integerName: StaticString { get }

Expand Down Expand Up @@ -114,74 +110,6 @@ extension _MIDIUnsignedInteger {
}
}

// MARK: - Equatable

extension _MIDIUnsignedInteger /*: Equatable */ {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.storage == rhs.storage
}
}

// MARK: - Comparable

extension _MIDIUnsignedInteger /*: Comparable */ {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.storage < rhs.storage
}
}

// MARK: - Hashable

extension _MIDIUnsignedInteger /*: Hashable */ {
public func hash(into hasher: inout Hasher) {
hasher.combine(storage)
}
}

// MARK: - Codable

extension _MIDIUnsignedInteger /*: Codable */ {
public func encode(to encoder: Encoder) throws {
var e = encoder.singleValueContainer()
try e.encode(storage)
}

public init(from decoder: Decoder) throws {
let d = try decoder.singleValueContainer()
let decoded = try d.decode(Storage.self)
guard let new = Self(exactly: decoded) else {
throw DecodingError.dataCorrupted(
.init(codingPath: decoder.codingPath,
debugDescription: "Encoded value is not a valid \(Self.integerName).")
)
}
self = new
}
}

// MARK: - CustomStringConvertible

extension _MIDIUnsignedInteger {//: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
storage.description
}

public var debugDescription: String {
"\(Self.integerName)(\(storage.description))"
}
}

// MARK: - ExpressibleByIntegerLiteral

extension MIDIUnsignedInteger /*: ExpressibleByIntegerLiteral */ {
//public typealias IntegerLiteralType = Storage
// IntegerLiteralType is already expressed as same-type constraint on MIDIUnsignedInteger

public init(integerLiteral value: Storage) {
self.init(value)
}
}

// MARK: - Strideable

extension MIDIUnsignedInteger /*: Strideable */ {
Expand All @@ -197,152 +125,13 @@ extension MIDIUnsignedInteger /*: Strideable */ {
}
}

// MARK: - _MIDIUnsignedInteger Default Implementation

extension _MIDIUnsignedInteger {
static func min<T: BinaryInteger>(as ofType: T.Type) -> T { 0 }
static func min<T: BinaryFloatingPoint>(as ofType: T.Type) -> T { 0 }

static func max<T: BinaryInteger>(as ofType: T.Type) -> T {
(0 ..< bitWidth)
.reduce(into: T()) { $0 |= (0b1 << $1) }
}

static func max<T: BinaryFloatingPoint>(as ofType: T.Type) -> T {
T(max(as: Int.self))
}
}

// MARK: - MIDIUnsignedInteger Conveniences

extension _MIDIUnsignedInteger {
/// Returns the integer converted to an `Int` instance (convenience).
public var intValue: Int { Int(storage) }
}

// MARK: - FixedWidthInteger

extension _MIDIUnsignedInteger /*: FixedWidthInteger */ {
public static var min: Self { Self(Self.min(as: Storage.self)) }

public static var max: Self { Self(Self.max(as: Storage.self)) }

// this would be synthesized if MIDIUnsignedInteger conformed to FixedWidthInteger
public static func >>= <RHS>(lhs: inout Self, rhs: RHS) where RHS : BinaryInteger {
lhs.storage >>= rhs
}

// this would be synthesized if MIDIUnsignedInteger conformed to FixedWidthInteger
public static func <<= <RHS>(lhs: inout Self, rhs: RHS) where RHS : BinaryInteger {
lhs.storage <<= rhs
}
}

// MARK: - Numeric

extension _MIDIUnsignedInteger /*: Numeric */ {
// public typealias Magnitude = Storage.Magnitude
// Magnitude is already expressed as same-type constraint on MIDIUnsignedInteger

public var magnitude: Storage.Magnitude {
storage.magnitude
}

public init?<T>(exactly source: T) where T: BinaryInteger {
if source < Self.min(as: Storage.self) ||
source > Self.max(as: Storage.self)
{
return nil
}
self.init(unchecked: Storage(source))
}

public static func * (lhs: Self, rhs: Self) -> Self {
Self(lhs.storage * rhs.storage)
}

public static func *= (lhs: inout Self, rhs: Self) {
lhs = Self(lhs.storage * rhs.storage)
}
}

// MARK: - AdditiveArithmetic

extension _MIDIUnsignedInteger /*: AdditiveArithmetic */ {
// static let zero synthesized by AdditiveArithmetic

public static func + (lhs: Self, rhs: Self) -> Self {
Self(lhs.storage + rhs.storage)
}

// += operator synthesized by AdditiveArithmetic

public static func - (lhs: Self, rhs: Self) -> Self {
Self(lhs.storage - rhs.storage)
}

// -= operator synthesized by AdditiveArithmetic
}

// MARK: - BinaryInteger
// MARK: - ExpressibleByIntegerLiteral

extension _MIDIUnsignedInteger /*: BinaryInteger */ {
// public typealias Words = Storage.Words
// Words is already expressed as same-type constraint on MIDIUnsignedInteger

public var words: Storage.Words {
storage.words
}

// synthesized?
// public static var isSigned: Bool { false }

public var bitWidth: Int { Self.bitWidth }

public var trailingZeroBitCount: Int {
storage.trailingZeroBitCount - (storage.bitWidth - Self.bitWidth)
}

public static func / (lhs: Self, rhs: Self) -> Self {
Self(lhs.storage / rhs.storage)
}

public static func /= (lhs: inout Self, rhs: Self) {
lhs = Self(lhs.storage / rhs.storage)
}

public static func % (lhs: Self, rhs: Self) -> Self {
Self(lhs.storage % rhs.storage)
}

public static func << <RHS>(lhs: Self, rhs: RHS) -> Self
where RHS: BinaryInteger {
Self(lhs.storage << rhs)
}

public static func >> <RHS>(lhs: Self, rhs: RHS) -> Self
where RHS: BinaryInteger {
Self(lhs.storage >> rhs)
}

public static func %= (lhs: inout Self, rhs: Self) {
lhs.storage %= rhs.storage
}

public static func &= (lhs: inout Self, rhs: Self) {
lhs.storage &= rhs.storage
}

public static func |= (lhs: inout Self, rhs: Self) {
lhs.storage |= rhs.storage
}

public static func ^= (lhs: inout Self, rhs: Self) {
lhs.storage ^= rhs.storage
}
extension MIDIUnsignedInteger /*: ExpressibleByIntegerLiteral */ {
//public typealias IntegerLiteralType = Storage
// IntegerLiteralType is already expressed as same-type constraint on MIDIUnsignedInteger

public static prefix func ~ (x: Self) -> Self {
// mask to bit width
Self(unchecked: ~x.storage & Self.max(as: Self.self).storage)
public init(integerLiteral value: Storage) {
self.init(value)
}
}
Loading

0 comments on commit 80baa7a

Please sign in to comment.