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

[SR-15621] Segmentation fault: 11 when referencing to Self in withCheckedThrowingContinuation #57917

Open
swift-ci opened this issue Dec 18, 2021 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-15621
Radar None
Original Reporter m1entus (JIRA User)
Type Bug
Environment

Xcode 13.2.1 (13C100)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6288d09b91d41e3753dda56643e512a4

Issue Description:

4.  While evaluating request IRGenRequest(IR Generation for file "/Users/m1entus/Documents/Programowanie/geneva-ios/Project/GenevaCore/GenevaCore/Extensions/INSOperation+Async.swift")
5.  While emitting IR SIL function "@$sSo12INSOperationC10GenevaCoreE28asyncRunWithTaskCancellation33_3E315D5698B48D5FD2124BA47A13F9DELL2inABXDSo16NSOperationQueueC_tYaKFABXDyYaKXEfU1_yScCyABXDs5Error_pGXEfU_".
 for expression at [/xxxx/INSOperation+Async.swift:26:59 - line:44:17] RangeText="{ continuation in
                    ins_addCompletionBlock { operation in
                        guard let operation = operation as? Self else {
                            fatalError()
                        }


                        if operation.isCancelled {
                            continuation.resume(throwing: CancellationError())
                        } else {
                            continuation.resume(returning: operation)
                        }
                    }
                    if self.state.rawValue >= INSOperationState.finishing.rawValue {
                        continuation.resume(returning: self)
                    } else {
                        operation = self
                        operationQueue.addOperation(self)
                    }
                "
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           0x00000001047e39c4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001047e2acc llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x00000001047e4004 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000193f904e4 _sigtramp + 56
4  swift-frontend           0x0000000100914cc8 swift::irgen::IRGenFunction::getDynamicSelfMetadata() + 140
5  swift-frontend           0x0000000100a0e3b4 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 528
6  swift-frontend           0x0000000100a0d98c swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 256
7  swift-frontend           0x0000000100a11b60 void llvm::function_ref<void (unsigned int, swift::CanType, swift::ProtocolConformanceRef)>::callback_fn<swift::irgen::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, swift::ProtocolConformanceRef)>(long, unsigned int, swift::CanType, swift::ProtocolConformanceRef) + 88
8  swift-frontend           0x0000000100960794 swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap, llvm::function_ref<void (unsigned int, swift::CanType, swift::ProtocolConformanceRef)>) + 272
9  swift-frontend           0x0000000100a11718 emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType, swift::irgen::DynamicMetadataRequest) + 644
10 swift-frontend           0x0000000100a0e248 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 164
11 swift-frontend           0x0000000100a0d98c swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 256
12 swift-frontend           0x000000010093be40 swift::irgen::IRGenFunction::emitValueWitnessTableRef(swift::SILType, swift::irgen::DynamicMetadataRequest, llvm::Value**) + 440
13 swift-frontend           0x000000010095164c swift::irgen::emitLoadOfAlignmentMask(swift::irgen::IRGenFunction&, swift::SILType) + 132
14 swift-frontend           0x000000010090ecbc swift::irgen::HeapNonFixedOffsets::HeapNonFixedOffsets(swift::irgen::IRGenFunction&, swift::irgen::HeapLayout const&) + 612
15 swift-frontend           0x0000000100903954 emitPartialApplicationForwarder(swift::irgen::IRGenModule&, llvm::Optional<swift::irgen::FunctionPointer> const&, bool, swift::irgen::Signature const&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::HeapLayout const*, llvm::ArrayRef<swift::ParameterConvention>) + 3256
16 swift-frontend           0x0000000100902870 swift::irgen::emitFunctionPartialApplication(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::FunctionPointer const&, llvm::Value*, swift::irgen::Explosion&, llvm::ArrayRef<swift::SILParameterInfo>, swift::SubstitutionMap, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::Explosion&, bool) + 3780
17 swift-frontend           0x00000001009e4b24 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 65884
18 swift-frontend           0x00000001009cfe3c swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7752
19 swift-frontend           0x00000001008a9284 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&) + 1332
20 swift-frontend           0x00000001009a3258 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 7572
21 swift-frontend           0x00000001009cdd1c swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
22 swift-frontend           0x00000001009ad718 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 752
23 swift-frontend           0x00000001009a6f0c 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**) + 236
24 swift-frontend           0x00000001005621c0 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*) + 2588
25 swift-frontend           0x0000000100555574 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6520
26 swift-frontend           0x00000001004aedf8 main + 932
27 dyld                     0x0000000106bed0f4 start + 520

When referencing to Self from withCheckedThrowingContinuation i am getting compiler error, in my case i have `extension INSOperation` which inherits from `Operation`. When adding compatibily to async and referencing to force case as Self i am getting compiler error:

return try await withTaskCancellationHandler(
            handler: {
                onCancel()
            },
            operation: {
                try await withCheckedThrowingContinuation { continuation in
                    ins_addCompletionBlock { operation in
                        guard let operation = operation as? Self else {
                            fatalError()
                        }


                        if operation.isCancelled {
                            continuation.resume(throwing: CancellationError())
                        } else {
                            continuation.resume(returning: operation)
                        }
                    }
                    if self.state.rawValue >= INSOperationState.finishing.rawValue {
                        continuation.resume(returning: self)
                    } else {
                        operation = self
                        operationQueue.addOperation(self)
                    }
                }
            }
        )

when i cast to `INSOperation` insted of `Self` it work fine

guard let operation = operation as? INSOperation else {
                            fatalError()
                        }

but seems later i have to force casting using another method:

public func asyncRun(in operationQueue: OperationQueue = INSOperationQueue.global()) async throws -> Self {
        try await asyncRunWithTaskCancellation(in: operationQueue) as! Self
    }
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant