Commit Graph

318 Commits

Author SHA1 Message Date
John McCall
c1f99b5fdb Cap type alignment in Swift at 16.
rdar://31411216
2018-08-28 16:13:50 -04:00
Joe Groff
9f02ecd1a5 IRGen: Use any field of structs for extra inhabitants.
This allows us to layout-optimize Optional<T> when T is a struct with an
extra-inhabitant-bearing field anywhere in its definition, not only at
the beginning. rdar://problem/43019427
2018-08-14 12:53:06 -07:00
Slava Pestov
e44721dd19 IRGen: Remove the 'access type'/'layout type' distinction from StructLayout
This was part of the old resilience workaround for classes and
is no longer used.
2018-08-10 00:42:34 -07:00
Slava Pestov
d460d5def6 IRGen: Remove ASTTy field from StructLayout 2018-08-07 04:26:43 -07:00
Arnold Schwaighofer
98577cf585 IRGen: Silence clang warning
I believe the warning is erroneous and filed a bug against clang.

GenStruct.cpp:290:19: warning: unused type alias 'super' [-Wunused-local-typedef]

rdar://40626108
2018-05-30 08:15:34 -07:00
John McCall
2ed90771f4 Use the VWT for value ops on types with ABI-inaccessible children.
rdar://39763787
2018-05-15 15:07:32 -04:00
Slava Pestov
d5868e5492 IRGen: ElementLayout now stores two TypeInfos
This allows us to perform fragile layout of resilient fields without
completely disabling value type resilience.
2018-04-09 21:53:45 -07:00
Pavel Yaskevich
78822bc23e [IRGen] Adjust element size of offset vector to 32-bit for structs
Type of elements contained by field offsets vector can be adjusted
to 32-bit integers (from being pointer sized) to safe space in the
binary since segment size is limited to 4 GB.

Resolves: rdar://problem/36560486
2018-04-03 13:32:06 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
John McCall
5ff8883c95 Pull TypeInfo::initializeMetadata into GenMeta; NFC.
GenMeta is already making decisions about what work is done by these
functions.
2018-03-26 01:13:45 -04:00
Joe Groff
0951648fe6 IRGen: Fix handling of empty fields in Clang-imported types.
Clang allows C structs to have zero-sized array fields for things like trailing buffers. Lower these correctly into Swift types in IRGen so that Swift codegen knows to treat them as empty types. Fixes rdar://problem/31042794.
2018-03-19 15:40:38 -07:00
Joe Groff
f01af883fc IRGen: Use known value witness tables for common type layouts.
If a type has the same layout as one of the basic integer types, or has a single refcounted pointer representation, we can use prefab value witness tables from the runtime instead of instantiating new ones. This saves quite a bit of code size, particularly in the Apple SDK overlays, where there are lots of swift_newtype wrappers and option set structs.
2018-03-11 11:04:37 -07:00
Joe Groff
4c2dde56a0 IRGen: Lower external key path components.
The key path pattern needs to include a reference to the external descriptor, along with hooks for lowering its type arguments and indices, if any. The runtime will need to instantiate and interpolate the external component when the key path object is instantiated.

While we're here, let's also reserve some more component header bytes for future expansion, since this is an ABI we're going to be living with for a while.
2018-02-23 19:03:15 -08:00
John McCall
9bbbe2c418 Update the metadata-initialization ABI:
- Create the value witness table as a separate global object instead
  of concatenating it to the metadata pattern.

- Always pass the metadata to the runtime and let the runtime handle
  instantiating or modifying the value witness table.

- Pass the right layout algorithm version to the runtime; currently
  this is always "Swift 5".

- Create a runtime function to instantiate single-case enums.

Among other things, this makes the copying of the VWT, and any
modifications of it, explicit and in the runtime, which is more
future-proof.
2017-12-21 00:26:37 -05:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
Joe Groff
b41888391f IRGen: Verify that known struct field offsets match the runtime field offset vector. 2017-09-22 12:28:50 -07:00
Erik Eckstein
90501578b0 IRGen: fix statically initialized globals which contain an empty type.
This caused a compiler assert or a miscompile

rdar://problem/34123143
2017-08-29 09:53:18 -07:00
Slava Pestov
e12c29ded9 IRGen: Refactor NonFixedStructTypeInfo::initializeMetadata()
The emitInitializeFieldOffsetVector() function used for
class metadata is now almost identical to the logic used
for structs. Refactor the code used for classes and also
use it to layout structs.
2017-08-09 01:07:09 -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
Joe Groff
aaddafa55b IRGen: Support for generic key path patterns. 2017-04-17 17:50:57 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00
Erik Eckstein
41c17a5b0c IRGen: emit type metadata and (value) witness tables lazily.
This gives big code size wins for unused types and also for types, which are never used in a generic context.
Also it reduces the amount of symbols in the symbol table.
The size wins heavily depend on the project. I have seen binary size reductions from 0 to 20% on real world projects.

rdar://problem/30119960
2017-03-10 12:50:43 -08:00
Slava Pestov
5296d02485 AST: More include-what-you-use gardening 2017-02-12 00:51:26 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
b9b2c81e40 [gardening] C++ gardening: Argument names. Overrides. End-of-namespace. 2016-12-18 18:04:01 +01:00
practicalswift
9d0b2abfc2 [gardening] Normalize end-of-namespace comments 2016-12-17 22:29:07 +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
78d11de396 IRGen: Emit fixed type descriptors for structs and enums with @_alignment attributes
This attribute is used in the simd overlay. To ensure we can layout
SIMD types correctly, emit a fixed type descriptor instead of a
field type descriptor for these types.
2016-11-16 19:23:04 -08:00
Huon Wilson
25b41906a2 [IRGen] Handle padding in global structs.
Previously there was a mismatch between SIL's concept of a
struct (padding is implicit) and LLVM's (padding is explicit) in IRGen's
constant evaluator. The explicit padding fields need to be given a value
in the IR.

This patch also moves the (currently small) list of constant evaluation
functions into their own file.

Fixes SR-716.
2016-09-29 05:21:49 -07:00
John McCall
b51a69f29f Count tail-padding in the size of imported C types.
This allows us to freely pass the address of a variable of such
types to a C function without worrying about it overwriting other
things if e.g. it memcpy's sizeof(T) bytes and thus clobbers the
otherwise-non-existent tail padding.

There are ways to get this optimization back, but they require
things like materializing to a temporary instead of passing the
address directly.  We haven't done that work yet, so we don't
get to take advantage of it.

rdar://26828018
2016-08-02 13:26:11 -07:00
Slava Pestov
60dff01093 Reflection: Simplify associated type metadata emission
Instead of hooking into nominal type and extension emission
and walking all conformances of those declarations, let's
just directly hook into the logic for emitting conformances.

This fixes an issue where we would apparently emit duplicate
conformances, as well as unnecessary conformances that are
defined elsewhere.
2016-05-26 19:33:00 -07:00
John McCall
f944d9133a Teach LoadableTypeInfos how to add themselves to a SwiftAggLowering. NFC. 2016-05-03 11:14:16 -07:00
David Farler
a1ff1e6a7b Eagerly emit reflection metadata as decls are emitted
Rather than collection nominal type and extension decls and emit
reflection metadata records in one go, we can emit them as they
are encountered and instead collection builtin types referenced
by those at the end.
2016-04-29 17:07:55 -07:00
John McCall
857489c2f6 When a generic type has dependent IR and thus requires each
specialization to be separately lowered in IRGen, use the mangling
of the specialized type as the name of the llvm::StructType instead
of the base, unspecialized type.

This tends to produce fewer collisions between IR type names.
LLVM does unique the names on its own, so that's not strictly
necessary, but it's still a good idea because it makes the test
output more reliable and somewhat easier to read (modulo the
impact of bigger type names).  Collisions will still occur if
the type is specialized at an archetype, since in this case we
will fall back on the unspecialized type.
2016-04-29 16:39:16 -07:00
John McCall
f33c84fb3d RemoteAST: implement getOffsetOfMember for structs and classes. 2016-04-28 16:29:20 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
Doug Gregor
ba304c38b0 [IRGen] IRGen fixes for SE-0033.
Teach IRGen's type lowering to cope with swift_newtype'd types.
2016-04-25 16:02:11 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Jordan Rose
66189ffac9 Convert many more classes to use llvm::TrailingObjects.
I only intend to do SIL instructions after this; I'm leaving the runtime alone.
2016-02-09 08:57:19 -08:00
David Farler
a6a5ece206 IRGen: Emit type references for remote reflection
- Implement emission of type references for nominal type field
  reflection, using a small custom encoder resulting in packed
  structs, not strings. This will let us embed 7-bit encoded
  32-bit relative offsets directly in the structure (not yet
  hooked in).
- Use the AST Mangler for encoding type references
  Archetypes and internal references were complicating this before, so we
  can take the opportunity to reuse this machinery and avoid unique code
  and new ABI.

Next up: Tests for reading the reflection sections and converting the
demangle tree into a tree of type references.

Todo: For concrete types, serialize the types for associated types of
their conformances to bootstrap the typeref substitution process.

rdar://problem/15617914
2016-02-03 13:52:26 -08:00
Slava Pestov
33ed1e0ab6 IRGen: Add ResilienceExpansion parameter to TypeInfo::isKnownEmpty(), NFC
In a few places, we have to be careful about the distinction between
"empty in this resilience domain" versus "empty in all resilience
domains". Make callers think about this by adding a parameter instead
of relying on them to check isFixedSize() as necessary first.

While making this change I noticed that the code for checking if
types are empty when computing extra inhabitants of structs and enums
might be slightly wrong in the face of resilience; I will revisit
this later.
2016-01-08 19:56:01 -08:00
Slava Pestov
7faf90a787 IRGen: Replace ResilienceScope enum with AST's ResilienceExpansion, NFC 2016-01-07 08:29:23 -08:00
Slava Pestov
1302539aab IRGen: Rename "Sequential Type" to "Record Type", the latter is more standard, NFC. 2016-01-07 07:49:06 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
25e43e3d48 IRGen: Mark more allocas with lifetime markers.
This should cover most temporary buffers, except for those used by indirected value arguments, which need some cooperation with CallEmission to properly mark lifetime end after the call's completed.
2015-12-26 15:19:07 -08:00
Slava Pestov
774dd10389 IRGen: Address a FIXME by adding an assertion to guard against invalid casts from ResilientStructTypeInfo 2015-11-17 17:59:20 -08:00
Slava Pestov
5fa9a7dc6d IRGen: Multi-payload enums only use spare bits if payloads are universally fixed-size
For example, if a @_fixed_layout struct A contains a resilient struct B
from the same module M, then inside M, A can have a fixed size, but
outside, A has a dynamic size because B is opaque. In this case, A is
not "universally fixed-size". This impacts multi-payload enums, because
if A is placed inside a multi-payload enum E which is lowered inside X,
we would get a fixed layout with spare bits, but lowering E outside of
X would yield a dynamic layout. This is incorrect.

Fix this by plumbing through a new predicate IsAlwaysFixedSize, which
is similar to IsPOD and IsBitwiseTakable, where a compound type inherits
the property if all leaf types exhibit it, and only use spare bits if
the original and substituted types have this property.
2015-11-16 16:34:56 -08:00
Slava Pestov
a05f6c80f6 IRGen: Use metadata accessors for types with resilient layout
If a struct has fixed layout but contains fields which are opaque,
or if the struct itself is opaque, use a metadata accessor function
instead of loading the metadata directly.

Let's say that A and B are two structs defined in the same module,
and B has a fixed size. This patch adds support for these two cases:

1) Fixed-layout struct A contains resilient struct B
2) Resilient struct A contains resilient struct B

In case 1),

a) Inside X: A is fixed-size and has constant metadata
 i) Direct metadata access can be performed on A and B
 ii) Direct field access can be performed on A and B
d) Outside X: B has an opaque layout
 i) Metadata accessor must be called for A and B
 ii) Fields of A do not have constant offsets, instead the offsets
     must be loaded from type metadata

Case 2) is the same as above except ii) does not apply, since fields
of resilient structs are manipulated via accessors.

Eventually, we will use metadata accessor functions for all public
struct and enum types.
2015-11-16 10:37:14 -08:00