Commit Graph

658 Commits

Author SHA1 Message Date
Mike Ash
0a6ea9733c Merge pull request #16281 from mikeash/warning-fix-libcshims-metadata
[Runtime] Fix warnings for inconsistent nullability annotation on _stdlib_getEnviron.
2018-05-10 16:13:02 -04:00
Mike Ash
022253e1e5 [Runtime] Fix warnings for inconsistent nullability annotation on _stdlib_getEnviron.
rdar://problem/39739801
2018-05-09 13:41:58 -04:00
Ben Rimmington
b65d0c1d11 Consolidate _stdlib_random functions (#2)
* Use the `__has_include` and `GRND_RANDOM` macros

* Use `getentropy` instead of `getrandom`

* Use `std::min` from the <algorithm> header

* Move `#if` out of the `_stdlib_random` function

* Use `getrandom` with "/dev/urandom" fallback

* Use `#pragma comment` to import "Bcrypt.lib"

* <https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp>
* <https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions>

* Use "/dev/urandom" instead of `SecRandomCopyBytes`

* Use `swift::StaticMutex` for shared "/dev/urandom"

* Add `getrandom_available`; use `O_CLOEXEC` flag

Add platform impl docs

Update copyrights

Fix docs

Add _stdlib_random test

Update _stdlib_random test

Add missing &

Notice about _stdlib_random

Fix docs

Guard on upperBound = 0

Test full range of 8 bit integers

Remove some gyb

Clean up integerRangeTest

Remove FixedWidthInteger constraint

Use arc4random universally

Fix randomElement

Constrain shuffle to RandomAccessCollection

warning instead of error

Move Apple's implementation

Fix failing test on 32 bit systems
2018-05-09 00:21:44 -05:00
Azoy
d23d219e95 Add shims for stdlib random
Initial random api

Use C syscall for I/O

1. Fixed an issue where integers would would result in an infinite loop if they were unsigned, or signed integers always returning negative numbers.
2. Fixed an issue with Bool initialization

Add shuffle functions

Add documentation to Random API

Fix a few typos within the documentation

Fixes more typos

Also states that the range for floating points is from 0 to 1 inclusive

Update API to reflect mailing list discussions

Remove unnecessary import

Make sure not to return upperBound on Range

Use SecRandomCopyBytes on older macOS

Update API to match mailing list discussion, add tests

Added pick(_:) to collection
Added random(in:using:) to Randomizable
Added tests

Fix typo in Randomizable documentation

Rename pick to sampling

Move sampling below random

Update docs

Use new Libc naming

Fix Random.swift with new Libc naming

Remove sampling

gybify signed integer creation

Make FloatingPoint.random exclusive

Refactor {Closed}Range.random

Fix FloatingPoint initialization

Precondition getting a random number from range

Fix some doc typos

Make .random a function

Update API to reflect discussion

Make .random a function
Remove .random() in favor of .random(in:) for all numeric types

Fix compile errors

Clean up _stdlib_random

Cleanup around API

Remove `.random()` requirement from `Collection`

Use generators

Optimize shuffle()

Thread safety for /dev/urandom

Remove {Closed}Range<BinaryFloatingPoint>.random()

Add Collection random requirement

Refactor _stdlib_random

Remove whitespace changes

Clean linux shim

Add shuffle and more tests

Provide finishing tests and suggestions

Remove refs to Countable ranges

Revert to checking if T is > UInt64
2018-05-04 21:02:57 -05:00
Jordan Rose
03a30782e0 Foundation overlay: include <pthread.h> (#15911)
Found by -Wsystem-headers. Apparently nothing that was already included
was actually defining 'pthread_main_np'.
2018-04-12 18:09:26 -07:00
Philippe Hausler
57d0ea8013 [Foundation] Guard Data access to NSData._isCompact under availability guards 2018-04-12 09:53:34 -07:00
Davide Italiano
6535d8cec8 [DebuggerSupport] Expose a way to query the reference counts.
lldb will use it to reimplement `language swift refcount <obj>`
which is currently not working. Asking the compiler allows us
to avoid maintinaing a bunch of information in the debugger which
are likely to change and break.

<rdar://problem/30538363>
2018-04-06 13:12:53 -07:00
Tony Allevato
fb9f7ecca1 Merge branch 'master' into unicode-properties 2018-03-31 09:54:18 -07:00
Tony Allevato
354f2ad66e [stdlib] Add "numeric{Type,Value}" to Unicode.Scalar.Properties 2018-03-27 21:07:27 -07:00
Jordan Rose
7297d76cc3 [CMake] Stop symlinking build/llvm/lib into build/swift/lib/swift/ (#15458)
We started doing this to test out libFuzzer, but that's now available
through the usual sanitizer interface, and it turns out this symlink
is actually harmful because it causes the llvm/lib/ folder to get
copied into the built LLDB framework, and it contains all sorts of
garbage intermediate files (static libraries and such). On my machine
it was an extra 9GB for no reason.

Anyway, we're not using this anymore, so take it out. I suggest
clearing out build/lib/swift/ after this change too.
2018-03-26 09:35:22 -07:00
Tony Allevato
e7fa49984a [stdlib] Add "{lower,title,upper}caseMapping" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00
Tony Allevato
9858d4edfb [stdlib] Add "name", "nameAlias" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00
Tony Allevato
af798fa972 [stdlib] Add "generalCategory" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00
Tony Allevato
d6ee54f4b5 [stdlib] Add "age" to Unicode.Scalar.Properties 2018-03-26 06:38:54 -07:00
Mike Ash
ed4e3b9bf3 [Runtime] Fix up the URC overflow test and support code after merging the latest master.
rdar://problem/33765960
2018-03-21 15:34:11 -07:00
Mike Ash
f2b89d1b94 Merge branch 'master' into fix-urc-overflow-to-side-table-in-deinit 2018-03-21 15:32:01 -07:00
Lance Parker
cbf157f924 [stdlib]Unify String hashing implementation (#14921)
* Add partial range subscripts to _UnmanagedOpaqueString

* Use SipHash13+_NormalizedCodeUnitIterator for String hashes on all platforms

* Remove unecessary collation algorithm shims

* Pass the buffer to the SipHasher for ASCII

* Hash the ascii parts of UTF16 strings the same way we hash pure ascii strings

* De-dupe some code that can be shared between _UnmanagedOpaqueString and _UnmanagedString<UInt16>

* ASCII strings now hash consistently for in hashASCII() and hashUTF16()

* Fix zalgo comparison regression

* Use hasher

* Fix crash when appending to an empty _FixedArray

* Compact ASCII characters into a single UInt64 for hashing

* String: Switch to _hash(into:)-based hashing

This should speed up String hashing quite a bit, as doing it through hashValue involves two rounds of SipHash nested in each other.

* Remove obsolete workaround for ARC traffic

* Ditch _FixedArray<UInt8> in favor of _UIntBuffer<UInt64, UInt8>

* Bad rebase remnants

* Fix failing benchmarks

* michael's feedback

* clarify the comment about nul-terminated string hashes
2018-03-17 22:13:37 -07:00
Stephen Canon
ddf70fa199 Cleanup tgmath wrappers. (#15304)
* Cleanup tgmath wrappers.

- Remove special-case gyb logic for lgamma on Darwin; the symbols we need are always present, even if not visible in the headers, so we only need a prototype.
- Add some deprecations for symbols that have direct stdlib analogues.
- Make some operations generic on [Binary]FloatingPoint, where they can map to the protocols instead of calling libm.
- Mark ldexp(Float/Double) renamed to scalbn; for binary formats these are identical functions, and we don't really want to use these names for hypothetical future Decimal support, as they're not Swifty.
2018-03-17 10:32:13 -04:00
Karoy Lorentey
2cf0e4daa1 [runtime] Collapse hashing parameters into a single struct
Having a single initializer function lets us not set a randomized seed in deterministic mode, slightly simplifying the stdlib.

Set related stdlib properties to be always inlined.
2018-03-14 17:44:13 +00:00
Michael Ilseman
b572bfe2f4 [stubs] Add CFString*Bytes stubs, drop some dead ones.
NFC, just stubs and plumbing.
2018-03-13 15:32:20 -07:00
Karoy Lorentey
879e4f9ce5 [runtime][stdlib] Better support for random hash seeds
- Hash seed randomization can now be disabled by defining the SWIFT_DETERMINISTIC_HASHING environment value with a value of "1".
- The random hash seed is now generated using arc4random, where available. On platforms where it isn't, don't construct std::random_device twice.
- _Hasher._secretKey is renamed _Hashing._seed, with no setter.
- _Hasher._isDeterministic is a new property exposing whether we're running with non-random hashes. (Set/Dictionary will need this information to decide if they're allowed to use per-instance seeding.)
2018-03-13 16:15:09 +00:00
Stephen Canon
f8a9e56957 Importer support for float80 (#14971)
* First pass at implementing support for mapping between long double and Float80.

* Only define CLongDouble on platforms where I know what it is.

* remove some hacks that are no longer necessary.
2018-03-07 16:49:21 -05:00
Saleem Abdulrasool
1ccb740676 shims: handle Windows aarch64 as well
Define the `__swift_ssize_t` for Windows AArch64 as well.
2018-02-28 16:15:21 -08:00
Joe Groff
be19535802 Merge pull request #14831 from jckarter/protected-runtime-visibility
Visibility fixes for ELF.
2018-02-26 13:26:14 -08:00
swift-ci
ac54feca49 Merge pull request #14734 from compnerd/icu-signature 2018-02-26 12:36:01 -08:00
Joe Groff
8656807b90 Visibility fixes for ELF.
- `_swiftEmpty{Array,Dictionary,Set}Storage` should be marked with `SWIFT_RUNTIME_STDLIB_INTERFACE` so that they can be linked from the standard library implementation.
- Runtime export symbols ought to have protected visibility.
2018-02-26 10:39:10 -08:00
Saleem Abdulrasool
73c04d1dd9 stubs: match ICU signature for unorm2_normalize (NFC)
Adjust the signature to match the ICU declaration for
`unorm2_normalize`.  This was adjusted to allow building against ICU
59.1.  The shim type definition for the UChar ensures that the signature
is correct on all the targets.  NFC.
2018-02-25 22:48:27 -08:00
Joe Groff
4c2dde56a0 IRGen: Lower external key path components.
The key path pattern needs to include a reference to the external descriptor, along with hooks for lowering its type arguments and indices, if any. The runtime will need to instantiate and interpolate the external component when the key path object is instantiated.

While we're here, let's also reserve some more component header bytes for future expansion, since this is an ABI we're going to be living with for a while.
2018-02-23 19:03:15 -08:00
Jordan Rose
6a1161bd93 Tweak _SwiftDispatchOverlayShims for use by swift-corelibs-libdispatch. (#6033) 2018-02-22 09:31:16 -08:00
Lance Parker
0661de22a2 [stdlib]Un-revert string comparison (#14694)
Restore (un-revert) sting comparison, with fixes

More exhaustive testing of opaque strings, which consistently reproduces prior sporadic failure. Shims fixups. Some test tweaking.
2018-02-18 10:50:33 -08:00
Saleem Abdulrasool
cd58f5c1c9 Shims: adjust the ICU interface
The default ICU build will change the underlying type of the UChar type,
with C++ using the builtin `char16_t` rather than `unsigned short`.
This adjusts the interface to account for that.  I've verified across
Apple's implementation that they always use the `unsigned short` as the
type for `UChar`.  Since we cannot guarantee that the ICU interfaces are
built the same way on all targets, especially when using the underlying
system's ICU.

Adjust the stubs implementation declaration to match the ICU header's
declaration.
2018-02-15 21:11:06 -08:00
Lance Parker
abe6a6d177 Revert string comparison (#14657) 2018-02-15 14:37:43 -08:00
swift-ci
8045963f34 Merge pull request #14636 from gonzalolarralde/libcshims-android-swift-mode-t 2018-02-14 17:33:41 -08:00
Lance Parker
db2de58dd6 Remove unecessary unicode collation algorithm shims 2018-02-14 15:44:11 -08:00
Lance Parker
32d21c489f Add unicode normalization shims 2018-02-14 15:44:11 -08:00
Gonzalo Larralde
fb08fb81a5 Adding the correct value for __swift_mode_t in Android.
As defined(__linux__) also matches, this never gets to the final else case.
2018-02-14 18:27:38 -03:00
Saleem Abdulrasool
48e208ecfa Shims: match the declared type for CF interfaces
`CFHashBytes` takes a `CFIndex`, not a `long`.  Because this type is
declared differently on different platforms, desugaring the type can
cause mismatches.  Make the shims match the real declarations in
swift-corelibs-foundation.
2018-02-08 14:28:29 -08:00
Jordan Rose
54a359731d [SDK] Remove Foundation's last use of _silgen_name (#14484)
No intended functionality change.
2018-02-08 11:42:40 -08:00
Michael Gottesman
68e2e708d0 [runtime] Add a dumping method to HeapObject when asserts are enabled.
Given any heap object, this method dumps:

* The pointer address of the heap object.
* The pointer address of the heap metadata of the object.
* The strong reference count.
* The unowned reference count.
* The weak reference count.
* Whether or not the value is in the deinit state.
* Whether or not the heap object uses swift_retain or objc_retain.
* The address of the object's side table if one exists.

This makes it really easy when debugging quickly to get all of the information
that you could possibly need from a HeapObject.
2018-02-07 11:54:48 -08:00
Mike Ash
146833c9b5 [Runtime] Fix unowned refcount overflow to side table during deinit.
32-bit has a 7-bit inline unowned refcount, then 31 bits in the side table. Overflowing the inline count in deinit on an object that didn't already have a side table would crash, because the code assumed that creating a side table in deinit was not allowed.

(64-bit has 31 bits inline and in the side table. Overflowing the inline count immediately overflows the side table as well, so there's no change in behavior there.)

rdar://problem/33765960
2018-01-30 15:38:08 -05:00
David Zarzycki
91823273d2 [build system] Prefer LLD if it exists (#14165)
Other changes:
1) Minimize unified versus build-script build differences.
2) Stop trying to make runtime variables have "protected" visibility.
   This combination is meaningless and lld rightly complains.

Finally, this blog post is worth reading:
http://www.airs.com/blog/archives/307
2018-01-30 07:18:36 -05:00
Greg Parker
e223f1fc9b [IRGen][runtime] Simplify runtime CCs and entry point ABIs (#14175)
* Remove RegisterPreservingCC. It was unused.
* Remove DefaultCC from the runtime. The distinction between C_CC and DefaultCC
  was unused and inconsistently applied. Separate C_CC and DefaultCC are
  still present in the compiler.
* Remove function pointer indirection from runtime functions except those
  that are used by Instruments. The remaining Instruments interface is
  expected to change later due to function pointer liability.
* Remove swift_rt_ wrappers. Function pointers are an ABI liability that we
  don't want, and there are better ways to get nonlazy binding if we need it.
  The fully custom wrappers were only needed for RegisterPreservingCC and
  for optimizing the Instruments function pointers.
2018-01-29 13:22:30 -08:00
Mishal Shah
fdbf76e9f5 Update master to build with Xcode 9.3 beta 1 2018-01-25 16:03:11 -08:00
Mike Ash
406ebaddfc [Runtime] Implement overflow check for weak refcounts (#14023)
* Check for overflow in incrementWeak().

This mirrors what is currently done for unowned reference counts, where overflowing the side table field produces a fatal error. Without this, the count silently wrapped from 2^31-1 to 0, which then caused breakage when the balancing releases happened (possibly including use-after-free bugs).

* Fix the implementation of RefCounts::getWeakCount().

The previous implementation was only appropriate for heap objects, but not side tables. This resulted in the weak count always returning 0 or 1. This change specializes the implementation for the two different cases and returns the correct count for side tables.

* Test large weak retain counts.

This tests the largest allowed weak retain count, as well as the overflow check when that count is exceeded.
2018-01-19 19:13:47 -08:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
Greg Parker
96c0ef6e48 [runtime] Clean up an unnecessary C++ template trampoline. (#13381) 2017-12-11 19:26:52 -08:00
troughton
a1518031ec Fix Windows errno() and _stdlib_open 2017-12-04 11:12:11 +13:00
Greg Parker
da14cd79a6 [runtime] Clean up symbol exports in libc functions. (#13202) 2017-12-01 17:49:11 -08:00
Greg Parker
1e894cd80b [runtime] Clean up symbols in error machinery. (#12853)
* [runtime] Clean up symbols in error machinery.

* [runtime] Clean up symbols in Foundation overlay.

* [runtime] Clean up symbols in collections and hashing.

* [runtime] Remove symbol controls from the Linux definition of swift_allocError.

* [tests] Add more stub functions for tests that link directly to the runtime.
2017-11-15 22:20:11 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00