Skip to content

Compiler crash with 'lazy var' that references element archetype #78690

Open
@hamishknight

Description

@hamishknight

The following crashes in SILGen:

func foo<each T>(_ xs: repeat each T) {
  for x in repeat each xs {
    lazy var y = x
  }
}
Assertion failed: (!result.getInterfaceType()->hasArchetype() && "interface type of result should not contain context archetypes"), function SILFunctionType, file ASTContext.cpp, line 5220.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Users/hamish/src/swift-dev/build/Release/swift-macosx-arm64/bin/swift-frontend -typecheck /Users/hamish/src/swift-test-arena/main.swift -sdk /Users/hamish/src/MacOSX.sdk -debug-diagnostic-names -diagnostic-style=llvm -emit-sil
1.      Swift version 6.2-dev (LLVM 01f9dd6fdcc4a17, Swift b52d154be49f37c)
2.      Compiling with effective version 5.10
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.      While silgen emitFunction SIL function "@$s4main3fooyyxxQpRvzlF".
 for 'foo(_:)' (at /Users/hamish/src/swift-test-arena/main.swift:823:1)
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           0x0000000108191be4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010818ff00 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108192260 SignalHandler(int, __siginfo*, void*) + 324
3  libsystem_platform.dylib 0x00000001810b4184 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018107ef70 pthread_kill + 288
5  libsystem_c.dylib        0x0000000180f8b908 abort + 128
6  libsystem_c.dylib        0x0000000180f8ac1c err + 0
7  swift-frontend           0x0000000108209518 swift::SILFunctionType::SILFunctionType(swift::GenericSignature, swift::SILExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, std::__1::optional<swift::SILResultInfo>, swift::SubstitutionMap, swift::SubstitutionMap, swift::ASTContext const&, swift::RecursiveTypeProperties, swift::ProtocolConformanceRef) (.cold.26) + 0
8  swift-frontend           0x0000000103a23628 swift::SILFunctionType::SILFunctionType(swift::GenericSignature, swift::SILExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, std::__1::optional<swift::SILResultInfo>, swift::SubstitutionMap, swift::SubstitutionMap, swift::ASTContext const&, swift::RecursiveTypeProperties, swift::ProtocolConformanceRef) + 1984
9  swift-frontend           0x0000000103a23ea4 swift::SILFunctionType::get(swift::GenericSignature, swift::SILExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, std::__1::optional<swift::SILResultInfo>, swift::SubstitutionMap, swift::SubstitutionMap, swift::ASTContext const&, swift::ProtocolConformanceRef) + 1120
10 swift-frontend           0x00000001033b589c 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) + 7436
11 swift-frontend           0x00000001033acc38 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) + 668
12 swift-frontend           0x00000001033af128 getUncachedSILFunctionTypeForConstant(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::SILDeclRef, swift::Lowering::TypeConverter::LoweredFormalTypes) + 1148
13 swift-frontend           0x00000001033afd44 swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) + 196
14 swift-frontend           0x00000001033a6ae4 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 128
15 swift-frontend           0x0000000102c19aac swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 344
16 swift-frontend           0x0000000102c1cb94 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 236
17 swift-frontend           0x0000000102c1a44c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 168
18 swift-frontend           0x0000000103b45248 swift::AbstractStorageDecl::visitExpectedOpaqueAccessors(llvm::function_ref<void (swift::AccessorKind)>) const + 68
19 swift-frontend           0x0000000103b451ec swift::AbstractStorageDecl::visitEmittedAccessors(llvm::function_ref<void (swift::AccessorDecl*)>) const + 160
20 swift-frontend           0x0000000102c1ea34 swift::Lowering::SILGenModule::visitEmittedAccessors(swift::AbstractStorageDecl*, llvm::function_ref<void (swift::AccessorDecl*)>) + 48
21 swift-frontend           0x0000000102c70eec swift::Lowering::SILGenFunction::visitVarDecl(swift::VarDecl*) + 148
22 swift-frontend           0x0000000102d10334 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4020
23 swift-frontend           0x0000000102d15cf8 void llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>::callback_fn<(anonymous namespace)::StmtEmitter::visitForEachStmt(swift::ForEachStmt*)::$_0>(long, swift::SILValue, swift::SILValue, swift::SILValue) + 648
24 swift-frontend           0x0000000102cd96c0 swift::Lowering::SILGenFunction::emitDynamicPackLoop(swift::SILLocation, swift::CanTypeWrapper<swift::PackType>, unsigned int, swift::SILValue, swift::SILValue, swift::GenericEnvironment*, bool, llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>, swift::SILBasicBlock*) + 1640
25 swift-frontend           0x0000000102cd9e40 swift::Lowering::SILGenFunction::emitDynamicPackLoop(swift::SILLocation, swift::CanTypeWrapper<swift::PackType>, unsigned int, swift::GenericEnvironment*, llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>, swift::SILBasicBlock*) + 48
26 swift-frontend           0x0000000102d14690 (anonymous namespace)::StmtEmitter::visitForEachStmt(swift::ForEachStmt*) + 564
27 swift-frontend           0x0000000102d10408 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4232
28 swift-frontend           0x0000000102d0f374 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 24
29 swift-frontend           0x0000000102ca8b20 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 420
30 swift-frontend           0x0000000102c1bbe8 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6016
31 swift-frontend           0x0000000102c1cba4 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 252
32 swift-frontend           0x0000000102c1a44c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 168
33 swift-frontend           0x0000000102c1efa8 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 160
34 swift-frontend           0x0000000102c1f498 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 616
35 swift-frontend           0x0000000102d0ed98 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&) + 132
36 swift-frontend           0x0000000102c2365c 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'()) + 324
37 swift-frontend           0x0000000102c1f7cc swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 120
38 swift-frontend           0x0000000102672b54 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1264
39 swift-frontend           0x000000010267ea6c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 164
40 swift-frontend           0x00000001026744c0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 700
41 swift-frontend           0x0000000102673d1c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2208
42 swift-frontend           0x0000000102464760 swift::mainEntry(int, char const**) + 3052
43 dyld                     0x0000000180cfc274 start + 2840
fish: Job 1, './swift -frontend -typecheck ~/…' terminated by signal SIGABRT (Abort)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaregenericsFeature: generic declarations and typespack iterationFeature → statements → for-in: Pack iterationparameter packsFeature → generics: Parameter packsswift 6.2

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions