Commit Graph

112 Commits

Author SHA1 Message Date
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
Bob Wilson
7339cc5da3 Remove the ZExt attribute for the MakeBoxUnique runtime function.
The IR verifier in recent versions of LLVM (used with the master-next branch)
complains about a ZExt attribute used with a non-integer type, and it does
not make sense to zero-extend the return value of MakeBoxUnique, which is
a pair of pointers.
2017-05-08 07:36:24 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
John McCall
6c16cfaa14 Implement a basic dynamic-enforcement runtime and teach IRGen to use it. 2017-04-18 11:23:43 -04:00
Slava Pestov
a5a40c7fc7 Runtime/IRGen: Preliminary plumbing for subclass existentials 2017-04-13 21:29:57 -07:00
Joe Groff
d42f2049f7 KeyPaths: Implement in-place instantiation of invariant key paths.
For key paths without generic or subscript parameterization, we can turn the compiler-generated key path pattern into a global object in-place.
2017-04-05 08:46:45 -07:00
Joe Groff
f929c29bdf IRGen: Lower keypath instructions to patterns for the runtime to instantiate. 2017-04-04 11:31:15 -07:00
Doug Gregor
5b3fe49cd0 [SE-0160] Log uses of @objc thunks emitted due to deprecated @objc inference.
Introduce a new runtime entry point,
`swift_objc_swift3ImplicitObjCEntrypoint`, which is called from any
Objective-C method that was generated due to `@objc` inference rules
that were removed by SE-0160. Aside from being a central place where
users can set a breakpoint to catch when this occurs, this operation
provides logging capabilities that can be enabled by setting the
environment variable SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT:

  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=0 (default): do not log
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=1: log failed messages
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2: log failed messages with
  backtrace
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=3: log failed messages with
  backtrace and abort the process.

The log messages look something like:

    ***Swift runtime: entrypoint -[t.MyClass foo] generated by
       implicit @objc inference is deprecated and will be removed in
       Swift 4
2017-03-31 21:22:16 -07:00
Arnold Schwaighofer
67e3d27fd9 Copy-on-write existential performance work (#8369)
* IRGen: Change c-o-w existential implementation functions

* initialzeBufferWith(Copy|Take)OfBuffer value witness implementation for cow existentials

Implement and use initialzeBufferWith(Copy|Take)OfBuffer value witnesses for
copy-on-write existentials.

Before we used a free standing function but the overhead of doing so was
noticable (~20-30%) on micro benchmarks.

* IRGen: Use common getCopyOutOfLineBoxPointerFunction

* Add a runtime function to conditionally make a box unique

* Fix compilation of HeapObject.cpp on i386

* Fix IRGen test case

* Fix test case for i386
2017-03-27 20:51:02 -07:00
Devin Coughlin
6ac36df1e7 SIL: Add SIL builtin for Thread Sanitizer inout accesses
...and IRGen it into a call to __tsan_write1 in compiler-rt. This is
preparatory work for a later patch that will add an experimental
option to treat Swift inout accesses as TSan writes.
2017-03-06 19:13:50 -08:00
Mikio Takeuchi
4f68ccf86e Add swift_nonatomic_unowned(Retain|Release)_n 2017-02-27 12:25:58 +09:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
2e0cb9c0a2 Runtime: getDynamicType can't drill into existentials when producing a concrete metatype.
For a value of an opaque generic type `<T> x: T`, the language currently defines `type(of: x)` and `T.self` as both producing a type `T.Type`, and the result of substituting an existential type by `T == P` gives `P.Protocol`, so the `type(of:)` operation on `x` can only give the concrete protocol metatype when `x` is an existential in this case. The optimizer understood this rule, but the runtime did not, causing SR-3304.
2016-12-19 11:03:52 -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
gregomni
b634aedb3c Emit calls to objc_allocWithZone(cls) when allocating obj-c objects. 2016-10-07 12:17:53 -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
practicalswift
66183cdbf7 [gardening] Fix unjustified spacing 2016-04-07 10:10:24 +02:00
Doug Gregor
7d1a2e8339 Reinstate "Implement support for Clang's objc_runtime_visible attribute."
When a Clang-defined Objective-C class has the objc_runtime_visible
attribute, use objc_lookUpClass to get the Objective-C class object
rather than referencing the symbol directly. Also, ban subclassing of
Objective-C-runtime-visible classes as well as @objc on members of
extensions of such classes.

As a drive-by needed for this test, make
ClassDecl::getObjCRuntimeName() respect the Clang objc_runtime_name
attribute.

Fixes rdar://problem/25494454.

Fix an i32 vs. 64 issue in the IR matching for the IR generation test.

This reverts commit 09973e6956.
2016-04-02 20:10:32 -07:00
Ted Kremenek
09973e6956 Revert "Implement support for Clang's objc_runtime_visible attribute."
This reverts commit 2c1f19a547.

This appears to be breaking all the iOS bots.
2016-04-02 07:33:14 -07:00
Doug Gregor
2c1f19a547 Implement support for Clang's objc_runtime_visible attribute.
When a Clang-defined Objective-C class has the objc_runtime_visible
attribute, use objc_lookUpClass to get the Objective-C class object
rather than referencing the symbol directly. Also, ban subclassing of
Objective-C-runtime-visible classes as well as @objc on members of
extensions of such classes.

As a drive-by needed for this test, make
ClassDecl::getObjCRuntimeName() respect the Clang objc_runtime_name
attribute.

Fixes rdar://problem/25494454.
2016-04-01 23:07:21 -07:00
Roman Levenstein
5d22a59e01 Provide non-atomic versions of many reference counting operations.
Provide the same guarantees regrading the barriers as the atomic versions.
2016-03-30 16:43:05 -07:00