Commit Graph

366 Commits

Author SHA1 Message Date
Joe Groff
cfa9cd9a08 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-14 15:50:13 -07:00
K Staring
f11d05717e CMAKE_SDK apparenty isn't always filled when cmake runs; always use /usr/local/include for now 2016-09-13 11:18:07 +02:00
K Staring
afc95a5e2a disable handy pthread wrappers on FreeBSD since they don't compile
Things like: PthreadBarriers.swift:114:50: error: cannot convert value of type 'UnsafeMutablePointer<pthread_mutex_t>' (aka 'UnsafeMutablePointer<OpaquePointer>') to expected argument type 'UnsafeMutablePointer<pthread_mutex_t?>' (aka 'UnsafeMutablePointer<Optional<OpaquePointer>>')
on barrier.pointee.mutex . I need to do more research to understand this
2016-09-13 11:08:00 +02:00
K Staring
6428295d70 Two fixes for FreeBSD build
add /usr/local/include to include path in stdlib/public/stubs
use FreeBSD procfs path to cmdline when building for FreeBSD
2016-09-14 20:00:33 +02:00
Dmitri Gribenko
e8e8b35610 stdlib: use SipHash-1-3 for string hashing on non-ObjC platforms
Part of rdar://problem/24109692
2016-09-06 20:41:03 -07:00
Dmitri Gribenko
daa7bfc281 stdlib: add a secret key for hashing 2016-09-06 20:41:03 -07:00
Dmitri Gribenko
e4aaba9ba6 stdlib: declare functions for assertion reporting in SwiftShims instead of using @_silgen_name 2016-09-05 22:47:24 -07:00
Dmitri Gribenko
e765091217 stdlib: remove an unused Unicode data table 2016-09-02 19:42:37 -07:00
Brian Gesiak
eda6e839ac [stdlib] Use _Nonnull over __nonnull in Foundation
The `__nonnull` keyword is deprecated in favor of `_Nonnull`.
2016-08-26 16:19:46 -04:00
Greg Parker
1c58cc20ba [stdlib] Remove workaround for an old clang bug (rdar://18950072). 2016-08-24 20:14:03 -07:00
Vivian Kong
416a36278f Removing SWIFT_CC annotation in SwiftShims 2016-08-10 08:33:24 -04:00
Dmitri Gribenko
b162f60070 runtime: make _SwiftNativeNSError use the Hashable conformance, if available
If the Swift error wrapped in a _SwiftNativeNSError box conforms to
Hashable, the box now uses the Swift's conformance to Hashable.

Part of rdar://problem/27574348.
2016-08-09 00:49:20 -07:00
Michael Gottesman
06a70d3942 [cmake] Add cmake support for only applying tsan to the swift stdlib/runtime. 2016-08-03 17:53:57 -07:00
Kevin Ballard
2530957bc6 Use shims for all calls to Dispatch APIs that take blocks
This ensures that blocks that come from `DispatchWorkItem`s will
function correctly.

The only exception is __dispatch_barrier_sync() as the block passed to
that call is not `@convention(block)` so it doesn't matter.

Fixes SR-2246.
2016-08-01 17:08:14 -07:00
Dmitri Gribenko
621d3b7c66 Merge pull request #3827 from mwwa/libdispatch-data-leak
[libdispatch-data-leak] DisaptchData never calls destructor
2016-07-29 14:58:37 -07:00
Andrew Trick
ed3813a876 Linux build fixes. 2016-07-28 21:06:40 -07:00
Andrew Trick
0b75ee975e Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
2016-07-28 20:42:23 -07:00
Matt Wright
a151db06cd [libdispatch-data-leak] DisaptchData never calls destructor
* _swift_dispatch_data_create should have been marked as returning a
    retained object, otherwise the object is never fully released and
    the destructor is never executed.

    Fixes: <rdar://problem/27577958>
2016-07-28 15:00:32 -07:00
Dmitri Gribenko
6e4ab972de Merge pull request #3820 from apple/stdlib-move-reflection-function
stdlib: move a function from runtime to stubs
2016-07-28 08:59:01 -07:00
Dmitri Gribenko
c1712cbdab stdlib: AnyHashable: remove a FIXME, no action required 2016-07-28 01:35:58 -07:00
Dmitri Gribenko
2d2c76f6ec stdlib: AnyHashable tests: finish tests for CF types 2016-07-28 01:35:58 -07:00
Dmitri Gribenko
561ac46679 stdlib: move a function from runtime to stubs
This function is not needed in the runtime.
2016-07-28 01:19:31 -07:00
Dmitri Gribenko
b0481b14f5 AnyHashable: add a runtime cache to speed up initialization
When initializing an AnyHashable instance we need to find a type that
introduces the Hashable conformance.  This commit adds a cache to
remember the result of this lookup.
2016-07-27 01:14:01 -07:00
Dmitri Gribenko
53c424409d stdlib: add AnyHashable
Implements SE-0131 "Add AnyHashable to the standard library".
2016-07-26 03:10:52 -07:00
swift-ci
395e967875 Merge pull request #3739 from practicalswift/normalize-headers 2016-07-25 04:55:55 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
practicalswift
a87d170b81 [gardening] Improve consistency in header formatting. 2016-07-24 21:36:25 +02:00
Matt Wright
56a579763f [libdispatch-data-fixes] Appending UnsafeBufferPointers to data is unsafe
* The buffer-pointer based init methods were passing the dispatch
    data default destructor in such a way that the
    @convention(block)-ness was lost. This leads to a thunk being passed
    to dispatch instead of NULL. Subsequently, dispatch would reference
    rather than copy the provided data.

    Fixes:
	SR-2050 (<rdar://problem/27293973>)
2016-07-20 16:46:31 -07:00
Tony Parker
fe932663a8 Merge pull request #3598 from parkera/se86_rename_process
Rename Process to CommandLine
2016-07-19 13:45:23 -07:00
Tony Parker
f65c1390cb Rename Process to CommandLine
Rename Process to CommandLine [SE-0086].
2016-07-18 17:02:02 -07:00
Matt Wright
8ac413a0b5 [libdispatch] Post-beta API changes and bug fixes
* Fix DispatchSourceSignal initialisation such that it no longer
    registers for the wrong source type.

    * Remove (group:) option from DispatchWorkItem, introduce group
    options to `.async` methods that accept DispatchWorkItem.

    * Rename `DispatchSourceType` to `DispatchSourceProtocol`

    * Rework DispatchQueue attributes and flags into a less confusing
    approach.

    * Fixes:

	SR-1817, SR-1771, SR-1770, SR-1769

	<rdar://problem/26725156> <rdar://problem/26873917>
	<rdar://problem/26918843> <rdar://problem/26810149>
	<rdar://problem/27117023> <rdar://problem/27121422>
	<rdar://problem/27236887> <rdar://problem/27337555>
2016-07-18 13:22:23 -07:00
Dmitri Gribenko
61fcdf5fcf Merge pull request #3527 from practicalswift/gardening-20160715
[gardening] Header fixes. Don't compare to false.
2016-07-15 13:12:17 -07:00
Stephen Canon
5564f94867 Intrinsics instead of shims (#3530)
* Use intrinsics instead of Libc stubs where we can.

This replaces most of the stubs used for basic operations on these
types with intrinsics, eliminating a level of indirection for fma,
ceil, floor, round, trunc.

square root and remainder still require stubs because there is no
remainder intrinsic and we can't use the square root intrinsic because
its behavior is undefined for negative inputs.  A previous commit
apparently either the compiler annotates static inline stubs wrong
or the SIL verifier can't handle them, so that change was backed out.

* Explicitly CHECK-NOT @llvm.sqrt instead of looking for @sqrt.
2016-07-15 12:08:25 -05:00
Andrew Trick
b1bf920a36 Revert "Use builtins instead of shims in FloatingPointTypes. (#3454)"
This reverts commit 999885fc8d.

This breaks the stdlib serialization tests:

Assertion failed: (!hasSharedVisibility(F->getLinkage()) && "external declaration of SILFunction with shared visibility is not " "allowed"), function visitSILFunction, file /s/sptr/swift/lib/SIL/SILVerifier.cpp, line 3267.
2016-07-15 08:58:53 -07:00
practicalswift
967a34e825 [gardening] Use consistent copyright notice (2014 - 2016). 2016-07-15 10:26:22 +02:00
Saleem Abdulrasool
5137f8beec stdlib: repair windows build
When building for a pure windows environment, we build against a newer CRT which
does not provide direct access to __argc, __argv.  They are hidden behind
macros which use a function call.  Use the header (stdlib) to get access to
these rather than declaring them extern.  This also makes the swift runtime more
portable across various Windows environments.

From stdlib.h in ucrt 10.0.10586.0:
  #ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
    extern int __argc;
    extern char** __argv;
  #else
    #define __argc (*__p___argc())
    #define __argv (*__p___argv())
  #endif

The indirection is particularly nice on COFF where all module external variables
are indirectly addressed.
2016-07-14 19:48:04 -07:00
Robert Widmann
97c6598e9d Merge pull request #3507 from compnerd/windows-msvc
build: support cross-compiling to windows
2016-07-14 16:54:15 -07:00
Stephen Canon
999885fc8d Use builtins instead of shims in FloatingPointTypes. (#3454)
* Map .round, .squareRoot, .addProduct, and .formRemainder onto builtins instead of shims where possible.
2016-07-14 17:50:30 -04:00
Robert Widmann
dc88e51321 Nuke entry-point-based process args
Provides a new fallback for Process arguments for those instances where we do
not own main (e.g. Frameworks, Objective-C owns main.m or main.c, etc.). This
includes a number of platform-specific specializations of argument grabbing
logic and a new thread-safe interface to Process.unsafeArgv.

main()  | _NSGetArgc/_NSGetArgv    | /proc/self/cmdline     | __argc/__argv
--------|--------------------------|------------------------|---------------
Scripts | OS X, iOS, tvOS, watchOS | Linux, FreeBSD, Cygwin | Windows

For interpreted Swift where we must filter out the arguments we now do so by
loading the standard library and calling into new SPI to override the arguments
that would have been grabbed by the runtime. This implementation completely
subsumes the use of the entry point  '_stdlib_didEnterMain' and it will be
removed in a future commit.
2016-07-14 01:06:19 -07:00
Saleem Abdulrasool
5e170ebcb5 build: support cross-compiling to windows 2016-07-13 21:37:04 -07:00
Stephen Canon
9c08fbf4ed SE-0113 + residual SE-0067 work (#3443)
Implemented SE-0113 + residual SE-0067 operations.

- adds `rounded` and `round` to `FloatingPoint`, from SE-0113.
- adds `remainder`, `squareRoot`, and `addingProduct`, from SE-0067.
- adds basic test coverage for all of the above.
- provides a default implementation of `nextDown` on `FloatingPoint`.
2016-07-11 09:38:25 -04:00
Joe Groff
789930b335 Merge pull request #3360 from jckarter/no-static-locals
StdlibStubs: Favor swift::Lazy over static local initialization.
2016-07-07 13:02:13 -07:00
Joe Groff
ba11a1c121 StdlibStubs: Favor swift::Lazy over static local initialization.
To minimize code size and VM live set, we try to funnel all one-time initialization through swift_once instead of mixing it with the C++ runtime's support for lazy static initialization.
2016-07-07 10:33:59 -07:00
Saleem Abdulrasool
3d174c372a stdlib: be more DLL friendly on Windows
When the standard library is built dynamically on COFF targets, the public
interfaces must be decorated in order to generate a proper DLL which can be
confused by the dependent libraries.  When the exported interface is used, it
must be indirectly addressed.  This can be done manually in code or the MS
extension of `__declspec(dllimport)` may be used to indicate to the compiler
that this symbol be addressed indirectly.  This permits building more pieces of
the standard library dynamically on Windows.
2016-07-06 17:51:31 -07:00
Dmitri Gribenko
1562c101f3 stdlib stubs: internalize private data 2016-07-02 02:23:39 -07:00
Saleem Abdulrasool
7888f1e69e stubs: do not expose internals
Remove the export decoration on implementations.  The details are indirected
through a pointer to the data.  There is no need to make the data itself
visible.  This was detected during work to support Windows/MSVCRT.
2016-07-01 22:55:45 -07:00
Dmitri Gribenko
ad559f9812 Merge pull request #3205 from compnerd/foreign-icus
build: support having more than one ICU in use
2016-06-28 23:23:01 -07:00
Saleem Abdulrasool
b5893cdfe0 stubs: export symbols properly
These two symbols were not correctly scoped, placing them inside of the swift
namespace.  This would change the linkage names and fail to link as a result.
Scope one as the header properly places it in an extern "C" block.  The gyb file
is unable to find the desired runtime header, so explicitly mark the exported
symbol as being exposed with C linkage.
2016-06-25 12:40:40 -07:00
Saleem Abdulrasool
4d2593fb95 build: support having more than one ICU in use
This allows us to cross-compile the standard library to foreign targets on a
single host.  The ICU dependencies can be specified on the command line on a
per-target basis.  If one is not specified, we fall back to the default search
path and use that for the other targets.

Special thanks to Dimitri Gribenko for the various hints in getting this wired
up.
2016-06-25 12:35:12 -07:00
Saleem Abdulrasool
e3c2c863d1 stdlib: define WIN32_LEAN_AND_MEAN and NOMINMAX
`WIN32_LEAN_AND_MEAN` prevents "rarely-used" headers from being pulled in.  This
significantly reduced preprocessor pressure, speeding up compile.  It also
reduces the amount of cruft pulled in by the Windows.h.

`NOMINMAX` ensures that the `min` and `max` macros are not defined.  These
macros collide with the use of `min` and `max` from C++ in certain cases: e.g.
`std::limits<T>`.
2016-06-16 07:34:17 -07:00