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

[SR-13491] GSB produces signatures with non-canonical same-type constraints #55933

Closed
swift-ci opened this issue Sep 3, 2020 · 11 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software Linux Platform: Linux swift for tensorflow

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 3, 2020

Previous ID SR-13491
Radar rdar://problem/65015626
Original Reporter xanderai (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Ubuntu 18.04

Additional Detail from JIRA
Votes 2
Component/s Compiler, Swift for TensorFlow
Labels Bug, CompilerCrash, Linux
Assignee @slavapestov
Priority Medium

md5: 81ed32786959c66c1898efb8b960df73

is duplicated by:

  • SR-13618 Assertion failed: (isCanonicalAnchor(secondType)), function getCanonical

Issue Description:

Recent changes in the Swift toolchain have caused the BigInt project (https://github.com/attaswift/BigInt) to produce a Swift compiler crash when building on Ubuntu 18.04. It does not occur on macOS 10.15.6.

I tested on Swift Trunk snapshots from August 31st and July 16th:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM 19447e27024a8d4, Swift f89dbd325b96dd6)
Target: x86_64-unknown-linux-gnu
$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-07-16-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM a2e0564af78e841, Swift 1224d8b2d312c55)

To reproduce:

$ git clone https://github.com/attaswift/BigInt.git
$ cd BigInt
$ swift build

The compiler crash:

$ swift build
swift-frontend: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/swift/lib/AST/GenericSignature.cpp:251:
 static swift::CanGenericSignature swift::CanGenericSignature::getCanonical(TypeArrayView<swift::GenericTypeParamType>, ArrayR
ef<swift::Requirement>, bool): Assertion `isCanonicalAnchor(secondType)' failed.
Stack dump:
0. Program arguments: /home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend -frontend -
c /home/xander/dev/BigInt/Sources/Addition.swift /home/xander/dev/BigInt/Sources/BigInt.swift /home/xander/dev/BigInt/Sources/
BigUInt.swift /home/xander/dev/BigInt/Sources/Bitwise Ops.swift /home/xander/dev/BigInt/Sources/Codable.swift /home/xander/dev
/BigInt/Sources/Comparable.swift -primary-file /home/xander/dev/BigInt/Sources/Data Conversion.swift -primary-file /home/xande
r/dev/BigInt/Sources/Division.swift -primary-file /home/xander/dev/BigInt/Sources/Exponentiation.swift -primary-file /home/xan
der/dev/BigInt/Sources/Floating Point Conversion.swift -primary-file /home/xander/dev/BigInt/Sources/GCD.swift -primary-file /
home/xander/dev/BigInt/Sources/Hashable.swift /home/xander/dev/BigInt/Sources/Integer Conversion.swift /home/xander/dev/BigInt
/Sources/Multiplication.swift /home/xander/dev/BigInt/Sources/Prime Test.swift /home/xander/dev/BigInt/Sources/Random.swift /h
ome/xander/dev/BigInt/Sources/Shifts.swift /home/xander/dev/BigInt/Sources/Square Root.swift /home/xander/dev/BigInt/Sources/S
trideable.swift /home/xander/dev/BigInt/Sources/String Conversion.swift /home/xander/dev/BigInt/Sources/Subtraction.swift /hom
e/xander/dev/BigInt/Sources/Words and Bits.swift -supplementary-output-file-map /tmp/supplementaryOutputs-092919 -target x86_6
4-unknown-linux-gnu -disable-objc-interop -I /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-versio$ 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -parse-as-library -module-name BigInt -o /home/xa$der/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion.swift.o -o /home/xander/dev/BigInt/.build/x$6_64-unknown-linux-gnu/debug/BigInt.build/Division.swift.o -o /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/B$gInt.build/Exponentiation.swift.o -o /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Floating Poin$ Conversion.swift.o -o /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/GCD.swift.o -o /home/xander$dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Hashable.swift.o -index-store-path /home/xander/dev/BigInt/.bui$d/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1. Swift version 5.3-dev (LLVM 19447e27024a8d4, Swift f89dbd325b96dd6)
2. While evaluating request TypeCheckSourceFileRequest(source_file "/home/xander/dev/BigInt/Sources/Division.swift")
3. While type-checking extension of FixedWidthInteger (at /home/xander/dev/BigInt/Sources/Division.swift:11:1)
4. While type-checking declaration 0x9d032e8 (at /home/xander/dev/BigInt/Sources/Division.swift:12:13)
5. While evaluating request PatternBindingEntryRequest((unknown decl), 0)
6. While evaluating request PatternTypeRequest((pattern @ 0x9d02ec8))
7. While canonicalizing generic signature <τ_0_0 where τ_0_0 : FixedWidthInteger, τ_0_0 == τ_0_0.Magnitude, τ_0_0.Magnit$de == τ_0_0.Magnitude.Magnitude.Magnitude> in requirement #&#8203;2
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x5232124]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x522fd1e]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x52323fc]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x128a0)[0x7f633b07b8a0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f633991df47]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f633991f8b1]
/lib/x86_64-linux-gnu/libc.so.6(+0x3042a)[0x7f633990f42a]
/lib/x86_64-linux-gnu/libc.so.6(+0x304a2)[0x7f633990f4a2]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x197ff7e]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x197f1dd]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x197f0cc]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1980377]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x18bfa25]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x145ef2f]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13e7846]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x143a308]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13edf67]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13eda66]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13e7171]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13e7144]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x14462c2]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13bf023]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13bed3f]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x13b1571]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1509f6f]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1508fb1]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x150c70b]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1508fb1]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1508ee1]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1472065]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1473270]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1472fa7]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1472eb1]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1471dae]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x1471d84]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x6467c9]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x646696]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x4fdd6c]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x491458]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f6339900b97]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift-frontend[0x49100a]

This regression is not related to any recent changes in the BigInt library. I reproduced the error on tags `master`, `v5.1.0`, `v5.2.0`, `v5.0.0`, and `v4.0.0`.

I wasn't able to find Trunk snapshots older than July 16th, but I am able to successfully compile this library with Swift for Tensorflow v0.10, which I believe is from June trunk:

$ which swift
/home/xander/swift-tensorflow-RELEASE-0.10-cuda10.2-cudnn7-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM 55d27a5828, Swift 6a5d84ec08)
Target: x86_64-unknown-linux-gnu

It also successfully complies on 5.3 release branch on Ubuntu 18.04:

$ which swift
/home/xander/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-08-31-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM 3fa9679add, Swift d24649a4d6)
Target: x86_64-unknown-linux-gnu

The regression appears specific to Trunk, and is preventing us from upgrading to Swift for Tensorflow v0.11 in our project because it breaks the build.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 2, 2020

Comment by Xander Dunn (JIRA)

This reproduces on latest Swift trunk:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-09-28-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM 8d6dfcd39f3bc7d, Swift 35d765f87cd2a30)
Target: x86_64-unknown-linux-gnu

@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 9, 2020

Comment by Xander Dunn (JIRA)

This issue is still present on Swift dev trunk 2020-10-07:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift
(base) xander@plutus-3:~/dev/BigInt$ swift --version
Swift version 5.3-dev (LLVM 240312aa7333e90, Swift 15bf0478ad7c47c)
Target: x86_64-unknown-linux-gnu
$ swift build                                                                                                                                                                           swift-frontend: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/swift/lib/AST/GenericSignature.cpp:251: static swift::CanGenericSignature swift::CanGenericSignature::getCanonical(TypeArrayView<sw$ft::GenericTypeParamType>, ArrayRef<swift::Requirement>, bool): Assertion `isCanonicalAnchor(secondType)' failed.                                                                                                          PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.                                                                                                                                      Stack dump:                                                                                                                                                                                                                0.      Program arguments: /home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend -frontend -c /home/xander/dev/BigInt/Sources/Addition.swift /home/xander/dev/BigInt/Sources/BigInt.swift /home/xander/dev/BigInt/Sources/BigUInt.swift /home/xander/dev/BigInt/Sources/Bitwise Ops.swift /home/xander/dev/BigInt/Sources/Codable.swift /home/xander/dev/BigInt/Sources/Comparable.swift -primary-file /home/xander/
dev/BigInt/Sources/Data Conversion.swift -primary-file /home/xander/dev/BigInt/Sources/Division.swift /home/xander/dev/BigInt/Sources/Exponentiation.swift /home/xander/dev/BigInt/Sources/Floating Point Conversion.swift
/home/xander/dev/BigInt/Sources/GCD.swift /home/xander/dev/BigInt/Sources/Hashable.swift /home/xander/dev/BigInt/Sources/Integer Conversion.swift /home/xander/dev/BigInt/Sources/Multiplication.swift /home/xander/dev/Big
Int/Sources/Prime Test.swift /home/xander/dev/BigInt/Sources/Random.swift /home/xander/dev/BigInt/Sources/Shifts.swift /home/xander/dev/BigInt/Sources/Square Root.swift /home/xander/dev/BigInt/Sources/Strideable.swift $
home/xander/dev/BigInt/Sources/String Conversion.swift /home/xander/dev/BigInt/Sources/Subtraction.swift /home/xander/dev/BigInt/Sources/Words and Bits.swift -emit-module-path /home/xander/dev/BigInt/.build/x86_64-unkn$
wn-linux-gnu/debug/BigInt.build/Data Conversion~partial.swiftmodule -emit-module-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Division~partial.swiftmodule -emit-module-doc-path /home/$
ander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion~partial.swiftdoc -emit-module-doc-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Division~partial.swi$
tdoc -emit-module-source-info-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion~partial.swiftsourceinfo -emit-module-source-info-path /home/xander/dev/BigInt/.build/x86_64-$
nknown-linux-gnu/debug/BigInt.build/Division~partial.swiftsourceinfo -emit-dependencies-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion.d -emit-dependencies-path /home/xa$
der/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Division.d -emit-reference-dependencies-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion.swiftdeps -emit-$
eference-dependencies-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Division.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/xander/dev/BigInt/.build/x86_64-u$
known-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymo$
s-context-mangled-names -parse-as-library -module-name BigInt -o /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/BigInt.build/Data Conversion.swift.o -o /home/xander/dev/BigInt/.build/x86_64-unknown-linux$
gnu/debug/BigInt.build/Division.swift.o -index-store-path /home/xander/dev/BigInt/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.      Swift version 5.3-dev (LLVM 240312aa7333e90, Swift 15bf0478ad7c47c)
2.      While evaluating request TypeCheckSourceFileRequest(source_file "/home/xander/dev/BigInt/Sources/Division.swift")
3.      While type-checking extension of FixedWidthInteger (at /home/xander/dev/BigInt/Sources/Division.swift:11:1)
4.      While type-checking declaration 0xa299e90 (at /home/xander/dev/BigInt/Sources/Division.swift:12:13)
5.      While evaluating request PatternBindingEntryRequest((unknown decl), 0)
6.      While evaluating request PatternTypeRequest((pattern @ 0xa299a70))
7.      While canonicalizing generic signature <τ_0_0 where τ_0_0 : FixedWidthInteger, τ_0_0 == τ_0_0.Magnitude, τ_0_0.Magnitude == τ_0_0.Magnitude.Magnitude.Magnitude> in requirement #&#8203;2
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x5663ef4]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x566198e]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x56640dc]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x128a0)[0x7fe0295e08a0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7fe027e82f47]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7fe027e848b1]
/lib/x86_64-linux-gnu/libc.so.6(+0x3042a)[0x7fe027e7442a]
/lib/x86_64-linux-gnu/libc.so.6(+0x304a2)[0x7fe027e744a2]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x19dc815]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x19dba6d]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x19db95c]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x19dcc37]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x1915c45]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x14cce7f]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x1457f96]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x14aa5b8]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x145e057]
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-07-a-ubuntu18.04/usr/bin/swift-frontend[0x145db56]

@swift-ci
Copy link
Collaborator Author

Comment by Xander Dunn (JIRA)

This issue is still present on Swift dev trunk 2020-10-15:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a-ubuntu18.04/usr/bin/swift
(base) xander@plutus-3:~/dev/BigInt$ swift --version
Swift version 5.3-dev (LLVM 2ea629d94ab01c3, Swift aa3e5904f8ba8bf)
Target: x86_64-unknown-linux-gnu

@swift-ci
Copy link
Collaborator Author

Comment by Xander Dunn (JIRA)

This issue is still present on trunk 2020-10-24:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-10-24-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM 56a74d3b9591abe, Swift 246fe46aa77b582)
Target: x86_64-unknown-linux-gnu

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 6, 2020

Comment by Xander Dunn (JIRA)

This issue is still present on trunk 2020-11-05:

$ which swift
/home/xander/swift-DEVELOPMENT-SNAPSHOT-2020-11-05-a-ubuntu18.04/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM ea8eac6ba760b92, Swift e8151ee2b27776f)
Target: x86_64-unknown-linux-gnu

@slavapestov
Copy link
Member

Yeah, I don't expect it to get fixed randomly along the way. The GSB needs some refactoring to address this and related issues with signature canonicalization.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 6, 2020

Comment by Xander Dunn (JIRA)

Thanks @slavapestov!

I don't know the causes of the issue so it appeared randomly for me and I didn't realize it had your attention. We are excited for the resolution so that we can use more recent versions of Swift for Tensorflow in our project.

I know commitments can't be made, but generally speaking is this the sort of thing you would imagine on the order of months or a year+? If it's a longer time horizon we should break up our project into multiple processes that communicate via shared memory so that our Swift for Tensorflow code doesn't rely on BigInt.

Thanks very much for working on it!

@slavapestov
Copy link
Member

Another option would be to change the BigInt library to avoid the problematic same-type constraint. I'm assuming your copy of BigInt.swift is identical to the one in test/Prototypes in the Swift repository. If so, it has a definition like this:

public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
  BinaryInteger, SignedInteger, CustomStringConvertible,
  CustomDebugStringConvertible
  where Word.Magnitude == Word

You'll need to remove the "where Word.Magnitude == Word" constraint and add a few forced casts now that the compiler no longer knows they're the same type. Here is the diff I used:

--- a/test/Prototypes/BigInt.swift
+++ b/test/Prototypes/BigInt.swift
@@ -16,11 +16,6 @@
 // REQUIRES: executable_test
 // REQUIRES: CPU=x86_64
 
-// See rdar://problem/65251059
-// UNSUPPORTED: windows
-// rdar://problem/65015626
-// XFAIL: asserts
-
 import StdlibUnittest
 #if canImport(Darwin)
   import Darwin
@@ -83,7 +78,6 @@ extension FixedWidthInteger {
 public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
   BinaryInteger, SignedInteger, CustomStringConvertible,
   CustomDebugStringConvertible
-  where Word.Magnitude == Word
 {
 
   /// The binary representation of the value's magnitude, with the least
@@ -331,7 +325,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
     var carry: Word = 0
     for i in 0..<_data.count {
       let product = _data[i].multipliedFullWidth(by: rhs)
-      (carry, _data[i]) = product.low.addingFullWidth(carry)
+      (carry, _data[i]) = product.low.addingFullWidth(carry as! Word.Magnitude) as! (Word, Word)
       carry = carry &+ product.high
     }
 
@@ -361,7 +355,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
 
     var carry: Word = 0
     for i in (0..<_data.count).reversed() {
-      let lhs = (high: carry, low: _data[i])
+      let lhs = (high: carry, low: _data[i] as! Word.Magnitude)
       (_data[i], carry) = rhs.dividingFullWidth(lhs)
     }
 
@@ -505,7 +499,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
         // `newData[ai + bi]` and any addition overflow in `carry`.
         let product = a[ai].multipliedFullWidth(by: b[bi])
         (carry, newData[ai + bi]) = Word.addingFullWidth(
-          newData[ai + bi], product.low, carry)
+          newData[ai + bi], product.low as! Word, carry)
 
         // Now we combine the high word of the multiplication with any addition
         // overflow. It is safe to add `product.high` and `carry` here without

The test file compiles and runs for me now, but I haven't done any further testing. I hope this helps!

@swift-ci
Copy link
Collaborator Author

Comment by Xander Dunn (JIRA)

This was hugely helpful, thank you very much @slavapestov!

I successfully made a workaround on the BigInt project. Diff is here.

@slavapestov
Copy link
Member

#42113

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software Linux Platform: Linux swift for tensorflow
Projects
None yet
Development

No branches or pull requests

4 participants