Commit Graph

1960 Commits

Author SHA1 Message Date
swift-ci
3aa10bbefc Merge remote-tracking branch 'origin/master' into master-next 2018-04-27 20:29:05 -07:00
Mike Ash
5fc07b8709 Merge pull request #16188 from mikeash/assert-metadata-mangled-name-roundtrip
[Runtime] Assert that metadata mangled names successfully roundtrip.
2018-04-27 20:09:24 -07:00
swift-ci
1f1646b88b Merge remote-tracking branch 'origin/master' into master-next 2018-04-27 08:49:00 -07:00
Mike Ash
91619c4cd0 [Runtime] Make mangled name roundtrip verification a soft failure. Disable it entirely when running tests and when bootstrapping swiftpm, for now.
rdar://problem/37551850
2018-04-27 10:09:06 -04:00
Arnold Schwaighofer
dab3b0b184 Runtime: Fix swift_bridgeObjectRetain family of functions to return the input
object

Now we can use swift_bridgeObjectRetain's return value in BridgeObjectBox.
2018-04-27 06:14:32 -07:00
swift-ci
647867db68 Merge remote-tracking branch 'origin/master' into master-next 2018-04-26 16:29:08 -07:00
tbkka
924b8e55d5 Updates to Floating-point printing code (SwiftDtoa.cpp) (#16178)
This collects a number of changes I've been testing over the
last month.

* Bug fix: The single-precision float formatter did not always
  round the last digit even in cases where there were two
  possible outputs that were otherwise equally good.

* Algorithm simplification: The condition for determining
  whether to widen or narrow the interval was more complex than
  necessary. I now simply widen the interval for all even
  significands.

* Code simplification: The single-precision float formatter now uses fewer
  64-bit features.  This eliminated some 32-bit vs. 64-bit conditionals in
  exchange for a minor loss of performance (~2%).

* Minor performance tweaks: Steve Canon pointed out a few places
  where I could avoid some extraneous arithmetic.

I've also rewritten a lot of comments to try to make the exposition
clearer.

The earlier testing regime focused on testing from first
principles.  For example, I verified accuracy by feeding the
result back into the C library `strtof`, `strtod`, etc. and
checking round-trip exactness.  Unfortunately, this approach
requires many checks for each value, limiting test performance.
It's also difficult to validate last-digit rounding.

For this round of updates, I've instead compared the digit
decompositions to other popular algorithms:
* David M. Gay's gdtoa library is a robust and well-tested
  implementation based on Dragon4.  It supports all formats, but
  is slow. (netlib.org/fp)
* Grisu3 supports Float and Double.  It is fast but incomplete,
  failing on about 1% of all inputs.
  (github.com/google/double-conversion)
* Errol4 is fast and complete but only supports Double.  The
  repository includes an implementation of the enumeration
  algorithm described in the Errol paper.
  (github.com/marcandrysco/errol)

The exact tests varied by format:

* Float: SwiftDtoa now generates the exact same digits as gdtoa
  for every single-precision Float.

* Double: Testing against Grisu3 (with fallback to Errol4 when
  Grisu3 failed) greatly improved test performance.  This
  allowed me to test 100 trillion (10^14) randomly-selected
  doubles in a reasonable amount of time.  I also checked all
  values generated by the Errol enumeration algorithm.

* Float80: I compared the Float80 output to the gdtoa library
  because neither Grisu3 nor Errol4 yet supports 80-bit extended
  precision.  All values generated by the Errol enumeration
  algorithm have been checked, as well as several billion
  randomly-selected values.
2018-04-26 16:09:49 -07:00
Mike Ash
77e9b967f3 [Runtime] When asserts are enabled, verify that each newly created Metadata successfully roundtrips its mangled name through the demangler.
rdar://problem/37551850
2018-04-25 16:26:23 -04:00
swift-ci
4a97d36810 Merge remote-tracking branch 'origin/master' into master-next 2018-04-23 15:09:14 -07:00
Doug Gregor
d755b38ee5 [Runtime] Teach BridgeObjectBox::retain() not to drop the "not native" bit.
The "not native" bit in a BridgeObject is important, because it tells
us when we need to go through the Objective-C -retain method
vs. swift_retain. Losing the bit means that swift_retain() will stomp
on some memory within an Objective-C object, thinking its the inline
reference count.

Co-debugged with Arnold, who then found where this bit was getting dropped.
Fixes rdar://problem/39629937.
2018-04-23 14:04:22 -07:00
swift-ci
ba738b8e7d Merge remote-tracking branch 'origin/master' into master-next 2018-04-20 23:29:32 -07: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
swift-ci
44b4be86f4 Merge remote-tracking branch 'origin/master' into master-next 2018-04-20 08:27: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
add7d7f078 Merge remote-tracking branch 'origin/master' into master-next 2018-04-17 13:29:17 -07:00
Joe Groff
b8426862c1 Runtime: Quell a warning about useless const on a function typedef. 2018-04-17 10:46:01 -07:00
swift-ci
4213f96247 Merge remote-tracking branch 'origin/master' into master-next 2018-04-15 18:29:35 -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
swift-ci
08a91a27dd Merge remote-tracking branch 'origin/master' into master-next 2018-04-12 14:37:29 -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
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
swift-ci
9494376793 Merge remote-tracking branch 'origin/master' into master-next 2018-04-12 09:53:01 -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
swift-ci
4b5a4a963d Merge remote-tracking branch 'origin/master' into master-next 2018-04-11 10:08:16 -07:00
Doug Gregor
5832a6fe12 [CMake] Link demangle tree dumper in +Asserts builds.
When building with assertions enabled, link the demangle tree dumper into
the runtime and remote mirrors libraries. This makes debugging demangling-related issues a whole lot easier.
2018-04-10 21:17:09 -07:00
swift-ci
f10f7caca7 Merge remote-tracking branch 'origin/master' into master-next 2018-04-10 18:29:44 -07:00
Joe Groff
4f26ef749c Merge pull request #15841 from jckarter/box-error-as-nserror
Runtime: Bridge Error-conforming types to id as NSError instances.
2018-04-10 18:19:50 -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
swift-ci
906bf7c41a Merge remote-tracking branch 'origin/master' into master-next 2018-04-09 12:29:46 -07:00
swift-ci
65b22697ae Merge pull request #15770 from dcci/refcount-obj 2018-04-09 12:12:32 -07:00
swift-ci
d6e4412890 Merge remote-tracking branch 'origin/master' into master-next 2018-04-09 12:09:20 -07:00
Joe Groff
a4aa054838 IRGen: Make type(of:) behavior consistent in ObjC bridged contexts.
When we use type(of: x) on a class in an ObjC bridged context, the optimizer turns this into a SIL `value_metatype @objc` operation, which is supposed to get the dynamic type of the object as an ObjC class. This was previously lowered by IRGen into a `object_getClass` call, which extracts the isa pointer from the object, but is inconsistent with the `-class` method in ObjC or with the Swift-native behavior, which both look through artificial subclasses, proxies, and so on. This inconsistency led to observably different behavior between debug and release builds and between ObjC-bridged and native entry points, so provide an alternative runtime entry point that replicates the behavior of getting a native Swift class. Fixes SR-7258.
2018-04-06 15:17:04 -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
swift-ci
58b2cad4ee Merge remote-tracking branch 'origin/master' into master-next 2018-04-05 19:11:48 -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
Saleem Abdulrasool
ebb21f50ee runtime: avoid UB on Windows x86_64 builds
Use the `ull` extension rather than `l` for LLP64 environment support.
Fixes UB on the Windows x86_64 port.
2018-04-04 14:34:49 -07:00
swift-ci
df70a77b65 Merge remote-tracking branch 'origin/master' into master-next 2018-04-04 00:29:13 -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
swift-ci
519df29eb7 Merge remote-tracking branch 'origin/master' into master-next 2018-04-01 19:29:12 -07:00
John McCall
b18af4f4e1 Merge pull request #15671 from rjmccall/cyclic-metadata
Finish the first stage of incomplete type metadata support
2018-04-01 22:15:39 -04:00
swift-ci
eca55d95da Merge remote-tracking branch 'origin/master' into master-next 2018-04-01 17:09:25 -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
John McCall
6c31586128 Add cyclic-metadata support to tuples.
I was going to put this off for awhile, but it turns out that a lot of
my testcases are enums with multi-payload cases, which we currently
compile as tuples, so they were all still hanging until this patch.
2018-04-01 19:23:57 -04:00
John McCall
f22d02a67a Detect unbreakable metadata dependency cycles and abort with a diagnostic. 2018-04-01 19:23:57 -04:00
John McCall
ea7dd7eca3 Minor changes to how we track and lock around metadata dependencies
to enable the general cycle-dependency runtime error.
2018-04-01 19:23:57 -04:00
John McCall
4d461831b8 Optimize the layout of MetadataCacheEntryBase to pack fields more effectively. 2018-04-01 19:23:57 -04:00
swift-ci
1a436bcb75 Merge remote-tracking branch 'origin/master' into master-next 2018-03-31 10:08:58 -07:00
Andrew Trick
e9d07d88fc Merge pull request #15501 from atrick/add-access-tracking-flag
[exclusivity] Add an access tracking flag.
2018-03-31 10:04:08 -07:00
swift-ci
485d502a0b Merge remote-tracking branch 'origin/master' into master-next 2018-03-30 20:08:53 -07:00
Mike Ash
99c15bc641 Merge pull request #15429 from mikeash/casting-hooks
[Runtime] Add hooks for back-deploying dynamic casting and type lookup changes
2018-03-30 19:54:35 -07:00