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

generic pack iteration compiler crash when accessing property #78385

Open
lukaskollmer opened this issue Dec 30, 2024 · 0 comments
Open

generic pack iteration compiler crash when accessing property #78385

lukaskollmer opened this issue Dec 30, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@lukaskollmer
Copy link

Description

Not sure how to describe this exactly, but basically if you try to access, in a pack iteration, a property of a generic type, which is itself a property of a generic type, the compiler crashes.

The program below is a simplified version of a program where I encountered this issue; i'm not sure if there's just one bug here or multiple, since there seem to be multilpe constellations of changes one can apply to the program to get it to work/crash.

For example, in the program below, any of the following changes will make it compile

  • make SampleType non-generic
  • add a property of type T to SampleType
  • remove either the title: String or the range: ClosedRange<Double>? property
  • make the range property non-optional
  • change the type of range to e.g. Int

Reproduction

struct SampleType<T> {
    let title: String
    let range: ClosedRange<Double>?
}


protocol Results {
    associatedtype Sample
    var sampleType: SampleType<Sample> { get }
}


final class Entry<R: Results> {
    let results: R
    
    init(results: R) {
        self.results = results
    }
}


struct View<each R: Results> {
    let entry: (repeat Entry<each R>)
    
    var broken: Void {
        for entry in repeat each entry {
            _ = entry.results.sampleType
        }
    }
    
    var fine: Void {
        func imp<T>(_ entry: Entry<T>) {
            _ = entry.results.sampleType
        }
        repeat imp(each entry)
    }
}

Stack dump

1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/lukas/Developer/test/test_2024-12-29b/test_2024-12-29b/main.swift")
4.	While emitting IR SIL function "@$s16test_2024_12_29b4ViewV6brokenytvg".
 for getter for broken (at /Users/lukas/Developer/test/test_2024-12-29b/test_2024-12-29b/main.swift:42:9)
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           0x0000000106426a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000106424cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106427068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019179a584 _sigtramp + 56
4  swift-frontend           0x00000001014a9924 swift::irgen::getTypeAndGenericSignatureForManglingOutlineFunction(swift::SILType) + 344
5  swift-frontend           0x00000001014abc44 swift::irgen::OutliningMetadataCollector::emitCallToOutlinedRelease(swift::irgen::Address, swift::SILType, swift::irgen::TypeInfo const&, swift::irgen::Atomicity) const + 352
6  swift-frontend           0x00000001014aba40 swift::irgen::TypeInfo::callOutlinedRelease(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, swift::irgen::Atomicity) const + 120
7  swift-frontend           0x0000000101421a88 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 75976
8  swift-frontend           0x000000010140dea4 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 13220
9  swift-frontend           0x000000010140a65c swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 2088
10 swift-frontend           0x0000000101255834 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 3364
11 swift-frontend           0x00000001013c15a8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4700
12 swift-frontend           0x0000000101409ba8 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
13 swift-frontend           0x00000001013ca394 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 784
14 swift-frontend           0x00000001013c3e90 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 180
15 swift-frontend           0x0000000100dd34bc generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
16 swift-frontend           0x0000000100dcece4 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2176
17 swift-frontend           0x0000000100dcdbd0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
18 swift-frontend           0x0000000100dd0e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
19 swift-frontend           0x0000000100dcfbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
20 swift-frontend           0x0000000100d56a5c swift::mainEntry(int, char const**) + 3680
21 dyld                     0x00000001913df154 start + 2476

Expected behavior

the code, as above, should compile fine when using pack iteration

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx14.0

Additional information

The slightly-less-simplified version where I encountered this bug, which does in fact use the `T` generic parameter in the `SampleType` struct:
class IdentifierBase {}

protocol IdentifierTypeProviding {
    associatedtype Identifier: IdentifierBase
}


struct SampleType<T: IdentifierTypeProviding> {
    let id: T.Identifier
    let title: String
    let range: ClosedRange<Double>?
}


protocol Results {
    associatedtype Sample: IdentifierTypeProviding
    var sampleType: SampleType<Sample> { get }
}


final class Entry<R: Results> {
    let results: R
    
    init(results: R) {
        self.results = results
    }
}


struct View<each R: Results> {
    let entry: (repeat Entry<each R>)
    
    var broken: Void {
        for entry in repeat each entry {
            _ = entry.results.sampleType
        }
    }
    
    var fine: Void {
        func imp<T>(_ entry: Entry<T>) {
            _ = entry.results.sampleType
        }
        repeat imp(each entry)
    }
}
@lukaskollmer lukaskollmer added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Dec 30, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant