Commit Graph

38 Commits

Author SHA1 Message Date
susmonteiro
848fad0021 [cxx-interop] Support for printing C++ foreign references 2025-06-10 12:15:21 +01:00
Becca Royal-Gordon
d1f14e5814 Eliminate objcImpl field offset vectors
We really don’t need ‘em; we can just adjust the direct field offsets.

The runtime entry point currently uses a weird little hack that we will refactor away shortly.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
9e83099279 [NFC] Refactor objcImpl matadata layout logic
Rather than having individual methods return without doing anything, arrange for ClassMetadataVisitor to never call them in the first place. This makes it so ClassMetadataScanner also knows which fields are omitted and it can compute offsets correctly.

The old logic is still present for field offsets to make this change NFC.
2024-04-24 11:39:24 -07:00
Kuba Mracek
b8bd832fba [embedded] Add IVarDestroyers into class metadata, add support for throws in initializers 2024-03-26 20:52:17 -07:00
Erik Eckstein
b33bb3828d IRGen: fix the superclass pointer for generic classes in embedded swift
fixes in IRGen crash
2023-11-06 21:08:22 +01:00
Kuba Mracek
d0c2a4ccf8 [embedded] Initial support for generic classes in embedded Swift
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used
- Don't use full type metadata refs in embedded Swift
- Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen
- Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
2023-09-12 09:44:54 -07:00
Kuba Mracek
51f54b4efb [embedded] add test for calling methods on classes, fix layout 2023-09-11 12:26:01 -07:00
Kuba Mracek
ae63e7549b [embedded] Add support for (non-generic) classes in embedded Swift
- In embedded Swift, classes get a simplified metadata: Basically just a vtable + destructor + superclass pointer.
- Only non-resilient (intended as permanent restriction), non-generic classes (for now) supported.
- Relax the check that prohibits metadata emission and usage to allow classes.
2023-09-11 11:22:11 -07:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Arnold Schwaighofer
20ff4dfc57 IRGen: Don't treat internal but visible via testable import classes as having fragile layout
That does not work if there is a resilient class in the hiearchy from a
different module than the testable imported one.  Rather treat an
internal but testable imported class as having resilient metadata.

The scenario that does not work assuming we can build a fragile layout
is the following.

FrameworkA is resilient and defines a public class `Base` with a stored field.
FrameworkB is resilient and defines an internal class `Sub` that inherits from
the class `Base` in FrameworkA and adds some fields. FrameworkB is compiled
with enable-testing.
The test case testable imports FrameworkB and accesses a field in the
internal class `Base` from FrameworkB. The test case only has access to
FrameworkA's public swiftinterface file and therefore does not know
`Base`'s layout.  The layout computation for `Sub` cannot take the field
from `Base` into account and things fail silently.

rdar://103323275
2022-12-19 07:35:56 -08:00
Slava Pestov
9f3267b5c0 IRGen: Refactor NominalMetadataVisitor.h 2022-12-13 11:56:33 -05:00
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: across

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: command

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: current

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: discrimination

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: entities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: except

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inserted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interfere

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intrinsic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: might

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: objective

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outlined

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: payload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rearchitecting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reverse

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewritable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: shareably

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: speedup

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: template

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: witness

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
Arnold Schwaighofer
3930fc4cfe IRGen: Fix enable-testing of internal with resilient super class
Enable testing makes `internal` types visible from outside the module.
We can no longer treat super classes as resilient.

Follow-up to #41044.

rdar://90489618
2022-03-30 07:12:14 -07:00
Arnold Schwaighofer
d48422f6f9 IRGen: Take enable-testing into account when computing whether a class has resilient metadata
rdar://87617621
2022-01-27 14:08:05 -08:00
John McCall
bad16fd105 Do dynamic layout of generic/resilient default actors properly.
Since these types have an implicit stored property, this requires
adding an abstraction over fields to IRGen, at least throughout
the class code.  In some ways I think this significantly improves
the code, especially in how we approach missing members.

Fixes rdar://72202671.
2020-12-15 20:10:46 -05:00
Joe Groff
3a9440a379 IRGen: Elide nonoverridden entries from public resilient vtables.
A formally virtual method still needs to provide the ABI of an overridable
method, including a dispatch thunk, method descriptor, and support in the
method lookup function for the class to handle `super.` calls from clients.
2020-07-23 20:40:49 -07:00
Davide Italiano
b0a419b297 [IRGen] Check if VTable isn't a nullptr.
Fixes a ubsan error on the lldb bots

runtime error: member call on null pointer of type 'swift::SILVTable'
undefined-behavior lib/IRGen/GenMeta.cpp:5107:24
2020-07-14 16:05:06 -07:00
Joe Groff
04c8f0df42 IRGen: Don't reify internal vtable entries that are marked overridden.
Private and internal classes shouldn't have ABI constraints on their concrete vtable layout, so if methods
don't have overrides in practice, we can elide their vtable entries.
2020-06-12 11:59:24 -07:00
David Zarzycki
97c89d8d3a Remove three ObjC fields from non-ObjC runtime 2020-05-22 09:21:21 -07:00
David Zarzycki
36257d6a62 [IRGen] NFC: Add static_assert cross references
The metadata visitors note the address start of the metadata, but that
is not actually the way the offsets are calculated.
2020-05-14 09:03:03 -04:00
Nate Chandler
525e25603f [IRGen] Pass argument/table to builders.
Previously, the various generic builders implemented the methods
addGenericArgument and addGenericWitnessTable without being provided
what argument or witness table they were to add (because it was not
previously needed).  Now, the GenericRequirement is passed along to both
methods.
2020-01-09 17:25:31 -08:00
Slava Pestov
ff09603f30 IRGen: @_fixed_layout classes still have resilient metadata 2018-11-29 23:20:02 -05:00
Slava Pestov
16a459d0f1 IRGen: Refactor ClassLayoutBuilder a bit to help distinguish resilient-metadata from resilient-storage
We want @_fixed_layout classes to have non-resilient storage, but still have
resilient metadata.
2018-11-29 23:20:02 -05:00
Slava Pestov
09027413bc IRGen: Emit field offsets before vtable entries
We want to be able to define classes with a fixed storage layout,
but a resilient (opaque) vtable. If the class is also generic,
we still have to load field offsets from the metadata if they
are dependent.

So put the field offsets after the generic arguments and before
the vtable.

This is an ABI break for @_fixed_layout classes, which are
defined by the stdlib.
2018-11-29 23:20:02 -05:00
Slava Pestov
de6e3bd6ea IRGen: Don't visit class members when building resilient class metadata layouts
If the class is resilient to us, we cannot assume anything about the
layout of its member area, so let's not even try; just skip visiting
the members entirely.
2018-09-07 21:57:16 -07:00
Slava Pestov
41aebf8e5a IRGen: Simplify NominalMetadataVisitor's treatment of generic requirements
We don't need to substitute the superclass type as we walk up a
class hierarchy, or look up the generic parameters and conformances
to check if they're concrete, since we're always just emitting
null pointers in place of the generic parameters and requirements,
to be filled at runtime.

Also, don't leave space for generic parameters and requirements from
Objective-C superclasses, since that's not how they're represented.
2018-08-14 00:20:12 -07:00
Slava Pestov
e3ff63a289 IRGen: Rename addSuperClass() => addSuperclass() for consistency 2018-07-09 23:56:25 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
John McCall
a7c5c80799 Compute class metadata bounds solely from class-descriptor chain information.
Change the "metadata base offset" variable into a "class metadata bounds"
variable that contains the base offset and the +/- bounds on the class.
Link this variable from the class descriptor when the class has a resilient
superclass; otherwise, store the +/- bounds there.  Use this variable to
compute the immediate-members offset for various runtime queries.  Teach the
runtime to fill it in lazily and remove the code to compute it from the
generated code for instantiation.  Identify generic arguments with the start
of the immediate class metadata members / end of the {struct,enum} metadata
header and remove the generic-arguments offset from generic type descriptors.
2018-03-04 02:14:32 -05:00
Slava Pestov
8024b81594 IRGen: Preliminary implementation of resilient method overrides
This is not the final mechanism, because it does not allow
re-ordering superclass methods, but at least it works if
you don't do that.
2018-01-03 19:30:30 -08:00
Slava Pestov
6af8d18a00 IRGen: Remove -enable-class-resilience staging flag 2018-01-03 00:26:10 -08:00
Slava Pestov
76499a3ce3 IRGen: Emit immediate class member offset global variable
Not used to access metadata members just yet.
2017-12-19 02:58:35 -07:00
Slava Pestov
fa719f75bd SIL: SILVTableVisitor no longer needs a TypeLowering reference 2017-12-18 23:28:33 -08:00
Joe Groff
39dfe07354 IRGen: Treat class layout for classes from other modules a bit more opaquely.
We would miscompile in mixed-language-version projects when a Swift class was compiled for one language version, while using Objective-C-imported types that are only available to that version, and then imported into a Swift module with a different language version that wasn't able to see all of the properties because of incompatible imported types. This manifested in a number of ways:

- We assumed we could re-derive the constant field offsets of the class's ivars from the layout, which is wrong if properties are missing, causing accesses to final properties or subclass properties to go to the wrong offsets.
- We assumed we could re-derive the instance size and alignment of a class instance in total, causing code to allocate the wrong amount of memory.
- We neglected to account for the space that stored properties take up in the field offset vector of the class object, causing us to load vtable entries for following subclass methods from the wrong offsets.

Eventually, resilience should reduce our exposure to these kinds of problems. As an incremental step in the right direction, when we look at a class from another module in IRGen, treat it as always variably-sized, so we don't try to hardcode offsets, size, or alignment of its instances. When we import a class, and we're unable to import a stored property, leave behind a new kind of MissingMemberDecl that records the number of field offset vector slots it will take up, so that we lay out subclass objects and compute vtable offsets correctly. Fixes rdar://problem/35330067.

A side effect of this is that the RemoteAST library is no longer able to provide fixed field offsets for class ivars. This doesn't appear to impact the lldb test suite, and they will ultimately need to use more abstract access patterns to get ivar offsets from resilient classes (if they aren't already), so I just removed the RemoteAST test cases that tested for class field offsets for now.
2017-11-17 14:38:08 -08:00
Slava Pestov
3ab5b6fa19 IRGen/Runtime: Remove parent field from type metadata
We no longer need this for anything, so remove it from metadata
altogether. This simplifies logic for emitting type metadata and
makes type metadata smaller.

We still pass the parent metadata pointer to type constructors;
removing that is a separate change.
2017-09-25 15:45:17 -07:00
John McCall
4e48bc0ff7 Cache type-metadata layouts instead of using scanners everywhere. NFC.
Also counts as incremental work towards metadata resilience.
2017-08-03 04:13:53 -04:00
John McCall
003bd81b86 Rename FooMetadataLayout to FooMetadataVisitor. NFC.
The *Layout namespace is more fitting for a structure that actually
holds information about the layout.
2017-08-03 02:04:14 -04:00