Commit Graph

3939 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
Timm Preetz
46d36c8136 [gardening] Correct comment 2018-04-21 11:34:02 +02: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
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
swift-ci
f45a9c8052 Merge pull request #16030 from lorentey/array-hash-encoding 2018-04-19 16:59:02 -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
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
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
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
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
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
Michael Gottesman
e071e46068 Add build-script flag --enable-exclusivity-checking to enable exclusivity checking always when we compile stdlibCore.
It is off by default.

rdar://39335800
2018-04-11 09:23:06 -07:00
Karoy Lorentey
cff4eb77ef [stdlib] {Set,Dictionary}.init(minimumCapacity:) Update docs
Avoid describing the exact algorithm that these collections use to allocate storage. (It is a private implementation detail that we want to be able to change.)

rdar://problem/36619317
2018-04-11 12:25:51 +01:00
Mox
b859cdc173 SR-7266: Avoid nesting of ReversedCollection
Applying reversed() two times should return identity.
2018-04-10 17:06:14 +03:00
crea
247ee7a82f fix documentation comment of flatMap<SegmentOfResult : Sequence> 2018-04-10 01:20:15 -07:00
Slava Pestov
14654590dc stdlib: remove some @_inlineable that snuck in recently 2018-04-09 18:00:58 -07:00
swift-ci
65b22697ae Merge pull request #15770 from dcci/refcount-obj 2018-04-09 12:12:32 -07:00
swift-ci
3430f38563 Merge pull request #11576 from airspeedswift/remove-elements 2018-04-06 17:45:54 -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
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Slava Pestov
61280ef951 stdlib: @_versioned was renamed to @usableFromInline 2018-04-05 14:31:47 -07:00
Mark Lacey
e137da5184 Merge pull request #15730 from rudkx/rdar33781464
stdlib: Collapse some multi-line closures to single-line closures.
2018-04-04 11:27:06 -07:00
Mark Lacey
32d006de4a stdlib: Collapse some multi-line closures to single-line closures.
The change in CheckMutableCollectionType.swift.gyb previously resulted
in a runtime failure, and before that a compiler crash.

It appears that whatever type checker bug(s) were causing the issue
have been resolved in the last few months, so I'm returning this
closure to a single-expression form and cleaning up a couple other
places where we had an unneeded temporary as well.

Resolves rdar://problem/33781464.
2018-04-03 22:26:33 -07:00
Pavel Yaskevich
78822bc23e [IRGen] Adjust element size of offset vector to 32-bit for structs
Type of elements contained by field offsets vector can be adjusted
to 32-bit integers (from being pointer sized) to safe space in the
binary since segment size is limited to 4 GB.

Resolves: rdar://problem/36560486
2018-04-03 13:32:06 -07:00
Jordan Rose
9be6519f5a [SILGen] Show a message when an unexpected enum value is switched on (#15614)
Builds on 36eae9d4f6 to emit a message instead of just trapping
when a switch over a non-frozen enum ends up not matching anything.
If the enum is known to be an @objc enum, the message is

  unexpected enum case 'MyEnum(rawValue: -42)'

and if it's anything else (a Swift enum, a tuple containing enums,
whatever), it's a more opaque

  unexpected enum case while switching on value of type 'MyEnum'

The reason for this is to avoid calling String(describing:) or
String(reflecting:) an arbitrary value when the enum might conform to
CustomStringConvertible and therefore /itself/ have a switch that's
going to fall off the end. By handling plain @objc enums (using a
bitcast), we've at least covered the 90% case.

rdar://problem/37728359
2018-04-03 11:21:36 -07:00
tbkka
97a934c412 SR-106: New floating-point description implementation (#15474)
* SR-106: New floating-point `description` implementation

This replaces the current implementation of `description` and
`debugDescription` for the standard floating-point types with a new
formatting routine based on a variation of Florian Loitsch' Grisu2
algorithm with changes suggested by Andrysco, Jhala, and Lerner's 2016
paper describing Errol3.

Unlike the earlier code based on `sprintf` with a fixed number of
digits, this version always chooses the optimal number of digits.  As
such, we can now use the exact same output for both `description` and
`debugDescription` (except of course that `debugDescription` provides
full detail for NaNs).

The implementation has been extensively commented; people familiar with
Grisu-style algorithms should find the code easy to understand.

This implementation is:

* Fast.  It uses only fixed-width integer arithmetic and has constant
  memory and time requirements.

* Simple. It is only a little more complex than Loitsch' original
  implementation of Grisu2.  The digit decomposition logic for double is
  less than 300 lines of standard C (half of which is common arithmetic
  support routines).

* Always Accurate. Converting the decimal form back to binary (using an
  accurate algorithm such as Clinger's) will always yield exactly the
  original binary value.  For the IEEE 754 formats, the round-trip will
  produce exactly the same bit pattern in memory.  This is an essential
  requirement for JSON serialization, debugging, and logging.

* Always Short.  This always selects an accurate result with the minimum
  number of decimal digits.  (So that `1.0 / 10.0` will always print
  `0.1`.)

* Always Close.  Among all accurate, short results, this always chooses
  the result that is closest to the exact floating-point value. (In case
  of an exact tie, it rounds the last digit even.)

This resolves SR-106 and related issues that have complained
about the floating-point `description` properties being inexact.

* Remove duplicate infinity handling

* Use defined(__SIZEOF_INT128__) to detect uint128_t support

* Separate `extracting` the integer part from `clearing` the integer part

The previous code was unnecessarily obfuscated by the attempt to combine
these two operations.

* Use `UINT32_MAX` to mask off 32 bits of a larger integer

* Correct the expected NaN results for 32-bit i386

* Make the C++ exceptions here consistent

Adding a C source file somehow exposed an issue in an unrelated C++ file.
Thanks to Joe Groff for the fix.

* Rename SwiftDtoa to ".cpp"

Having a C file in stdlib/public/runtime causes strange
build failures on Linux in unrelated C++ files.

As a workaround, rename SwiftDtoa.c to .cpp to see
if that avoids the problems.

* Revert "Make the C++ exceptions here consistent"

This reverts commit 6cd5c20566.
2018-04-01 16:52:48 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Vedant Kumar
f9319037a9 Merge pull request #15615 from vedantk/fuzzdebug
Add a transform to help test lldb expression evaluation
2018-03-30 18:04:47 -07:00
Vedant Kumar
ca27e829ba Add a transform to help test lldb expression evaluation
The initial version of the debugger testing transform instruments
assignments in a way that allows the debugger to sanity-check its
expression evaluator.

Given an assignment expression of the form:

```
  a = b
```

The transform rewrites the relevant bits of the AST to look like this:

```
  { () -> () in
    a = b
    checkExpect("a", stringForPrintObject(a))
  }()
```

The purpose of the rewrite is to make it easier to exercise the
debugger's expression evaluator in new contexts. This can be automated
by having the debugger set a breakpoint on checkExpect, running `expr
$Varname`, and comparing the result to the expected value generated by
the runtime.

While the initial version of this testing transform only supports
instrumenting assignments, it should be simple to teach it to do more
interesting rewrites.

There's a driver script available in SWIFT_BIN_DIR/lldb-check-expect to
simplfiy the process of launching and testing instrumented programs.

rdar://36032055
2018-03-30 16:50:31 -07:00
Joe Groff
1f5513f221 stdlib: Fix some @_inlineable/Builtin.addressof bad interactions.
The resilience model forces inlinable code to use resiliently conservative access paths for properties in the same module, but some stdlib methods by design escapes storage of a global variable. The additional `Builtin.addressof` validation introduced in #15608 exposed the latent issue here.
2018-03-30 13:44:39 -07:00
Saleem Abdulrasool
72a4f19311 stdlib: disable FP80 patterns on Windows (#15588)
Windows does not support FP80 operations even on x86 and x86_64. Disable the generation of those operations on that target.
2018-03-29 09:56:08 -04:00
Michael Ilseman
683fb47c01 Merge pull request #14755 from milseman/so_smol
Smol String
2018-03-28 18:29:50 -07:00
Karoy Lorentey
5f32944816 Merge pull request #15569 from lorentey/detect-mutations
[stdlib] Set, Dictionary: Clarify assert message when a duplicate key is found
2018-03-28 23:06:48 +01:00
Karoy Lorentey
e485c1506b Merge pull request #15382 from lorentey/conditional-hashable2
[SE-0143][stdlib] Conditionally conform stdlib types to Hashable
2018-03-28 21:45:02 +01:00
Karoy Lorentey
96d93a4f94 [stdlib] Set, Dictionary: Clarify assert message when a duplicate key is found
When a duplicate key is found during rehashing, it is usually either because a key was mutated after insertion, or because the dictionary itself was mutated from multiple threads at the same time.

Both of these are serious programmer errors. Promote the sanity check for duplicate keys to a full precondition and improve the error message to point out the most probable cause of the failure.
2018-03-28 11:59:13 +01:00
Michael Gottesman
a1089a2923 [+0-all-args] Mark the storage parameter to _adoptStorage as a +1 parameter.
This fixes the optionset test with +0 enabled. It is now re-enabled.

rdar://38152291
2018-03-27 18:25:39 -07:00
Michael Ilseman
388622c393 [string] Small fast-path for hasPrefix/Suffix 2018-03-27 14:01:00 -07:00
Michael Ilseman
8b6d0f6402 [string] Aggressively form small strings.
Whenever possible, prefer the small string format. Updates creation
logic. Adds assertion on large strings that they're not intended to be
small.
2018-03-27 14:00:59 -07:00
Michael Ilseman
93d6130066 [string] Integrate small strings.
Switch StringObject and StringGuts from opaquely storing tagged cocoa
strings into storing small strings. Plumb small string support
throughout the standard library's routines.
2018-03-27 14:00:59 -07:00
Michael Ilseman
cb9dc84d72 [string] Initial small string implementation.
This adds a small string representation capable of holding up to 15
ASCII code units directly in registers. This is extendable to UTF-8 in
the future.

It is intended to be the preferred representation whenever possible
for String, and is intended to be a String fast-path. Future small
forms may be added in the future (likely off the fast-path).

Small strings are available on 64-bit, where they are most beneficial
and well accomodated by limited address spaces. They are unavailable
on 32-bit, where they are less of a win and would require much more
hackery due to full address spaces.
2018-03-27 14:00:55 -07:00