Commit Graph

1343 Commits

Author SHA1 Message Date
David Farler
e6d1d9748b SILGen: Use the base SILDeclRef for super_method override constant info
getOverriddenVTableEntry only goes one level up in the class hierarchy,
but getConstantOverrideInfo requires that the next level up not itself be an
override.

A little bit of refactoring:

SILDeclRef::getOverriddenVTableEntry()
  -> SILDeclRef::getNextOverriddenVTableEntry()

static findOverriddenFunction()
  -> SILDeclRef::getBaseOverriddenVTableEntry()

rdar://problem/22749732
2015-12-10 15:47:50 -08:00
Maxim Moiseev
0e0191380a OptionSetType => OptionSet 2015-12-10 14:58:24 -08:00
Maxim Moiseev
2c95bb6d51 BooleanType => Boolean 2015-12-10 14:56:32 -08:00
Max Moiseev
d610fa0d1c Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-10 10:29:52 -08:00
Maxim Moiseev
844b81c46b SequenceType => Sequence 2015-12-09 17:16:56 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
atrick
405f9f59b4 Merge pull request #204 from atrick/optionalcast
Runtime optional casts.
2015-12-09 16:32:49 -08:00
Andrew Trick
a98de1ba1c Add an Optional metadata kind for runtime casts.
Reuses the enum metadata layout and builder because most of the logic is
also required for Optional (generic arg and payload). We may want to
optimize this at some point (Optional doesn't have a Parent), but I
don't see much opportunity.

Note that with this approach there will be no change in metadata layout.
Changing the kind still breaks the ABI of course.

Also leaves the MirrorData summary string as "(Enum Value)". We should
consider changing it.
2015-12-09 15:01:33 -08:00
Davide Italiano
d2193f13f5 [IRGen] Prevent (possibly infinite) recursion. 2015-12-09 01:14:34 +00:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
David Farler
9ccc2dd359 IRGen: super_method: Dynamically get superclass of static base class
After talking with @jckarter and @slavapestov we decided that getting
the superclass at runtime for super_method lookup was the right approach
if its based in the static base class and the lookup doesn't start with
  the instance pointer.

NFC for current IRGen - SILGen doesn't lead to here yet.

rdar://problem/22749732
2015-12-05 01:29:27 -08:00
David Farler
58e2b0d321 IRGen: Use the static superclass for virtual dynamic dispatch
Following the self instance pointer to its class metadata isn't sound
for chained super calls since it means the same metadata is pulled,
resulting infinite recursion.

NFC for actual IRGen. SILGen isn't using super_method for native
dispatch yet.

rdar://problem/22749732
2015-12-03 00:30:05 -08:00
David Farler
fbbb593b1c IRGen: Lower super_method SIL instruction for native classes
This is the first part of making class method dispatch resilient.

If we have the following class hierarchy:

    // Module A
    class Parent {
      func foo() {}
    }

    class Child : Parent {}

    // Module B
    class Grandchild : Child {
      override func foo() {
        super.foo()
      }
    }

dispatch to `Parent.foo` will be static via a `function_ref`, so if
someone adds a `foo()` to `Child` later on, `Grandchild` won't know
about it without recompiling.

Stage in the IRGen portion of dynamic dispatch when calling methods on
`super`:

- Don't assert in IRGen if we see a native super_method instruction.
- Perform virtual lookup on superclass's metadata. If we see a
  `super_method` instruction for a native class:
  - Get the address of the superclass's metadata at offset 1
  - Load the superclass's metadata
  - Perform virtual lookup on this metadata instead

TODO: SILGen super_method instructions for native classes.
TODO: Devirtualize back down to static dispatch with a reslience lookup
mechanism.

rdar://problem/22749732
2015-11-30 21:19:06 -08:00
Slava Pestov
c06f3353c9 IRGen: Remove unused IGM parameter from some methods on EnumImplStrategy, NFC
We already stash the IRGenModule in an instance variable.
2015-11-30 13:32:55 -08:00
Ted Kremenek
72adaea719 Revert "Revert "IRGen: If Objective-C interop is disabled foreign classes should use Swift reference counting""
This reverts commit d326c8e5f7.

We believe the failure now may be in the setup of the test harness.
Re-applying this change, since the tests passed in our other
configurations.
2015-11-20 15:19:58 -08:00
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