Commit Graph

428 Commits

Author SHA1 Message Date
Ted Kremenek
d326c8e5f7 Revert "IRGen: If Objective-C interop is disabled foreign classes should use Swift reference counting"
This reverts commit 54a6b46da9.

This is breaking testing on iOS.
2015-11-20 07:22:54 -08:00
Slava Pestov
54a6b46da9 IRGen: If Objective-C interop is disabled foreign classes should use Swift reference counting
I'm not sure how to write an automated test for this yet.

Fixes <rdar://problem/23545207>.
2015-11-19 23:22:26 -07:00
Slava Pestov
5fc23a7b7d IRGen: Use metadata templates for non-generic types with fields of resilient type
Let's say that A and B defined in modules X and Y respectively.
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 both cases:

a) Metadata access requires an accessor call
b) Fields of A do not have constant offsets, instead the offsets
   must be loaded from type metadata

A future patch will switch over to initializing the template in-place,
instead of heap-allocating a copy.
2015-11-16 11:11:08 -08:00
Slava Pestov
4b094264ff IRGen: Clean up metadata template logic, NFC
The predicate for evaluating if a nominal type has constant metadata was
repeated in a few places, factor it out. Also, the generic signature was
passed down to GenericMetadataBuilderBase, but its not actually used there,
so remove it.
2015-11-16 11:11:07 -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
Slava Pestov
72fa928b75 IRGen: name create_generic_metadata functions for easier debugging 2015-11-16 10:37:14 -08:00
Slava Pestov
3d19691bab IRGen: Always use Swift reference counting when Obj-C interop is not available
The swift_unknown* entry points are not available on the Linux port.
Previously we would still attempt to use them in a couple of cases:

1) Foreign classes
2) Existentials and archetypes
3) Optionals of boxed existentials

Note that this patch changes IRGen to never emit the
swift_errorRelease/Retain entry points on Linux. We would like to
use them in the future if we ever adopt a tagged-pointer representation
for small errors. In this case, they can be brought back, and the
TypeInfo for optionals will need to be generalized to propagate the
reference counting of the payload type, instead of defaulting to
unknown if the payload type is not natively reference counted.
A similar change will need to be made to support blocks, if we ever
want to use the blocks runtime on Linux.

Fixes <rdar://problem/23335318>, <rdar://problem/23335537>,
<rdar://problem/23335453>.
2015-11-03 13:03:50 -08:00
Ben Langmuir
4082355244 Split KnownProtocolKind enum case from protocol name
This avoids us using reserved identifiers as the enum case names of all
our underscored protocols like _ObjectiveCBridgeable. I used the
convention PROTOCOL_WITH_NAME to mirror how the known identifiers work.

Swift SVN r32924
2015-10-27 23:10:36 +00:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Adrian Prantl
1a2dcc0102 Revert "Speculatively revert a debug-info-implicating change in my"
This reverts commit r32548 after fixing the underlying issue in r32816.

Swift SVN r32836
2015-10-23 00:27:56 +00:00
Adrian Prantl
2f9f964219 Change the contract between Swift compiler and LLDB about how the function
prologue is handled in the line table.
We now mark the first instruction after the stack setup as end_prologue and
any further initilizations (which may include function calls to metadata
accessors) with line 0 which lldb will skip. This allows swiftc to emit
debug info for compiler-generated functions such as metadata accessors.
Mixing debug and non-debug functions is not very well supported by LLVM
and the resulting line table makes it impossible for LLDB to determine
where a function with debug info ends and a nondebug function starts.

rdar://problem/23042642

Swift SVN r32816
2015-10-22 00:20:03 +00:00
Michael Gottesman
113fac2871 Update use of GlobalAlias::create API for upstream changes.
Swift SVN r32798
2015-10-21 21:45:08 +00:00
Slava Pestov
54dd7892e8 SIL: Emit native ivar destroyer and store it in class metadata
Swift SVN r32644
2015-10-13 00:27:57 +00:00
Joe Groff
42c71b7972 Don't mangle directness into type metadata symbols.
Anywhere we can't directly address type metadata in Swift, we've found we need a function call. Directness isn't useful here.

Swift SVN r32626
2015-10-12 17:22:40 +00:00
John McCall
e1eb240603 Speculatively revert a debug-info-implicating change in my
last series of patches in an attempt to placate the build.

Swift SVN r32548
2015-10-09 03:44:41 +00:00
John McCall
7f975f000b Generalize code emission for lazy metadata caches; we'll use this
for non-dependent protocol witness tables, too.

Swift SVN r32540
2015-10-09 01:06:03 +00:00
John McCall
411b9e15e4 Don't create unwanted global declarations.
Swift SVN r32539
2015-10-09 01:06:00 +00:00
John McCall
a945bacc6b Split GenProto.cpp into three files; NFC.
- GenProto.cpp for protocols and protocol conformances
  - GenExistential.cpp for existential type layout and operations
  - GenArchetype.cpp for archetype type layout and operations

Swift SVN r32493
2015-10-07 18:41:12 +00:00
Slava Pestov
255a1e63ac Random comment typo fixes, NFC
Swift SVN r32492
2015-10-07 18:33:46 +00:00
Joe Groff
9eea4d3838 IRGen: Rename TypeMetadataAccessStrategy -> MetadataAccessStrategy.
NFC, but this set of access modes applies more generally to other kinds of metadata that may need to be guarded by accessors, such as witness tables.

Swift SVN r31838
2015-09-10 00:51:05 +00:00
Michael Gottesman
0606d5843a Remove calls to raw_svector_ostream::flush()
This function is deleted since LLVM r244928.

Swift SVN r31798
2015-09-09 04:37:13 +00:00
Joe Groff
95b5ff359d Remove dead code.
Swift SVN r31589
2015-08-31 22:22:32 +00:00
Joe Groff
773eadb9f2 IRGen/Runtime: Populate the runtime protocol conformance table with relative references.
By using relative references, either directly to symbols internal to the current TU, or to the GOT entry for external symbols, we avoid unnecessary runtime relocations, and we save space on 64-bit platforms, since a single image is still <2GB in size. For the 64-bit standard library, this trades 26KB of fake-const data in __DATA,__swift1_proto for 13KB of true-const data in __TEXT,__swift2_proto. Implements rdar://problem/22334380.

Swift SVN r31555
2015-08-28 18:07:22 +00:00
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00
Joe Groff
8e2ce60f5b IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects, and also makes IR a lot less cluttered. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Chris Willmore
51f08e0285 Add FileReference object literals and _FileReferenceLiteralConvertible protocol.
<rdar://problem/21781451> Add file literal to Swift

Swift SVN r31232
2015-08-13 22:38:55 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
Slava Pestov
b52fafe1c2 IRGen: Fix emission of optional dynamic self type when bound to a generic argument
Fixes <rdar://problem/21081782>.

Swift SVN r30743
2015-07-29 00:10:56 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Slava Pestov
871d71a555 Sema: Differentiate between 'class is @objc' and 'class has implicitly @objc members'
Generic subclasses of @objc classes are thus no longer @objc, but still
have implicitly @objc members.

Explicit @objc on generic classes or classes that inherit from @objc
classes is now forbidden with a diagnostic. Users need to know that
while they can override Objective-C methods and properties in such
a class, they cannot refer to the class by name from Objective-C code,
since it will not appear in the bridging header.

Fixes <rdar://problem/21342574>.

Swift SVN r30494
2015-07-22 06:34:20 +00:00
Joe Groff
4182c44cfe Runtime: Provide prefab value witness tables for unowned and weak references.
Fixes rdar://problem/21315113.

Swift SVN r30291
2015-07-17 00:09:37 +00:00
Joe Groff
25f0dc31c2 IRGen: Fix up layout generation for reference storage types.
If we have an unowned/weak protocol type with witness tables, we can't use the prefab NativeObject/UnknownObject layouts. While we're here, fix up some tests for 32-bit portability too.

Swift SVN r30270
2015-07-16 20:07:35 +00:00
Joe Groff
ec61fa4c5a IRGen/Runtime: Use only the 'layout' subset of the vwtable to perform value type layout.
Full type metadata isn't necessary to calculate the runtime layout of a dependent struct or enum; we only need the non-function data from the value witness table (size, alignment, extra inhabitant count, and POD/BT/etc. flags). This can be generated more efficiently than the type metadata for many types--if we know a specific instantiation is fixed-layout, we can regenerate the layout information, or if we know the type has the same layout as another well-known type, we can get the layout from a common value witness table. This breaks a deadlock in most (but not all) cases where a value type is recursive using classes or fixed-layout indirected structs like UnsafePointer. rdar://problem/19898165

This time, factor out the ObjC-dependent parts of the tests so they only run with ObjC interop.

Swift SVN r30266
2015-07-16 15:38:17 +00:00
Ted Kremenek
a3d88266b2 Revert "IRGen/Runtime: Use only the 'layout' subset of the vwtable to perform value type layout."
This reverts commit r30243.

This appears to be breaking the Linux build.

Swift SVN r30253
2015-07-16 06:28:24 +00:00
Joe Groff
2641d566ac IRGen/Runtime: Use only the 'layout' subset of the vwtable to perform value type layout.
Full type metadata isn't necessary to calculate the runtime layout of a dependent struct or enum; we only need the non-function data from the value witness table (size, alignment, extra inhabitant count, and POD/BT/etc. flags). This can be generated more efficiently than the type metadata for many types--if we know a specific instantiation is fixed-layout, we can regenerate the layout information, or if we know the type has the same layout as another well-known type, we can get the layout from a common value witness table. This breaks a deadlock in most (but not all) cases where a value type is recursive using classes or fixed-layout indirected structs like UnsafePointer. rdar://problem/19898165

Swift SVN r30243
2015-07-16 01:28:42 +00:00
Slava Pestov
cdd5a4121c IRGen: Generate value witnesses to get enum tag and project payload
These will be used for reflection, and eventually to speed up generic
operations on single payload enums as well.

Progress on <rdar://problem/21739870>.

Swift SVN r30214
2015-07-15 06:03:18 +00:00
Joe Groff
3494d95dba Remove dead code.
Swift SVN r30126
2015-07-12 01:06:08 +00:00
Joe Groff
6c3efc0d8f IRGen: Use opaque Builtin.IntNN metadata for Builtin.Vec types.
Builtin.Int128 and Builtin.Int256 already have the proper size and alignment for common vector types on our platform, and since they're opaque builtins, they only need placeholder metadata.

Swift SVN r29890
2015-07-02 17:05:27 +00:00
Joe Groff
a9e69dda79 IRGen/Runtime: Mark indirect cases in an enum's field type infos.
And use this information in EnumMirror to project boxed payloads when we encounter them.

Swift SVN r29866
2015-07-02 00:00:42 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Joe Groff
e57c470019 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

This time, fix a paste-o that caused SILBlockStorageTypes to get replaced with SILBoxTypes during type substitution. Oops.

Swift SVN r29489
2015-06-18 15:21:52 +00:00
Mark Lacey
39087cd36b Revert "Introduce a "@box T" type for SIL."
This reverts commit r29474 because it looks like it is breaking the
build of the SpriteKit overlay.

Swift SVN r29482
2015-06-18 06:28:04 +00:00
Joe Groff
7b0045c790 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

Swift SVN r29474
2015-06-18 04:07:03 +00:00
Joe Groff
2852a3951f IRGen: Mark metadata loads as invariant.
And mark loads of the value witness table as dereferenceable, so that LLVM is able to better optimize metadata accesses.

Swift SVN r29372
2015-06-13 20:44:05 +00:00
Slava Pestov
623642c533 IRGen: Remove dead code
NFC

Swift SVN r29339
2015-06-07 10:16:24 +00:00
Joe Groff
2bf783dfe8 Runtime: Generate a mangled name as the ObjC runtime name of generic class instances.
Our hack to generate a unique name by appending the class pointer doesn't produce a stable class name that can persist in NSKeyedArchiver, or eventually be used as a key for dynamic runtime instantiation. Generate a proper mangled name for the class instance by building a demangling AST from the metadata nodes and feeding it into the remangler. Should fix rdar://problem/18884563, though I need to try using an archiver with a generic class to verify.

Swift SVN r29316
2015-06-05 14:27:58 +00:00
Slava Pestov
56dec64e5c IRGen: Trying to get dynamic layout for @objc working
It looks like John and Joe already did a good part of this. The previous
patch to enable polymorphic @objc_method signatures takes us further, and
I think this patch fills in the rest.

Fixes <rdar://problem/18505295>, <rdar://problem/20700287>.

Swift SVN r29259
2015-06-03 00:01:27 +00:00
Ted Kremenek
eaa0f93710 Revert "IRGen: Trying to get dynamic layout for @objc working"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29146
2015-05-29 14:11:28 +00:00
Slava Pestov
83b789ea34 IRGen: Trying to get dynamic layout for @objc working
It looks like John and Joe already did a good part of this. The previous
patch to enable polymorphic @objc_method signatures takes us further, and
I think this patch fills in the rest.

Fixes <rdar://problem/18505295>, <rdar://problem/20700287>.

Swift SVN r29137
2015-05-29 06:19:04 +00:00