Commit Graph

9748 Commits

Author SHA1 Message Date
Vijaya Prakash Kandel
a912a12805 Update ErrorType.swift documentation on IntParsingError (#16092)
Update ErrorType.swift

Example on IntParsingError should have Character as associated value type not String.
Also updated sample code to use c rather than s
2018-04-23 10:16:15 -05:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Karoy Lorentey
67852ed460 Merge pull request #16066 from lorentey/better-hash-tests
[stdlib] Review & update hash testing to use Hasher's new features
2018-04-21 23:42:38 +01:00
Timm Preetz
46d36c8136 [gardening] Correct comment 2018-04-21 11:34:02 +02:00
Slava Pestov
902c0d3586 Runtime: Handle symbolic references inside other mangling nodes
Previously we could only handle symbolic references at the
top level, but this is insufficient; for example, you can
have a nested type X.Y where X is defined in the current
translation unit and Y is defined in an extension of X in
a different translation unit. In this case, X.Y mangles as
a tree where the child contains a symbolic reference to X.

Handle this by adding a new form of Demangle::mangleNode()
which takes a callback for resolving symbolic references.

Fixes <rdar://problem/39613190>.
2018-04-20 21:55:45 -07:00
Jordan Rose
f6b67f33fe Declare some FloatingPointSign members explicitly for @inlinable (#16043)
The compiler can synthesize these, but it doesn't mark them
@inlinable, since in the general case they're just a "default"
implementation and not "the only implementation forever". But for a
two-element enum that's based on a part of IEEE 754, it's probably
safe to assume this is the only implementation forever, and that
can be important for performance.

https://bugs.swift.org/browse/SR-7094
2018-04-20 15:28:53 -07:00
Karoy Lorentey
5ab67115dc [test] MinimalHashable types: Replace hashValue hook with hash(into:) 2018-04-20 19:22:19 +01:00
Karoy Lorentey
8d18d1a55d [test] checkHashable: Check that unequal values produce different hashes
This is safe to do with hash(into:), because random hash collisions can be eliminated with awesome certainty by trying a number of different hash seeds. (Unless there is a weakness in SipHash.)

In some cases, we intentionally want hashing to produce looser equivalency classes than equality — to let those cases keep working, add an optional hashEqualityOracle parameter.

Review usages of checkHashable and add hash oracles as needed.
2018-04-20 19:22:19 +01:00
Karoy Lorentey
d55b14b193 [test] MinimalHashable{Value,Class}: Implement CustomStringConvertible
This makes it easier to understand failure traces in test logs.
2018-04-20 17:42:02 +01:00
Karoy Lorentey
f873a5193e [test] MinimalTypes: Move ==, < definitions into the corresponding type (NFC) 2018-04-20 17:40:42 +01:00
Andrew Trick
abab49e54c Support exclusivity enforcement of KeyPath read-only access.
Use begin_unpaired_access [no_nested_conflict] for
Builtin.performInstantaneousReadAccess. This can't be optimized away
and is the proper marker to use when the access scope is unknown.

Drop the requirement that
_semantics("optimize.sil.preserve_exclusivity") be @inline(never). We
actually want theses inlined into user code. Verify that the
@_semantic functions are not inlined or otherwise tampered with prior
to serialization.

Make *no* change to propagate @inline(__always) into LLVM. This no longer has
any relationship to this PR and can be investigated seperately.
2018-04-19 22:46:10 -07:00
Devin Coughlin
ef4a89c479 [Exclusivity] Enforce exclusive access for class offsets in KeyPaths
Add dynamic enforcement of exclusive access when a KeyPath directly accesses a final
stored property on an instance of a class. For read-only projections, this begins and ends
the access immediately. For mutable projections, this uses the ClassHolder to perform
a long-term access that lasts as long as the lifetime of the ClassHolder.

rdar://problem/31972680
2018-04-19 21:37:12 -07:00
Michael Gottesman
636b5f67f0 [runtime] Add support for an asserts only debugging routine called swift_dumpTrackedAccesses().
This makes it easy to perform printf debugging in the debugger. I have found it
to be useful in understanding programs around exclusivity quickly.
2018-04-19 21:37:12 -07:00
swift-ci
f45a9c8052 Merge pull request #16030 from lorentey/array-hash-encoding 2018-04-19 16:59:02 -07:00
Michael Ilseman
46b88ed906 Merge pull request #15928 from milseman/boilerplate_generated
[test] De-gyb stdlib unittest.
2018-04-19 16:25:00 -07:00
Michael Ilseman
c4614a9208 [test] De-gyb stdlib unittest.
StdlibUnittest uses gyb to avoid duplicating many source-context
arguments. However, this means that any test that wishes to add new
expect helpers has to also be gybbed. Given that this structure hasn't
changed in years, and we should have a real language support
eventually, de-gyb it.
2018-04-19 13:06:14 -07:00
Karoy Lorentey
882462ff8a [stdlib] Array._hash(into:): Include the count as a discriminator value
This makes the hash encoding unambiguous when arrays are hashed in sequence.
2018-04-19 20:05:29 +01:00
Karoy Lorentey
ebf290a598 [stdlib] Optimize ASCII String hashing
- String hashing is not inlinable, so it can use _Hasher._core operations directly. Remove custom buffering.
- Speed up ASCII hashing by as much as 5.5x by feeding the storage buffer directly into hasher in a single go.
- For other strings, just feed the UTF-8 encoding of the normalized string to the hasher; don't switch to UTF-16 at the first non-ASCII scalar. (Doing that would make the hash encoding of some string sequences ambiguous, leading to artificial collisions.)
- Add a single unconditional terminator byte, 0xFF. It's not a valid UTF-8 code unit, so it won't ever occur within a normalized string encoding.
2018-04-19 11:49:51 +01:00
Karoy Lorentey
7ed7354003 Merge pull request #16009 from lorentey/brand-new-combine-harvester2
[SE-0206][stdlib] Implement Hasher API (underscored)
2018-04-19 09:59:10 +01:00
Joe Groff
0ee381ea04 Merge pull request #15608 from jckarter/withUnsafePointer-for-lets
[pending] stdlib: Add withUnsafeBytes(of:) and withUnsafePointer(to:) for immutable arguments.
2018-04-18 13:31:55 -07:00
swift-ci
577b2722f7 Merge pull request #13140 from troughton/windows-cross-compile-fixes 2018-04-18 10:56:06 -07:00
Morten Bek Ditlevsen
a5a68ca25d Fix negation of 0 length Decimal (#15986)
A Decimal value with _length 0 and _isNegative set to 1 is interpreted as a NaN. The 'negate()' function however, flipped the _isNegative flag without regard for the _length 0 case. This meant that -0 would become NaN. The fix checks for the _length 0 special case. In NSDecimalSubtract() the same check was performed. Since this now happens in negate(), it is removed from the NSDecimalSubtract() function.
2018-04-18 10:18:34 -07:00
Karoy Lorentey
7e66a38af8 [stdlib] De-gyb SipHash; implement full Hasher API 2018-04-18 17:33:24 +01:00
Joe Groff
62771a0c9d stdlib: Add withUnsafeBytes(of:) and withUnsafePointer(to:) for immutable arguments.
Since the functions produce pointers with tightly-scoped lifetimes there's no formal reason these have to only work on `inout` things.  Now that arguments can be +0, we can even do this without copying values that we already have at +0.
2018-04-18 09:13:45 -07:00
Saleem Abdulrasool
ad26c68d53 Merge pull request #15942 from compnerd/windbg
stdlib: add additional compiler rt routines
2018-04-18 08:27:49 -07:00
Karoy Lorentey
ccdc218cbd [stdlib] _Hasher: append => combine 2018-04-18 14:18:44 +01:00
Ben Cohen
ca7aea02e9 [stdlib] Add compatibility typealias for CountablePartialRangeFrom (#15989)
* Add compatibility typealias for CountablePartialRangeFrom
2018-04-17 15:48:54 -07:00
Karoy Lorentey
6c5a6a6a16 [stdlib] Make sure _SwiftNewtypeWrapper hashes the same way as its RawValue
_SwiftNewtypeWrapper forwarded hashValue to its rawValue, but it failed to do the same for _hash(into:), which resulted in the wrapper struct having subtly different hashing than the raw value.

This violated an implicit invariant when dictionaries/sets of such types were bridged to Objective-C through AnyHashable, leading to nondeterministic but frequent crashes.

rdar://problem/39398060
2018-04-17 22:04:55 +01:00
Joe Groff
b8426862c1 Runtime: Quell a warning about useless const on a function typedef. 2018-04-17 10:46:01 -07:00
Saleem Abdulrasool
d3ab36fd46 Merge pull request #15745 from compnerd/dota
runtime: avoid UB on Windows x86_64 builds
2018-04-15 18:18:47 -07:00
Saleem Abdulrasool
d55d348016 stdlib: add additional compiler rt routines
The quad precision support in visual studio does not support
the operations which clang will sometimes lower.  These currently
generate code using GNU extensions.  Add additional stubs for math
routines on Windows.  This allows the standard library to build in
debug mode.
2018-04-15 17:01:30 -07:00
Saleem Abdulrasool
302ce638eb stubs: silence unused function warning
When building on Linux, the definition of `swift_snprintf_l` would cause
an unused function warning.  Expand the scope of the preprocessor guard
to encompass the function for the single use.  This avoids the unused
function warning.
2018-04-13 18:07:07 -07:00
Saleem Abdulrasool
a34ac086d4 stubs: clean up android support routines
Some of the previously used stubs are no longer needed in newer releases
of the Android API.  Android L and Android O provide the functions in
their associated versions of bionic.  This is needed to build against a
newer version of the SDK.
2018-04-13 18:06:50 -07:00
Saleem Abdulrasool
dfa8a3113f Merge pull request #15912 from compnerd/compiler-rt
stubs: split up compiler-rt routines
2018-04-13 15:15:39 -07:00
swift-ci
92310038d9 Merge pull request #15919 from compnerd/truncation 2018-04-13 12:56:15 -07:00
Saleem Abdulrasool
9f045add2c stdlib: silence truncation warning on Windows
The returned type `std::streamoff` on Windows x64 is a `long long`
rather than `int`.  This results in a 64-to-32 bit shortening of the
value.  Use the appropriate type to avoid the truncation.

`strlen` returns a unsigned value, but `std::streamoff` is an signed
value.  Explicitly cast the value to avoid the warning about the
implicit signed conversion.
2018-04-13 10:28:17 -07:00
Saleem Abdulrasool
0a1352efff stubs: split up compiler-rt routines
Move the duplicated compiler-rt support routines into its own source
file.  This will need to be expanded for Windows.  As on Linux, there
are certain builtin routines which are not available from the standard
runtime and need to be augmented for now.
2018-04-13 09:44:42 -07: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
Max Moiseev
02aef12281 Merge pull request #15815 from Moximillian/SR-7266-avoid-nesting-reversed
SR-7266: Avoid nesting of ReversedCollection
2018-04-12 15:05:54 -07:00
Saleem Abdulrasool
3b45ce660c Merge pull request #15905 from compnerd/protocol
stdlib: correct protocol registration on ELF
2018-04-12 14:29:11 -07:00
Tony Parker
daef47ce25 Merge pull request #15901 from parkera/pr/39340548_master
[Foundation] Guard Data access to NSData._isCompact under availabilit…
2018-04-12 14:12:14 -07:00
Saleem Abdulrasool
9969679515 stdlib: correct protocol registration on ELF
We were misinterpreting the protocol conformances as the protocol sections.  It
is interesting that this never was caught in any of the runs on the build bots
nor was it caught during the normal execution of code.
2018-04-12 10:07:41 -07:00
Philippe Hausler
57d0ea8013 [Foundation] Guard Data access to NSData._isCompact under availability guards 2018-04-12 09:53:34 -07:00
tbkka
1cc1832b96 SR-3131: Adjust choice of decimal vs. exponential format (#15805)
Merge SR-3131 fix:

For each floating-point type, there is a range of integers which
can be exactly represented in that type.  Adjust the formatting
logic so that we use decimal format for integers within this
range, exponential format for numbers outside of this range.

For example, Double has a 53-bit significand so can exactly
represent every integer from `-(2^53)...(2^53)`.  With this
change, we now use decimal format for these integers and
exponential format for values outside of this range.  This is
a relatively small change from the previous logic -- we've
basically just moved the cutoff from 10^15 to 2^53 (about 10^17).

The decision for using exponential format for small numbers is
not changed.
2018-04-12 09:35:49 -07:00
Michael Gottesman
f5ed323b7d Merge pull request #15865 from gottesmm/pr-64a51a9306ab1faab72f4e6bb58d6d062f984dcf
Add build-script flag --enable-exclusivity-checking to enable exclusi…
2018-04-11 13:15:09 -07:00
Nate Cook
69ce965881 Merge pull request #15794 from natecook1000/nc-fixes-83-1
[stdlib] Documentation revisions
2018-04-11 15:07:04 -05:00
Nate Cook
61c79f33c0 [stdlib] Address feedback from @airspeedswift and @CodaFi 2018-04-11 13:03:36 -05:00
swift-ci
537a8461ff Merge pull request #15867 from DougGregor/cleanup-autolink-hack 2018-04-11 09:59:31 -07:00
Nate Cook
a63f5bf788 [stdlib] Revise masking shift and unsafe operation docs 2018-04-11 11:34:59 -05:00
Nate Cook
b6a0d9ed26 [stdlib] Documentation revisions
- Make RawRepresentable Codable abstracts distinguishable
- Make the UnboundedRange example a little more user friendly
- Correct the RangeReplaceableCollection example description
- Revise CaseIterable discussion
2018-04-11 11:34:51 -05:00