Commit Graph

5783 Commits

Author SHA1 Message Date
Andrew Trick
0b5fa792e1 Force manual allocation (via Unsafe*Pointer) to use >= 16 alignment.
This fixes the Windows platform, where the aligned allocation path is
not malloc-compatible. It won't have any observable difference on
Darwin or Linux, aside from manually allocated memory on Linux now
being consistently 16-byte aligned (heap objects will still be 8-byte
aligned on Linux).

It is unfortunate that we can't guarantee Swift-allocated memory via
Unsafe*Pointer is malloc compatible on Windows. It would have been
nice for that to be a cross platform guarantee since it's normal to
allocate in C and deallocate in Swift or vice-versa. Now we have to
tell developers to always use _aligned_malloc/_aligned_free when
transitioning between Swift/C if they expect their code to work on
Windows.

Even though this fix isn't required today on Darwin/Linux, it makes
good sense to guarantee that the allocation/deallocation paths are
consistent.

This is done by specifying a constant that stdlib can use to round up
alignment, _swift_MinAllocationAlignment. The runtime asserts that
this constant is greater than MALLOC_ALIGN_MASK for all platforms.
This way, manually allocated buffers will always use the aligned
allocation path. If users specify an alignment less than m

round up so users don't need
to pass the same alignment to deallocate the buffer). This constant
does not need to be ABI.

Alternatives are:

1. Require users of Unsafe*Pointer to specify the same alignment
   during deallocation. This is obviously madness.

2. Introduce new runtime entry points:
   swift_alignedAlloc/swift_alignedDealloc, introduce corresponding
   new builtins, and have Unsafe*Pointer always call those. This would
   make the runtime API a little more obvious but would introduce
   complexity in other areas of the compiler and it doesn't have any
   other significant benefit. Less than 16-byte alignment of manually
   allocated buffers on Linux is a non-goal.
2019-01-03 12:35:51 -08:00
Raj Barik
4be5ab167e Add inline(always) to AnyCollection routines like _suffix, _prefix, _drop 2019-01-03 11:33:09 -08:00
Michael Ilseman
e6586ac209 Merge pull request #21465 from linux-on-ibm-z/s390x-unicode-scalar-fix
[stdlib] Fix Unicode.Scalar to String cast on big endian machines
2019-01-03 11:32:23 -07:00
Johannes Weiss
f87ffd2077 conform Unsafe(Mutable)RawBufferPointer conform to _HasContiguousBytes 2019-01-03 18:23:08 +00:00
Harlan Haskins
b29f1ee1a2 Merge pull request #21527 from nordicio/stdlib_warning_stringstorage
[stdlib] fixes warning: result of call to 'initialize(from:)' is unused
2019-01-03 10:03:49 -08:00
Valeriy Van
a4496d51d8 Fixes typo in var name in example snippet (#21553)
imagePaths is declared in line 320
2019-01-02 16:21:42 -06:00
Dennis Vennink
45429ffa24 Add Zip2Sequence.underestimatedCount (#21530) 2019-01-02 12:46:49 -05:00
Saleem Abdulrasool
b7aca2bd06 Merge pull request #21462 from compnerd/build-host-target
build: differentiate better between host and target
2019-01-02 08:35:51 -08:00
Valeriy Van
9c733ed67d Fixes example snippet of AnyHashable
Otherwise, `print(descriptions[AnyHashable(45)])` prints `an Int8`, not `nil`.
2018-12-26 18:35:49 +02:00
Andreas Jönsson
121f15b2ac [stdlib] fixes warning: result of call to 'initialize(from:)' is unused 2018-12-23 00:20:01 +01:00
Saleem Abdulrasool
f1043e4aa7 build: correct case for STREQUAL (NFC)
The swift variables use the upper case spelling while CMake uses mixed
case.  Use the correct case to fix the build.  This is preferable to
using MATCH to avoid the unnecessary configure time penalties.
2018-12-21 15:51:57 -08:00
Max Moiseev
1116525f92 Merge pull request #21475 from moiseev/atomic-int-func-public
[stdlib] Make a couple internal functions back public
2018-12-21 12:12:25 -08:00
David Smith
4e4325d248 Merge pull request #21235 from Catfish-Man/cheaper-by-the-dozen
Adopt bulk Dictionary creation in bridging
2018-12-21 11:37:40 -08:00
Robert Widmann
2efbeb3912 Merge pull request #21451 from CodaFi/logicd
[SR-8272] Drop the last remnants of LogicValue
2018-12-20 23:33:20 -05:00
swift-ci
0ae5dd409e Merge pull request #21461 from compnerd/shellwapi 2018-12-20 16:47:13 -08:00
Maxim Moiseev
a550606412 Make a couple internal functions back public 2018-12-20 14:23:27 -08:00
Max Moiseev
ff47c303ad Merge pull request #21443 from compnerd/ilp32
core: remove unsupported architecture conditional
2018-12-20 13:49:40 -08:00
Saleem Abdulrasool
c764e8a273 build: differentiate better between host and target
Assume that the build currently targets only a single target.  Use the target to
determine the linked libraries for the target library (swiftCore).  This is more
precise and more importantly, is required to enable cross-compilation of various
targets.
2018-12-20 09:18:27 -08:00
Saleem Abdulrasool
f1c2a57557 build: link swiftCore against Shell32
We are now using Shell APIs for the command line parsing.  Ensure that we link
against the Shell32 library.  This is needed for the cross-compilation as on
Windows, the environment will set a default link against a number of libraries.
This is more precise and explicit.
2018-12-20 09:13:34 -08:00
Michael Munday
cdd5aa0624 [stdlib] Fix Unicode.Scalar to String cast on big endian machines
We need to explicity ensure that an integer is in the required byte
order (little-endian in this case) before accessing it as an array
of bytes through an unsafe pointer.
2018-12-20 14:58:16 +00:00
Robert Widmann
426fe886dc [SR-8272] Drop the last remnants of LogicValue
Removes the _getBuiltinLogicValue intrinsic in favor of an open-coded
struct_extract in SIL.  This removes Sema's last non-literal use of builtin
integer types and unblocks a bunch of cleanup.

This patch would be NFC, but it improves line information for conditional expression codegen.
2018-12-19 23:14:59 -05:00
Michael Ilseman
0ac802a95b Merge pull request #21310 from milseman/4_bit_string
[String] Last-minute ABI adjustment: 4-bit discriminator
2018-12-19 16:42:20 -08:00
Karoy Lorentey
624135641d Merge pull request #21057 from lorentey/actually-deprecate-hashValue
[Sema] Emit a deprecation warning if a Hashable type only implements hashValue
2018-12-19 22:47:16 +00:00
Saleem Abdulrasool
f8b41740e5 core: remove unsupported architecture conditional
AArch64 ILP32 support has not yet been integrated into the frontend.
Remove the conditional compilation for the target.
2018-12-19 13:56:18 -08:00
Michael Ilseman
5a6d2dfa59 [String] Switch ABI to only use 4 discriminator bits.
In anticipation of potential future HW features, e.g. armv8.5 memory
tagging, only use the high 4 bytes as discriminator bits in
_BridgeObject rather than the top 8 bits. Utilize two perf flags to
cover this instead. This requires shifting around a fair amount of
internal complexity.
2018-12-19 13:54:50 -08:00
Michael Ilseman
5d67236bc0 [String] Refactor 32-bit StringObject.
Remove Discriminator, Flags, etc., abstractions from
StringObject. These cause code divergence between 32-bit and 64-bit
ABI, complicate ABI changes, and otherwise contribute to bloat.
2018-12-19 11:19:08 -08:00
Maxim Moiseev
165fe328c3 [stdlib] tee _stdlib_AtomicInt > SwiftPrivate
Turns out some people used this type despite it being prefixed with
`_stdlib_`, so we have to keep it, with an obsoletion message this time.
Second copy of the same type is kept available past Swift 5 in
SwiftPrivate for use in tests.
2018-12-18 16:12:47 -08:00
Karoy Lorentey
9d61bad1e5 [stdlib] Keep the first duplicate key instead of the last 2018-12-18 09:49:58 -08:00
Karoy Lorentey
f862ad3741 [stdlib] Doc updates 2018-12-18 09:49:58 -08:00
Karoy Lorentey
f0e04f73f4 [stdlib] Process elements from back to front 2018-12-18 09:49:58 -08:00
Karoy Lorentey
039891c24b [stdlib] Dictionary: Add support for non-unique keys in bulk loading init 2018-12-18 09:49:58 -08:00
Karoy Lorentey
f1f5e0f2bf [stdlib] Dictionary: Add unsafe bulk-loading initializer
Interface inspired by this Array pitch:
https://forums.swift.org/t/array-initializer-with-access-to-uninitialized-buffer/13689
2018-12-18 09:49:58 -08:00
Nate Cook
646849ee64 Doc fix
Co-Authored-By: lorentey <klorentey@apple.com>
2018-12-18 17:27:08 +00:00
Doug Gregor
ad17e8a3ab [SIMD] Delete unnecessary comment on debugDescription.
It maakes documentation works by overriding the default.
2018-12-17 11:08:46 -08:00
Doug Gregor
69c9fbc3c8 Move SIMD operators back into the Swift standard library
Moving them out to SIMDOperators didn't help, but the type checker hack
might. Move them back into the Swift standard library where they belong,
but leave SIMDOperators there to smooth over any short-term
incompatibilities.
2018-12-17 11:07:32 -08:00
Doug Gregor
34113d1f86 Merge pull request #21339 from DougGregor/simd-custom-string-convertible
[SIMD] Add CustomDebugStringConvertible conformance for SIMD types.
2018-12-14 20:43:36 -08:00
Luciano Almeida
2bc5623bdf [stdlib] Resolving some FIXME comments on Set type. (#20631)
* Fixing some fixmes on stdlib Set

* Adding @inline attr

* Fixing spaces

* Adding isEmpty as fast path in other places where is possible.

* Quotes on variable name on comment.

* Update stdlib/public/core/Set.swift

Co-Authored-By: LucianoPAlmeida <passos.luciano@outlook.com>

* Adding benchmark for isDisjoint Set method

* Adding empty sets to benchmark

* Fixing the factor on benchmarks and naming warnings for empty 5 words
2018-12-14 22:11:12 -06:00
Doug Gregor
fbf4bb738d [SIMD] Add CustomDebugStringConvertible conformance for SIMD types.
The old SIMD types had a conformance to CustomDebugStringConvertible,
but the new ones do not, causing a source compatibility
regression. Add back a CustomDebugStringConvertible conformance.

Fixes rdar://problem/46746829.
2018-12-14 17:00:17 -08:00
Erik Eckstein
aae60ff271 stdlib: Code size improvements for Dictionary for -Osize
The first change is to remove some @inline(__always) attributes. Those were added before we had the guaranteed-by-default calling convention. They are not necessary anymore.

The second change is to not specialize some slow-path functions. This results that no specialization code for these functions is generated at the client side. Instead those functions are directly called in the libSwiftCore.
Note that Key-related hash and equality comparisons are still specialized, because otherwise the performance hit for Osize would be too big.

Some Dictionary benchmarks regress a bit with -Osize, but the code size wins are big.

rdar://problem/46534453
2018-12-13 16:59:19 -08:00
Max Moiseev
83ccb23c97 Merge pull request #20958 from jshier/add-result
SE-0235: Add Result<Success, Failure: Error> to Standard Library
2018-12-12 14:00:15 -08:00
Ben Cohen
929539b4ab Merge branch 'master' into remove-strideable-closed-range-operator 2018-12-12 08:03:50 -08:00
Joe Groff
e30c86769a KeyPath: Allow existing context descriptors to be used as generic environment.
If a key path literal appears in a generic context with an existing context descriptor, this will allow us to
save some code size by not having to emit a separate GenericEnvironment descriptor.
2018-12-11 09:05:47 -08:00
Joe Groff
85eb634191 stdlib: Make _typeByName Foundation SPI reject symbolic references.
It's used for recovering type metadata from deserialized mangled names, which should never have symbolic
references in them.
2018-12-10 20:22:03 -08:00
Joe Groff
1f5f6dbb6d Merge pull request #21186 from jckarter/public-getTypeByMangledName
Runtime: Make getTypeByMangledNameIn(Context|Environment) a public entry point.
2018-12-10 18:58:53 -08:00
Michael Ilseman
6a18fb8d83 Merge pull request #21178 from milseman/string_storage_view
[String] UTF8View implements withContiguousStorageIfAvailable
2018-12-10 15:57:15 -08:00
Mike Ash
a39ee29f0e Merge pull request #21127 from mikeash/rename-anykeypath-and-valistbuilder
[Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs.
2018-12-10 18:11:23 -05:00
Joe Groff
021053d499 Runtime: Make getTypeByMangledNameIn(Context|Environment) a public entry point.
This can be used by compiler-generated code as a size optimization for metadata access, using a
mangled name instead of possibly many open-coded metadata calls. It can also allow reflection
libraries outside of the standard library to turn type reference strings into in-process metadata
pointers in a robust way. rdar://problem/46451849
2018-12-10 14:22:41 -08:00
Jordan Rose
c66a445ef7 [stdlib] Make some more *Pointer operations _transparent (#21126)
Not only was this affecting performance when building from parseable
interfaces, but we'd also want these to be inlined for any sort of
bounds-checking diagnostics / static analysis we might get in the
future.
2018-12-10 13:37:15 -08:00
Nate Cook
2bb0b5c842 Revise some documentation comments. 2018-12-10 14:31:28 -06:00
Michael Ilseman
1d9032991b [String] UTF8View implements withContiguousStorageIfAvailable 2018-12-10 11:01:28 -08:00