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-13533] crash: "deserialization produced an invalid type" #55970

Open
mayoff opened this issue Sep 9, 2020 · 2 comments
Open

[SR-13533] crash: "deserialization produced an invalid type" #55970

mayoff opened this issue Sep 9, 2020 · 2 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

Comments

@mayoff
Copy link

mayoff commented Sep 9, 2020

Previous ID SR-13533
Radar rdar://problem/68621818
Original Reporter @mayoff
Type Bug

Attachment: Download

Environment

swift-5.3-DEVELOPMENT-SNAPSHOT-2020-09-07-a.xctoolchain

macOS 10.15.6 (19G2021)

export TOOLCHAINS=org.swift.53202009071a

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

md5: 87fd73e073df8eae83ec9b50e67168b7

Issue Description:

The attached swift package crashes the 5.3 compiler as of the 2020-09-07 nightly. The crash output references rdar://problem/30382791 but I couldn't find a relevant bugs.swift.org issue.

The package contains a single source file, which I reproduce entirely here:

protocol P {
    associatedtype A
    func g(_: A)
}

// This struct must be present to trigger the crash, but is not otherwise used.
struct S<U: P>: P {
    func g(_: U.A) { }
}

@_functionBuilder struct B<X> { }

extension P {
    func f(@B<A> _: () -> Void) { }
}

Build the package with swift build. The crash happens during the -merge-modules build step. Here is the crash output:

:; swift build
/Users/mayoff/t/bugPackage/Sources/bugTarget/bugSource.swift:1:10: error: circular reference
protocol P {
         ^
(error_type
  (original_type=generic_type_param_type depth=0 index=0 decl=bugTarget.(file).P.Self))
deserialization produced an invalid type (rdar://problem/30382791)
UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-5.3-package-osx/swift/lib/Serialization/Deserialization.cpp:5608!
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-09-07-a.xctoolchain/usr/bin/swift -frontend -merge-modules -emit-module /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/bugTarget.build/bugSource~partial.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-12b6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -I /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug -I /Applications/Xcode-12b6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-12b6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -target-sdk-version 11.0 -emit-module-doc-path /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/bugTarget.swiftdoc -emit-module-source-info-path /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/bugTarget.swiftsourceinfo -emit-objc-header-path /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/bugTarget.build/bugTarget-Swift.h -module-name bugTarget -o /Users/mayoff/t/bugPackage/.build/x86_64-apple-macosx/debug/bugTarget.swiftmodule 
1.  Apple Swift version 5.3-dev (LLVM 13790f33d5, Swift 6c3e7a8215)
2.  While deserializing SIL function "$s9bugTarget1SVyxGAA1PA2aEP1gyy1AQzFTW"
3.  While evaluating request DirectLookupRequest(directly looking up 'A' on bugTarget.(file).P@/Users/mayoff/t/bugPackage/Sources/bugTarget/bugSource.swift:1:10 with options {  })
4.  While loading members for extension of P (in module 'bugTarget')
5.  While deserializing 'f' (FuncDecl @ 99995) in 'bugTarget'
6.      ...decl is named 'f(_:)'
7.  While deserializing type 'Self'
0  swift                    0x000000010d383cc5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010d382f45 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010d384296 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff6a9375fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338728114720
5  libsystem_c.dylib        0x00007fff6a80d808 abort + 120
6  swift                    0x000000010d2f9e42 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 482
7  swift                    0x0000000109ab0b22 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 770
8  swift                    0x0000000109ac2040 swift::TypeDeserializer::deserializeBoundGenericType(llvm::ArrayRef<unsigned long long>, llvm::StringRef) + 320
9  swift                    0x0000000109ac045f swift::TypeDeserializer::getTypeCheckedImpl() + 719
10 swift                    0x0000000109ab0908 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 232
11 swift                    0x0000000109ab70d9 swift::DeclDeserializer::deserializeDeclAttributes() + 3049
12 swift                    0x0000000109ab5b39 swift::DeclDeserializer::getDeclCheckedImpl(llvm::function_ref<bool (swift::DeclAttributes)>) + 41
13 swift                    0x0000000109aadaa6 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::function_ref<bool (swift::DeclAttributes)>) + 470
14 swift                    0x0000000109aacc6d swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>) + 29
15 swift                    0x0000000109aacb08 swift::ModuleFile::readParameterList() + 264
16 swift                    0x0000000109acc730 swift::DeclDeserializer::deserializeAnyFunc(llvm::ArrayRef<unsigned long long>, llvm::StringRef, bool) + 3072
17 swift                    0x0000000109ab5f50 swift::DeclDeserializer::getDeclCheckedImpl(llvm::function_ref<bool (swift::DeclAttributes)>) + 1088
18 swift                    0x0000000109aadaa6 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::function_ref<bool (swift::DeclAttributes)>) + 470
19 swift                    0x0000000109ac3e41 swift::ModuleFile::loadAllMembers(swift::Decl*, unsigned long long) + 609
20 swift                    0x000000010a211e41 swift::IterableDeclContext::loadAllMembers() const + 465
21 swift                    0x000000010a211c5e swift::IterableDeclContext::getMembers() const + 14
22 swift                    0x000000010a2b4af9 swift::DirectLookupRequest::evaluate(swift::Evaluator&, swift::DirectLookupDescriptor) const + 745
23 swift                    0x000000010a2cb6d1 swift::SimpleRequest<swift::DirectLookupRequest, llvm::TinyPtrVector<swift::ValueDecl*> (swift::DirectLookupDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::DirectLookupRequest const&, swift::Evaluator&) + 33
24 swift                    0x000000010a2c306b llvm::Expected<swift::DirectLookupRequest::OutputType> swift::Evaluator::getResultUncached<swift::DirectLookupRequest>(swift::DirectLookupRequest const&) + 347
25 swift                    0x000000010a2b4680 swift::DirectLookupRequest::OutputType swift::evaluateOrDefault<swift::DirectLookupRequest>(swift::Evaluator&, swift::DirectLookupRequest, swift::DirectLookupRequest::OutputType) + 32
26 swift                    0x000000010a2b461a swift::NominalTypeDecl::lookupDirect(swift::DeclName, swift::OptionSet<swift::NominalTypeDecl::LookupDirectFlags, unsigned int>) + 122
27 swift                    0x000000010a24c4d8 swift::GenericSignatureBuilder::EquivalenceClass::lookupNestedType(swift::GenericSignatureBuilder&, swift::Identifier, llvm::SmallVectorImpl<swift::TypeDecl*>*) + 616
28 swift                    0x000000010a255bac swift::GenericSignatureBuilder::maybeResolveEquivalenceClass(swift::Type, swift::ArchetypeResolutionKind, bool) + 908
29 swift                    0x000000010a252beb swift::ArchetypeType::resolveNestedType(std::__1::pair<swift::Identifier, swift::Type>&) const + 59
30 swift                    0x000000010a2eed16 swift::ArchetypeType::getNestedType(swift::Identifier) const + 342
31 swift                    0x000000010a2f0135 getMemberForBaseType(llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::Type, swift::Type, swift::AssociatedTypeDecl*, swift::Identifier, swift::SubstOptions) + 485
32 swift                    0x000000010a2f9213 llvm::Optional<swift::Type> llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>::callback_fn<substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions)::$_26>(long, swift::TypeBase*) + 2531
33 swift                    0x000000010a2f24c4 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 68
34 swift                    0x000000010a2f0779 substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) + 297
35 swift                    0x000000010a2f120f swift::Type::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) const + 127
36 swift                    0x000000010a24121a swift::GenericEnvironment::mapTypeIntoContext(swift::Type, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const + 74
37 swift                    0x000000010a240f74 swift::GenericEnvironment::mapTypeIntoContext(swift::Type) const + 36
38 swift                    0x0000000109ac1b16 swift::TypeDeserializer::deserializeNestedArchetypeType(llvm::ArrayRef<unsigned long long>, llvm::StringRef) + 246
39 swift                    0x0000000109ac05af swift::TypeDeserializer::getTypeCheckedImpl() + 1055
40 swift                    0x0000000109ab0908 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 232
41 swift                    0x0000000109aad87b swift::ModuleFile::getType(llvm::PointerEmbeddedInt<unsigned int, 31>) + 27
42 swift                    0x0000000109adf6a5 swift::SILDeserializer::readSILBasicBlock(swift::SILFunction*, swift::SILBasicBlock*, llvm::SmallVectorImpl<unsigned long long>&) + 165
43 swift                    0x0000000109add830 swift::SILDeserializer::readSILFunctionChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, swift::SILFunction*, llvm::StringRef, bool, bool) + 5520
44 swift                    0x0000000109af15aa swift::SILDeserializer::getAllSILFunctions() + 650
45 swift                    0x0000000109b6eb92 swift::SILDeserializer::getAll(bool) + 34
46 swift                    0x0000000109b6ebf9 swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 41
47 swift                    0x0000000109291434 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 84
48 swift                    0x00000001091a3041 performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 897
49 swift                    0x0000000109197e5f performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 7743
50 swift                    0x0000000109194f85 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3589
51 swift                    0x000000010912696d main + 861
52 libdyld.dylib            0x00007fff6a73ecc9 start + 1
53 libdyld.dylib            0x000000000000002d start + 18446603338730181477
@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@stackotter
Copy link

This seems to be fixed in Swift 5.6

@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
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
Projects
None yet
Development

No branches or pull requests

4 participants