Skip to content

Compiler crash with SegFault11 with actors/task/implicit self combinations #64605

Open
@PoltoraIvana

Description

@PoltoraIvana

Description
The following code crashes the compiler with Segmentation Fault 11.

actor MyActor {
  
  private var task: Task<Void, Never>?
  private var flag = false
  
  func foo() {
    task = Task { [weak self] in
      guard !Task.isCancelled, let self = self else { return }
      flag.toggle()
    }
  }
}

If we remove check for 'Task.isCancelled', the compiler doesn't crash, but the context inside the Task is not inherited from actor and we have compilation error:

Actor-isolated property 'flag' can not be mutated from a non-isolated context

Steps to reproduce
Try to compile the code above.

Expected behavior
Compiler doesn't crash, actor context is inherited in the task.

Environment

  • Swift compiler version info
    swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.1 clang-1403.0.22.11.100)
    Target: arm64-apple-macosx13.0

  • Xcode version info
    Xcode 14.3
    Build version 14E222a

  • Deployment target: iOS 16.4 (doesn't matter)

Additional info
Seems like [weak self] capture breaks context inheritance from actor, and combination with 'Task.isCancelled' crashes the compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    actorFeature → concurrency: `actor` declarationsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featurescrashBug: A crash, i.e., an abnormal termination of softwaretype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions