Giter Club home page Giter Club logo

Comments (4)

younata avatar younata commented on June 2, 2024 1

@erudel

Everything I'm seeing indicates that when SE-0316 (which defines global actors, such as the main actor) gives the following criteria for when a class can be annotated with a global actor:

A class can only be annotated with a global actor if it has no superclass, the superclass is annotated with the same global actor, or the superclass is NSObject. A subclass of a global-actor-annotated class must be isolated to the same global actor.

What it actually means is that, you can annotate a subclass with a global actor, but unless the above criteria is met, then only methods on that subclass will run on the global actor.

Additionally, I think the "superclass is NSObject" criteria is also misleading, and on Apple platforms means "the superclass is implemented in Objective-C".

My evidence for this is based on the fact that the SPM version of Quick has QuickSpec.spec defined in Swift, but the Cocoapods version of Quick has QuickSpec.spec defined in Objective-C. The following sample code should also demonstrate the issue. (which I wrote off the top of my head and have not verified if it compiles - I imagine there's weird completionHandler -> async in subclass thing that's probably invalid with the compiler. Regardless, you get the idea, I hope):

@interface ObjcBaseClass: NSObject
- (void)someMethod:(void (^)(void))completionHandler;
@end

@implementation ObjcBaseClass
- (void)someMethod:(void (^)(void))completionHandler { completionHandler(); }
@end
class SwiftBaseClass {
    func someMethod() async {}
}

@MainActor class SwiftSubClass: SwiftBaseClass {
    override func someMethod() async {
        assert(NSThread.isMainThread)  // this assert will almost certainly fail.
    }
}

@MainActor class ObjcSubClass: ObjcBaseClass {
    override func someMethod() {
        assert(NSThread.isMainThread)  // this assert will never fail.
    }
}

I have not filed any feedbacks/swift bugs based off this observation. I assume that the cocoapods version of Quick is relying on undefined behavior, so a feedback wouldn't be all that helpful anyway.

from quick.

younata avatar younata commented on June 2, 2024

This is a known issue. I don't have a good solution for it. I'm sorry.

from quick.

erudel avatar erudel commented on June 2, 2024

I'm trying to find more information about this issue and could not find anything. Are there discussions or open bugs (in this project or another) elaborating why this doesn't work in SPM?

EDIT: after some browsing I was able to find some of issues that were previously raised. Linking them here for posterity:

It's not clear to me yet why the behavior is so different when using SPM, I'll keep digging a bit more and update this post if I find anything.

from quick.

erudel avatar erudel commented on June 2, 2024

Thank you very much for the detailed explanation and the link @younata , I wasn't aware of the difference in the implementation used between SPM and Cocoapods but now it makes perfect sense.

from quick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.