Skip to content
Open
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
56 changes: 56 additions & 0 deletions COMMIT_MESSAGE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
feat!: Rename module to SwiftBigInt to fix module stability compilation

BREAKING CHANGE: Module name changed from BigInt to SwiftBigInt

## Problem
The module name "BigInt" conflicted with the struct name "public struct BigInt",
causing Swift compiler errors when building with BUILD_LIBRARY_FOR_DISTRIBUTION=YES
(required for XCFramework distribution and module stability):

```
error: 'BigInt' is not a member type of struct 'BigInt.BigInt'
```

## Solution
Renamed the module to "SwiftBigInt" following Swift community conventions
(similar to SwiftNIO, SwiftLog, SwiftCrypto).

## Changes
- Package name: Remains "BigInt" (matches repository name)
- Product name: BigInt → SwiftBigInt
- Module name: BigInt → SwiftBigInt
- Type names: UNCHANGED (BigInt and BigUInt structs remain the same)

## Migration for Consumers
Only import statements need to change:

```swift
// Before (v5.x):
import BigInt

// After (v6.0+):
import SwiftBigInt

// Type names unchanged:
let x = BigInt(100) // ✓ Still works
let y = BigUInt(50) // ✓ Still works
```

## Benefits
- ✅ Fixes module stability compilation errors
- ✅ Enables XCFramework distribution without compiler workarounds
- ✅ Eliminates need for -no-verify-emitted-module-interface flag
- ✅ Follows Swift community naming conventions
- ✅ Minimal breaking changes (import statements only)

## Files Modified
- Package.swift: Updated module and product names
- All test files (18 files): Updated imports
- Demo playground files (5 files): Updated imports
- README.md: Added migration guide
- Documentation: Updated import examples

## Version
Requires major version bump: 5.4.0 → 6.0.0

Fixes module interface verification bug when building with library evolution enabled.
16 changes: 16 additions & 0 deletions COMMIT_MESSAGE_SHORT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
feat!: Rename module to SwiftBigInt to fix module stability compilation

BREAKING CHANGE: Module name changed from BigInt to SwiftBigInt

Fixes Swift compiler error when building with BUILD_LIBRARY_FOR_DISTRIBUTION=YES:
"'BigInt' is not a member type of struct 'BigInt.BigInt'"

Changes:
- Product/module name: BigInt → SwiftBigInt
- Package name: Remains "BigInt" (repository name)
- Type names: UNCHANGED (BigInt/BigUInt still work)

Migration: Only import statements change from `import BigInt` to `import SwiftBigInt`

Follows Swift naming conventions (SwiftNIO, SwiftLog, SwiftCrypto).
Requires version bump to 6.0.0.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//: [Previous](@previous)
import BigInt
import SwiftBigInt
//: ## Let's calculate the first thousand digits of π
//:
//: A fun application of BigInts is generating the digits of π.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//: [Previous](@previous)
import Foundation
import BigInt
import SwiftBigInt
//: The canonical way to demo big integers is with the factorial function. Here is a fancy definition for it:
func fact(_ n: Int) -> BigInt {
return (1 ... n).map { BigInt($0) }.reduce(BigInt(1), *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//: [Previous](@previous)
import Foundation
import BigInt
import SwiftBigInt
//: # Generating Large Prime Numbers
//:
//: `BigUInt` has an `isPrime()` method that does a [Miller-Rabin Primality Test][mrpt]. Let's use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//: (`BigInt` represents integers in base 2^64, storing digits in an `Array<UInt64>`, so the theoretical
//: maximum value it can store is (2^64)^`Int.max` - 1.)
import Foundation
import BigInt
import SwiftBigInt
//: `BigInt` has several interesting initializers, but for now, the simplest way to create big integers is to use integer
//: or string literals. The latter is useful when you want to create a number that's larger than `UIntMax.max`:
let a: BigInt = 123
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//: [Previous](@previous)
import Foundation
import BigInt
import SwiftBigInt
//: # RSA cryptography
//:
//: Another useful thing to have is a function that finds a random n-bit prime number:
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ let package = Package(
.visionOS(.v1),
],
products: [
.library(name: "BigInt", targets: ["BigInt"])
.library(name: "SwiftBigInt", targets: ["SwiftBigInt"])
],
targets: [
.target(
name: "BigInt", path: "Sources",
name: "SwiftBigInt", path: "Sources",
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]),
.testTarget(
name: "BigIntTests", dependencies: ["BigInt"], path: "Tests",
name: "BigIntTests", dependencies: ["SwiftBigInt"], path: "Tests",
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]),
]
)
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,34 @@ Setup instructions:
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.4.0")
```

## <a name="migration">Migration from v5.x to v6.0</a>

**Module Name Change**: Starting with v6.0, the module has been renamed from `BigInt` to `SwiftBigInt` to resolve Swift compiler conflicts when building with `BUILD_LIBRARY_FOR_DISTRIBUTION=YES` (required for XCFramework distribution and module stability).

**The Issue**: The previous module name `BigInt` conflicted with the struct name `public struct BigInt`, causing compilation errors:
```
'BigInt' is not a member type of struct 'BigInt.BigInt'
```

**Migration Guide**: Simply update your import statements:
```swift
// Before (v5.x):
import BigInt

// After (v6.0+):
import SwiftBigInt
```

**Important**: Type names remain unchanged. All code using `BigInt` and `BigUInt` continues to work as before:
```swift
import SwiftBigInt // Only the import changes

let x = BigInt(100) // Type names stay the same ✓
let y = BigUInt(50) // Type names stay the same ✓
```

This change follows Swift community naming conventions (similar to `SwiftNIO`, `SwiftLog`, `SwiftCrypto`).

## <a name="notes">Implementation notes</a>

[`BigUInt`][BigUInt] is a `MutableCollectionType` of its 64-bit digits, with the least significant
Expand Down Expand Up @@ -189,7 +217,7 @@ generic variant that was slower but more flexible.
It is easy to use `BigInt` to calculate the factorial function for any integer:

```Swift
import BigInt
import SwiftBigInt

func factorial(_ n: Int) -> BigInt {
return (1 ... n).map { BigInt($0) }.reduce(BigInt(1), *)
Expand Down
43 changes: 43 additions & 0 deletions SwiftBigInt.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Pod::Spec.new do |s|
s.name = "SwiftBigInt"
s.version = "6.0.1"
s.summary = "Arbitrary-precision arithmetic in pure Swift"
s.description = <<-DESC
This library provides arbitrary-precision integer arithmetic using pure Swift.
It defines two integer types: BigUInt for unsigned integers, and BigInt for
signed integers. Both types have the full set of operations supported by Swift's
standard integer types, plus more complicated arithmetic operations like division,
exponentiation, modulo, GCD, square root, primality testing, and more.
DESC

s.homepage = "https://github.com/jlalvarez18/BigInt"
s.license = { :type => "MIT", :file => "LICENSE.md" }
s.author = { "Károly Lőrentey" => "karoly@lorentey.hu" }

s.swift_version = "5.9"

# Platform support matching Package.swift
s.ios.deployment_target = "12.0"
s.osx.deployment_target = "10.13"

s.source = { :git => "https://github.com/jlalvarez18/BigInt.git", :tag => "v#{s.version}" }
s.source_files = "Sources/**/*.swift"

s.module_name = "SwiftBigInt"
s.requires_arc = true

# Enable strict concurrency as specified in Package.swift
s.pod_target_xcconfig = {
'SWIFT_STRICT_CONCURRENCY' => 'complete'
}

s.frameworks = "Foundation"

# Test spec
s.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'Tests/**/*.swift'
test_spec.pod_target_xcconfig = {
'SWIFT_STRICT_CONCURRENCY' => 'complete'
}
end
end
2 changes: 1 addition & 1 deletion Tests/BigIntTests/BigIntTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
@testable import BigInt
@testable import SwiftBigInt
import Foundation

class BigIntTests: XCTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/BigUIntTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import XCTest
import Foundation
@testable import BigInt
@testable import SwiftBigInt

extension BigUInt.Kind: Equatable {
public static func ==(left: BigUInt.Kind, right: BigUInt.Kind) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/ProfileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
import BigInt
import SwiftBigInt

#if Profile

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Tools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 Károly Lőrentey. All rights reserved.
//

import BigInt
import SwiftBigInt

@inline(never)
func noop<T>(_ value: T) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet - Helpers/BitWidthTestCases.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file was written by LiarPrincess for Violet - Python VM written in Swift.
// https://github.com/LiarPrincess/Violet

@testable import BigInt
@testable import SwiftBigInt

internal enum BitWidthTestCases {

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet - Helpers/GenerateValues.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file was written by LiarPrincess for Violet - Python VM written in Swift.
// https://github.com/LiarPrincess/Violet

@testable import BigInt
@testable import SwiftBigInt

// MARK: - Int

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet - Helpers/StringTestCases.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file was written by LiarPrincess for Violet - Python VM written in Swift.
// https://github.com/LiarPrincess/Violet

@testable import BigInt
@testable import SwiftBigInt

// swiftlint:disable number_separator
// swiftlint:disable line_length
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet - Helpers/WordsTestCases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// MARK: - Asserts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// swiftlint:disable type_name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// swiftlint:disable type_name

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntCOWTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// swiftlint:disable file_length

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// Well… actually… hash and equatable
class BigIntHashTests: XCTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntIntegerInitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

private typealias Word = BigInt.Word

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntPowerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

class BigIntPowerTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntPropertyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

private typealias Word = BigInt.Word

Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/Violet/BigIntStringInitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/LiarPrincess/Violet

import XCTest
@testable import BigInt
@testable import SwiftBigInt

private typealias Word = BigInt.Word
private typealias WordsExpected = (words: [Word], expected: String)
Expand Down
2 changes: 1 addition & 1 deletion Tests/BigIntTests/WordTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
@testable import BigInt
@testable import SwiftBigInt

// TODO: Return to `where Word.Magnitude == Word` when SR-13491 is resolved
struct TestDivision<Word: FixedWidthInteger> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h2 id='a-name-samples-calculation-samples-a' class='heading'><a name="samples">
<h3 id='a-name-factorial-obligatory-factorial-demo-a' class='heading'><a name="factorial">Obligatory Factorial Demo</a></h3>

<p>It is easy to use <code><a href="Structs/BigInt.html">BigInt</a></code> to calculate the factorial function for any integer:</p>
<pre class="highlight plaintext"><code>import BigInt
<pre class="highlight plaintext"><code>import SwiftBigInt

func factorial(_ n: Int) -&gt; BigInt {
return (1 ... n).map { BigInt($0) }.reduce(BigInt(1), *)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h2 id='a-name-samples-calculation-samples-a' class='heading'><a name="samples">
<h3 id='a-name-factorial-obligatory-factorial-demo-a' class='heading'><a name="factorial">Obligatory Factorial Demo</a></h3>

<p>It is easy to use <code><a href="Structs/BigInt.html">BigInt</a></code> to calculate the factorial function for any integer:</p>
<pre class="highlight plaintext"><code>import BigInt
<pre class="highlight plaintext"><code>import SwiftBigInt

func factorial(_ n: Int) -&gt; BigInt {
return (1 ... n).map { BigInt($0) }.reduce(BigInt(1), *)
Expand Down