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-6754] Swift Compiler Crash using Swift 4.1 toolchain with (!ty->hasError() && "Serializing error type"), function addTypeRef assertion failure #49303

Closed
pitiphong-p opened this issue Jan 13, 2018 · 26 comments
Assignees
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 regression swift 4.1 type checker Area → compiler: Semantic analysis

Comments

@pitiphong-p
Copy link
Contributor

Previous ID SR-6754
Radar rdar://36497404
Original Reporter @pitiphong-p
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.2, Swift 4.1 Development Snapshot 2018-01-12, MacBook Pro 13" late 2015 macOS 10.13.2

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 4.1Regression, CompilerCrash, TypeChecker
Assignee @pitiphong-p
Priority Medium

md5: d1f2be406482197087c0b06371cd5c1e

Issue Description:

Hi, Swift team

We've tried to update our open-sourced Swift library to support Swift 4.1 with the Swift 4.1 Development Toolchain 2018-01-12. However it results with the Compiler Crash with assertion failure

(!ty->hasError() && "Serializing error type"), function addTypeRef

You can try with our open-sourced Swift repo

https://github.com/pitiphong-p/URLQueryItemEncoder

@belkadan
Copy link
Contributor

Thanks for filing. I'm kind of surprised by the build log, which seems to be missing a bunch of information. I haven't tried looking at the project yet, but if you've got time it would be great to see if you can reproduce the issue with a smaller set of files. Failing that, just getting the full output from the compiler when it fails would be nice—there should be a backtrace and some extra information about what it was doing at the time.

@pitiphong-p
Copy link
Contributor Author

I would love to help you. I tried to do some investigate but I can't see any information on what file that caused this. However I'll try to reduce the set of files that could reproduce this issue

@pitiphong-p
Copy link
Contributor Author

Do you have any recommend command or log files that would like me to attach here?

@pitiphong-p
Copy link
Contributor Author

@belkadan Good news here. I was investigating and found that the file that caused this bug is `URLQueryItemEncoder.swift` which I copy from my another open-source project
https://github.com/pitiphong-p/URLQueryItemEncoder

So I try building that project with Swift 4.1 development snapshot and it fails too. That project has only 1 swift file which should be a lot easier for you to investigate?

@belkadan
Copy link
Contributor

Oh, excellent! Thanks a lot, Pitiphong; that makes things much easier.

Here's the backtrace I get for that, including the "pretty stack info" at the bottom:

Assertion failed: (!ty->hasError() && "Serializing error type"), function addTypeRef, file /Volumes/Data/swift-public/swift/lib/Serialization/Serialization.cpp, line 617.
0  swift                    0x000000010c043b48 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010c044256 SignalHandler(int) + 694
2  libsystem_platform.dylib 0x00007fff57457dfa _sigtramp + 26
3  swift                    0x000000010d189698 cmark_strbuf__initbuf + 111659
4  libsystem_c.dylib        0x00007fff57322ff9 abort + 127
5  libsystem_c.dylib        0x00007fff572eb923 basename_r + 0
6  swift                    0x00000001099a6228 swift::serialization::Serializer::addTypeRef(swift::Type) + 408
7  swift                    0x00000001099adc91 swift::serialization::Serializer::writeSubstitutions(llvm::ArrayRef<swift::Substitution>, std::__1::array<unsigned int, 256ul> const&, swift::GenericEnvironment*) + 161
8  swift                    0x00000001099ad31b swift::serialization::Serializer::writeNormalConformance(swift::NormalProtocolConformance const*) + 2891
9  swift                    0x00000001099bdb2b swift::serialization::Serializer::writeAllDeclsAndTypes() + 2843
10 swift                    0x00000001099bf0bf swift::serialization::Serializer::writeAST(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, bool) + 3279
11 swift                    0x00000001099c613b swift::serialization::Serializer::writeToStream(llvm::raw_ostream&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SILModule const*, swift::SerializationOptions const&) + 139
12 swift                    0x0000000109a09b73 void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*)::$_4>(long, llvm::raw_ostream&) + 179
13 swift                    0x00000001099c7398 withOutputFile(swift::ASTContext&, llvm::StringRef, llvm::function_ref<void (llvm::raw_ostream&)>) + 440
14 swift                    0x00000001099c715c swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*) + 220
15 swift                    0x0000000108ac2a60 std::__1::__function::__func<performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_6, std::__1::allocator<performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_6>, void ()>::operator()() + 608
16 swift                    0x0000000109707c84 swift::SILModule::serialize() + 36
17 swift                    0x0000000108aba8b2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13314
18 swift                    0x0000000108ab6407 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3191
19 swift                    0x0000000108a75e03 main + 3075
20 libdyld.dylib            0x00007fff5727621d start + 1
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -merge-modules -emit-module /var/folders/g6/djx_5sv95d90j_6xgcfknlhc0000gn/T/URLQueryItemEncoder-c96c5f.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-apple-darwin18.0.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -g -emit-module-doc-path /var/folders/g6/djx_5sv95d90j_6xgcfknlhc0000gn/T/URLQueryItemEncoder-9d4faf.swiftdoc -color-diagnostics -module-name URLQueryItemEncoder -o /var/folders/g6/djx_5sv95d90j_6xgcfknlhc0000gn/T/URLQueryItemEncoder-9d4faf.swiftmodule 
1.  While serializing type 'τ_1_0'

That is a very suspicious "While serializing type 'τ_1_0'"! It looks like a type variable leaked out of the type checker…so over to them. @xedin?

@belkadan
Copy link
Contributor

(tested with swiftc -emit-module URLQueryItemEncoder.swift)

@pitiphong-p
Copy link
Contributor Author

I tried again with Swift 4.1 development snapshot 2018-01-23 and it still failed. However it works great in the Xcode 9.3 beta

@belkadan
Copy link
Contributor

That's just the difference between asserts on and asserts off. It could very possibly be miscompiling.

@pitiphong-p
Copy link
Contributor Author

   That's just the difference between asserts on and asserts off

Yeah, I agree

It could very possibly be miscompiling.

You meant the cause of this bug may be a miscompiling?

@belkadan
Copy link
Contributor

No, I mean the fact that it "works" in Xcode 9.3 could mean that the compiler is outputting incorrect code without recognizing it.

@pitiphong-p
Copy link
Contributor Author

I see and got it 🙂

@xedin
Copy link
Member

xedin commented Feb 15, 2018

@pitiphong-p I've tried the latest beta Xcode with 4.1 nightly toolchain from 02/08 (and default toolchain as well) and 'swift-4.1' branch built successfully, can you please try as well?

@pitiphong-p
Copy link
Contributor Author

The problem is still persists in the Xcode 9.2 and 9.3 with nightly toolchain from 02/08 and 4.1 development 02/08 on my machine

@xedin
Copy link
Member

xedin commented Feb 15, 2018

@pitiphong-p Thanks! I'm going to try and reproduce then.

@xedin
Copy link
Member

xedin commented Mar 28, 2018

It looks like the problem here is that structs/classes like `KeyedContainer` do not actually conform to `KeyedEncodingContainerProtocol` and `UnkeyedEncodingContainer` since there are multiple `encode` implementations missing, but for some reason we don't diagnose that properly and just let it all fall-through to serialization...

@pitiphong-p
Copy link
Contributor Author

@xedin Great to hear some update on this. Please feel free to ask me if you want me help on this issue 🙂

1 similar comment
@pitiphong-p
Copy link
Contributor Author

@xedin Great to hear some update on this. Please feel free to ask me if you want me help on this issue 🙂

@swift-ci
Copy link
Collaborator

Comment by Enrique Lacal (JIRA)

I can also reproduce this exact issue on Swift 4.1. I have the code as a git repo [here|https://github.com/EnriqueL8/SwiftBug.] Uncommenting two lines in the Model.swift makes the issue go away...

@xedin
Copy link
Member

xedin commented Apr 19, 2018

@pitiphong-p enriquel8 (JIRA User) I have PR to fix this #16023 hope to get it in soon.

@swift-ci
Copy link
Collaborator

Comment by Enrique Lacal (JIRA)

Thanks!

@pitiphong-p
Copy link
Contributor Author

@xedin Thank you for your help. I hope it will get approved soon 🙂

@xedin
Copy link
Member

xedin commented Apr 20, 2018

Changed got merged into master. Please use nightly snapshot of master available tomorrow (or day after) to validate.

@xedin
Copy link
Member

xedin commented Apr 20, 2018

enriquel8 (JIRA User) The problem with the project you mentioned hides in the ordering of the `dropTable` if you move it to the end I think it might be only temporary workaround...

@pitiphong-p
Copy link
Contributor Author

@xedin It works now!!! Thank you so much

@swift-ci
Copy link
Collaborator

swift-ci commented May 2, 2018

Comment by Enrique Lacal (JIRA)

Hey @xedin, the workaround with the ordering of the `dropTable` did not seem to work... any other workaround?

@xedin
Copy link
Member

xedin commented May 2, 2018

enriquel8 (JIRA User) Maybe try moving all of the methods after last `findAll` to the top to make it so block of `findAll` is the last.

@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 regression swift 4.1 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants