Assertion in swift/lib/AST/Type.cpp, but only on M1 / arm64 (FB9786622)

I'm running in a swift-frontend crash when building my project on an M1 max on Monterey. The same project builds fine on my older x86 MBP on Big Sur.

The Xcode version is 13.2b2 (13C5081f) but this happens on 13.1 as well. I installed the latest toolchain from swift.org, but the problem persisted - only the diagnostics got better :slight_smile:

It's either Assertion failed: (Result && "Case not implemented!"), function computeCanonicalType, file Type.cpp, line 1406.
or
SIL-only types are always canonical! UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/lib/AST/Type.cpp:1344!

The weird thing is, that this crash happens when building for the second time. I have to clean build and close Xcode to be able to build once. After that I run constantly into this crash, until I clean build and restart Xcode.

I'm not very fluent in C++, can anyone tell what could be the problem in my code that is crashing swift-frontend? Unfortunately I cannot share the project and I failed to reproduce the problem in a sample project.

This is the stack trace for "UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/lib/AST/Type.cpp:1344!":

0  swift-frontend           0x0000000109157858 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109156ab8 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x0000000109157ebc SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001a59c04e4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a59a915c pthread_kill + 288
5  libsystem_c.dylib        0x00000001a58e6314 abort + 164
6  swift-frontend           0x00000001090ca27c llvm::install_out_of_memory_new_handler() + 0
7  swift-frontend           0x0000000105f91334 swift::TypeBase::computeCanonicalType() + 2804
8  swift-frontend           0x0000000105139050 swift::ide::getReceiverType(swift::Expr*, llvm::SmallVectorImpl<swift::NominalTypeDecl*>&) + 332
9  swift-frontend           0x000000010515c338 (anonymous namespace)::IndexSwiftASTWalker::initFuncRefIndexSymbol(swift::ValueDecl*, swift::SourceLoc, swift::index::IndexSymbol&) + 276
10 swift-frontend           0x000000010515bf0c (anonymous namespace)::IndexSwiftASTWalker::reportPseudoAccessor(swift::AbstractStorageDecl*, swift::AccessorKind, bool, swift::SourceLoc) + 224
11 swift-frontend           0x000000010515ce30 (anonymous namespace)::IndexSwiftASTWalker::reportRef(swift::ValueDecl*, swift::SourceLoc, swift::index::IndexSymbol&, llvm::Optional<swift::AccessKind>) + 424
12 swift-frontend           0x0000000105159b4c (anonymous namespace)::IndexSwiftASTWalker::visitDeclReference(swift::ValueDecl*, swift::CharSourceRange, swift::TypeDecl*, swift::ExtensionDecl*, swift::Type, swift::ReferenceMetaData) + 472
13 swift-frontend           0x0000000105150f28 (anonymous namespace)::SemaAnnotator::passReference(swift::ValueDecl*, swift::Type, swift::SourceLoc, swift::SourceRange, swift::ReferenceMetaData) + 324
14 swift-frontend           0x000000010514fa84 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 1552
15 swift-frontend           0x0000000105d4bc90 swift::Expr::walk(swift::ASTWalker&) + 44
16 swift-frontend           0x000000010514fc60 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 2028
17 swift-frontend           0x0000000105d4bc90 swift::Expr::walk(swift::ASTWalker&) + 44
18 swift-frontend           0x000000010514f890 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 1052
19 swift-frontend           0x0000000105d4e1fc swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 572
20 swift-frontend           0x0000000105d4e1a8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 488
21 swift-frontend           0x0000000105d4cff8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2896
22 swift-frontend           0x0000000105d4c3fc (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 184
23 swift-frontend           0x0000000105d4c664 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 444
24 swift-frontend           0x0000000105d4c3fc (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 184
25 swift-frontend           0x0000000105d4c664 swift::ASTVisitor<(anonymous namespace)::Traversal,

And this for "(Result && "Case not implemented!"), function computeCanonicalType, file Type.cpp, line 1406."

0  swift-frontend           0x00000001046e3858 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001046e2ab8 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x00000001046e3ebc SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001a59c04e4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a59a915c pthread_kill + 288
5  libsystem_c.dylib        0x00000001a58e6314 abort + 164
6  libsystem_c.dylib        0x00000001a58e572c err + 0
7  swift-frontend           0x0000000104b1b588 swift::TypeBase::computeCanonicalType() (.cold.2) + 0
8  swift-frontend           0x000000010151d260 swift::TypeBase::computeCanonicalType() + 2592
9  swift-frontend           0x00000001006c5050 swift::ide::getReceiverType(swift::Expr*, llvm::SmallVectorImpl<swift::NominalTypeDecl*>&) + 332
10 swift-frontend           0x00000001006e8338 (anonymous namespace)::IndexSwiftASTWalker::initFuncRefIndexSymbol(swift::ValueDecl*, swift::SourceLoc, swift::index::IndexSymbol&) + 276
11 swift-frontend           0x00000001006e7f0c (anonymous namespace)::IndexSwiftASTWalker::reportPseudoAccessor(swift::AbstractStorageDecl*, swift::AccessorKind, bool, swift::SourceLoc) + 224
12 swift-frontend           0x00000001006e8e30 (anonymous namespace)::IndexSwiftASTWalker::reportRef(swift::ValueDecl*, swift::SourceLoc, swift::index::IndexSymbol&, llvm::Optional<swift::AccessKind>) + 424
13 swift-frontend           0x00000001006e5b4c (anonymous namespace)::IndexSwiftASTWalker::visitDeclReference(swift::ValueDecl*, swift::CharSourceRange, swift::TypeDecl*, swift::ExtensionDecl*, swift::Type, swift::ReferenceMetaData) + 472
14 swift-frontend           0x00000001006dcf28 (anonymous namespace)::SemaAnnotator::passReference(swift::ValueDecl*, swift::Type, swift::SourceLoc, swift::SourceRange, swift::ReferenceMetaData) + 324
15 swift-frontend           0x00000001006dba84 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 1552
16 swift-frontend           0x00000001012d7c90 swift::Expr::walk(swift::ASTWalker&) + 44
17 swift-frontend           0x00000001006dbc60 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 2028
18 swift-frontend           0x00000001012d7c90 swift::Expr::walk(swift::ASTWalker&) + 44
19 swift-frontend           0x00000001006db890 (anonymous namespace)::SemaAnnotator::walkToExprPre(swift::Expr*) + 1052
20 swift-frontend           0x00000001012da1fc swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 572
21 swift-frontend           0x00000001012da1a8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 488
22 swift-frontend           0x00000001012d8ff8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2896
23 swift-frontend           0x00000001012d83fc (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 184
24 swift-frontend           0x00000001012d8664 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 444
25 swift-frontend           0x00000001012d83fc (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 184
26 swift-frontend           0x00000001012d8664 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 444
27 swift-frontend           0x00000001012d9eec (anonymous namespace)::Traversal::visitSelfApplyExpr(swift::SelfApplyExpr*) + 112
28 swift-frontend           0x00000001012d862c swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 388
29 swift-frontend           0x00000001012da22c swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 620
30 swift-frontend           0x00000001012da1a8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 488
31 swift-frontend           0x00000001012dcda4 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 684
32 swift-frontend           0x00000001012d8198 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 108
33 swift-frontend           0x00000001012dc248 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Decl*) + 2196
34 swift-frontend           0x00000001012d8198 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 108
35 swift-frontend           0x00000001012d8120 swift::Decl::walk(swift::ASTWalker&) + 32
36 swift-frontend           0x00000001014784bc swift::SourceFile::walk(swift::ASTWalker&) + 180
37 swift-frontend           0x00000001006daaa4 swift::SourceEntityWalker::walk(swift::SourceFile&) + 196
38 swift-frontend           0x00000001006e434c (anonymous namespace)::IndexSwiftASTWalker::visitModule(swift::ModuleDecl&) + 188
39 swift-frontend           0x00000001006e423c swift::index::indexSourceFile(swift::SourceFile*, swift::index::IndexDataConsumer&) + 316
40 swift-frontend           0x00000001006e9bc8 recordSourceFileUnit(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, llvm::StringRef, llvm::ArrayRef<clang::FileEntry const*>, clang::CompilerInstance const&, swift::DiagnosticEngine&) + 1052
41 swift-frontend           0x00000001006e9788 swift::index::indexAndRecord(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, llvm::StringRef, swift::DependencyTracker const&) + 312
42 swift-frontend           0x00000001003f2970 emitIndexDataForSourceFile(swift::SourceFile*, swift::CompilerInstance const&) + 260
43 swift-frontend           0x00000001003eb92c performEndOfPipelineActions(swift::CompilerInstance&) + 4940
44 swift-frontend           0x00000001003e7184 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3004
45 swift-frontend           0x00000001003a6780 swift::mainEntry(int, char const**) + 500
46 dyld                     0x000000010ca810f4 start + 520

Compiler crashes are never normal! Please file a bug about this. Usually, that would be over at bugs.swift.org. If this is proprietary code and you can't reduce it down to something that can be shared publicly, you could file an Apple feedback instead.

Being able to see the code that produced this bug would similarly help with the discussion here.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy