Commit Graph

1326 Commits

Author SHA1 Message Date
John McCall
8f30faa4c1 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This speculatively re-applies 7576a91009,
i.e. reverts commit 11ab3d537f.
We have not been able to duplicate the build failure in
independent testing; it might have been spurious or unrelated.
2015-12-29 12:14:40 -08: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
Dmitri Gribenko
11ab3d537f Revert "Include access functions for the metadata and witness tables"
This reverts commit 7576a91009.
It broke the testsuite for swift-corelibs-foundation.
2015-12-25 19:17:50 +02:00
John McCall
7576a91009 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This reverts commit 6528ec2887, i.e.
it reapplies b1e3120a28, with a fix
to unbreak release builds.
2015-12-24 20:21:17 -08:00
Nadav Rotem
f451406ca7 Fix warnings that only show up in Release builds. NFC. 2015-12-24 14:40:48 -08:00
Slava Pestov
800821f980 IRGen: Layout of root classes containing resiliently-sized fields
Now that all the machinery is in place, the ClassMetadataBuilder
can (more accurately) query the ClassLayout instead of trying to
re-derive whether the field offset vector is dependent, etc.

Apart from performing dynamic layout for resiliently-sized fields
in concrete classes, this also lets us *skip* dynamic layout
if we have a generic class without any dependent fields.

I haven't tested subclassing with resilient field layout yet, but
getting that working is the next step and should not be too much
work.

Also, swift_initClassMetadata_UniversalStrategy() only stores
the computed field offsets in the field offset globals when the
Objective-C runtime is available, because it gets the offset
pointers from the Objective-C class rodata. On Linux, we will
need to emit code to copy from the field offset vector into
field offset globals in IRGen. This is pretty easy, but I'll do
it in a follow-up patch so for now the new execution test is
XFAIL'd on Linux.
2015-12-24 02:54:56 -08:00
Slava Pestov
45c82828f2 IRGen: Some field offset globals can be constant
It is questionable if emitting globals for constant offsets is of
any use; the only scenario where one could not compute the offset
directly in IRGen is if the class has a fixed-size layout inside
its own resilience domain, but has a non-fixed layout outside,
*and* we're doing direct stored property access.

Right now we don't plan on doing this, but it might come up in
the future with more exotic resilience domain configurations or
perhaps optimizations.
2015-12-24 02:11:15 -08:00
Slava Pestov
d27b16ffe2 IRGen: We only ever have a dependent superclass if we're emitting a metadata template
After recent simplifications we can remove some logic.
2015-12-24 02:11:15 -08:00
Joe Groff
9af439b87e Runtime: Rename reportMissingMethod to deletedMethodError.
The runtime entry doesn't just report the error, unlike the other report* functions, it also does the crashing.

Reapplying independent of unrelated reverted patches.
2015-12-23 16:01:21 -08:00
Sean Callanan
6528ec2887 Revert "Include access functions for the metadata and witness tables"
This reverts commit b1e3120a28.

Reverting because this patch uses WitnessTableBuilder::PI in NDEBUG code.
That field only exists when NDEBUG is not defined, but now NextCacheIndex, a
field that exists regardless, is being updated based on information from PI.

This problem means that Release builds do not work.
2015-12-23 15:42:10 -08:00
Sean Callanan
09f48ee2b4 Revert "Runtime: Rename reportMissingMethod to deletedMethodError."
This reverts commit bdffe703b0.
Required to revert b1e3120a28.
2015-12-23 15:41:06 -08:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Joe Groff
bdffe703b0 Runtime: Rename reportMissingMethod to deletedMethodError.
The runtime entry doesn't just report the error, unlike the other report* functions, it also does the crashing.
2015-12-23 09:17:07 -08:00
Slava Pestov
1b4fd375f8 IRGen: Move field offset global emission out of Objective-C-specific code
We're going to start using these for pure Swift classes as well,
when they have a resilient superclass, or fields of resilient
value type.
2015-12-23 03:17:10 -08:00
Slava Pestov
5098ca9085 IRGen: Factor out ClassLayout class
ClassLayoutBuilder computes a bunch of stuff in addition to the
StructLayout, which is then stashed in ClassTypeInfo. Extract this
into a new ClassLayout type. It probably should not exist at all,
if we only generalized StructLayout a bit.
2015-12-23 01:18:54 -08:00
John McCall
b1e3120a28 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.
2015-12-23 00:37:24 -08:00
Slava Pestov
e0451c8f70 IRGen: Redo concrete subclasses of generic classes
Now, such classes will emit a metadata pattern and use the
generic metadata instantiation logic.

This was all wired up to handle the case of no generic
parameters previously, to support resilient struct layout
in the runtime.

The swift_initializeSuperclass() entry point still exists,
providing a fast path for when there's no field layout to
do, which is currently always true if we have a concrete
class.

This entry point no longer needs the global lock, since
now we get a per-class lock from the metadata cache.
Also, previously we would call the superclass accessor
function on every access of class metadata for a concrete
subclass of a generic class. Now that we re-use the
existing metadata cache logic, this extra call only occurs
during initialization.

Both swift_initializeSuperclass() and
swift_initClassMetadata_UniversalStrategy() used to take
the superclass as a parameter, but this isn't really
necessary, since it was loaded out of the class metadata
immediately prior to the call by the caller. Removing
this parameter makes the ABI a little simpler.

Once class layout supports resilient types, we will also
use swift_initClassMetadata_UniversalStrategy() to lay
out classes with resilient types as fields.

Singleton metadata caches will still allocate a copy of
the template, which is a slight performance regression
from the previous implementation of concrete subclasses
of generic classes. This will be optimized soon.

Right now, the template can always be modified in place;
in the future, it will be possible to modify in place as
long as the superclass is fixed-layout; a resilient superclass
might add or remove fields, thus we cannot leave room for
it in the metadata of the subclass, and will need to grow
the metadata and slide field offsets at runtime using a
new entry point.

Also, the representation of the cache itself could be
optimized to handle the singleton case, since all we
really need here is a lock without any kind of mapping
table.
2015-12-22 15:30:17 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Slava Pestov
c35d9bd092 IRGen: Simplify generated code for generic class metadata instantiation
Move the following from IRGen to runtime:

- Copying generic parameters from superclass to subclass
- Copying field offsets from superclass to subclass
- Initializing the Objective-C runtime name of the subclass

This eliminates some duplication between the generic subclass and
concrete subclass of a generic class cases.

Also this should reduce generated code size and have no impact on
performance (the instantiation logic only runs once per substituted
type).
2015-12-22 02:09:03 -08:00
Slava Pestov
1368db7872 IRGen: Fix layout of concrete subclasses of generic subclasses of imported Objective-C classes
class B<T> : NSFoo {}
class A : B<Int> {}

IRGen computes the ivar layout starting from offset zero, since
the size of the 'NSFoo' is unknown and we rely on the Objective-C
runtime to slide the ivar offsets.

The instantiated metadata for B<Int> would contain a field offset
vector with the correct offsets, because of how
swift_initClassMetadata_UniversalStrategy() works.

However, A's metadata is emitted statically, and this includes a
copy of the field offset vector from the superclass. A's metadata
was initialized by swift_initializeSuperclass(), which did not
copy the field offset vector over from A<Int>. And since the
Objective-C runtime only slides the immediate ivars of a class,
the field offsets corresponding to A<Int>'s fields in B's type
metadata were never slid, resulting in problems when an instance
of B was passed to a function operating on an A<T> generically.

Fixes <rdar://problem/23200051>.
2015-12-21 16:23:39 -08:00
Max Moiseev
2f7b64e475 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-21 12:02:13 -08:00
Slava Pestov
304f4f051f IRGen: Fix for fixed-layout enum with resilient payload
If an enum is fixed-layout in our resilience domain but not
universally fixed-layout, other resilience domains will use
runtime functions to project and inject payloads.

These expect to find the payload size in the metadata, so
emit it if the enum is not universally fixed-layout.

Note that we do know the payload size, so it is constant
for us; there's no runtime call required to initialize
the metadata.
2015-12-19 00:47:47 -08:00
Doug Gregor
a97ab6dd14 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-18 10:15:47 -08:00
Dmitri Gribenko
6a66b3cff8 Merge pull request #561 from practicalswift/typos-again
[Typo] Replace PR#514-525 with one large PR
2015-12-18 03:37:02 -08:00
Max Moiseev
3fe0c60d7f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-17 11:00:02 -08:00
John McCall
ba3959681d Rename tryEmitConstantHeapMetadataRef for consistency. NFC. 2015-12-16 18:20:23 -08:00
David Farler
101cf49880 Use -enable-resilience for IRGen super_method tests
We've already got -enable-resilience and @_fixed_layout to compare
IRGen differences when lowering super_method instructions, so nuke
the -force-resilient-super-dispatch testing flag. While
we're at it, consolidate the super tests a bit.
2015-12-16 14:01:49 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Max Moiseev
2021dd5a4d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-15 12:49:22 -08:00
David Farler
86f815bd32 IRGen: Statically load superclass metadata for non-resilient classes
We only need to indirectly load the superclass's metadata when the
superclass is resilient. For example, we may be calling a super method
inside an extension of a class we don't own. Otherwise, we can
immediately load the statically known superclass.

Adds a testing flag to force resilient super dispatch, since the
IRGen module resilience checks aren't fully implemented yet.

SIL -> IR tests added.

rdar://problem/22749732

Also fixes rdar://problem/23884670
2015-12-14 17:37:34 -08:00
Joe Groff
fd457fb343 Revert "IRGen/Runtime: Use relative addresses in nominal type descriptors."
This reverts commit fbb832665a. It causes LLVM to complain with
"Cannot represent a subtraction with a weak symbol" when targeting Linux.
2015-12-11 15:41:11 -08:00
Joe Groff
fbb832665a IRGen/Runtime: Use relative addresses in nominal type descriptors.
Decrease the size of nominal type descriptors and make them true-const by relative-addressing the other metadata they need to reference, which should all be included in the same image as the descriptor itself. Relative-referencing string constants exposes a bug in the Apple linker, which crashes when resolving relative relocations to coalesceable symbols (rdar://problem/22674524); work around this for now by revoking the `unnamed_addr`-ness of string constants that we take relative references to. (I haven't tested whether GNU ld or gold also have this problem on Linux; it may be possible to conditionalize the workaround to only apply to Darwin targets for now.)
2015-12-11 15:21:12 -08:00
Max Moiseev
786e1ea2b1 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-11 15:19:02 -08:00
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