Commit Graph

3245 Commits

Author SHA1 Message Date
Joe Groff
6349dea762 Regression test for https://bugs.swift.org/browse/SR-7357 2018-04-10 14:22:04 -07:00
Joe Groff
78b5ff8b6b Runtime: Bridge Error-conforming types to id as NSError instances.
NSError is a more useful box for a swift Error than the generic box. Fixes rdar://problem/38631791 | SR-7232.
2018-04-10 12:23:49 -07:00
Tim Kientzle
339eddac98 Avoid Float80 test data on platforms that lack Float80
This was an oversight from PR #15474.  Most of the Float80
tests were correctly compiled only on `!Windows && (x86 || i386)`
but I failed to mark some Float80 test data.

Fixes: Radar 39246292
2018-04-10 12:07:38 -07:00
Daniel Tull
47149528a0 [stdlib] SR-7266 Make sure to actually run the tests 2018-04-10 19:27:57 +03:00
Daniel Tull
9c13a276f2 [stdlib] SR-7266 Add ReverseCompatibility test 2018-04-10 17:14:49 +03:00
swift-ci
65b22697ae Merge pull request #15770 from dcci/refcount-obj 2018-04-09 12:12:32 -07:00
Davide Italiano
c850bfd12e [DebuggerSupport] Mark this test as requiring optimized stdlib. 2018-04-09 10:04:06 -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
Tony Allevato
ff40d04555 Add tests for some complex Unicode.Scalar.Properties properties 2018-04-06 06:30:40 -07:00
Joe Groff
b51d43377e Runtime: Properly handle demangling nested generic typerefs with symbolic manglings.
The demangling tree for a symbolic reference doesn't indicate the generic context depth of the referenced type, so we have to form the type metadata from whole cloth without incrementally building up nested types as we do for concrete mangled types. Notice when DecodedMetadataBuilder is passed a context descriptor ref without a parent and directly form the entire type in this case. Fixes rdar://problem/38891999.
2018-04-05 16:23:16 -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
Jordan Rose
104d042885 Merge pull request #14949 from Keno42/fixWarning
[Test] Replace unused variable with _
2018-04-02 11:36:21 -07:00
Arnold Schwaighofer
bdca017a51 stdlib: Printable_Double signaling nan tests on i386 only in Onone mode
i386 does not support signaling nans *accross calls* (SR-1515). However,
after inlining we do get a signaling representation. So only run the
test in Onone mode.

rdar://39104087
2018-04-02 07:08:57 -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
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
Michael Ilseman
683fb47c01 Merge pull request #14755 from milseman/so_smol
Smol String
2018-03-28 18:29:50 -07: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
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
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
Greg Parker
072e9827aa Use SwiftObject's old name when building for the pre-stable ABI.
rdar://35554345
2018-03-26 14:04:30 -07:00
Ben Cohen
ba11a23901 Add removeAll(where:) to RangeReplaceableCollection 2018-03-26 13:49:50 -07:00
Joe Groff
a6a792c740 Add a MemoryLayout<T>.offset(of:) method for getting the offset of inline storage.
If a key path refers to inline storage of the root type, this produces the offset in bytes between a pointer to the root and a pointer to the projected storage. Otherwise, returns nil.
2018-03-26 12:22:41 -07:00
Max Moiseev
6c5d2e948a Merge pull request #15470 from moiseev/proto-dw
[stdlib] Move DoubleWidth to test/Prototypes
2018-03-26 07:39:26 -07:00
Max Moiseev
141fefc06b Update tests after removal of DoubleWidth 2018-03-23 17:14:46 -07:00
Karoy Lorentey
c196667686 [stdlib] Remove non-obvious conditional Hashable conformances
This removes Hashable conformance for types that do not already implement Equatable:

- CollectionOfOne
- AnyCollection
- DictionaryLiteral
2018-03-23 19:09:28 +00:00
Morten Bek Ditlevsen
c9337114d2 [WIP] Conditional conformance to Hashable for Optional, Dictionary and Array types. (#14247)
* Add conditional Hashable conformance to Optional, Dictionary, Array, ArraySlice and ContiguousArray

* Modified hashValue implementations
The hashValues are now calculated similar to the automatically synthesized values when conforming to Hashable.
This entails using _combineHashValues as values of the collections are iterated - as well as calling _mixInt before returning the hash.

* Added FIXMEs as suggested by Max Moiseev

* Use checkHashable to check Hashable conformance

* Use 2 space indentation

* Hashing of Dictionary is now independent of traversal order

* Added a test to proof failure of (previous) wrong implementation of Dictionary hashValue. Unfortunately it does not work.

* Removed '_mixInt' from 'hashValue' implementation of Optional and Array types based on recommendations from lorentey

* Another attempt at detecting bad hashing due to traversal order

* Dictionary Hashable validation tests now detect bad hashing due to dependence on traversal order

* Removed superfluous initial _mixInt call for Dictionary hashValue implementation.

* Add more elements to dictionary in test to increase the number of possible permutations - making it more likely to detect order-dependent hashes

* Added Hashable conformance to CollectionOfOne, EmptyCollection and Range types

* Fix indirect referral to the only member of CollectionOfOne

* Re-added Hashable conformance to Range after merge from master

* Change hashValue based on comment from @lorentey

* Remove tests for conditional Hashable conformance for Range types. This is left for a followup PR

* Added tests for CollectionOfOne and EmptyCollection

* Added conditional conformance fo Equatable and Hashable for DictionaryLiteral. Added tests too.

* Added conditional Equatable and Hashable conformance to Slice

* Use 'elementsEqual' for Slice equality operator

* Fixed documentation comment and indentation

* Fix DictionaryLiteral equality implementation

* Revert "Fix DictionaryLiteral equality implementation"

This reverts commit 7fc1510bc3.

* Fix DictionaryLiteral equality implementation

* Use equalElements(:by:) to compare DictionaryLiteral elements

* Added conditional conformance for Equatable and Hashable to AnyCollection

* Revert "Use 'elementsEqual' for Slice equality operator"

This reverts commit 0ba2278b96.

* Revert "Added conditional Equatable and Hashable conformance to Slice"

This reverts commit 84f9934bb4.

* Added conditional conformance for Equatable and Hashable for ClosedRange
2018-03-23 19:08:38 +00:00
Wei Wang
416761ff0d No need to repeat the same test twice
It might be due to a historical reason before bridging works as it does now. There should be no need to repeat the same assertion twice here.
2018-03-23 16:31:06 +09:00
Stephen Canon
8e11af4012 Make the naming of underlying builtin for FP + Vector match Integer. (#15430)
* Make the underlying builtins for FP + Vector match Integer.

For stdlib integer types, these are named `_value` and `init(_ _value: Builtin.xxx)`. This patch adopts the same scheme for stdlib floating point and SDK overlay vector types, and removes a legacy init for integers that was only needed to support them. There should be no changes visible outside of the stdlib, and no functional change within the stdlib; the naming of some implementation details is simply more uniform now.
2018-03-22 16:43:20 -04:00
Pavel Yaskevich
fc93edbc96 [CSSolver] Attempt unavailable overloads only in "diagnostic" mode
Such overloads are not going to result in viable solutions anyway,
so it makes sense to attempt them only if solver failed to deduce
proper solution.

Helps to improve type-checking performance of operators which have
multiple unavailable overloads for compatibility reasons.
2018-03-21 18:17:22 -07:00
David Zarzycki
f5ae7b2584 [validation tests] Improve concurrency
This improves 'ninja check-swift-validation' by about 35% on my Linux desktop.
2018-03-21 09:28:51 -04:00
David Zarzycki
c00c18fc68 [Tests] Consolidate stress/long tests in validation-tests 2018-03-20 22:19:37 -04:00
David Zarzycki
283713d61d [Testing] Formalize stress tests
Stress tests are, by definition, stressful. They intentionally burn a
lot of resources by using randomness to hopefully surface state machine
bugs. Additionally, many stress tests are multi-threaded these days and
they may attempt to use all of the available CPUs to better uncover
bugs. In isolation, this is not a problem, but the test suite as a whole
assumes that individual tests are single threaded and therefore running
multiple stress tests at once can quickly spiral out of control.

This change formalizes stress tests and then treats them like long
tests, i.e. tested via 'check-swift-all' and otherwise opt-in.

Finally, with this change, the CI build bots might need to change if
they are still only testing 'validation' instead of all of the tests.
I see three options:

1) Run all of the tests. -- There are very few long tests left these
   days, and the additional costs seems small relative to the cost of
   the whole validation test suite before this change.
2) Continue checking 'validation', now sans stress tests.
3) Check 'validation', *then* the stress tests. If the former doesn't
   pass, then there is no point in the latter, and by running the stress
   tests separately, they stand a better chance of uncovering bugs and
   not overwhelming build bot resources.
2018-03-20 21:45:28 -04:00
Stephen Canon
d3cb915abb Updates to tgmath functions for CGFloat (#15360)
* Updates to tgmath functions for CGFloat

These changes bring CGFloat in line with the other FloatingPoint types.  Some of this stuff is now defined at the protocol level, so we can get rid of it at the concrete type level.  A couple other functions have been deprecated for all types, with protocol or tgmath replacements.
2018-03-20 11:14:57 -04:00
Max Moiseev
d50f60cc73 Merge pull request #15144 from rockbruno/overflow-assignment-2
[stdlib][SR-4818] Add overflow assignment operators
2018-03-19 16:05:56 -07:00
Stephen Canon
ba97a32cfc Skip testing remoquo for Linux + x86_64, because it's busted. (#15348)
Further details and discussion of longer-term fix in SR-7234.
2018-03-19 18:46:01 -04:00
bruno-rocha-movile
08610df3e7 [stdlib] Improve masked operator tests 2018-03-19 18:45:09 -03:00
bruno-rocha-movile
16d793afbd [stdlib] Add overflow operator tests 2018-03-19 17:46:21 -03: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
ff7dde6230 Make tgmath tests generic over TGMath protocol, extend to Float80 (#15289)
* Make tgmath tests generic over a TGMath protocol, extend them to Float80.

Define most of the test machinery in terms of a internal TGMath protocol that refines BinaryFloatingPoint. Add a little bit of gyb support to automate adding additional types, as it is likely these tests will need to support Float16 and Float128 in the future. Make all the input values exactly representable in all of the types in question, to avoid representation errors, loosen default tolerance to 3 to make porting to new platforms less noisy.

* Further tgmath test cleanup.

Merge #if conditions where possible so that they're not all over the file. Get rid of placeholder CGFloat on non-Darwin, which is no longer needed and doesn't work with the new approach anyway.

* Remove ldexp, it's been renamed scalbn.
2018-03-17 11:38:50 -04:00
Slava Pestov
fbdd36cda8 Merge pull request #15319 from slavapestov/remove-disable-resilience
Remove build-script flag to disable resilience
2018-03-16 20:37:29 -07:00
David Zarzycki
20d943592e Merge pull request #15244 from davezarzycki/mark_param_passing_tests_as_long_test
[Testing] Mark two latent long tests as 'long_test'
2018-03-16 23:11:09 -04:00
Slava Pestov
694fcddf4e Remove build-script flag to disable resilience 2018-03-16 19:56:17 -07:00
Stephen Canon
3ff628158b Add a note on policy for error tolerances in test/stdlib/tgmath.swift 2018-03-14 20:56:50 -04:00
tbkka
ed25361b6c Test tgmath without printing (#15218)
* Test tgmath without printing

The tgmath tests have been comparing the printed form of the numeric results.
This worked only because the old floating-point formatting logic was inaccurate.
As such, they implicitly tolerate slight inaccuracies.

This commit rewrites the test to verify the numeric values directly.
This is both more explicit and more robust.  (In particular, it
protects this test against future changes to the floating-point
formatting logic.)

For example, the previous code verified `log1p` with this code:
```
(d1, f1, g1) = (log1p(dx), log1p(fx), log1p(gx))
expectEqual("log1p 0.0953101798043249 0.0953102 log1p",
  print3("log1p", d1, f1, g1))
```
which implicitly relies on inaccurate printing.

The new code uses a custom helper:
```
expectEqualWithAccuracy(log1p(dx), log1p(fx), log1p(gx), 0.09531017980432487, ulps: 1)
```
which verifies that the `Double`, `Float`, and `CGFloat` values
match the provided number within 1 ULP.

Note: I've somewhat arbitrarily set the `ulps:` parameter to 1 for most tests.
This might be unnecessarily strict and these parameters could be relaxed: The
goal of the tgmath test is simply to ensure that Swift's functions map to the
correct C math library routines.  This test is not trying to validate the
accuracy of those underlying routines.

* Verify that C `nextafter` matches Swift `.nextUp`/`.nextDown`

As suggested by Steve Canon.

* Verify only the bottom three bits of remquo().1

Note: The C/C++ standards only require the bottom three
bits to be correct, although macOS assures 7 bits.

* Comment and simplify a bit

Note: it's possible that this commit will cause test failures on platforms other than Mac and Linux/x86 if libm is not sufficiently accurate on these values. Previously these tests were enforcing that values had to print identically, now there is an explicit tolerance. The new approach is formally better, but it may be necessary to relax some of the tolerances from 1ulp to 2 or more for some platforms.
2018-03-14 20:50:52 -04:00
David Zarzycki
89b524000b [Testing] Mark two latent long tests as 'long_test'
This improves 'ninja check-swift-validation' performance by about 2.9x
on my Linux desktop. Also, move them to validation-test where the other
long tests live.
2018-03-14 16:17:27 -04:00
Michael Ilseman
c3d9a22548 [test] Split CString API tests into other file; NFC 2018-03-13 15:32:20 -07:00
Ben Cohen
f9b3e14137 [stdlib] Use Swift-native Character iteration for hasPrefix/Suffix (#14390)
* Use Swift-native Character iteration for hasPrefix/Suffix

* Remove old tests for removed C shims
2018-03-12 17:41:55 -07:00
Erik Eckstein
677fcad92a tests: temporarily disable stdlib/os.swift osAPI.logData test 2018-03-11 12:36:42 -07:00