Commit Graph

627 Commits

Author SHA1 Message Date
Jordan Rose
82930033d2 Add VTablePlaceholderDecl (but don't hook it up to anything yet). 2017-05-10 11:55:54 -06:00
Slava Pestov
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
Erik Eckstein
b1d5c77cec Runtime support for the NSArchiver class attributes.
Register class names for NSKeyedArchiver and NSKeyedUnarchiver based on the @NSKeyedArchiveLegacy and @_staticInitializeObjCMetadata class attributes.

@NSKeyedArchiveLegacy registers a class name translation.
@_staticInitializeObjCMetadata just makes sure that the metadata of a class is instantiated.

This registration code is executed as a static initializer, like a C++ global constructor.
2017-05-08 14:00:03 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Joe Groff
3d178be169 Merge pull request #8875 from jckarter/keypaths
Keypaths
2017-04-21 17:51:17 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Joe Groff
aaddafa55b IRGen: Support for generic key path patterns. 2017-04-17 17:50:57 -07:00
Slava Pestov
497336c4bc IRGen: Use the right reference counting for subclass existentials 2017-04-17 17:22:28 -06:00
Joe Groff
85ad6b355e Merge branch 'master' into keypaths 2017-04-06 18:02:07 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00
Joe Groff
f929c29bdf IRGen: Lower keypath instructions to patterns for the runtime to instantiate. 2017-04-04 11:31:15 -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
John McCall
d61d966451 Use ConstantInitBuilder in most kinds of metadata emission.
This is NFC in intent, but I had to restructure the code to emit more
of the lists "inline", which means I inevitably altered some IRGen
emission patterns in ways that are visible to tests:

- GenClass emits property/ivar/whatever descriptors in a somewhat
  different order.

- An ext method type list is now emitted as just an array, not a struct
  containing only that array.

- Protocol descriptors are no longer emitted as packed structs.

I was sorely tempted to stop using packed structs for all the metadata
emission, but didn't really want to update that many tests in one go.
2017-03-06 14:18:47 -05:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Pawel Szot
99db7258a0 [SR-3882] fix objc conformance from inherited protocols 2017-02-22 09:42:13 +01:00
Doug Gregor
042e6510c3 [AST] Drop ProtocolDecl's "inherited protocols" list.
The list of directly inherited protocols of a ProtocolDecl is already
encoded in the requirement signature, as conformance constraints where
the subject is Self. Gather the list from there rather than separately
computing/storing the list of "inherited protocols".
2017-02-20 09:41:00 -08:00
Arnold Schwaighofer
2307145c0e IRGen: Cast an ObjC allocation to the instantiated class type
Lowering of phi nodes expects the more refined type rather than objc_object.

rdar://30268690
2017-02-07 11:07:13 -08:00
Roman Levenstein
383dc9c1e6 Fix a couple of places in the IRGen where we still don't use interface types 2017-01-27 16:38:07 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
b253b21014 [gardening] Make sure argument names in comments match the actual parameter names 2016-12-21 22:56:01 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08: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
Arnold Schwaighofer
4b279d1541 IRGen: Decend into superclass constraint types when building exemplar archetypes
When building exemplar archetypes we would build different exemplars for the
archetype "S: A<T>" of the example below because we would just use the pointer
to the class type ": A<T>" instead of profiling (decending) into the type.
This caused us to end up with different exemplar types for different uses of M
and ultimately several llvm type instances for the same generic type M<S,T>.

 class A<T> {}
 class M<T, S: A<T>> {...}

Also reverts "IRGen: Cast the type of class pointer to the storage type"
 from commit 2d73b3cef2 but keeps its test case.

Proper fix for rdar//28684642
2016-10-28 13:55:40 -07:00
Arnold Schwaighofer
2d73b3cef2 IRGen: Cast the type of class pointer to the storage type
We can run into an opaque pointer type.

rdar://28684642
2016-10-25 09:34:35 -07:00
Joe Groff
b4041a5b57 SIL: Restrict partial_apply when -disable-sil-partial-apply is enabled.
Allow it only to have one context parameter, whose ownership convention matches the convention of the resulting thick function, effectively limiting it to binding a closure invocation function to its context.
2016-10-10 11:25:57 -07:00
Erik Eckstein
db00c5e924 SIL: allow alloc_ref_dynamic to allocate tail elements.
It's the same thing as for alloc_ref: the optional [tail_elems ...] attribute specify the tail elements to allocate.
For details see docs/SIL.rst

This feature is needed so that we can allocate a MangedBuffer with alloc_ref_dynamic.
The ManagedBuffer.create() function uses the dynamic self type to create the buffer instance.
2016-10-06 08:46:23 -07:00
Slava Pestov
745a4a3974 IRGen: Disable resilient class metadata unless -enable-class-resilience is passed in
Resilient classes are not fully implemented yet, and can cause
crashes at runtime; add a flag disabling them until the code is
done, to unblock standard library testing with resilience
enabled.
2016-09-30 18:28:11 -07:00
Slava Pestov
584316d5f2 Runtime: Fix breakage when generic subclasses directly inherit NSObject
Remove special-casing that makes NSObject fragile since
this messes up layout. The optimization probably has little
practical benefit anyway.

Fixes <https://bugs.swift.org/browse/SR-2586>.
2016-09-20 16:08:20 -07:00
practicalswift
4b35268741 [gardening] Fix two recently introduced typos 2016-09-16 21:44:21 +02:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Slava Pestov
c98ce0c770 IRGen: Fix Dispatch overlay for non-optimized builds
I apologize in advance to @jrose-apple, who is not a fan
of this fix ;-)

In unoptimized builds, the convenience initializers on
DispatchQueue allocate and immediately deallocate an
instance of OS_dispatch_queue prior to calling the
C function that returns the "real" instance.

This is because we don't have a way to write user-defined
factory initializers yet; convenience initializers still
have an 'initializing' entry point that takes an existing
instance, which we have no choice but to throw away.

Unfortunately, when we perform the fake allocation, we
look up class metadata by calling the wrong Swift runtime
function, causing a crash when we send +allocWithZone:.

Fix this so that the metadata is accessed via a lookup
from the Objective-C runtime, instead of making a totally
fake 'foreign metadata' object -- it looks like there was
code for this already, it just wasn't used in all cases.

While getting metadata for a runtime-only class should be
rare, this feels like a real bug fix, to me.

Second, we would ultimately free the fake object by sending
-release, however OS_dispatch_queue has an override of
-dealloc which doesn't like to be called with a completely
uninitialized instance.

Here, I'm going to drop all pretense of sanity. The patch
just changes IRGen to lower the dealloc_partial_ref instruction
as a call to the object_dispose() Objective-C runtime function
when the class in question is a runtime-only class. This
frees the object without running -dealloc, which *happens*
to work for OS_dispatch_queue.

Fixes <rdar://problem/27226313>.
2016-08-13 01:51:45 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -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
Jordan Rose
f0c3bc25ff [IRGen] Don't emit ObjC class property metadata on old targets. (#2350)
The ObjC runtime on OS X 10.10 and older and iOS 9 and older can't
handle them, so for these targets, emit nil for all class property
lists.

It's a little unfortunate that this is target-dependent, but there's
not much we can do about it.

rdar://problem/25605427
2016-05-02 13:10:02 -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
0273167b5d Use the known type parameters to determine static offsets to stored
properties of classes with generic layouts.

Previously we were falling back on accessing them via the field
offset vector even when we knew everything about the type.

As a minor benefit, this allows RemoteAST to also determine offsets
for members of classes with generic layout.

Half of the test changes are IR type-name uniquing; I'm going to
explore mangling these with the full type where possible.
2016-04-29 15:33:05 -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
Joe Groff
9c5564f808 Allow subclasses of specific instantiations of ObjC generic classes.
If a subclass grounds all the type parameters from its base class, we don't have to worry about any erasure edge cases. We should be able to support this, giving existing code that subclasses the nongeneric form of the class a migration path. Spot-fix some places in IRGen where we assume we can't emit static references to ObjC generic classes or metaclasses.
2016-04-06 21:19:11 -07:00
Jordan Rose
4dd3c10a42 [IRGen] Correctly emit metadata for ObjC class properties.
...which is important because Clang CodeGen was already claiming we were!

rdar://problem/25473573
2016-04-04 19:26:48 -07:00
Joe Groff
c877900624 IRGen: Set instanceStart correctly in ObjC rodata when first stored property is empty.
Give empty fields a notional byte offset so we can still use the offset of the first field as an approximation of the instanceStart of a class.

Fixes SR-1055.
2016-03-29 08:48:39 -07:00
practicalswift
11a8b6c2ba [gardening] Daily cleanup: typos, header formatting. 2016-03-28 09:29:38 +02:00