Skip to content

Conversation

@eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Dec 5, 2025

For example:

  public class C: MyClass {
    public init(p: some P) {
      // ...
    }
  }

Constructors are not called via the vtable (except "required" constructors).
Therefore we can allow generic constructors.

fixes: #78150
rdar://138576752

and make `AbstractFunctionDecl.isOverridden` final
We first have to remove _all_ old entries from the cache, then add the new entries.
Otherwise we'll wrongly remove an existing entry from the cache again if a previous entry was deleted from the vtable.
For example:

```
  public class C: MyClass {
    public init(p: some P) {
      // ...
    }
  }
```

Constructors are not called via the vtable (except "required" constructors).
Therefore we can allow generic constructors.

swiftlang#78150
rdar://138576752
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein requested review from DougGregor, kubamracek and rauhul and removed request for hborla, jckarter, slavapestov and xedin December 5, 2025 10:55
{
// For some reason, SILGen is putting constructors in the vtable, though they are never
// called through the vtable.
// Dropping those vtable entries allows using constructors with generic arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of working around it here, is it hard to fix SILGen to not put them in the vtable? IRGen must have a similar workaround too then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of working around it here, is it hard to fix SILGen to not put them in the vtable?

I don't know. We (= someone who knows SILGen) can do this as a follow-up.

IRGen must have a similar workaround too then.

No, in regular SIL it's totally fine to have a generic function in a vtable. And in embedded the compiler aborted with an error in this case.

Copy link
Member

Choose a reason for hiding this comment

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

This solution seems brittle. Why not update NeedsNewVTableEntryRequest::evaluate to suppress generic initializers from the vtable in the first place? There's no way to specialize these appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solution seems brittle.

No. It does not change the vtable layout. It just marks the constructor as dead. Also, we are doing this is-generic check on the call site, too (i.e. for class_method instructions) which is the double check that we are not calling such a "dead" constructor.

Why not update NeedsNewVTableEntryRequest::evaluate to suppress generic initializers from the vtable in the first place?

I tried this but did run into assertion failures in SILGen later. It's probably a more involved thing to change the vtable layout.

@rauhul rauhul added the embedded Embedded Swift label Dec 5, 2025
@eeckstein eeckstein merged commit d0f8cce into swiftlang:main Dec 5, 2025
3 checks passed
@eeckstein eeckstein deleted the fix-vtable-specialization branch December 5, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

embedded Embedded Swift

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Invalid "Classes cannot have non-final generic functions in embedded Swift" error

4 participants