-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Fix SR-12641: Handle address-only types in derivative fn types #31496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...utoDiff/compiler_crashers/sr12641-silgen-immutable-address-use-verification-failure.swift
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...f/compiler_crashers_fixed/sr12641-silgen-immutable-address-use-verification-failure.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// RUN: %target-swift-frontend -enable-resilience -emit-sil -verify %s | ||
// REQUIRES: asserts | ||
|
||
// SR-12641: SILGen verification error regarding `ImmutableAddressUseVerifier` and AutoDiff-generated code. | ||
|
||
import _Differentiation | ||
|
||
public struct Resilient: Differentiable { | ||
var x: Float | ||
} | ||
|
||
public class Class: Differentiable { | ||
var x: Resilient | ||
init(_ x: Resilient) { | ||
self.x = x | ||
} | ||
} | ||
|
||
public func f(_ c: Class) -> Resilient { | ||
return Resilient(x: 0) | ||
} | ||
|
||
_ = pullback(at: Class(Resilient(x: 10)), in: f) | ||
|
||
// swift/lib/SIL/Verifier/SILVerifier.cpp:456: bool (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingArgumentConvention(swift::SILArgumentConvention): Assertion `conv.isIndirectConvention() && "Expect an indirect convention"' failed. | ||
// Stack dump: | ||
// ... | ||
// 1. Swift version 5.3-dev (LLVM be43a34c3c, Swift 6d5b2f5220) | ||
// 2. While evaluating request SILGenWholeModuleRequest(SIL Generation for module main) | ||
// 3. While verifying SIL function "@$s4main5ClassC13TangentVectorVAA9ResilientVADVIeggr_AeHIegnr_TR". | ||
// ... | ||
// #8 0x00000000011e7a3e (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingApplyUse(swift::Operand*) | ||
// #9 0x00000000011e6add (anonymous namespace)::ImmutableAddressUseVerifier::isMutatingOrConsuming(swift::SILValue) | ||
// #10 0x00000000011ce0b4 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) | ||
|
||
// Related crasher discovered while fixing SR-12641. | ||
|
||
class LoadableOriginal<T: Differentiable>: Differentiable { | ||
var x: T | ||
init(_ x: T) { self.x = x } | ||
} | ||
|
||
@differentiable | ||
func loadableOriginal<T: AdditiveArithmetic>(_ loadable: LoadableOriginal<T>) -> T { | ||
return T.zero | ||
} | ||
|
||
// swift/include/swift/SIL/TypeLowering.h:845: swift::SILType swift::Lowering::TypeConverter::getLoweredLoadableType(swift::Type, swift::TypeExpansionContext, swift::SILModule &): Assertion `(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) && "unexpected address-only type"' failed. | ||
// Stack dump: | ||
// ... | ||
// 2. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Guaranteed Passes } on SIL for main.main) | ||
// 3. While running pass #153 SILModuleTransform "Differentiation". | ||
// 4. While processing // differentiability witness for loadableOriginal<A>(_:) | ||
// sil_differentiability_witness hidden [parameters 0] [results 0] <T where T : AdditiveArithmetic, T : Differentiable> @$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF : $@convention(thin) <T where T : Additive | ||
// Arithmetic, T : Differentiable> (@guaranteed LoadableOriginal<T>) -> @out T { | ||
// } | ||
// | ||
// on SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". | ||
// for 'loadableOriginal(_:)' | ||
// 5. While generating VJP for SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". | ||
// for 'loadableOriginal(_:)' | ||
// 6. While generating pullback for SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". | ||
// for 'loadableOriginal(_:)' | ||
// ... | ||
// #9 0x0000000000f83fbb swift::autodiff::PullbackEmitter::emitZeroDirect(swift::CanType, swift::SILLocation) | ||
// #10 0x0000000000f8248b swift::autodiff::PullbackEmitter::emitZeroDerivativesForNonvariedResult(swift::SILValue) | ||
// #11 0x0000000000f7fcae swift::autodiff::PullbackEmitter::run() | ||
// #12 0x0000000000f3fba4 swift::autodiff::VJPEmitter::run() | ||
// #13 0x0000000000eb1669 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILFunction*, swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) | ||
// #14 0x0000000000eaea5e (anonymous namespace)::Differentiation::run() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.