Commit Graph

43 Commits

Author SHA1 Message Date
Alex Lorenz
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00
Nate Chandler
4156382f07 [NFC] Corrected typo.
ClassMetadataLayout::getOffsett -> ClassMetadataLayout::getOffset
2020-11-12 18:20:09 -08: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
Nate Chandler
2b50150e61 [metadata prespecialization] Zero trailing flags.
Previously, the trailing flags field of runtime instantiated generic
metadata for types which had prespecialization enabled were not zeroed.
Consequently, the field always contained garbage.  Often, metadata was
instantiated on new (and so, zeroed) pages, so the garbage happened to
be zero as is appropriate.  However, when the metadata was instantiated
on pages which had previously been dirtied, the garbage value would
sometimes indicate that the metadata was canonical statically
specialized.  When that occurred, swift_checkMetadataState would
incorrectly return a metadata state of complete, despite the fact that
the metadata might not in fact be complete.  As a result, the runtime
was trafficking in incomplete metadata as if it were complete, resulting
in various crashes that would arise from for example missing a witness
table or a value witness table.

Here the problem is corrected.  The trailing flags field of structs and
enums that have the field is set to 0.

For structs, this is accomplished by modifying the extra data pattern to
exist not only when there is fixed type info for the type but also when
the type is being prespecialized.  Specifically, the extra data for a
struct is, rather than an i32 array of field offsets, a struct
consisting of none, one, or both of the following: (1) the array of
field offsets, (2) the trailing flags.

Similarly, enums now have an extra data pattern which consists of none,
one, or both of the following: (1) the payload size, (2) the trailing
flags.  Enum metadata extra data setting was previously achieved by
customizing the metadata allocation function; that customization is now
eliminated, being replaced with the shared runtime code for copying
extra data into place, a modest code size savings.

rdar://problem/61465515
2020-04-23 18:18:40 -07:00
technicated
b0e424f469 Added support for tuples with dynamic layout (ie generic tuples)
Extracted a base CRTP class MetadataVisitor from NominalMetadataVisitor
Added new tuple metadata visitors extending the new MetadataVisitor
2019-02-18 10:19:43 +01:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Slava Pestov
0eb762fec3 IRGen: Remove a few unused methods 2018-09-07 12:15:24 -07:00
Joe Groff
9c9fa8545a IRGen: Use base-relative offsets to identify methods in fragile subclasses of resilient bases in key paths.
The resilient methods will all be keyed by their dispatch thunks, so for methods of local subclasses, we can use the offsets relative to the dynamic base as identifiers without having to adjust for that dynamic base.
2018-07-27 13:15:49 -07:00
John McCall
aaa40ee82b Move metadata-accessing IRGen out of GenMeta. NFC.
Abstract type/heap metadata access goes into MetadataRequest.
Metadata access starting from a heap object goes into GenHeap.
Accessing various components of class metadata goes into GenClass
or MetadataLayout.
2018-03-18 23:53:11 -04:00
John McCall
f2bb319bdb Change the pattern of generic class metadata instantiation.
Minimize the generic class metadata template by removing the
class header and base-class members.  Add back the set of
information that's really required for instantiation.
Teach swift_allocateGenericClass how to allocate classes without
superclass metadata.  Reorder generic initialization to establish
a stronger phase-ordering between allocation (the part that doesn't
really care about the generic arguments) and initialization (the
part that really does care about the generic arguments and therefore
might need to be delayed to handle metadata cycles).

A similar thing needs to happen for resilient class relocation.
2018-03-04 00:01:56 -05:00
Slava Pestov
3269b9ad2a Merge pull request #13718 from slavapestov/class-resilience-part-12
Class resilience part 12
2018-01-04 11:57:39 -08:00
Doug Gregor
12a774abec [Runtime] Fill in the superclass of foreign class metadata.
When emitting foreign class metadata (e.g., for an imported CF type), fill
in the superclass when we have one. The superclass will itself be a foreign
metadata candidate, so also register an initialization function that uniques
the superclass metadata once we've picked the canonical foreign class
metadata.
2018-01-04 10:15:32 -08:00
Slava Pestov
93af58dead IRGen: Correctly calculate base offset variable for generic classes
If a generic class has non-resilient ancestry, we cannot use
the template size so far as the constant value of the base offset
variable, because the template will not contain entries for all
metadata members; instead, use metadata layout as with everything
else.
2018-01-03 22:11:41 -08:00
Slava Pestov
e3d6a2b9a2 IRGen: Correctly set class metadata base offset variable
We need to subtract the address point from the metadata size,
since the metadata size includes prefix matter.
2018-01-02 22:29:08 -08:00
Slava Pestov
0103cf6e75 IRGen: Use dynamic offsets in resilient class metadata 2017-12-25 00:00:44 -08:00
Slava Pestov
2df1b0a501 IRGen: Support dynamic offsets for various metadata fields
Not hooked up until some more MetadataLayout changes land.
2017-12-23 16:18:53 -08:00
Slava Pestov
dd7f09d8de IRGen: Change the meaning of a dynamic StoredOffset
Instead of storing an llvm::Constant, store an offset relative to
the class metadata base.
2017-12-23 16:18:52 -08:00
Slava Pestov
354f4989e1 IRGen: Store type declaration in the NominalMetadataLayout 2017-12-19 00:36:47 -08:00
Slava Pestov
e65d3a7019 IRGen: Note metadata size offset in metadata layout 2017-12-19 00:36:47 -08:00
Slava Pestov
5dcc6b13ed IRGen: Count number of immediate class members in ClassMetadataLayout 2017-12-07 14:21:59 -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
Slava Pestov
293f50251a IRGen: Another MetadataScanner => MetadataLayout refactoring 2017-08-15 01:32:12 -04:00
Slava Pestov
72c4974212 IRGen: Store start of vtable in MetadataLayout 2017-08-15 01:31:23 -04:00
Slava Pestov
aa20f404e9 IRGen: Remove MetadataSizer 2017-08-10 22:14:21 -07:00
Slava Pestov
9f6507cee8 IRGen: Use MetadataLayout in more places 2017-08-10 19:42:24 -07:00
Slava Pestov
ea5a99a3f7 IRGen: Record start of field offset vector in StructMetadataLayout 2017-08-09 01:07:08 -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
Slava Pestov
c90a77df31 IRGen: Use SubstitutionMap instead of ArrayRef<Substitution> in a few places
The crazy indexing logic is gone.
2017-02-03 19:55:41 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
98a0e73b02 AST: Merge BoundGenericType::getSubstitutions() with TypeBase::gatherAllSubstitutions(), NFC 2016-06-13 00:57:09 -07:00
John McCall
3ce1ba3e65 Only store the minimal requirements in generic metadata, where
"minimal" is defined as the set of requirements that would be
passed to a function with the type's generic signature that
takes the thick metadata of the parent type as its only argument.
2016-02-25 10:33:33 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Slava Pestov
6b67758372 IRGen: remove requiresProtocolWitnessTable()
We can call TypeConverter::protocolRequiresWitnessTable() instead. NFC

Swift SVN r27986
2015-04-30 18:41:06 +00:00
Joe Groff
e29a5e4b54 IRGen: Share requiresProtocolWitnessTable implementation between SIL and IRGen.
No reason to duplicate this. NFC.

Swift SVN r27328
2015-04-15 21:16:42 +00:00
Joe Groff
3d60786a30 IRGen: Add a requiresProtocolWitnessTable fn instead of peppering isObjC() everywhere.
Swift SVN r9497
2013-10-18 21:49:06 +00:00
Joe Groff
b8c75769b3 IRGen: Emit nominal type descriptors in struct and enum metadata.
Build a nominal type descriptor when we emit the metadata or generic metadata pattern for a nominal type, and put a reference into the formerly null slot in the struct or enum metadata. We need to make a place for them in class metadata; that'll come next.

Swift SVN r9492
2013-10-18 21:04:58 +00:00
Joe Groff
ea61572b41 IRGen: Tail-emplace dependent vwtables into generic metadata patterns.
If a generic type has dynamic layout, the value witness table for its instances is dependent on its generic parameters for size and alignment. Instead of emitting a global symbol for the vwtable in these circumstances, embed the value witness table template in the generic metadata template so that both get instantiated in tandem by the runtime when the generic instance metadata is requested.

Swift SVN r7931
2013-09-05 00:33:38 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
John McCall
65db19395d Make metatype layout compatible with struct objc_class.
The principal difficulty here is that we need accessing the
value witness table for a type to be an efficient operation,
but there (obviously) isn't a VWT field for ObjC classes.
Placing this field after the metatype would tend to bloat
metatypes by quite a bit.  Placing it before is best, but
it introduces an unfortunate difference between the address
point of a metatype and the address of the global symbol.
That, however, can be fixed with appropriate linker support.
Still, for now this is rather unfortunately over-subtle.

Swift SVN r3307
2012-11-30 02:47:01 +00:00
John McCall
1f5b775bc7 Use metatype pointers as generic type arguments. Movements
towards optimizing generic calls to derive things from the
'this' pointer, which is actually crucial for virtual
dispatch (to get all methods to agree about how the
implicit arguments are passed).  Fix a number of assorted
bugs in metadata emission.  Lots of assorted enhancements.

This was proving surprisingly difficult to actually tease
apart into smaller patches.

Swift SVN r2927
2012-10-03 08:57:40 +00:00
John McCall
32cc48dc84 More restructuring and start emitting struct metadata.
Swift SVN r2892
2012-09-21 07:53:02 +00:00