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-6963] Typealias of type alias crashes 4.1 & 4.2 compilers on Linux & macOS #49511

Closed
Lukasa opened this issue Feb 9, 2018 · 8 comments
Closed
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

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Feb 9, 2018

Previous ID SR-6963
Radar rdar://problem/37384120
Original Reporter @Lukasa
Type Bug
Status Resolved
Resolution Done
Environment

Ubuntu 16.04
Swift version 4.1-dev (LLVM 7598a1fc69, Clang 8be462d5b8, Swift 4e7b4de)
Target: x86_64-unknown-linux-gnu

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

md5: 43f48fce709961242ed4944319ac008e

is duplicated by:

  • SR-7730 Swift 4.2 Compiler crashes on building SwiftNIO

Issue Description:

Using the following sample "module" on Linux will crash the Swift 4.1 development compiler. If you save the following to a file called test.swift:

typealias SliceType = RandomAccessSlice

And run the following compiler invocation with a recent 4.1 snapshot compiler on Linux:

swift -frontend -c -primary-file test.swift -module-name Test -emit-module-path test.swiftmodule -o test.o

then the compiler will crash with the following output:

test.swift:1:23: warning: 'RandomAccessSlice' is deprecated: renamed to 'Slice'
typealias SliceType = RandomAccessSlice
                      ^
test.swift:1:23: note: use 'Slice' instead
typealias SliceType = RandomAccessSlice
                      ^~~~~~~~~~~~~~~~~
                      Slice
swift: /home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/lib/Serialization/Serialization.cpp:604: DeclID swift::serialization::Serializer::addDeclRef(const swift::Decl *, bool, bool): Assertion `(allowTypeAliasXRef || !isa<TypeAliasDecl>(D) || D->getModuleContext() == M) && "cannot cross-reference typealiases directly (use the NameAliasType)"' failed.
/usr/bin/swift[0x3f23334]
/usr/bin/swift[0x3f23676]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f7251e4a390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f7250589428]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f725058b02a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f7250581bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f7250581c82]
/usr/bin/swift[0x1443e67]
/usr/bin/swift[0x14590a0]
/usr/bin/swift[0x145a855]
/usr/bin/swift[0x145c214]
/usr/bin/swift[0x14630a3]
/usr/bin/swift[0x14a5c66]
/usr/bin/swift[0x1465762]
/usr/bin/swift[0x14654d7]
/usr/bin/swift[0x4cb154]
/usr/bin/swift[0x11bb214]
/usr/bin/swift[0x4c3210]
/usr/bin/swift[0x4bee6c]
/usr/bin/swift[0x477864]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f7250574830]
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-07-a-ubuntu16.04/usr/bin/swift[0x475119]
Stack dump:
0.      Program arguments: swift -frontend -c -primary-file test.swift -module-name Test -emit-module-path test.swiftmodule -o test.o
Aborted (core dumped)

The compiler warnings are expected: the assert is not. Removing the -emit-module-path test.swiftmodule prevents the crash, so this suggests that the issue is specifically due to having a module context.

I've only reproduced this on Linux: running equivalent code on macOS does not hit the same crash.

@Lukasa
Copy link
Contributor Author

Lukasa commented Feb 9, 2018

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Feb 9, 2018

Weird. Thanks, Cory.

@weissi
Copy link
Member

weissi commented Apr 30, 2018

@belkadan same happens on a very recent snapshot with this: apple/swift-nio@673a964

and that's on macOS

@belkadan
Copy link
Contributor

Workaround: redeclare the generic parameters on the new typealias:

typealias SliceType<T> = RandomAccessSlice<T> where T: RandomAccessCollection

@weissi
Copy link
Member

weissi commented May 21, 2018

thanks!

@xedin
Copy link
Member

xedin commented May 23, 2018

I've talked to @DougGregor about this and it looks like we'd want to ban generic typealias spelling without generic parameters specified but it only currently broken when underlying type is a typealias as well, temporarily I'm going to allow their serialization again but we'll need to figure out more comprehensive solution for long term.

@xedin
Copy link
Member

xedin commented May 23, 2018

Opened #16784 to temporary address the problem.

@xedin
Copy link
Member

xedin commented May 23, 2018

My PR has been merged into both master and 4.2 branch, I've filled a separate radar for more comprehensive solution for this.

@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
Projects
None yet
Development

No branches or pull requests

5 participants