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
assertion failureBug → crash: An assertion failureAutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfcrashBug: A crash, i.e., an abnormal termination of softwareIRGenLLVM IR generationswift 6.0
We have seen other issues in the past that cause this assertion to fail, such as this one: #72363
In some cases, the root cause is AutoDiff related, in others, it isn't. Below is another reproducer which causes the aforementioned assertion failure.
The full assertion failure (from the 2024-04-11a toolchain) is: Assertion failed: (srcAddr->getType() == destAddr->getType()), function createCopyAddr, file SILBuilder.h, line 1190.
Reproduction
Copy and paste this code into a single file and attempt to build in Debug mode.
Nightly toolchains from 2024-04-01a to 2024-04-11a cause this issue.
M1 MacBook Pro, Xcode 15.1.
Additional information
There are several individual changes to the code above that can be made that can cause the compilation to succeed; each of these can be performed independently of any other. Note that this list is not exhaustive.
Comment out line 9, which contains if sd > 0 {}.
In line 2, remove var d: B.M from struct O, and in line 16, remove d: u8. (Note that adding a third instance of B.M to return here will cause the same crash.)
In line 21, removing var m5 = Array<Float>(), even though it isn't used anywhere.
Comment out line 15, which contains u9.g3 = u3.r.
Change line 14 to u9.g2 = C(i.g2).r and then delete let u2 = C(i.g2); from line 5.
Note that if we remove the conformance to AdditiveArithmetic in line 25, that is, we rewrite the line to look like this: struct C<E>: Differentiable where E: Differentiable, E: AdditiveArithmetic
we get a different assertion failing: Assertion failed: (!ActiveDiagnostic && "Already have an active diagnostic"), function diagnose, file DiagnosticEngine.h, line 1204.
This may come with additional diagnostic information:
main.swift:28:6: error: can only differentiate functions with results that conform to 'Differentiable', but 'C<E>' does not conform to 'Differentiable'
26 | typealias TangentVector = C<E.TangentVector>
27 | var v: [E]; var a: E
28 | @differentiable(reverse) init(_ c: [E], t: E = .zero) {self.v = c; self.a = .zero}
| `- error: can only differentiate functions with results that conform to 'Differentiable', but 'C<E>' does not conform to 'Differentiable'
29 | @differentiable(reverse) var r: [E] {return v}
30 | @inlinable @derivative(of: init(_:t:))
The stack trace for this modification looks like this:
I've tried the workaround via the -disable-large-loadable-types-reg2mem compilation flag and it does appear to work in this case.
(On a MacOS terminal window, the command-line steps below assume SDKROOT is set correctly, e.g., export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk
Otherwise, the error message <unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT? may appear).
If I try to compile without the flag, then the compiler crashes, as above. /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/bin/swiftc main.swift
If I add the reg2mem flag, the compilation succeeds: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/bin/swiftc -disable-large-loadable-types-reg2mem main.swift
assertion failureBug → crash: An assertion failureAutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfcrashBug: A crash, i.e., an abnormal termination of softwareIRGenLLVM IR generationswift 6.0
Description
We have seen other issues in the past that cause this assertion to fail, such as this one:
#72363
In some cases, the root cause is AutoDiff related, in others, it isn't. Below is another reproducer which causes the aforementioned assertion failure.
The full assertion failure (from the 2024-04-11a toolchain) is:
Assertion failed: (srcAddr->getType() == destAddr->getType()), function createCopyAddr, file SILBuilder.h, line 1190.
Reproduction
Copy and paste this code into a single file and attempt to build in Debug mode.
Expected behavior
The compilation should succeed.
Environment
Nightly toolchains from 2024-04-01a to 2024-04-11a cause this issue.
M1 MacBook Pro, Xcode 15.1.
Additional information
There are several individual changes to the code above that can be made that can cause the compilation to succeed; each of these can be performed independently of any other. Note that this list is not exhaustive.
if sd > 0 {}
.var d: B.M
fromstruct O
, and in line 16, removed: u8
. (Note that adding a third instance ofB.M
to return here will cause the same crash.)var m5 = Array<Float>()
, even though it isn't used anywhere.u9.g3 = u3.r
.u9.g2 = C(i.g2).r
and then deletelet u2 = C(i.g2);
from line 5.The stack trace is as below:
Note that if we remove the conformance to
AdditiveArithmetic
in line 25, that is, we rewrite the line to look like this:struct C<E>: Differentiable where E: Differentiable, E: AdditiveArithmetic
we get a different assertion failing:
Assertion failed: (!ActiveDiagnostic && "Already have an active diagnostic"), function diagnose, file DiagnosticEngine.h, line 1204.
This may come with additional diagnostic information:
The stack trace for this modification looks like this:
The text was updated successfully, but these errors were encountered: