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-7203] SILGen Assertion failed in emitNativeToCBridgedValue #49751

Closed
swift-ci opened this issue Mar 15, 2018 · 5 comments
Closed

[SR-7203] SILGen Assertion failed in emitNativeToCBridgedValue #49751

swift-ci opened this issue Mar 15, 2018 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C) regression swift 4.2

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7203
Radar rdar://problem/38508755
Original Reporter flovilmart (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.2

toolchain: swift-DEVELOPMENT-SNAPSHOT-2018-03-14-a.xctoolchain

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, CompilerCrash, KeyPaths
Assignee None
Priority Medium

md5: f217799804da9a0ca483bc92dcfe8d21

duplicates:

  • SR-7106 4.1 Regression: Compiler crashes when generating KeyPath in conditional NSObject extension of generic container type

Issue Description:

Compiling a simple class will trigger this assertion error.

import UIKit
class VC: UICollectionViewController {
    func crash() {
        _ = collectionView?.observe(\.frame, options: [.new, .old]) {  _, change in
            print(change)
        }
    }
}
Assertion failed: (bridgedType->isEqual(SGF.getASTContext().getAnyObjectType())), function emitNativeToCBridgedNonoptionalValue, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/SILGenBridging.cpp, line 660.
0  swift                    0x000000010b9df678 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010b9dfd86 SignalHandler(int) + 694
2  libsystem_platform.dylib 0x00007fff76a42f5a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000003a58 _sigtramp + 2304510744
4  libsystem_c.dylib        0x00007fff7686d312 abort + 127
5  libsystem_c.dylib        0x00007fff76835368 basename_r + 0
6  swift                    0x00000001089880c7 emitNativeToCBridgedValue(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 6631
7  swift                    0x00000001089866c4 swift::Lowering::SILGenFunction::emitNativeToBridgedValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 116
8  swift                    0x00000001089a782c swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 188
9  swift                    0x00000001089a8796 swift::Lowering::ConvertingInitialization::copyOrInitValueInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool) + 198
10 swift                    0x00000001089519ea void copyOrInitValuesInto<((anonymous namespace)::ImplodeKind)1>(swift::Lowering::Initialization*, llvm::ArrayRef<swift::Lowering::ManagedValue>&, swift::CanType, swift::SILLocation, swift::Lowering::SILGenFunction&) + 794
11 swift                    0x0000000108951613 swift::Lowering::RValue::forwardInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::Initialization*) && + 179
12 swift                    0x00000001089470c9 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 201
13 swift                    0x00000001089a73e5 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 549
14 swift                    0x0000000108947491 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 129
15 swift                    0x000000010897eb0f (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3439
16 swift                    0x000000010897d2b5 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 453
17 swift                    0x000000010897cb47 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1975
18 swift                    0x0000000108969b6e (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3166
19 swift                    0x0000000108971e49 swift::Lowering::SILGenFunction::emitGetAccessor(swift::SILLocation, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::Lowering::ArgumentSource&&, bool, bool, swift::Lowering::RValue&&, swift::Lowering::SGFContext) + 1737
20 swift                    0x00000001089bfaf4 swift::Lowering::SILGenFunction::emitRValueForStorageLoad(swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, bool, swift::AbstractStorageDecl*, swift::Lowering::RValue, llvm::ArrayRef<swift::Substitution>, swift::AccessSemantics, swift::Type, swift::Lowering::SGFContext, bool) + 916
21 swift                    0x00000001089c6f41 getOrCreateKeyPathGetter(swift::Lowering::SILGenModule&, swift::SILLocation, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::Substitution>, swift::AccessStrategy, swift::GenericEnvironment*, llvm::ArrayRef<swift::KeyPathPatternComponent::Index>, swift::CanType, swift::CanType) + 2849
22 swift                    0x00000001089c5878 swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, unsigned int&, bool&, llvm::ArrayRef<swift::Substitution>, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType) + 488
23 swift                    0x00000001089d9c0e (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 1422
24 swift                    0x00000001089cd5d6 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 150
25 swift                    0x00000001089c2d59 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
26 swift                    0x000000010897e933 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2963
27 swift                    0x000000010897f718 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1352
28 swift                    0x000000010897de53 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 179
29 swift                    0x0000000108980dde (anonymous namespace)::ArgEmitter::emitShuffle(swift::TupleShuffleExpr*, swift::Lowering::AbstractionPattern) + 5054
30 swift                    0x000000010897f79e (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1486
31 swift                    0x000000010897de53 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 179
32 swift                    0x000000010897d2b5 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 453
33 swift                    0x000000010897cb47 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1975
34 swift                    0x0000000108969b6e (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3166
35 swift                    0x0000000108968853 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 51
36 swift                    0x00000001089cd598 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 88
37 swift                    0x00000001089c2d59 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
38 swift                    0x00000001089a3cb5 swift::Lowering::SILGenFunction::emitOptionalSome(swift::SILLocation, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext) + 533
39 swift                    0x00000001089d33a9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 24169
40 swift                    0x00000001089c2d59 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
41 swift                    0x00000001089dbb5b void llvm::function_ref<void (llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::RValueEmitter::visitOptionalEvaluationExpr(swift::OptionalEvaluationExpr*, swift::Lowering::SGFContext)::$_13>(long, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, swift::Lowering::SGFContext) + 123
42 swift                    0x00000001089caf3a swift::Lowering::SILGenFunction::emitOptionalEvaluation(swift::SILLocation, swift::Type, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, swift::Lowering::SGFContext, llvm::function_ref<void (llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, swift::Lowering::SGFContext)>) + 794
43 swift                    0x00000001089cf461 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 7969
44 swift                    0x00000001089c3317 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1287
45 swift                    0x00000001089ce95a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5146
46 swift                    0x00000001089c3317 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1287
47 swift                    0x0000000108a2db33 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8867
48 swift                    0x0000000108a2b885 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
49 swift                    0x00000001089e537d swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 509
50 swift                    0x0000000108963d87 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 311
51 swift                    0x000000010895bd8d swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 733
52 swift                    0x0000000108a37115 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 21
53 swift                    0x0000000108a35823 (anonymous namespace)::SILGenType::emitType() + 467
54 swift                    0x0000000108a35649 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
55 swift                    0x0000000108960d3b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 811
56 swift                    0x0000000108961af0 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 352
57 swift                    0x00000001089620df swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>) + 95
58 swift                    0x000000010824f146 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 8598
59 swift                    0x000000010824bf9e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3310
60 swift                    0x0000000108202af3 main + 2051
61 libdyld.dylib            0x00007fff767c1115 start + 1
62 libdyld.dylib            0x000000000000004a start + 2307125046
Stack dump:
0.    Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-14-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/florent/Documents/TEsting/TEsting/File.swift -target arm64-apple-ios11.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -I /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Products/Debug-iphoneos -F /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/florent/Library/Developer/Xcode/DerivedData/ModuleCache -swift-version 4 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -report-errors-to-debugger -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/SilGenCrash-generated-files.hmap -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/SilGenCrash-own-target-headers.hmap -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/SilGenCrash-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/SilGenCrash-project-headers.hmap -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Products/Debug-iphoneos/include -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/DerivedSources/arm64 -Xcc -I/Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/florent/Documents/TEsting -emit-module-doc-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File~partial.swiftdoc -serialize-diagnostics-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File.dia -parse-as-library -module-name SilGenCrash -emit-module-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File~partial.swiftmodule -emit-dependencies-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File.d -emit-reference-dependencies-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File.swiftdeps -o /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Build/Intermediates.noindex/TEsting.build/Debug-iphoneos/SilGenCrash.build/Objects-normal/arm64/File.o -index-store-path /Users/florent/Library/Developer/Xcode/DerivedData/TEsting-fbxwfroyzickofejtbriiomhfifu/Index/DataStore -index-system-modules
1.    While emitting SIL for 'crash()' at /Users/florent/Documents/TEsting/TEsting/File.swift:12:5
2.    While silgen emitFunction SIL function "@$S11SilGenCrash2VCC5crashyyF".
 for 'crash()' at /Users/florent/Documents/TEsting/TEsting/File.swift:12:5

Note that not all keypaths are yeilding the error

ex:

_ = collectionView?.observe(\.contentSize, options: [.new, .old]) {  _, change in
   print(change)
}

will compile just fine.

@belkadan
Copy link
Contributor

Seems to work in Xcode 9.3. Can you check that it's doing the right thing when you get a chance?

@swift-ci
Copy link
Collaborator Author

Comment by Florent Vilmart (JIRA)

@belkadan

Xcode 9.3b4 exibits the issue with toolchain: swift-DEVELOPMENT-SNAPSHOT-2018-03-14-a

it is fine with default toolchain. Seems to be a regression.

@belkadan
Copy link
Contributor

Ah, interesting. Or it could be an asserts-only problem. Okay, thanks.

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Florent Vilmart (JIRA)

Could be just and assert-only. I was suggested to open it anyway 😉 Discovered it while benchmarking the `-enable-batch-mode` flag.

@jckarter
Copy link
Member

This sounds like a dup of SR-7106.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C) regression swift 4.2
Projects
None yet
Development

No branches or pull requests

4 participants