Skip to content

Conversation

@ktoso
Copy link
Contributor

@ktoso ktoso commented Dec 8, 2025

Add a warning about 'final' in front of actor declarations. We've never started rejecting it, however it doesn't do anything, so we should warn about it because otherwise people may think this is actually doing something

@ktoso
Copy link
Contributor Author

ktoso commented Dec 8, 2025

@swift-ci please smoke test


@_expose(Cxx)
public final actor ActorWithField {
public final actor ActorWithField { // expected-warning{{'final' on actor 'ActorWithField' has no effect}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we want to remove this final to reduce noise, since it's not really intentional in this test case, from what I can tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll follow up later adding a separate test for it.

TypeChecker::checkConcurrencyAvailability(CD->getLoc(), CD);

if (CD->isFinal()) {
CD->diagnose(diag::actor_final_no_effect, CD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this came up somewhat recently on the forums (see here), and when i had suggested banning this, @tshortli had this to say:

final is not meaningless on actor, unfortunately [...] marking an actor method final, or marking the whole actor final, changes the ABI of calling methods on the actor since calls will no longer go through dynamic dispatch.

given that, should this warning be further conditioned upon the declaration's access level or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ouch that's unfortunate... FYI @rjmccall

We could then make it only earn for non public declarations probably 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although... it should never actually be possible to inherit from an actor right (except for maybe some objc runtime trickery?)? does that mean, at least for optimized WMO builds, the vtable entries should always be removed? maybe the risk of issues in practice would be pretty low.

@ktoso
Copy link
Contributor Author

ktoso commented Dec 10, 2025

So there's ongoing discussion about this one; this would be adding more noise for a "harmless" thing potentially, so maybe we just leave it be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants