Commit Graph

22 Commits

Author SHA1 Message Date
Dan Zheng
723b2d2cbe [AutoDiff upstream] Add derivative function witness/vtable entry SILGen. (#30569)
`@differentiable` attribute on protocol requirements and non-final class
members now produces derivative function entries in witness tables and vtables.

This enables `witness_method` and `class_method` differentiation.

Existing type-checking rules:

- Witness declarations of `@differentiable` protocol requirements must have a
  `@differentiable` attribute with the same configuration (or a configuration
  with superset parameter indices).
  - Witness table derivative function entries are SILGen'd for `@differentiable`
    witness declarations.

- Class vtable derivative function entries are SILGen'd for non-final
  `@differentiable` class members.
  - These derivative entries can be overridden or inherited, just like other
    vtable entries.

Resolves TF-1212.
2020-03-22 16:59:01 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Saleem Abdulrasool
32151c6463 SIL: silence -Wunused-variable (NFC) 2019-11-04 15:07:30 -08:00
Slava Pestov
9dd835c71b Sema: Replace the finalizeDecl() mechanism with ClassDecl::getEmittedMembers()
The only thing remaining in finalizeDecl() is synthesis of
certain class members. Let's turn that into a request.
2019-08-09 19:08:47 -04:00
Slava Pestov
37f0d6a613 Sema: Refactor away maybeAddAccessorsToStorage()
This centralizes the decision to add or not to add accessors in one place.
2019-07-31 14:54:57 -04:00
Slava Pestov
0026493f4d SIL: VTable visitor now visits accessors as part of their storage
This is NFC for now, but soon accessors will not no longer appear
when iterating over NominalTypeDecl::getMembers().
2019-07-30 15:14:33 -04:00
Slava Pestov
a31248997c SILGen: Correctly emit vtables when an override is more visible than the base
If an override B.f() is more visible than a base method A.f(), it is
possible that an override C.f() of B.f() cannot see the original method
A.f().

In this case, we would encounter linker errors if we referenced the
method descriptor or method dispatch thunk for A.f().

Make this work by treating B.f() as the least derived method in this
case, and ensuring that the vtable thunk for B.f() dispatches through
the vtable again.

Fixes <rdar://problem/48330571>, <https://bugs.swift.org/browse/SR-10648>.
2019-06-01 00:08:05 -04:00
Joe Groff
77a0923ca6 SILGen: Emit convenience initializers as allocating entry points.
And only dispatch designated inits by their allocating entry points. rdar://problem/29634243
2018-09-13 12:31:23 -07:00
Joe Groff
351808920a SIL: Don't include convenience initializers in vtables.
They should never be dynamically dispatched (unless `required`), so this entry should never be used.
We were accidentally dynamically dispatching to them in convenience-to-convenience `self.init`
delegations; fix that.
2018-09-10 15:15:38 -07:00
Slava Pestov
1602580303 SIL: Sort vtable entries for synthesized methods
Completes the fix for <rdar://problem/35647420> and
<https://bugs.swift.org/browse/SR-6468>.
2018-04-20 12:36:02 -07:00
Slava Pestov
4d18e923d4 SIL: Clean up includes 2017-12-19 02:00:25 -08:00
Slava Pestov
fa719f75bd SIL: SILVTableVisitor no longer needs a TypeLowering reference 2017-12-18 23:28:33 -08:00
Slava Pestov
c16c2c35bf SIL: Move getOverriddenVTableEntry() from TypeLowering to SILDeclRef
There's no reason for this to be an instance method on the TypeLowering
object, because it (no longer?) uses any type lowering operations.
2017-12-18 23:28:33 -08:00
Slava Pestov
ce2a434587 SILGen: Fix bug with vtable entries for allocating initializers
Some changes I was working on uncovered a latent bug where we would
emit a class_method instruction to call an allocating initializer
that did not have a vtable entry.

Previously this wasn't caught because the only example of this in
our test suite was in test/SILGen/objc_bridging_any.swift, which
did not test with IRGen; if it did, an IRGen crash would have been
observed.

Factor out some code duplication to prevent this from happening
again, and add a SILGen test that we emit a vtable entry in this
case, and that the test case passes IRGen also.
2017-11-11 02:01:50 -08:00
Joe Groff
c374763632 SILGen: Fix override handling when a dynamic init is also required.
A missed case from #11107. Fixes SR-5542 | rdar://problem/33490780.
2017-07-25 10:24:19 -07:00
Jordan Rose
384b2a674b Actually honor MissingMemberDecls in ClassMetadataScanner.
...which is sufficient to correctly invoke methods in a vtable
even when members have been deleted. 🎉
2017-05-10 12:41:22 -06:00
Jordan Rose
6c098033de Lift the decision of whether a method needs a vtable slot up to AST.
This lets us serialize that decision, which means we can conceivably
/change/ the decision in later versions of the compiler without
breaking existing code. More immediately, it's groundwork that will
eventually allow us to drop decls from the AST without affecting
vtable layout.

This isn't actually a great answer; what we really want is for SIL
vtables to be serialized consistently and treated as the point of
truth. But that would be more change than we're comfortable taking in
the Swift 4 timeframe.

First part of rdar://problem/31878396.
2017-05-04 17:49:47 -07:00
practicalswift
b704f1448b [gardening] Improve header consistency 2017-04-12 15:13:11 +02:00
Slava Pestov
7aabd80898 SIL: Stub out TypeConverter::getOverriddenVTableEntry()
This replaces SILDeclRef::getBaseOverriddenVTableEntry(). It lives
in the TypeConverter because it needs to use type lowering information
to determine if the method requires a new vtable entry or not.
2017-03-24 01:53:39 -07:00
Slava Pestov
ef7f6bf0ea SIL: Stub out TypeConverter::requiresNewVTableEntry() 2017-03-24 01:52:42 -07:00
Slava Pestov
aebf843dda SIL: Addressors don't need vtable entries
In the old vtable emission code, IRGen would skip addressors,
but they had entries in the SILVTable. This is still correct
behavior, so skip addressors explicitly in SILVTableVisitor.

We never call addressors dynamically, only inside a getter,
setter or materializeForSet. When a property with addressors
is overridden we provide new getters and setters (which may
or may not statically dispatch to a peer addressor).
2017-03-23 20:36:12 -07:00
Slava Pestov
c94e6b8a5e SIL: Add new SILVTableVisitor
This is a CRTP utility to walk the members of a class and
produce vtable entries. It will be used to clean up some
code duplication between SILGen and IRGen, and to provide
missing functionality for multiple vtable entries per
method.
2017-03-23 18:17:42 -07:00