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-14224] [AutoDiff] Differentiable derived conformances crash for invalid recursive type #54260

Closed
dan-zheng opened this issue Nov 25, 2019 · 1 comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-14224
Radar None
Original Reporter @dan-zheng
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee None
Priority Medium

md5: 091e67bbb38655e52345bba6fb91f6fb

Issue Description:

struct StoredProperty: Differentiable {
  var stored: Self
}
swift crash.swift
crash.swift:2:7: error: value type 'StoredProperty' cannot have a stored property that recursively contains it
  var stored: Self
      ^
Assertion failed: (DerivedConformance::canDeriveAdditiveArithmetic(tangentStruct, parentDC) && "Should be able to derive `AdditiveArithmetic`"), function getOrSynthesizeTangentVectorStructType, file /Users/danielzheng/swift-build/swift/lib/Sema/DerivedConformanceDifferentiable.cpp, line 760.
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-build/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -interpret crash.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name crash
1.  Swift version 5.1.1-dev (Swift b8c38b8560)
2.  While type-checking 'StoredProperty' (at crash.swift:1:1)
3.  While type-checking protocol conformance to 'Differentiable' (in module 'Swift') for type 'StoredProperty' (declared at [crash.swift:1:1 - line:3:1] RangeText="struct StoredProperty: Differentiable {
  var stored: Self
")
0  swift                    0x000000010a3fd955 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010a3fc958 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010a3fdf48 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff728e4b5d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000117357938 _sigtramp + 2762419704
5  libsystem_c.dylib        0x00007fff7279e6a6 abort + 127
6  libsystem_c.dylib        0x00007fff7276720d basename_r + 0
7  swift                    0x000000010a6e9a83 swift::DerivedConformance::deriveDifferentiable(swift::AssociatedTypeDecl*) (.cold.6) + 35
8  swift                    0x0000000106e2e239 swift::DerivedConformance::deriveDifferentiable(swift::AssociatedTypeDecl*) + 6537
9  swift                    0x0000000106f1fae1 swift::TypeChecker::deriveTypeWitness(swift::DeclContext*, swift::NominalTypeDecl*, swift::AssociatedTypeDecl*) + 369
10 swift                    0x0000000106f3449b swift::AssociatedTypeInference::computeDerivedTypeWitness(swift::AssociatedTypeDecl*) + 107
11 swift                    0x0000000106f34532 swift::AssociatedTypeInference::computeAbstractTypeWitness(swift::AssociatedTypeDecl*, bool) + 82
12 swift                    0x0000000106f352fd swift::AssociatedTypeInference::findSolutionsRec(llvm::ArrayRef<swift::AssociatedTypeDecl*>, llvm::SmallVectorImpl<swift::InferredTypeWitnessesSolution>&, llvm::SmallVectorImpl<swift::InferredTypeWitnessesSolution>&, llvm::SmallVector<std::__1::pair<swift::ValueDecl*, swift::ValueDecl*>, 4u>&, unsigned int, unsigned int, unsigned int) + 365
13 swift                    0x0000000106f350e7 swift::AssociatedTypeInference::findSolutions(llvm::ArrayRef<swift::AssociatedTypeDecl*>, llvm::SmallVectorImpl<swift::InferredTypeWitnessesSolution>&) + 87
14 swift                    0x0000000106f37f6c swift::AssociatedTypeInference::solve(swift::ConformanceChecker&) + 1004
15 swift                    0x0000000106f384cf swift::ConformanceChecker::resolveTypeWitnesses() + 271
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@BradLarson
Copy link
Collaborator

This no longer causes an assertion failure and seems to provide the desired diagnostic output:

SR14224.swift:4:7: error: value type 'StoredProperty' cannot have a stored property that recursively contains it
  var stored: Self
      ^
SR14224.swift:5:1: error: type 'StoredProperty.TangentVector' does not conform to protocol 'AdditiveArithmetic'
}
^
Swift.AdditiveArithmetic:2:34: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'ExpressibleByIntegerLiteral'
    @inlinable public static var zero: Self { get }
                                 ^
SR14224.swift:5:1: error: type 'StoredProperty.TangentVector' does not conform to protocol 'Equatable'
}
^
<unknown>:0: note: stored property type 'SR14224.StoredProperty.TangentVector' does not conform to protocol 'Equatable', preventing synthesized conformance of 'SR14224.StoredProperty.TangentVector' to 'Equatable'
Swift.==:1:24: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'RawRepresentable'
@inlinable public func == <T>(lhs: T, rhs: T) -> Bool where T : RawRepresentable, T.RawValue : Equatable
                       ^
Swift.FloatingPoint:2:24: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'FloatingPoint'
    public static func == (lhs: Self, rhs: Self) -> Bool
                       ^
Swift.BinaryInteger:2:24: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'BinaryInteger'
    public static func == <Other>(lhs: Self, rhs: Other) -> Bool where Other : BinaryInteger
                       ^
Swift._Pointer:2:24: note: candidate would match if 'StoredProperty.TangentVector' conformed to '_Pointer'
    public static func == (lhs: Self, rhs: Self) -> Bool
                       ^
Swift._Pointer:3:35: note: candidate would match if 'StoredProperty.TangentVector' conformed to '_Pointer'
    @inlinable public static func == <Other>(lhs: Self, rhs: Other) -> Bool where Other : _Pointer
                                  ^
Swift.Strideable:3:35: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'Strideable'
    @inlinable public static func == (x: Self, y: Self) -> Bool
                                  ^
Swift.StringProtocol:2:35: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'StringProtocol'
    @inlinable public static func == <RHS>(lhs: Self, rhs: RHS) -> Bool where RHS : StringProtocol
                                  ^
Swift.SIMD:4:24: note: candidate would match if 'StoredProperty.TangentVector' conformed to 'SIMD'
    public static func == (a: Self, b: Self) -> Bool
                       ^
Swift.AdditiveArithmetic:2:16: note: protocol requires property 'zero' with type 'StoredProperty.TangentVector'
    static var zero: Self { get }
               ^
Swift.Equatable:2:17: note: protocol requires function '==' with type '(StoredProperty.TangentVector, StoredProperty.TangentVector) -> Bool'
    static func == (lhs: Self, rhs: Self) -> Bool

It's probably safe to close out this older issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants