Skip to content

Commit

Permalink
This patch adds **unavailable** I128 and U128 models (#143).
Browse files Browse the repository at this point in the history
The underlying `Swift.Int128` and `Swift.UInt128` models fail some tests (crash). I have submitted some fixes that got merged into the `Swift 6.1` branch. I'll try again later and make the `I128` and `U128` available when all tests pass successfully.
  • Loading branch information
oscbyspro committed Dec 17, 2024
1 parent a8af93f commit db12067
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 31 deletions.
28 changes: 18 additions & 10 deletions Sources/CoreIop/BinaryInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ import CoreKit
// MARK: * Binary Integer
//*============================================================================*

extension IX: CompactIntegerInteroperable { }
extension I8: CompactIntegerInteroperable { }
extension I16: CompactIntegerInteroperable { }
extension I32: CompactIntegerInteroperable { }
extension I64: CompactIntegerInteroperable { }
extension IX: CompactIntegerInteroperable { }
extension I8: CompactIntegerInteroperable { }
extension I16: CompactIntegerInteroperable { }
extension I32: CompactIntegerInteroperable { }
extension I64: CompactIntegerInteroperable { }

extension UX: NaturalIntegerInteroperable { }
extension U8: NaturalIntegerInteroperable { }
extension U16: NaturalIntegerInteroperable { }
extension U32: NaturalIntegerInteroperable { }
extension U64: NaturalIntegerInteroperable { }
@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
extension I128: CompactIntegerInteroperable { }

extension UX: NaturalIntegerInteroperable { }
extension U8: NaturalIntegerInteroperable { }
extension U16: NaturalIntegerInteroperable { }
extension U32: NaturalIntegerInteroperable { }
extension U64: NaturalIntegerInteroperable { }

@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
extension U128: NaturalIntegerInteroperable { }
92 changes: 92 additions & 0 deletions Sources/CoreKit/Models/CoreInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,52 @@
}
}

//*============================================================================*
// MARK: * Core Int x I128
//*============================================================================*

/// A 128-bit signed binary integer.
@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
@frozen public struct I128: CoreInteger, SignedInteger, CoreIntegerWhereIsNotByte, CoreIntegerWhereIsNotToken {

public typealias Stdlib = Swift.Int128

public typealias BitPattern = Stdlib.BitPattern

public typealias Element = Self

public typealias Signitude = Self

public typealias Magnitude = U128

//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=

@usableFromInline var base: Stdlib

//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=

@inlinable public init(_ source: Stdlib) {
self.base = source
}

@inlinable public init(raw source: BitPattern) {
self.base = Stdlib(bitPattern: source)
}

@inlinable public init(integerLiteral source: Stdlib) {
self.base = source
}

@inlinable public consuming func stdlib() -> Stdlib {
self.base
}
}

//*============================================================================*
// MARK: * Core Int x UX
//*============================================================================*
Expand Down Expand Up @@ -453,3 +499,49 @@
self.base
}
}

//*============================================================================*
// MARK: * Core Int x U128
//*============================================================================*

/// A 128-bit unsigned binary integer.
@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
@frozen public struct U128: CoreInteger, UnsignedInteger, CoreIntegerWhereIsNotByte, CoreIntegerWhereIsNotToken {

public typealias Stdlib = Swift.UInt128

public typealias BitPattern = Stdlib.BitPattern

public typealias Element = Self

public typealias Signitude = I128

public typealias Magnitude = Self

//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=

@usableFromInline var base: Stdlib

//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=

@inlinable public init(_ source: Stdlib) {
self.base = source
}

@inlinable public init(raw source: BitPattern) {
self.base = source
}

@inlinable public init(integerLiteral source: Stdlib) {
self.base = source
}

@inlinable public consuming func stdlib() -> Stdlib {
self.base
}
}
21 changes: 21 additions & 0 deletions Sources/CoreKit/Stdlib/Swift+Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,24 @@ extension Int64: BitCastable {
Magnitude(bitPattern: self)
}
}

//*============================================================================*
// MARK: * Swift x Int128
//*============================================================================*

@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
extension Int128: BitCastable {

//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=

@inlinable public init(raw source: consuming Magnitude) {
self.init(bitPattern: source)
}

@inlinable public consuming func load(as type: Magnitude.Type) -> Magnitude {
Magnitude(bitPattern: self)
}
}
8 changes: 8 additions & 0 deletions Sources/CoreKit/Stdlib/Swift+UInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ extension UInt32: BitCastable { public typealias BitPattern = Magnitude }
//*============================================================================*

extension UInt64: BitCastable { public typealias BitPattern = Magnitude }

//*============================================================================*
// MARK: * Swift x UInt128
//*============================================================================*

@available(*, unavailable)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)
extension UInt128: BitCastable { public typealias BitPattern = Magnitude }
48 changes: 38 additions & 10 deletions Tests/UltimathiopTests/Utilities/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,42 @@ let typesAsLenientIntegerInteroperable: [any LenientIntegerInteroperable.Type] =
InfiniInt<IX>.self,
]

let typesAsCompactIntegerInteroperable: [any CompactIntegerInteroperable.Type] = [
IX.self, I8 .self, I16.self, I32.self, I64 .self,
DoubleInt<I8>.self, DoubleInt<DoubleInt<I8>>.self,
DoubleInt<IX>.self, DoubleInt<DoubleInt<IX>>.self,
]
let typesAsCompactIntegerInteroperable: [any CompactIntegerInteroperable.Type] = reduce([]) {
$0.append(IX .self)
$0.append(I8 .self)
$0.append(I16.self)
$0.append(I32.self)
$0.append(I64.self)

#if false
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *) {
$0.append(I128.self)
}
#endif

$0.append(DoubleInt<I8>.self)
$0.append(DoubleInt<IX>.self)

$0.append(DoubleInt<DoubleInt<I8>>.self)
$0.append(DoubleInt<DoubleInt<IX>>.self)
}

let typesAsNaturalIntegerInteroperable: [any NaturalIntegerInteroperable.Type] = [
UX.self, U8 .self, U16.self, U32.self, U64 .self,
DoubleInt<U8>.self, DoubleInt<DoubleInt<U8>>.self,
DoubleInt<UX>.self, DoubleInt<DoubleInt<UX>>.self,
]
let typesAsNaturalIntegerInteroperable: [any NaturalIntegerInteroperable.Type] = reduce([]) {
$0.append(UX .self)
$0.append(U8 .self)
$0.append(U16.self)
$0.append(U32.self)
$0.append(U64.self)

#if false
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *) {
$0.append(CoreKit.U128.self)
}
#endif

$0.append(DoubleInt<U8>.self)
$0.append(DoubleInt<UX>.self)

$0.append(DoubleInt<DoubleInt<U8>>.self)
$0.append(DoubleInt<DoubleInt<UX>>.self)
}
50 changes: 39 additions & 11 deletions Tests/UltimathnumTests/Utilities/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,42 @@ let typesAsSystemsInteger: [any SystemsInteger.Type] = {
typesAsSystemsIntegerAsUnsigned
}()

let typesAsSystemsIntegerAsSigned: [any SystemsIntegerAsSigned.Type] = [
IX.self, I8 .self, I16.self, I32.self, I64 .self,
DoubleInt<I8>.self, DoubleInt<DoubleInt<I8>>.self,
DoubleInt<IX>.self, DoubleInt<DoubleInt<IX>>.self,
]

let typesAsSystemsIntegerAsUnsigned: [any SystemsIntegerAsUnsigned.Type] = [
UX.self, U8 .self, U16.self, U32.self, U64 .self,
DoubleInt<U8>.self, DoubleInt<DoubleInt<U8>>.self,
DoubleInt<UX>.self, DoubleInt<DoubleInt<UX>>.self,
]
let typesAsSystemsIntegerAsSigned: [any SystemsIntegerAsSigned.Type] = reduce([]) {
$0.append(IX .self)
$0.append(I8 .self)
$0.append(I16.self)
$0.append(I32.self)
$0.append(I64.self)

#if false
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *) {
$0.append(I128.self)
}
#endif

$0.append(DoubleInt<I8>.self)
$0.append(DoubleInt<IX>.self)

$0.append(DoubleInt<DoubleInt<I8>>.self)
$0.append(DoubleInt<DoubleInt<IX>>.self)
}

let typesAsSystemsIntegerAsUnsigned: [any SystemsIntegerAsUnsigned.Type] = reduce([]) {
$0.append(UX .self)
$0.append(U8 .self)
$0.append(U16.self)
$0.append(U32.self)
$0.append(U64.self)

#if false
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *) {
$0.append(CoreKit.U128.self)
}
#endif

$0.append(DoubleInt<U8>.self)
$0.append(DoubleInt<UX>.self)

$0.append(DoubleInt<DoubleInt<U8>>.self)
$0.append(DoubleInt<DoubleInt<UX>>.self)
}

0 comments on commit db12067

Please sign in to comment.