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-14241] [AutoDiff] Struct member ordering/naming causes compiler crash #56601
Comments
@rxwei I'm transitioning from the TF 0.12 release and I've got a cascade of compiler crashes that look related to this one, I wonder if you could take a look? Seems like there's a chance it's a recent regression, so hopefully there's a quick fix. If it's not readily solvable I can go about finding workarounds. |
Just want to make sure this one is on your radar @rxwei, I'd like to take advantage of some recent fixes like SR-14106 , but I'm stuck back on the 1/19 toolchain because of this bug. I'm effectively blocked by either this bug or SR-14106 depending on the toolchain, so I'm going back to the TF toolchain for now. |
@porterchild Thanks. Will take a look this week. |
@swift-ci create |
Thanks! |
@porterchild I'm unable to reproduce this with |
I'm trying to get a command line reproducer, getting some weird error. I'll upload the Xcode project version in the meantime Uploaded. Does that crash for you? |
Thanks, it helped me find the actual problem. This happens when we read SIL modules. Here's a command line reproducer. xcrun /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-02-20-a.xctoolchain/usr/bin/swift-frontend -module-name SR_14241 -emit-module SR-14241.swift
xcrun /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-02-20-a.xctoolchain/usr/bin/swift-frontend -c SR_14241.swiftmodule |
One strange behavior here is that when you emit SIL, the tangent vector properties are laid out in a different order. swiftc SR-14241.swift -emit-silgen public struct Thing : Differentiable {
@differentiable(reverse, wrt: self)
@_hasStorage public var simd: [Float] { get set }
@differentiable(reverse, wrt: self)
@_hasStorage public var scalar: Float { get set }
struct TangentVector : AdditiveArithmetic, Differentiable {
static func + (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
static func - (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
@_implements(Equatable, ==(_:_:)) static func __derived_struct_equals(_ a: Thing.TangentVector, _ b: Thing.TangentVector) -> Bool
typealias TangentVector = Thing.TangentVector
init(simd: Array<Float>.DifferentiableView, scalar: Float)
@_hasStorage var scalar: Float { get set }
@_hasStorage var simd: Array<Float>.DifferentiableView { get set }
static var zero: Thing.TangentVector { get }
}
init(simd: [Float], scalar: Float)
mutating func move(by offset: Thing.TangentVector)
} |
If you do `-print-ast` the layout is correct however: import _Differentiation
public struct Thing : Differentiable {
@differentiable(reverse, wrt: self)
public var simd: [Float]
@differentiable(reverse, wrt: self)
public var scalar: Float
public struct TangentVector : AdditiveArithmetic, Differentiable {
public var simd: Array<Float>.TangentVector
public var scalar: Float.TangentVector
public static func + (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
public static func - (lhs: Thing.TangentVector, rhs: Thing.TangentVector) -> Thing.TangentVector
@_implements(Equatable, ==(_:_:)) public static func __derived_struct_equals(_ a: Thing.TangentVector, _ b: Thing.TangentVector) -> Bool
public typealias TangentVector = Thing.TangentVector
public init(simd: Array<Float>.TangentVector, scalar: Float.TangentVector)
public static var zero: Thing.TangentVector { get }
}
internal init(simd: [Float], scalar: Float)
public mutating func move(by offset: Thing.TangentVector)
} |
CodaFi (JIRA User) offered a lot of help bugging this and #36154 is a possible fix. |
Attachment: Download
Environment
2/9 snapshot
Additional Detail from JIRA
md5: bc029c769146d96103460a0dc9cb8f14
Issue Description:
This ordering of struct members causes a compiler crash:
and this ordering is fine:
Also, changing the name to from "simd" to "array", "fish", "pineapple" etc. stops the crash:
("s", "si", "sim", and "simdd" also cause the crash)
Also, changing access control stops the crash (removing `public`).
As a possible hint, this wasn't an issue on the 1/19 snapshot. So it may be a recent regression.
Stack trace:
The text was updated successfully, but these errors were encountered: