Commit Graph

9748 Commits

Author SHA1 Message Date
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
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
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
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
a38fe375d8 Merge pull request #15823 from devincoughlin/data-exclusivity-warning 2018-04-09 17:30:04 -07:00
Devin Coughlin
302d82731a [Foundation] Address exclusivity violation in Data
Address an exclusivity violation in Data's Iterator.next() by changing two private
'let' stored properties to be 'var'.

Making the properties 'var' changes code generation of next() so that the stored
properties are read independently of the other contents of the struct. This
prevents an exclusivity violation when reading '_endIdx' and '_data' while
simultaneously mutating '_buffer' with the call to withUnsafeMutablePointer().

The 'let' pattern is an idiom we would eventually like to support (see SR-7396),
but for now we need to remove the exclusivity violation.
2018-04-09 16:18:17 -07:00
swift-ci
65b22697ae Merge pull request #15770 from dcci/refcount-obj 2018-04-09 12:12:32 -07:00
Joe Groff
0bfe25072b Merge pull request #15798 from jckarter/objc-value-metatype
IRGen: Make type(of:) behavior consistent in ObjC bridged contexts.
2018-04-09 11:13:27 -07:00
swift-ci
3430f38563 Merge pull request #11576 from airspeedswift/remove-elements 2018-04-06 17:45:54 -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
Slava Pestov
178e676864 Merge pull request #15787 from slavapestov/se-0193-inlinable-is-usable-from-inline
SE-0193: @inlinable implies @usableFromInline
2018-04-06 12:03:29 -07:00
swift-ci
09e1e3c859 Merge pull request #15790 from compnerd/pedentary 2018-04-06 11:29:19 -07:00
Saleem Abdulrasool
b432249a17 stubs: silence pedantic warning (NFC)
C requires that there is at least one declaration in a translation unit.
Because this file is ObjC and not ObjC++, this restriction applies.  Add
a declaration to silence the warning in the case that ObjC interop is
disabled.
2018-04-06 09:29:05 -07:00
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Joe Groff
161afd6be5 Merge pull request #15781 from jckarter/demangle-symbolic-reference-nested-type
Runtime: Properly handle demangling nested generic typerefs with symbolic manglings.
2018-04-05 18:58:47 -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
Slava Pestov
61280ef951 stdlib: @_versioned was renamed to @usableFromInline 2018-04-05 14:31:47 -07:00
Sho Ikeda
9efd347100 [gardening][Overlay] Use isEmpty in Data.swift 2018-04-05 17:50:20 +09:00
Jordan Rose
20ae19ef22 [CMake] Improve Xcode project generation with folders (#15738)
- Re-enable the use of folders with the USE_FOLDER setting. This got
  lost a while ago when we stopped including LLVM's top-level
  CMakeLists.txt.

- Put a bunch of new targets into folders.

Should not affect the built product and definitely shouldn't affect
anyone not building with Xcode (or MSVC, I guess).
2018-04-04 18:22:59 -07:00
swift-ci
2cbe98eb27 Merge pull request #15744 from compnerd/visualc-modulemap 2018-04-04 17:04:23 -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
Saleem Abdulrasool
f6dcc22598 platform: enhance the VisualC modulemap
Add the `vadefs` and `stdint` submodules.  These are required to get the
importing of the standard types (`intmax_t` and `uintptr_t`) correct
with the Visual C runtime.  This allows building the libdispatch Swift
overlay.
2018-04-04 14:27:54 -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
Sho Ikeda
68e76535bc [gardening][Calendar] No need to discard the retrun value of insert(_:) which is discardable 2018-04-04 19:29:42 +09: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
Michael Gottesman
9accf4a82f Merge pull request #15686 from gottesmm/pr-2aa38499b4210d8c66240446893c4f340fc62351
[+0-all-args] Remove autoreleasepool on non-x86_64 platforms from Str…
2018-04-02 13:29:57 -07:00
Michael Gottesman
bc48a66c77 [+0-all-args] Remove autoreleasepool on non-x86_64 platforms from String stubs.
This is only necessary on x86-64. On arm/arm64 we are already ok since the
assembly marker that we use there does not suffer from this issue.

For x86-64 we need to solve the problem upstream by not tailing calling
objc_retainAutoreleasedReturnValue.

rdar://38675842
2018-04-02 10:50:08 -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
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
Xi Ge
d93e0dfa01 Merge pull request #15636 from Fidetro/master
Fixed JSONEncoder code style issues
2018-04-01 08:39:04 -07:00
swift-ci
6c42bcccbd Merge pull request #15507 from devincoughlin/foundation-datecomponents-exclusivity-warnings 2018-03-31 10:47:38 -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
ee57586822 Merge pull request #15652 from brennanMKE/semicolon 2018-03-31 08:19:28 -07:00
brennanMKE
fb2f55f558 [stdlib] remove trailing semicolon in stdlib source 2018-03-30 22:44:05 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -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
Andrew Trick
4ed120e46c Merge branch 'master' into add-access-tracking-flag 2018-03-30 19:25:46 -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
Joe Groff
b76fdef020 Merge pull request #15632 from jckarter/addressof-vs-inlinable
stdlib: Fix some `@_inlineable`/`Builtin.addressof` bad interactions.
2018-03-30 17:03:59 -07:00