You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfcrashBug: A crash, i.e., an abnormal termination of software
macOS 10.13.1, Xcode 9.2 with recent toolchain (eg snapshot 2017-12-06)
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug, CompilerCrash
Assignee
None
Priority
Medium
md5: e18abd46bc32fad921bd003c0499c367
Issue Description:
Below is a reduced version of my original project (which is now kind of stalled because of this bug 🙁 ), the comments include the few clues I managed to find while trying to isolate it.
Attached is the same code in an Xcode project (in its compiler crashing state).
NOTE: Only intended for recent snapshots.
main.swift:
// This (AFAICS valid) program will crash the compiler (while type checking).
// The program consists of these three files:
// main.swift
// Vector.swift
// Table.swift
// The behavior will not be the same if all the code is in a single file.
// Each one of the 5 "workarounds" (see numbered comments) makes the program
// compile successfully (ie avoids triggering the compiler crash).
func hmm() {
// 1. Compiler crash not triggered if either of the
// following two lines is commented out:
let _ = Table(V1Float1D())
let _ = VectorRange(V1(123)).points
}
hmm()
Vector.swift:
protocol VectorIndex {
// 2. Compiler crash not triggered if commenting out this line:
associatedtype BV : Vector where BV.Index == Self, BV.Element == UInt8
}
struct VectorIndex1 : VectorIndex {
typealias BV = V1<UInt8>
}
protocol Vector {
associatedtype Index: VectorIndex
associatedtype Element
// 3. Compiler crash not triggered if commenting out this line:
init(elementForIndex: (Index) -> Element)
}
extension Vector where Index == VectorIndex1 {
init(_: Element) { fatalError() }
}
extension Vector where Element: Comparable {
// 4. Compiler crash not triggered if commenting out this line:
init(randomInRange range: VectorRange<Self>) { fatalError() }
}
struct V1<Element> : Vector {
typealias Index = VectorIndex1
init(elementForIndex: (VectorIndex1) -> Element) { }
}
struct VectorRange<Bound> where Bound: Vector, Bound.Element: Comparable {
init(_: Bound) { }
}
extension VectorRange where Bound == V1<Int> {
var points: VectorRangePoints<Bound> { fatalError() }
}
struct VectorRangePoints<V> where V: Vector, V.Element: FixedWidthInteger {
}
Table.swift:
protocol TableData {
associatedtype Value
associatedtype Coordinate: Vector where Coordinate.Element == Int
}
struct V1Float1D : TableData {
typealias Value = V1<Float>
typealias Coordinate = V1<Int>
}
final class Table<Data: TableData> {
init(_: Data) { }
}
// 5. The compiler crash is not triggered if commenting out this line:
extension Table where Data.Coordinate.Index == VectorIndex1 { }
This is what the crash looks like:
$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-12-06-a.xctoolchain/usr/bin/swiftc main.swift Vector.swift Table.swift
Assertion failed: (isCanonicalTypeInContext(result, builder)), function getCanonicalTypeInContext, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/AST/GenericSignature.cpp, line 862.
/.../
1. While type-checking 'hmm()' at main.swift:14:1
2. While type-checking declaration 0x7fdad685af18 at main.swift:18:5
3. While type-checking expression at [main.swift:18:13 - line:18:34] RangeText="VectorRange(V1(123)).p"
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
The text was updated successfully, but these errors were encountered:
We're getting an awful interleaving between associated type inference (for V1: Vector, to determine Element) and the type checking of the constrained extension of VectorRange where Bound == V1<Int>. The actual problem is... annoyingly... checkRedeclaration's way-too-early call to validateDecl (see https://github.com/apple/swift/blob/master/lib/Sema/TypeCheckDecl.cpp#L918) is causing the interleaving.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfcrashBug: A crash, i.e., an abnormal termination of software
Attachment: Download
Environment
macOS 10.13.1, Xcode 9.2 with recent toolchain (eg snapshot 2017-12-06)
Additional Detail from JIRA
md5: e18abd46bc32fad921bd003c0499c367
Issue Description:
Below is a reduced version of my original project (which is now kind of stalled because of this bug 🙁 ), the comments include the few clues I managed to find while trying to isolate it.
Attached is the same code in an Xcode project (in its compiler crashing state).
NOTE: Only intended for recent snapshots.
main.swift:
Vector.swift:
Table.swift:
This is what the crash looks like:
The text was updated successfully, but these errors were encountered: