Commit Graph

242 Commits

Author SHA1 Message Date
Joe Groff
8edde2c503 Runtime: Push swift_demangleSimpleClass into XCTest overlay.
The only place it's used.
2015-12-23 11:19:42 -08:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -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
Chris Lattner
5bcd4bc3bd Merge pull request #738 from practicalswift/another-typo-round
[Typos] Fix typos
2015-12-22 15:41:49 -08:00
practicalswift
6e3b700b44 Fix typos. 2015-12-23 00:31:13 +01: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
806be29941 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-14 12:05:35 -08:00
practicalswift
14f2addaa3 Fix typo: avaialble → available 2015-12-14 00:11:17 +01: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
d610fa0d1c Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-10 10:29:52 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -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
Slava Pestov
65a5a03f26 IRGen: Add a new destructiveInjectEnumTag value witness function
This value witness function takes an address of an enum value where the
payload has already been initialized, together with a case index, and
forms the enum value.

The formal behavior can be thought of as satisfying an identity in
relation to the existing two enum value witnesses. For any enum
value, the following is to leave the value unchanged:

  tag = getEnumTag(value)
  destructiveProjectEnumData(value)
  destructiveInjectEnumData(value, tag)

This is the last missing piece for the inject_enum_addr SIL instruction
to handle resilient enums, allowing the implementation of an enum to be
decoupled from its uses. Also, it should be useful for dynamically
constructing enum cases with write reflection, once we get around to
doing such a thing.

The body of the value witness is emitted by a new emitStoreTag() method
on EnumImplStrategy. This is similar to the existing storeTag(), except
the case index is a value instead of a contant.

This is implemented as follows for the different enum strategies:

1) For enums consisting of a single case, this is trivial.

2) For enums where all cases are empty, stores the case index into the
   payload area.

3) For enums with a single payload case, emits a call to a runtime
   function. Note that for non-generic single payload enums, this could
   be open-coded more efficiently, but the function still has the
   correct behavior since it supports extra inhabitants and so on.
   A follow-up patch will make this more efficient.

4) For multi-payload enums, there are two cases:

   a) If one of the payloads is generic or resilient, the enum is
      dynamically-sized, and a call to a runtime function is emitted.

   b) If the entire enum is fixed-size, the value witness checks if
      the case is empty or not.

      If the case has a payload, the case index is swizzled into
      spare bits of the payload, if any, with remaining bits going
      into the extra tag area.

      If the case is empty, the case index is swizzled into the
      spare bits of the payload, the remaining bits of the payload,
      and the extra tag area.

The implementations of emitStoreTag() duplicate existing logic in the
enum strategies, in particular case 4)b) is rather complicated.

Code cleanups are welcome here!
2015-12-08 15:43:55 -08:00
Slava Pestov
9ee10e7d39 IRGen: destructiveProjectEnumData() value witness doesn't need a return value
The rest of the runtime assumes the payload starts at the beginning
of the enum, so simplify some code by removing the return value here.
2015-11-30 13:32:55 -08:00
Joe Groff
a3b6bef4e5 Runtime: Use new(InPlace) in more places to avoid unwanted null checks. 2015-11-17 14:13:48 -08:00
Slava Pestov
6057ede7d1 Runtime: Add new swift_getResilientMetadata() entry point 2015-11-16 11:11:07 -08: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
Joe Groff
f78fc20271 IRGen: Remove workarounds for rdar://problem/22467267.
Lang fixed MCJIT to support subtractor relocations in LLVM, so we can use direct relative references in JITed metadata now.

Swift SVN r31904
2015-09-11 19:30:57 +00:00
Joe Groff
081f647935 Fill in partial comment
Swift SVN r31840
2015-09-10 00:51:09 +00:00
Joe Groff
686505c498 Runtime: Rename RelativePointer types to be more descriptive.
Not every relative address makes sense to be conditionally indirect, so separate RelativeIndirectablePointer (which takes a tag bit to indicate whether the reference is directly to the object in question or to memory containing its address, such as its GOT entry) and RelativeDirectPointer. NFC.

Swift SVN r31839
2015-09-10 00:51:08 +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
Slava Pestov
f183beb576 Add missing doc comment requested by Greg Parker and a random typo, NFC
Not trying to game my patch count! :-)

Swift SVN r31257
2015-08-15 23:18:15 +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
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
db0fea590e stdlib: Use unqualified names in 'print'.
Leave the qualification off of enum cases and type names when 'print'-ing them, but keep them on 'debugPrint'. (At least, at the outermost level; since ad-hoc printing of structs and tuples uses debugPrint, we'll still get qualification at depth, which kind of sucks but needs more invasive state management in print to make possible.) Implements rdar://problem/21788604.

Swift SVN r30166
2015-07-13 21:42:11 +00:00
Joe Groff
feebd56bf4 IRGen: Reorder the extra inhabitant value witnesses so that the count and flags go first.
This nicely gathers all the layout information together in one contiguous bundle we can potentially emit independently for use in generic type layout. A step on the way to rdar://problem/19898165.

Swift SVN r30128
2015-07-12 01:06:15 +00:00
Joe Groff
16c8a3b6c0 Runtime: Fix crash when first allocation for a metadata cache is page-sized or greater.
We incorrectly tested the uninitialized "next" pointer against MAP_FAILED, instead of the real result of mmap. Fixes rdar://problem/21659505.

Swift SVN r30030
2015-07-09 18:19:59 +00:00
Joe Groff
ab1f459a40 Runtime/stdlib: Non-verbatim bridging of metatypes.
Metatypes can't directly conform to _ObjectiveCBridgeable, but we can pretend they do by making a struct with the same ABI conform and returning that conformance when we call findBridgeWitness on a metatype. Fixes rdar://problem/16238475.

Swift SVN r29999
2015-07-08 23:23:55 +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
Joe Groff
8ec59e5c11 Runtime: Implementation for generic typed boxes.
Provide new swift_{alloc,dealloc,project}Box2 entry points that allocate, project, and deallocate typed boxes using runtime-instantiated metadata. Give these a new metadata kind, so that external tools recognize the difference and can interpret the metadata appropriately.

Swift SVN r29714
2015-06-26 00:06:17 +00:00
Joe Groff
9a33c50f04 Runtime: Look through artificial subclasses when generating metatype names.
Fixes rdar://problem/20307995.

Swift SVN r29325
2015-06-05 23:37:33 +00:00
Joe Groff
9b4dc24721 Runtime: (Almost) cleanse of global constructors and destructors.
Configure the runtime to build with -Wglobal-constructors, and Lazy-fy almost everything that gets flagged. (I gave "swift_isaMask" a pass since that's almost definitely hot enough to warrant a static initialization.) Make some improvements to the Lazy wrapper, using aligned_storage to ensure that it's trivially constructed and destructed.

Swift SVN r28199
2015-05-06 04:59:56 +00:00
Joe Groff
4afbe78d59 Runtime: Entry points for dynamic multi-payload enums.
Swift SVN r27791
2015-04-27 00:35:10 +00:00
Joe Groff
0b339b9a46 IRGen: Populate nominal type descriptor metadata for enums.
Store the number of payload and no-payload cases, the case names, and a lazy case type accessor function for enums, like we do for stored properties of structs and classes. This will be useful for multi-payload runtime support, and should also be enough info to hack together a reflection implementation for enums.

For dynamic multi-payload enums to not be ridiculously inefficient, we'll need to track the size of the payload area in the enum, like we do the field offsets of generic structs and classes, so hack off a byte in the payload case count to track the offset of that field in metadata records. 16 million payloads ought to be enough for anyone, right? (and 256 words between the enum metadata's address point and the payload size offset)

Swift SVN r27789
2015-04-27 00:35:04 +00:00
Michael Gottesman
e43570f1f0 Add MetadataKind.def, a header for metaprogramming with MetadataKinds
and use it to update LeaksChecker in a robust way to handle new metadata
kinds.

I also fixed a small typo where the native ErrorType was not included in
the range of non-ObjC isa metadata kinds.

Swift SVN r27718
2015-04-25 19:04:55 +00:00
Joe Groff
00f7520888 IRGen/Runtime: Combine the separate per-convention function metadata caches into one.
We have enough flag bits on function types now to warrant stashing an extra word in the metadata key alongside the arguments and results, so add one, and pack the number of arguments, function convention, and 'throws' bit in there. This lets us merge the separate metadata caches for thick/thin/block/C functions into one, saving a bit of runtime memory, and simplifying a bunch of repetitive code in the runtime and IRGen.

This also fixes a subtle bug we had where the runtime getFunctionTypeMetadata function expected the result argument to be passed in the arguments array, but IRGen was passing it as a separate argument, which would have caused function type metadata to fail to be uniqued by result type.

Swift SVN r27651
2015-04-23 22:58:11 +00:00
Joe Groff
c4ec47ddea IRGen/Runtime: Metadata for @convention(c) function types.
For now, C&P a new metadata cache for C function pointers, like we do for blocks and thin types.

Swift SVN r27595
2015-04-22 18:06:23 +00:00
Joe Groff
fcf535d682 Runtime: Implement ObjC-free metatype dynamic casts.
Swift SVN r27414
2015-04-17 05:30:35 +00:00
Joe Groff
225a0ebd70 Runtime: Non-ObjC-interoperable version of ErrorObject implementation.
This gets the runtime building again with ObjC interop disabled, though the standard library still has issues.

Swift SVN r27326
2015-04-15 20:27:24 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Joe Groff
41f73d43ae Runtime: Try to make lazy ErrorType-to-NSError bridging thread-safe.
Atomically initialize and load the NSError bridging fields within an ErrorType box so that we do the right thing when two threads concurrently coerce the box to NSError.

Swift SVN r26996
2015-04-05 00:17:34 +00:00
Joe Pamer
980bd819a2 Propagate 'throws' information into function type metadata.
Swift SVN r26956
2015-04-03 21:45:33 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Joe Groff
ff5f87f56b Runtime: Add ExistentialTypeMetadata helpers for taking values.
Add a 'mayTakeValue' function, which returns true if we're allowed to take the value from an existential container (assuming we own the existential container value). This is true for class and opaque existential containers, but not for boxed existentials, where multiple owners may share references to the boxed value. Also add a 'deinitExistentialContainer' function to do any cleanup that must happen after the value has been consumed out of an existential container. Fix up an off-by-one indirection level in the SwiftError implementations of the existing existential container methods.

Swift SVN r26561
2015-03-25 23:02:56 +00:00