Skip to content

Passing actor as parameter to another actor causes compiler assertion failure #62731

Open
@gregcotten

Description

@gregcotten

Description
When passing an actor as a parameter to another actor, a compiler assertion is raised:

Assertion failed: SGF.ExpectedExecutor || SGF.unsafelyInheritsExecutor(), file D:\a\1\s\swift\lib\SILGen\SILGenProlog.cpp, line 880

Steps to reproduce
Clone repo at https://github.com/gregcotten/swift-unsafe-inherited-bug
swift build or swift build --use-integrated-swift-driver using a swift toolchain that will raise compiler assertion errors.

Environment
5.7.1 or 5.7.2 release on Windows (on this platform swift build will fail on assertions)

It's a very simple swift file:

actor ParentActor: ChildActorDelegate {
    let child: ChildActor

    init() async {
        child = ChildActor()
        await child.setActorDelegate(self)
    }
}

protocol ChildActorDelegate: Actor {}
actor ChildActor {
    weak var delegate: ChildActorDelegate?

    init() {}

    func setActorDelegate(_ delegate: ChildActorDelegate) {
        self.delegate = delegate
    }
}

Stack dump:

0.	Program arguments: swift-frontend.exe -emit-module -experimental-skip-non-inlinable-function-bodies-without-types D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\Sources\\swift-unsafe-inherited\\swift_unsafe_inherited.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk -I D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug -I C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64 -enable-testing -g -module-cache-path D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug\\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift -enable-anonymous-context-mangled-names -module-name swift_unsafe_inherited -emit-module-doc-path D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug\\swift_unsafe_inherited.swiftdoc -emit-module-source-info-path D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug\\swift_unsafe_inherited.swiftsourceinfo -emit-dependencies-path D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug\\swift_unsafe_inherited.build\\swift_unsafe_inherited.emit-module.d -parse-as-library -o D:\\a\\swift-unsafe-inherited-bug\\swift-unsafe-inherited-bug\\.build\\x86_64-unknown-windows-msvc\\debug\\swift_unsafe_inherited.swiftmodule
1.	compnerd.org Swift version 5.7.2 (swift-5.7.2-RELEASE)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module swift_unsafe_inherited)
4.	While silgen constructor initializer SIL function "@$s22swift_unsafe_inherited11ParentActorCACyYacfc".
 for 'init()' (at D:\a\swift-unsafe-inherited-bug\swift-unsafe-inherited-bug\Sources\swift-unsafe-inherited\swift_unsafe_inherited.swift:4:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stageactorFeature → 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 software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions