Commit Graph

108 Commits

Author SHA1 Message Date
Stephen Canon
57a4553832 SE-0246: Protocols and static functions (#23824)
This implements the protocols and static functions proposed in SE-0246, plus some initial test coverage. It also has some rough accompanying cleanup of tgmath. It does not include the globals (on scalars or SIMD types) nor does it deprecate much in tgmath.h.
2019-04-17 23:57:33 +02:00
Stephen Canon
c5e3f85378 Revert SE-0246 (#23800)
* Revert "Merge pull request #23791 from compnerd/you-know-nothing-clang"

This reverts commit 5150981150, reversing
changes made to 8fc305c03e.

* Revert "Merge pull request #23780 from compnerd/math-is-terrible"

This reverts commit 2d7fedd25f, reversing
changes made to 0205150b8f.

* Revert "Merge pull request #23140 from stephentyrone/mafs"

This reverts commit 777750dc51, reversing
changes made to 0c8920e747.
2019-04-04 19:35:25 -04:00
Steve (Numerics) Canon
42abd7f494 update stability-stdlib-abi.swift.expected to match new baseline 2019-04-03 08:10:32 -04:00
Steve (Numerics) Canon
3fda509805 Implementation of ElementaryFunctions / Real protocols.
This commit implements SE-0246, by adding conformance to Real to the Float, CGFloat, Double, and Float80 types, implemented either in terms of the system's C math library, existing standard library functionality, or LLVM intrinsics. It includes basic test coverage for these new functions, and deprecates and obsoletes *some* existing functionality in the Platform overlay. We still need to make a decision about how to handle the remaining "tgmath" functions, because obsoleting them is technically a source-breaking change (if users have unqualified names like "exp(1)", it's fine, but it would break users who have used qualified names like "Darwin.exp(1)".)
2019-04-02 18:49:31 -04:00
Xi Ge
c5b4aaec47 ABI/API checker: re-baseline after recent tooling changes 2019-04-02 11:06:29 -07:00
Ben Cohen
0f339d3663 Merge branch 'master' into safe-conversion 2019-02-11 12:58:51 -08:00
Ben Cohen
95a15d12bd Revert count(where:) (#22289) 2019-02-01 15:05:06 -08:00
Max Moiseev
556e089d19 Merge pull request #22138 from moiseev/spring-cleaning
[stdlib] Remove a bunch of declarations marked as obsoleted in 4
2019-02-01 11:03:37 -08:00
Ben Cohen
779ea19a6a Revert count(where:) 2019-01-31 18:57:17 -08:00
Ben Cohen
2010f02e8a Remove overly-permissive UnsafePointer init 2019-01-31 18:05:11 -08:00
Harlan Haskins
9ad009484c Merge pull request #22199 from harlanhaskins/type-extensionality
[api-digester] Don’t synthesize type nodes with no public members or conformances
2019-01-30 16:35:22 -08:00
Harlan Haskins
081b05a4b4 [api-digester] Don’t synthesize type nodes with no public members
Upon seeing an extension for a type outside the current module, the digester
creates a dummy type node and puts all the extensions’ members and conformances
in that type. This allows us to track new API endpoints that are retroactively
added.

Unfortunately, if there are no public members/conformances (only internal or
private ones), the type itself ends up in the SDK dump without any public
children. This causes an issue when you dump the SDK from a parseable
interface, where the internal extension was not printed.
2019-01-30 11:45:19 -08:00
John McCall
8be4ec32e6 Protocol requirement overrides must match in mutating-ness.
Without this change, SILGen will crash when compiling a use of the
derived protocol's requirement: it will instead attempt to use
the base protocol's requirement, but the code will have been
type-checked incorrectly for that.

This has a potential for source-compatibility impact if anyone's
using explicit override checking for their protocol requirements:
reasonable idioms like overriding a mutating requirement with a
non-mutating one will no longer count as an override.  However,
this is arguably a bug-fix, because the current designed intent
of protocol override checking is to not allow any differences in
type, even "covariant" changes like making a mutating requirement
non-mutating.  Moreover, we believe explicit override checking in
protocols is quite uncommon, so the overall compatibility impact
will be low.

This also has a potential for ABI impact whenever something that
was once an override becomes a non-override and thus requires a
new entry.  It might require a contrived test case to demonstrate
that while using the derived entry, but it's quite possible to
imagine a situation where the derived entry is not used directly
but nonetheless has ABI impact.

Furthermore, as part of developing this patch (earlier versions of
which used stricter rules in places), I discovered a number of
places where the standard library was unintentionally introducing
a new requirement in a derived protocol when it intended only to
guide associated type deduction.  Fixing that (as I have in this
patch) *definitely* has ABI impact.
2019-01-30 01:33:09 -05:00
Maxim Moiseev
b3e883bebc List removals in ABI expected breakage test 2019-01-29 11:13:47 -08:00
Ben Cohen
72c000631c Add (false positive) removals to ABI checker file 2019-01-25 14:00:32 -08:00
Stephen Canon
3501568fc0 Make SIMD types Codable. (#22092)
* Make SIMD types codable. We're considering this a bugfix.

This is a very tiny ABI change, in that user-defined SIMD types compiled with an earlier version of 5.0 will be missing the necessary conformance to Codable. Discussed with Ben, and we're OK with this because we don't think there are such types yet, and it can be fixed with a recompile.

* Add basic tests
2019-01-24 23:08:29 -05:00
Ben Cohen
eb083ce84d Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage" (#21874)
* Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage"
2019-01-16 10:22:58 -08:00
Mike Ash
fa5888fb3f [Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names.
Old Swift and new Swift runtimes and overlays need to coexist in the same process. This means there must not be any classes which have the same ObjC runtime name in old and new, because the ObjC runtime doesn't like name collisions.

When possible without breaking source compatibility, classes were renamed in Swift, which results in a different ObjC name.

Public classes were renamed only on the ObjC side using the @_objcRuntimeName attribute.

This is similar to the work done in pull request #19295. That only renamed @objc classes. This renames all of the others, since even pure Swift classes still get an ObjC name.

rdar://problem/46646438
2019-01-15 12:21:20 -05:00
Michael Ilseman
5a6d2dfa59 [String] Switch ABI to only use 4 discriminator bits.
In anticipation of potential future HW features, e.g. armv8.5 memory
tagging, only use the high 4 bytes as discriminator bits in
_BridgeObject rather than the top 8 bits. Utilize two perf flags to
cover this instead. This requires shifting around a fair amount of
internal complexity.
2018-12-19 13:54:50 -08:00
Michael Ilseman
5d67236bc0 [String] Refactor 32-bit StringObject.
Remove Discriminator, Flags, etc., abstractions from
StringObject. These cause code divergence between 32-bit and 64-bit
ABI, complicate ABI changes, and otherwise contribute to bloat.
2018-12-19 11:19:08 -08:00
Xi Ge
9ece618087 [test] regenerate API/ABI baseline for stdlib after recent compiler and tooling enhancements. 2018-12-12 11:27:00 -08:00
Ben Cohen
929539b4ab Merge branch 'master' into remove-strideable-closed-range-operator 2018-12-12 08:03:50 -08:00
Ben Cohen
ad50a39b12 [stdlib] Add withContiguous{Mutable}StorageIfAvailable (#21092)
* Add MutableCollection.withContiguousMutableStorageIfAvailable

* Add withContiguousMutableStorageIfAvailable impls

* Add tests on concrete types

* Add Sequence.withContiguousStorageIfAvailable

* Implement withContiguousStorageIfAvailable in concrete types
2018-12-07 10:01:18 -08:00
Doug Gregor
00d2acd809 Merge pull request #21037 from DougGregor/flatten-abs
[ABI] [stdlib] Remove magnitude-based overload of abs(_:).
2018-12-06 08:36:24 -08:00
Doug Gregor
85d488d461 [stdlib] Remove magnitude-based overload of abs(_:).
The standard library has two versions of the `abs(_:)` function:

```
func abs<T : SignedNumeric>(_ x: T) -> T where T.Magnitude == T
func abs<T : SignedNumeric & Comparable>(_ x: T) -> T
```

The first is more specialized than the second because `T.Magnitude` is
known to conform to `Comparable`. Indeed, it’s a more specialized
implementation that returns `magnitude`.

However, this overload behaves oddly: in the expression `abs(-8)`, the type
checker will pick the first overload because it is more specialized. That’s
a general guiding principle for overloading: pick the most specialized
overload that works.

However, to select that overload, it needs to pick a type for the literal
“8” for which that overload works, and it chooses `Double`. The “obvious”
answer, `Int`, doesn’t work because `Int.Magnitude == UInt`.

There is a conflict between the two rules, here: we prefer more-specialized
overloads (but we’ll fall back to less-specialized if those don’t work) and we prefer to use `Int` for integer literals (but we’ll fall back to `Double` if it doesn’t work). We have a few options from a type-checker
perspective:

1. Consider the more-specialized-function rule to be more important
2. Consider the integer-literals-prefer-`Int` rule to be more important
3. Call the result ambiguous and make the user annotate it

The type checker currently does #1, although at some point in the past it
did #2. Moving forward, #1 is a better choice because it prunes the number
of overloads that need to be considered: if the more-specialized overload
succeeds its type-check, the others need not be considered. It’s also
easier to reason about than the literal-scoring approach, because there can
be a direct definition for “more specialized than” that can be reasoned
about.

I think we should dodge the issue by removing the more-specialized version
of `abs(_:)`. Its use of `magnitude` seems unlikely to provide a
significant performance benefit, and the presence of overloading either
forces us to consider both overloads always (which is bad for type checker
performance) or accept the regression that `abs(-8)` is `Double`. Better
to eliminate the overloading and, if needed in the future, find a better
way to introduce the more-specialized implementation without it being a
separate signature.

Fixes rdar://problem/42345366.
2018-12-04 23:10:04 -08:00
Ben Cohen
fc7830a4ed Remove Swift 3-only Compatibility Shims (#21019) 2018-12-04 18:22:27 -08:00
Michael Ilseman
3e8b015afe Merge pull request #20983 from milseman/comparison_reform
[String] Comparison Speedups
2018-12-04 14:53:45 -08:00
Michael Ilseman
c0c530aef8 [String] Speed up constant factors on comparison.
Include some tuning and tweaking to reduce the constant factors
involved in string comparison. This yields considerable improvement on
our micro-benchmarks, and allows us to make less inlinable code and
have a smaller ABI surface area.

Adds more extensive testing of corner cases in our existing
fast-paths.
2018-12-03 15:49:38 -08:00
Azoy
a2dafc3d26 Remove _getBool 2018-12-01 18:51:25 -06:00
Michael Ilseman
b01ee7267a [String] Custom iterator for UTF16View (#20929)
Defining a custom iterator for the UTF16View avoid some redundant
computation over the indexing model. This speeds up iteration by
around 40% on non-ASCII strings.
2018-12-01 09:35:27 -08:00
Ben Cohen
da614764ed Make reduce(inout:) take its initial value owned 2018-11-28 17:19:39 -08:00
David Smith
8b57921905 Assorted bridging changes:
• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it
2018-11-28 16:04:34 -08:00
swift-ci
d3bd4c5817 Merge pull request #20812 from milseman/sliced_guts 2018-11-27 17:45:23 -08:00
Michael Ilseman
e44972dcea [String] Expunge _StringGutsSlice from ABI
_StringGutsSlice is an implementation helper that's no longer needed
from inlinable code. Internalize it.
2018-11-27 15:07:27 -08:00
Ben Rimmington
c5997491da [stdlib] Remove Strideable closed range operator 2018-11-27 12:58:22 +00:00
Slava Pestov
86b5411a5a stdlib: __SwiftNativeNSString does not need to be public 2018-11-27 00:16:34 -05:00
Ben Cohen
f86fc100a5 Ditch the underscore 2018-11-15 20:55:10 -08:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
swift-ci
f76d920709 Merge pull request #20612 from DougGregor/runtime-demangle-to-metadata-overriode 2018-11-15 17:16:29 -08:00
Michael Ilseman
0a5177d778 Merge pull request #20605 from milseman/abi_publishing
Finish String and Unicode ABI audit
2018-11-15 14:03:28 -08:00
Karoy Lorentey
7df40769a4 Merge pull request #20509 from lorentey/not-quite-shadowy-enough
[stdlib] Unexport shadow protocols
2018-11-15 20:09:26 +00:00
Michael Ilseman
6576f6aa4e [test] Update the API and ABI expected checks 2018-11-15 11:53:48 -08:00
Doug Gregor
a53b2e285c [Standard library] Drop _typeByMangledName().
This underscored function was only intended for testing; drop it from the
ABI. We’re keeping _typeByName because it’s used by Foundation.
2018-11-15 11:06:52 -08:00
Karoy Lorentey
ca10375a48 [test] Remove spurious ABI change (?) 2018-11-15 15:10:07 +00:00
Karoy Lorentey
93a3ebe509 [stdlib] Make the rest of the shadow protocols internal
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
2018-11-15 09:54:25 +00:00
Karoy Lorentey
c4c4c17871 [stdlib] _BridgeStorage: Remove second type parameter (ObjCClass)
It used to be a shadow protocol existential, but now it’s invariably AnyObject.
I see no reason to keep supporting this unused abstraction.
2018-11-15 09:54:25 +00:00
Karoy Lorentey
0463230e2f [stdlib] _SliceBuffer: Make the order of fields a bit more sensible
Also, move field declarations to the top of the struct.
2018-11-15 09:54:25 +00:00
Karoy Lorentey
ee17e975ca [stdlib] Make protocol _NSArrayCore internal
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
2018-11-15 09:54:25 +00:00
Karoy Lorentey
c71abaaf51 [stdlib] Make protocol _NSNumber internal 2018-11-15 09:54:25 +00:00
Karoy Lorentey
4f8eeae64e [stdlib] Make _NSSetCore, _NSSet internal
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
2018-11-15 09:54:25 +00:00