Commit Graph

22 Commits

Author SHA1 Message Date
Parker Schuh
fa69a73ee4 Add -enable-cxx-interop flag and support for extern "C" {} 2019-07-08 11:43:35 -07:00
Saleem Abdulrasool
0983ea66ae stdlib: use placement new on Windows, disable asserts
The assertions here are based around the idea that `std::atomic` is
trivially constructible which is not a guarantee that the standard fully
provides.  The default initialization of the `std::atomic` type may
leave it in an undetermined state.  These were caught using the Visual
C++ preview runtime.

Ideally, the object constructor would use a placement new operator.
However, prior to C++17, the C++ standard mandated that there be a
NULL pointer check in the placement new operator.  This is something
which is no longer the case with C++17.  Switch to the placement new
operator for C++17 and newer and enable that codepath for Windows as
well (which seemingly elides the null-pointer check with clang-cl).
2019-02-27 15:29:06 -08:00
Karoy Lorentey
911d4ab5a4 [runtime] Update empty singletons for Set/Dictionary
Also add static_assert for Set/Dictionary storage header size.
2018-09-27 01:49:50 +01:00
Karoy Lorentey
6d81663716 [stdlib] Make Hashable._rawHashValue(seed:) safer and more convenient
- Don’t expose the raw execution seed to _rawHashValue.
- Change the type of _rawHashValue’s seed from (UInt64,UInt64) to a single Int. Working with a pair of UInt64s is unwieldy, and overkill in practice. Int as a seed also integrates nicely with Int as a hash value.
- Remove _HasherCore._generateSeed(). Instead, simply call finalize() on a copy of the hasher to get a seed suitable for _rawHashValue.
- Update Set and Dictionary to store a single Int as the seed value.

Note that this doesn’t affect the core hasher, which still mixes in the actual 128-bit execution seed during its initialization. To reduce the potential of confusion, use the name “rawSeed” to refer to an actual 128-bit seed value.
2018-09-24 13:30:05 +01:00
Karoy Lorentey
ace19fd106 [runtime] Fix layout of empty Set/Dictionary singletons 2018-09-22 02:04:11 +01:00
Karoy Lorentey
098275f3c7 [stdlib] Clean up Set and Dictionary
- Use _HashTable to unify low-level hashing operations across Set and Dictionary.
- Store the capacity directly inside the storage header. This allows the maximum load factor to be controlled by non-inlinable code.
- Introduce a dedicated class for the empty singleton.
- Add _BridgingHashBuffer, a standalone flat hash buffer for use in deferred bridging. Use it to eliminate the need to support non-hashable storage/wrapper variants and to improve memory use in cases where Key or Value are verbatim bridged.
- Eliminate the “TypedNative*Storage” class and _NativeSet/_NativeDictionary’s support for non-hashable keys.
- Rename storage classes as follows:

_RawNativeSetStorage ⟹ _RawSetStorage
_RawNativeDictionaryStorage ⟹ _RawDictionaryStorage
_TypedNativeSetStorage ⟹ (removed)
_TypedNativeDictionaryStorage ⟹ (removed)
_HashableTypedNativeSetStorage ⟹ _SetStorage
_HashableTypedNativeDictionaryStorage ⟹ _DictionaryStorage

The new names make it obvious which ivar layout is in use.
2018-09-22 02:04:07 +01:00
Karoy Lorentey
edb8a73203 [stdlib] Set, Dictionary: New storage classes for the empty singletons
This allows us to move the empty NSSet/NSDictionary overrides out of the root storage class; they don’t really belong there. More importantly, it makes empty sets/dictionaries super obvious to lldb and other runtime tools.
2018-09-22 02:04:05 +01:00
Azoy
b8fc8b333c Remove _interface 2018-07-29 10:41:22 -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
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
Joe Groff
525001f7a7 Support key paths on 32-bit platforms.
I had optimistically written the code here optimistically hoping #7837 would land in time for me to merge, but that didn't happen, so adjust some things to match the current 12-byte object header size on 32-bit, and introduce some ABI constants for the expected 32- and 64-bit object header sizes we can assert against so that we have some robustness when it eventually changes again. Implements rdar://problem/31768303.
2017-05-02 18:19:07 -07:00
Hugh Bellamy
05a50fd978 Remove extern "C" from uses of SWIFT_RUNTIME_STDLIB_INTERFACE 2017-01-22 18:32:17 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
Alexis Beingessner
21405f1ac1 [runtime] statically construct the Dictionary and Set singletons 2016-11-18 13:56:57 -05:00
Dmitri Gribenko
daa7bfc281 stdlib: add a secret key for hashing 2016-09-06 20:41:03 -07: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
3743cbc563 stdlib: annotate some more symbols with interfaces
Mark some more of the SwiftShim interfaces with the RUNTIME_INTERFACE
decoration.
2016-05-11 11:20:39 -07:00
Xin Tong
8a6fdebc38 Fix thread-unsafety in Process.Argument initialization
rdar://problem/24250684
2016-03-18 15:19:32 -07:00
practicalswift
a3f857ca7b [gardening] Add "-*- C++ -*-" to header files currently missing it 2016-01-23 11:53:05 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Hrybenko
350248dae5 Reorganize the directory structure under 'stdlib'
The standard library has grown significantly, and we need a new
directory structure that clearly reflects the role of the APIs, and
allows future growth.

See stdlib/{public,internal,private}/README.txt for more information.

Swift SVN r25876
2015-03-09 05:26:05 +00:00