Skip to content

Crash when mangling TypeKind::OpenedArchetype (while Lowering AST to SIL) #69620

Open
@art-divin

Description

@art-divin

Description

While tinkering with swift-syntax I have added a simple function to SyntaxVisitor.swift:

public extension SyntaxProtocol {
  func visit() -> SyntaxVisitorContinueKind { .visitChildren }
  func visitPost() {}
}

open class SyntaxVisitor {
  ...
  ...
  func visit(_ node: some SyntaxProtocol) -> SyntaxVisitorContinueKind { node.visit() }
  func visitPost(_ node: some SyntaxProtocol) { node.visitPost() }
  ...
}

But then swift compiler cannot compile code and reports a crash report (see below).

Steps to reproduce

  1. Checkout https://github.com/art-divin/swift-syntax/ at branch resolve-compilation-time-issues at commit 83d2d64e66bb49d2eb562ed8dafc4ea8739ca8ee
  2. cd into cloned repository
  3. execute swift build

Expected behavior

Code should either compile, or generate appropriate error message.

Environment

  • Swift compiler version info Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
  • Xcode version info Xcode 15.0.1 (Build version 15A507)
  • Deployment target: macOS 14.0 (23A344)
Stack dump:
0.	Program arguments: /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -filelist /var/folders/90/8tcwdk19055d0rrgfp00h25h0000gn/T/TemporaryDirectory.9mvEOa/sources-1 -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxCollections+6.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxCollections+7.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxCollections+8.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxCollections+9.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxEnum.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxKind.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxRewriter.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxTraits.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxVisitor.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/TokenKind.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/Tokens.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/TriviaPieces.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+0.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+1.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+10.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+11.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+12.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+13.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+14.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+15.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+16.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+17.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+18.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+19.swift -primary-file /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB+2.swift -supplementary-output-file-map /var/folders/90/8tcwdk19055d0rrgfp00h25h0000gn/T/TemporaryDirectory.9mvEOa/supplementaryOutputs-9 -target arm64-apple-macosx10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -I /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug -I /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -warn-long-function-bodies=30 -warn-long-expression-type-checking=30 -empty-abi-descriptor -resource-dir /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -isysroot -Xcc /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -Xcc -F -Xcc /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -module-name SwiftSyntax -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0 -external-plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxCollections+6.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxCollections+7.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxCollections+8.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxCollections+9.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxEnum.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxKind.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxRewriter.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxTraits.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/SyntaxVisitor.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/TokenKind.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/Tokens.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/TriviaPieces.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+0.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+1.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+10.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+11.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+12.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+13.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+14.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+15.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+16.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+17.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+18.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+19.swift.o -o /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/SwiftSyntax.build/generated/raw/RawSyntaxNodesAB+2.swift.o -index-store-path /Users/art-divin/Documents/Projects/swift-syntax/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
2.	Compiling with the current language version
3.	Contents of /var/folders/90/8tcwdk19055d0rrgfp00h25h0000gn/T/TemporaryDirectory.9mvEOa/sources-1:
---
...
<redacted>
...
---
4.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxVisitor.swift")
5.	While silgen emitFunction SIL function "@$s11SwiftSyntax0B7VisitorC14visitationFunc33_F966D2E530B0A562820FA4876E472C28LL3foryAA0B0VcAH_tF".
 for 'visitationFunc(for:)' (at /Users/art-divin/Documents/Projects/swift-syntax/Sources/SwiftSyntax/generated/SyntaxVisitor.swift:3461:11)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000107ce314c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a861f2c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001065a310c SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000018a7a5a24 _sigtramp + 56
4  swift-frontend           0x000000010810beb4 swift::Mangle::ASTMangler::appendTypeListElement(swift::Identifier, swift::Type, swift::ParameterTypeFlags, swift::GenericSignature, swift::ValueDecl const*) + 188
5  swift-frontend           0x000000010810beb4 swift::Mangle::ASTMangler::appendTypeListElement(swift::Identifier, swift::Type, swift::ParameterTypeFlags, swift::GenericSignature, swift::ValueDecl const*) + 188
6  swift-frontend           0x000000010810b790 swift::Mangle::ASTMangler::appendFunctionSignature(swift::AnyFunctionType*, swift::GenericSignature, swift::ValueDecl const*, swift::Mangle::ASTMangler::FunctionManglingKind) + 388
7  swift-frontend           0x0000000108107fc4 swift::Mangle::ASTMangler::appendFunctionType(swift::AnyFunctionType*, swift::GenericSignature, bool, swift::ValueDecl const*) + 36
8  swift-frontend           0x000000010810b6c0 swift::Mangle::ASTMangler::appendFunctionSignature(swift::AnyFunctionType*, swift::GenericSignature, swift::ValueDecl const*, swift::Mangle::ASTMangler::FunctionManglingKind) + 180
9  swift-frontend           0x0000000108107fc4 swift::Mangle::ASTMangler::appendFunctionType(swift::AnyFunctionType*, swift::GenericSignature, bool, swift::ValueDecl const*) + 36
10 swift-frontend           0x000000010810d528 swift::Mangle::ASTMangler::appendClosureComponents(swift::Type, unsigned int, bool, swift::DeclContext const*) + 388
11 swift-frontend           0x00000001080ebacc swift::Mangle::ASTMangler::mangleClosureEntity(swift::AbstractClosureExpr const*, swift::Mangle::ASTMangler::SymbolKind) + 148
12 swift-frontend           0x0000000106e0007c swift::SILDeclRef::mangle(swift::SILDeclRef::ManglingKind) const + 1748
13 swift-frontend           0x0000000106e5af80 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 76
14 swift-frontend           0x0000000107fa96a8 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 464
15 swift-frontend           0x0000000108103b28 (anonymous namespace)::SILGenApply::visitAbstractClosureExpr(swift::AbstractClosureExpr*) + 124
16 swift-frontend           0x0000000108044ca4 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 344
17 swift-frontend           0x000000010830d36c (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) + 4720
18 swift-frontend           0x00000001082a7254 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
19 swift-frontend           0x0000000108098b44 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 4680
20 swift-frontend           0x000000010803dd78 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 224
21 swift-frontend           0x000000010809255c (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 260
22 swift-frontend           0x000000010810dea0 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 672
23 swift-frontend           0x000000010810cab4 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1000
24 swift-frontend           0x00000001056cb34c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 4044
25 swift-frontend           0x000000010804574c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3072
26 swift-frontend           0x000000010837d620 void llvm::function_ref<void (swift::Expr*)>::callback_fn<swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_18>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_18)::'lambda'(swift::Expr*)>(long, swift::Expr*) + 36
27 swift-frontend           0x00000001082b59fc swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 792
28 swift-frontend           0x0000000108308490 (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext) + 272
29 swift-frontend           0x00000001082a8468 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
30 swift-frontend           0x0000000105e7f570 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) (.llvm.5384354941888427540) + 5512
31 swift-frontend           0x00000001083d5864 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 632
32 swift-frontend           0x00000001056b8a4c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8004
33 swift-frontend           0x0000000107fc563c emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef) (.llvm.12369091251732681984) + 168
34 swift-frontend           0x0000000107facbe8 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 292
35 swift-frontend           0x0000000108775e3c (anonymous namespace)::SILGenType::emitType() (.llvm.16014246188637114379) + 876
36 swift-frontend           0x0000000107faac64 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
37 swift-frontend           0x0000000107fd4608 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2908
38 swift-frontend           0x0000000106bfc4fc swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 200
39 swift-frontend           0x0000000107ff2948 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
40 swift-frontend           0x000000010a8198d8 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
41 swift-frontend           0x000000010a81d474 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
42 swift-frontend           0x000000010a1634e0 swift::mainEntry(int, char const**) + 4116
43 dyld                     0x000000018a3fd058 start + 2224

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closurescompilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsmanglingArea → compiler: Manglingswift 5.9triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions