Commit Graph

283 Commits

Author SHA1 Message Date
Doug Gregor
adf38f5486 [Runtime] Pack element count into the flags of swift_getTupleTypeMetadata.
Reduces the # of parameters we need to pass to this runtime API.
2018-01-11 10:06:57 -08:00
swift-ci
ea489cead0 Merge pull request #13844 from DougGregor/runtime-protocol-name-lookup 2018-01-09 23:06:09 -08:00
Doug Gregor
0f4963dba8 [IRGen] Put references to all emitted protocols into a special section.
Introduce a new section that contains (relative) references to all of the
Swift protocol descriptors emitted into this module. We'll use this to
find protocol descriptors by name.
2018-01-09 16:10:18 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Doug Gregor
5853cf3c87 [Runtime] Teach swift_getTupleTypeMetadata() to copy "labels" string.
Introduce a flags parameter to swift_getTupleTypeMetadata(). Add a flag
stating when the "labels" parameter points into nonconstant memory, in
which case we need to make a copy of the string before adding an entry
into the concurrent map.
2018-01-05 23:11:21 -08:00
Pavel Yaskevich
0f071848f3 [Runtime/ABI] NFC: Refactor function type metadata generation 2018-01-05 13:38:20 -08:00
Pavel Yaskevich
86de71ee6d [Runtime/ABI] Remove swift_getFunctionTypeMetadata{1-3}WithFlags
Since it's not very common to use such ABI endpoints, let's remove
them and use the most general one `swift_getFunctionTypeMetadata`
instead when function parameters have flags attached to them.

Resolves: rdar://problem/36278686
2018-01-04 16:32:51 -08:00
Pavel Yaskevich
8409cdb8a2 [Runtime/ABI] Add swift_getFunctionTypeMetadata0 function
This ABI endpoint is used to retrieve metadata about functions
without parameters. Which is very common use-case and it
makes sense to save some code size for that.
2018-01-04 16:32:51 -08:00
John McCall
9bbbe2c418 Update the metadata-initialization ABI:
- Create the value witness table as a separate global object instead
  of concatenating it to the metadata pattern.

- Always pass the metadata to the runtime and let the runtime handle
  instantiating or modifying the value witness table.

- Pass the right layout algorithm version to the runtime; currently
  this is always "Swift 5".

- Create a runtime function to instantiate single-case enums.

Among other things, this makes the copying of the VWT, and any
modifications of it, explicit and in the runtime, which is more
future-proof.
2017-12-21 00:26:37 -05:00
Erik Eckstein
48d49a4cc2 Fix the IR attributes of swift_getObjectType.
It's not readnone, because it reads the metatype from an object.
Readnone would let the llvm ARC optimizer reschedule the call with a release-call for the object.

fixes SR-6560.
2017-12-11 18:16:46 -08:00
Slava Pestov
ffabf60118 IRGen: Hollow out generic class templates
Don't emit placeholders for field offsets and vtable entries,
since they were always null. Instead, calculate the final size
of class metadata at runtime using the size of the superclass
metadata and the number of immediate members, and only copy
this prefix from the template to the instantiated metadata,
zero-filling the rest.

For this to work with non-generic resilient classes and
non-generic subclasses of generic classes, we need a new
runtime entry point to relocate non-generic class metadata,
calculating its size at runtime using the same strategy.
2017-12-08 13:50:56 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
Slava Pestov
0fa7440e51 IRGen/Runtime: Remove old class metadata relocation mechanism 2017-12-07 14:21:58 -08:00
Pavel Yaskevich
622cc1c64a [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
e9d4a5304e [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
f5ed1a8759 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
9b3739b91d [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
659c1bc2e0 Revert "[IRGen] Add parameter flags to function type metadata"
This reverts commit b33a6c7cdf.
2017-11-07 00:24:24 -08:00
Pavel Yaskevich
37185390f8 Revert "[IRGen] Switch function metdata to use Metdata * for parameter references"
This reverts commit 99f188e311.
2017-11-07 00:24:23 -08:00
Pavel Yaskevich
72bf180d0f Revert "[IRGen] Fix function metadata endpoints to use separate parameter/flags arguments"
This reverts commit 728d2a4c2f.
2017-11-07 00:24:22 -08:00
Pavel Yaskevich
aa89c4f4a8 Revert "[ABI/IRGen] Add custom function parameter flags representation for metadata use"
This reverts commit f6b0d2d2cf.
2017-11-07 00:24:21 -08:00
Pavel Yaskevich
e23a6f1359 Merge pull request #12500 from xedin/fn-metadata-changes
[IRGen] Improvements to function type metadata
2017-11-06 19:50:19 -08:00
Joe Groff
f8aef0a7e3 Merge pull request #12732 from jckarter/objc-class-metadata-unwrapping
[WIP] Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
2017-11-06 11:32:15 -08:00
Pavel Yaskevich
f6b0d2d2cf [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
728d2a4c2f [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-06 11:16:46 -08:00
Pavel Yaskevich
99f188e311 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
b33a6c7cdf [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-06 11:16:46 -08:00
Joe Groff
95d251051b Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
This is a small code size win, and also gives us some abstraction so that future cooperative ObjC compilers/runtimes might be able to interoperate ObjC class objects with Swift type metadata efficiently than they currently are in the fragile Swift runtime.

While I'm here, I also noticed that swift_getObjCClassMetadata was unnecessarily getting exposed in non-ObjC-interop runtime builds, so I fixed that as well.
2017-11-03 10:18:38 -07:00
Arnold Schwaighofer
e7dbf7cc4d runtime: Add and use swift_deallocUninitializedObject for uninitialized objects
This is different from swift_deallocObject in that it applies to objects
at +1 while swift_deallocObject actually only applies to objects whose
state is deiniting (swift_release was called).
2017-11-03 09:44:07 -07:00
Arnold Schwaighofer
e0646d4321 IRGen: Use swiftcc for swift_unexpectedError and swift_errorInMain
It is a runtime function defined in swift. This currently did not have
ABI implications because the ABI happened to be compatible but ...

SR-6235
rdar://problem/35222489
2017-10-27 10:56:44 -07:00
Joe Groff
9af6cd8537 Merge pull request #12009 from jckarter/revive-type-layout-verifier
IRGen: Un-bit-rot type layout verifier.
2017-09-19 17:55:37 -07:00
Joe Groff
e1a05d768e IRGen: Un-bit-rot type layout verifier. 2017-09-19 14:45:44 -07:00
Arnold Schwaighofer
3ae6d7cb4d runtime/IRGen: return the argument from swift_retain family of functions
On architectures where the calling convention uses the same argument register as
return register this allows the argument register to be live through the calls.

We use LLVM's 'returned' attribute on the parameter to facilitate this.

We used to perform this optimization via an optimization pass. This was ripped
out some time ago around commit 955e4ed652.
By using LLVM's 'returned' attribute on swift_*retain, we get the same
optimization from the LLVM backend.
2017-09-19 07:16:37 -07:00
Arnold Schwaighofer
d008e37b13 Merge pull request #11950 from aschwaighofer/runtime_return_dest_2
runtime: Also return the destination argument of the unknownWeak- and…
2017-09-15 14:54:44 -07:00
Arnold Schwaighofer
90f51f2599 runtime: Also return the destination argument of the unknownWeak- and unknownUnownedInit/Assign functions
rdar://18172130
2017-09-15 11:28:27 -07:00
Joe Groff
b7566dacdb IRGen: Lowering for key paths with indices. 2017-09-15 10:24:28 -07:00
Arnold Schwaighofer
30d1cada7a Fix type name in a comment 2017-09-14 08:05:40 -07:00
Arnold Schwaighofer
a39c831493 Add llvm:Attribute::Returned to the weak runtime functions
rdar://18172130
2017-09-13 14:10:28 -07:00
Arnold Schwaighofer
efe22fc9e6 runtime: return the destination address in swift_weakInit/Assign/Copy/Take operations
rdar://18172130
2017-09-13 14:10:21 -07:00
Arnold Schwaighofer
8a85a9efd5 Use array copy runtime implementation instead of the array value witnesses
And add builtins for the added runtime functions (assign-take, assign-copy).

rdar://27412867
SR-3376
2017-09-12 12:43:26 -07:00
Erik Eckstein
f4f1298286 runtime: add a runtime function to initialize the header of a statically allocated object 2017-08-23 09:15:01 -07:00
Slava Pestov
9555a593ec IRGen: Refactor swift_initClassMetadata_UniversalStrategy() to use TypeLayout
Both swift_init{Struct,Class}Metadata_UniversalStrategy() wish to
avoid instantiating type metadata for field types if possible.

The struct version took an array of the more general TypeLayout objects,
whereas the class version was implemented earlier and took an array
of size/alignment pairs.

Since we can emit static TypeLayouts for all fixed-size types,
the class version can use the more general TypeLayout type also.
2017-08-09 01:07:09 -07:00
Arnold Schwaighofer
ee17bab396 IRGen: Enable usage of attributes from RuntimeFunctions.def
* Add some ZExt function attributes on functions returning bool
* swift_dynamicCast is not readonly as it writes to the 'dest' buffer
* Fix tail_alloc.sil test

rdar://20802330
2017-07-26 14:39:28 -07:00
Devin Coughlin
c971816c69 [TSan] Change TSan inout accesses to use __tsan_external_write callback (#11032)
Adopt the  __tsan_external_write compiler-rt callbacks when IRGen'ing
the TSan inout access builtin.

rdar://problem/32260994
rdar://problem/33461691
2017-07-24 00:10:08 -07:00
Arnold Schwaighofer
48e889b51b IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums (#10326)
* IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums

We map nil to the .None case of Optional. Instead use a singleton object.

SR-5148
rdar://32618580
2017-06-17 09:33:41 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Joe Groff
80c6671c39 Runtime: Only complain about a deprecated ObjC entry point once.
We only need to alert the user once. rdar://problem/32229417
2017-05-17 12:05:53 -07:00
Joe Groff
c8a7a442ae Runtime: Include source location information in log messages about deprecated implicit Objective-C entry points.
Make it easier for migration by pinpointing exactly where to insert @objc to keep the entry points in Swift 4 mode. rdar://problem/32230003
2017-05-16 19:02:47 -07:00
John McCall
e01c31a17c Remember a PC in the exclusivity-tracking set and report it during failures. 2017-05-10 14:44:56 -04: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