Skip to content

Bug: Fell off the end: (generic_type_param_type depth=0 index=0 param_kind=type) #82492

Open
@johnbean393

Description

@johnbean393

Description

The Swift compiler crashes during SIL generation with an assertion failure: Fell off the end: (generic_type_param_type ...). The crash occurs in MapLocalArchetypesOutOfContext::getInterfaceType, the same function implicated in related generic substitution crashes.

This suggests the compiler has encountered an unhandled case while attempting to map a generic type parameter out of its original context, likely during the lowering of a function that involves closures and complex generic signatures.

Reproduction

The crash occurs when compiling the Swallow library as a dependency.

To reproduce:

  1. Clone the Swallow library: https://github.com/vmanot/Swallow
  2. Add it as a Swift Package dependency to a macOS project.
  3. Build the project with Xcode Beta (or using the command line).

The compiler crashes when compiling the Swallow module. The failing build command processes a batch of files, including ActorIsolated.swift.

Build command that triggers the crash:

swift build

Or by building the parent project in Xcode.

Stack dump

Fell off the end:
(generic_type_param_type depth=0 index=0 param_kind=type)

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           0x0000000106a87450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000106a84de0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106a87a7c SignalHandler(int, __siginfo*, void*) + 344
3  libsystem_platform.dylib 0x0000000182eec624 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000182eb288c pthread_kill + 296
5  libsystem_c.dylib        0x0000000182dbbc60 abort + 124
6  swift-frontend           0x00000001021d5330 swift::MapLocalArchetypesOutOfContext::getInterfaceType(swift::Type, swift::GenericEnvironment*) const + 444
7  swift-frontend           0x00000001021d55fc swift::Type llvm::function_ref<swift::Type (swift::SubstitutableType*)>::callback_fn<swift::MapLocalArchetypesOutOfContext>(long, swift::SubstitutableType*) + 84
8  swift-frontend           0x000000010232bb78 swift::InFlightSubstitution::substType(swift::SubstitutableType*, unsigned int) + 48
9  swift-frontend           0x0000000102330f6c (anonymous namespace)::TypeSubstituter::transformLocalArchetypeType(swift::LocalArchetypeType*, swift::TypePosition) + 64
10 swift-frontend           0x000000010232c95c swift::TypeTransform<(anonymous namespace)::TypeSubstituter>::doIt(swift::Type, swift::TypePosition) + 1944
11 swift-frontend           0x000000010232cb6c swift::TypeTransform<(anonymous namespace)::TypeSubstituter>::doIt(swift::Type, swift::TypePosition) + 2472
12 swift-frontend           0x000000010232c158 swift::Type::subst(swift::InFlightSubstitution&) const + 272
13 swift-frontend           0x000000010232baec swift::Type::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) const + 392
14 swift-frontend           0x0000000100ff68e8 getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 5152
15 swift-frontend           0x0000000100fed468 getNativeSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 684
16 swift-frontend           0x0000000100ff02a8 getUncachedSILFunctionTypeForConstant(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::SILDeclRef, swift::Lowering::TypeConverter::LoweredFormalTypes) + 1392
17 swift-frontend           0x0000000100ff0ec4 swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) + 200
18 swift-frontend           0x0000000100fe6d1c swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 124
19 swift-frontend           0x00000001011cb128 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 728
20 swift-frontend           0x00000001011d6c98 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 92
21 swift-frontend           0x0000000101284958 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 3144
22 swift-frontend           0x000000010125b33c swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
23 swift-frontend           0x00000001011f3af4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 5256
24 swift-frontend           0x00000001011e0324 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 204
25 swift-frontend           0x00000001011f2010 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern, llvm::ArrayRef<swift::LifetimeDependenceInfo>) + 304
26 swift-frontend           0x00000001011feac8 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 676
27 swift-frontend           0x00000001011fe27c (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1112
28 swift-frontend           0x00000001011e4edc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1112
29 swift-frontend           0x00000001011e3874 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3192
30 swift-frontend           0x000000010125ba98 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 988
31 swift-frontend           0x0000000101318140 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6504
32 swift-frontend           0x0000000101319210 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 10808
33 swift-frontend           0x00000001013181b0 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6616
34 swift-frontend           0x00000001012908a0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 384
35 swift-frontend           0x00000001011cde54 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
36 swift-frontend           0x00000001011ceea4 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 236
37 swift-frontend           0x00000001011cc094 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 136
38 swift-frontend           0x00000001011d2c1c swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
39 swift-frontend           0x0000000101315e80 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 208
40 swift-frontend           0x00000001011d76a4 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 572
41 swift-frontend           0x00000001006f3f0c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 964
42 swift-frontend           0x00000001006f7274 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
43 swift-frontend           0x00000001006f5e90 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
44 swift-frontend           0x0000000100677444 swift::mainEntry(int, char const**) + 5412
45 dyld                     0x0000000182b12b98 start + 6076

Expected behavior

The compiler should successfully compile the code without crashing. If there is an issue with the generic type handling, it should produce a diagnostic error instead of an internal compiler error.

Environment

  • Swift Version: 6.2 (swiftlang-6.2.0.x clang-1700.x)
  • Xcode: Xcode-beta.app
  • Platform: arm64-apple-macos11.0
  • Target: macOS 11.0+
  • Build Configuration: Debug (-Onone)

Additional information

The key diagnostic message Fell off the end: (generic_type_param_type ...) is the primary indicator of the fault. Given the identical crash location in the stack trace (MapLocalArchetypesOutOfContext), this appears to be a variant of the same underlying bug as this issue, related to generic substitution, but triggered in a way that hits an unhandled case in the compiler's logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage 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