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-7978] Referencing class from library in test target causes a DESERIALIZATION FAILURE #50512

Closed
ffried opened this issue Jun 12, 2018 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself serialization Area → compiler: Serialization & deserialization

Comments

@ffried
Copy link
Contributor

ffried commented Jun 12, 2018

Previous ID SR-7978
Radar None
Original Reporter @ffried
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Serialization
Assignee @belkadan
Priority Medium

md5: 0ee1b1bcf86099d95e02805c261a0824

Issue Description:

This bug seems to require a certain constellation. The following steps worked for me to reproduce it:

First, create Swift Package with:

mkdir DeserializationCrash && cd DeserializationCrash && swift package init --type library

Then replace the contents of Sources/DeserializationCrash/DeserializationCrash.swift with the following code:

protocol MyProtocol {
    var string: String { get }
    var int: Int { get }

    init(with string: String, and int: Int)

    func doSomething<T, U>(with this: T, for string: String, expecting: U.Type) throws -> U
    func doSomething<T>(with this: T, for string: String) throws
}

class MyClass: MyProtocol {
    var string: String
    var int: Int

    required init(with string: String, and int: Int) {
        self.string = string
        self.int = int
    }

    func doSomething<T>(with this: T, for string: String) throws {}
    func doSomething<T, U>(with this: T, for string: String, expecting: U.Type) throws -> U {
        fatalError()
    }
}

Next, open Tests/DeserializationCrashTests/DeserializationCrashTests.swift and replace the contents of the func testExample() with the following line:

_ = MyClass(with: "test", and: 341)

Finally, run swift test. The compilation of the test target will fail with the following output:

Compile Swift Module 'DeserializationCrash' (1 sources)
Compile Swift Module 'DeserializationCrashTests' (2 sources)
<unknown>:0: error: fatal error encountered while reading from module 'DeserializationCrash'; please file a bug report with your project and the crash log

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
(see "While..." info below)
0  swift                    0x000000010da45fea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010da453a6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff583a0f5a _sigtramp + 26
3  swift                    0x000000010e3bc900 (anonymous namespace)::DarwinX86AsmBackend::getCompactUnwindRegNum(unsigned int) const::CU32BitRegs + 103822
4  libsystem_c.dylib        0x00007fff5813e1ae abort + 127
5  swift                    0x000000010b174d5e swift::ModuleFile::fatal(llvm::Error) + 2062
6  swift                    0x000000010b186f7e swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 12958
7  swift                    0x000000010b18bcc1 swift::ModuleFile::maybeReadSubstitution(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 177
8  swift                    0x000000010b190bb6 swift::ModuleFile::finishNormalConformance(swift::NormalProtocolConformance*, unsigned long long) + 4790
9  swift                    0x000000010b49e3ca swift::NormalProtocolConformance::getWitness(swift::ValueDecl*, swift::LazyResolver*) const + 58
10 swift                    0x000000010b10581b (anonymous namespace)::LookupResultBuilder::add(swift::ValueDecl*, swift::DeclContext*, swift::Type) + 1307
11 swift                    0x000000010b106590 swift::TypeChecker::lookupMember(swift::DeclContext*, swift::Type, swift::DeclName, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 336
12 swift                    0x000000010affbd6e swift::constraints::ConstraintSystem::simplifyApplicableFnConstraint(swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 2750
13 swift                    0x000000010aff94bc swift::constraints::ConstraintSystem::addConstraint(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 732
14 swift                    0x000000010afdffca (anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*) + 1338
15 swift                    0x000000010afd7e84 (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 212
16 swift                    0x000000010b3f835d swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 6413
17 swift                    0x000000010afd15da swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 730
18 swift                    0x000000010b017a95 swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 2165
19 swift                    0x000000010b0bb8e4 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 52
20 swift                    0x000000010b0bbf9b swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1099
21 swift                    0x000000010b14c05e swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 11278
22 swift                    0x000000010b1485f7 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 727
23 swift                    0x000000010b14d6e1 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 561
24 swift                    0x000000010b16fe0b swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 2491
25 swift                    0x000000010adf1e7d swift::CompilerInstance::performSema() + 6301
26 swift                    0x000000010a09d4f4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1892
27 swift                    0x000000010a09b304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
28 swift                    0x000000010a04fce5 main + 18917
29 libdyld.dylib            0x00007fff58092015 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/florianfriedrich/temp/DeserializationCrash/Tests/DeserializationCrashTests/DeserializationCrashTests.swift /Users/florianfriedrich/temp/DeserializationCrash/Tests/DeserializationCrashTests/XCTestManifests.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/ModuleCache -swift-version 4 -Onone -D SWIFT_PACKAGE -color-diagnostics -emit-module-doc-path /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/DeserializationCrashTests.build/DeserializationCrashTests~partial.swiftdoc -parse-as-library -module-name DeserializationCrashTests -emit-module-path /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/DeserializationCrashTests.build/DeserializationCrashTests~partial.swiftmodule -emit-dependencies-path /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/DeserializationCrashTests.build/DeserializationCrashTests.d -emit-reference-dependencies-path /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/DeserializationCrashTests.build/DeserializationCrashTests.swiftdeps -num-threads 8 -o /Users/florianfriedrich/temp/DeserializationCrash/.build/x86_64-apple-macosx10.10/debug/DeserializationCrashTests.build/DeserializationCrashTests.swift.o 
1.  While type-checking 'testExample()' at /Users/florianfriedrich/temp/DeserializationCrash/Tests/DeserializationCrashTests/DeserializationCrashTests.swift:5:5
2.  While type-checking expression at [/Users/florianfriedrich/temp/DeserializationCrash/Tests/DeserializationCrashTests/DeserializationCrashTests.swift:6:9 - line:6:43] RangeText="_ = MyClass(with: "test", and: 341)"
3.  While reading from 'DeserializationCrash'
4.  While finishing conformance for type 'MyClass'
5.  While ... to 'MyProtocol' in module 'DeserializationCrash'
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/florianfriedrich/temp/DeserializationCrash/.build/debug.yaml test output:
    

I've also attached zip with the failing project.

@ffried
Copy link
Contributor Author

ffried commented Jun 12, 2018

It seems like this has already been fixed in Swift 4.2.

@belkadan Is there still any interest in finding the cause for this? It was kind of a special case since it required a protocol with an initializer requirement as well as property requirements. And on top of all that, the order of the method requirements in the protocol also mattered.

If not, this can be closed as fixed in 4.2.

@belkadan
Copy link
Contributor

I'll add your example as a test case and then we can close it. Even if it was a finicky example, it does test a number of features at once.

@ffried
Copy link
Contributor Author

ffried commented Jun 12, 2018

Sounds great, thanks!

@belkadan
Copy link
Contributor

#17141

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 serialization Area → compiler: Serialization & deserialization
Projects
None yet
Development

No branches or pull requests

2 participants