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-10436] type(of: bla).AChildClass() crashes the compiler when AChildClass is defined in an extension in an external module #52836

Closed
marcrasi mannequin opened this issue Apr 10, 2019 · 5 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 5.0

Comments

@marcrasi
Copy link
Mannequin

marcrasi mannequin commented Apr 10, 2019

Previous ID SR-10436
Radar rdar://problem/49778430
Original Reporter @marcrasi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 5.0Regression, CompilerCrash
Assignee @CodaFi
Priority Medium

md5: e2f9b4a34e8b58a8e70d5482125eca7c

Issue Description:

I have uploaded a SwiftPM package here: https://github.com/marcrasi/fastai_docs/tree/f9632e6ee37717446051b00634f4201180f778c5/Reduced

You can reproduce the crash by cd'ing to the directory and running `swift run`.

I have tried a few different versions of Swift:

  • Swift 5.0 on Ubuntu 18.04: crash

  • swift-DEVELOPMENT-SNAPSHOT-2019-04-07-a-ubuntu18.04.tar.gz: crash

  • Swift 4.2.4 on Ubuntu 18.04: no crash

The crash message is:

swift: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/swift/lib/Sema/TypeCheckDecl.cpp:4315: void finalizeType(swift::TypeChecker &, swift::NominalTypeDecl *): Assertion `isa<SourceFile>(nominal->getModuleScopeContext())' failed.
Stack dump:
0.  Program arguments: /home/marcrasi/snapshot-2019-04-07/usr/bin/swift -frontend -c -primary-file /home/marcrasi/fastai_docs/Reduced/Sources/Reduced/main.swift -emit-module-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/Reduced.build/main~partial.swiftmodule -emit-module-doc-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/Reduced.build/main~partial.swiftdoc -emit-dependencies-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/Reduced.build/main.d -emit-reference-dependencies-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/Reduced.build/main.swiftdeps -target x86_64-unknown-linux -disable-objc-interop -sdk / -I /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug -enable-testing -g -module-cache-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/ModuleCache -swift-version 4.2 -Onone -D SWIFT_PACKAGE -D DEBUG -color-diagnostics -enable-anonymous-context-mangled-names -module-name Reduced -o /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/Reduced.build/main.swift.o -index-store-path /home/marcrasi/fastai_docs/Reduced/.build/x86_64-unknown-linux/debug/index/store -index-system-modules 
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x44895c4]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x448721e]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x44899d8]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f4a2caa4890]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f4a2af07e97]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f4a2af09801]
/lib/x86_64-linux-gnu/libc.so.6(+0x3039a)[0x7f4a2aef939a]
/lib/x86_64-linux-gnu/libc.so.6(+0x30412)[0x7f4a2aef9412]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0xeeeb40]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0xf81407]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0xf821d6]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x73d14a]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x73c088]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x73b701]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x4cfdb5]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x4ce99e]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x4734f6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f4a2aeeab97]
/home/marcrasi/snapshot-2019-04-07/usr/bin/swift[0x47315a]
@belkadan
Copy link
Contributor

Reproduced on master. Only reproduces with asserts on, I guess.

7  swift                    0x0000000105cbb8d2 swift::TypeChecker::finalizeDecl(swift::ValueDecl*) + 1058
8  swift                    0x0000000105d5102b typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 827
9  swift                    0x0000000105d51a69 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1065
10 swift                    0x00000001054d5ea6 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 502
11 swift                    0x00000001054d49b3 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 339

@rxwei
Copy link
Member

rxwei commented Apr 24, 2019

Inline reproducer:

// In ModuleA
public final class Foo {
    public init() {}
}
extension Foo {
    public class Bar {
        public init() {}
    }
}
import ModuleA
let foo = Foo()
let _ = type(of: foo).Bar()

If Bar was defined in the Foo's original type declaration instead of an extension, this doesn't crash.

@rxwei
Copy link
Member

rxwei commented Apr 24, 2019

Could someone suggest a path to look into this?

@belkadan
Copy link
Contributor

I'd look at what AST's getting generated for the client code and seeing if it makes sense; if it does, the next step might be figuring out what's different with regards to `finalizeDecl` between the bad version and the simpler `Foo.Bar()`.

@CodaFi
Copy link
Member

CodaFi commented Jul 14, 2021

Happy to report this no longer crashes in Swift 5.5

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

No branches or pull requests

4 participants