Commit Graph

5277 Commits

Author SHA1 Message Date
Slava Pestov
f2c4250962 Merge pull request #20345 from slavapestov/reflection-bitwise-takable
Reflection: Compute if types are bitwise takable
2018-11-07 02:51:13 -05:00
Nate Cook
e5c1567957 [stdlib] Switch to a stable sort algorithm (#19717)
This switches the standard library's sort algorithm from an in-place
introsort to use a modified timsort, a stable, adaptive sort that
merges runs using a temporary buffer. This implementation performs
straight merges instead of adopting timsort's galloping strategy.

In addition to maintaining the relative order of equal/non-comparable
elements, this algorithm outperforms the introsort on data with any
intrinsic structure, such as runs of ascending or descending elements
or a significant number of equality collisions.
2018-11-07 00:05:04 -06:00
Slava Pestov
00c1279dbb Reflection: Compute if types are bitwise takable
Bitwise takability is now part of the layout of a type, because
non-bitwise takable types are never stored inline in an
existential or resilient global's buffer, even if they would
fit.

The basic rule is that weak references, unknown-refcounted
unowned references, and aggregates that contain them, are not
bitwise takable, whereas everything else is bitwise takable.

Also, since the bitwise takable for an unowned reference
depends on the reference counting style, we have to record the
superclass of a protocol, if any, to correctly determine the
reference counting style of the protocol existential.
2018-11-07 00:32:12 -05:00
Max Moiseev
d3e7d59ff4 Merge pull request #20290 from moiseev/atomic-int
[stdlib] Move _stdlib_AtomicInt and friends out of the stdlib
2018-11-06 14:48:46 -08:00
Pavel Yaskevich
5c77d88d74 Merge pull request #20359 from xedin/rdar-41331096
[IDE] NFC: Add a test-case for a fixed SourceKit crasher
2018-11-06 13:32:51 -08:00
Pavel Yaskevich
0a3f666367 [IDE] NFC: Add a test-case for a fixed SourceKit crasher
Resolves: rdar://problem/41331096
2018-11-06 11:58:38 -08:00
Maxim Moiseev
ca51626fd3 [stdlib] Move _stdlib_AtomicInt and friends out of the stdlib 2018-11-06 09:53:58 -08:00
Michael Ilseman
1f9ff2a2e7 [test] un-XFAIL passing parse_stdlib test.
The problematic class no longer exists, so the test passes.
2018-11-06 09:20:48 -08:00
Doug Gregor
5e439f7647 [Mangling] Mangle types as generic only when they have generic arguments.
The `isSpecialized()` check didn’t account for the possibility that a
typealias in a parent of a nominal type could be non-generic when the
parent declaration was generic, leading to incorrect mangling that stated
that they were generic but had no generic arguments.

Fixes SR-8930 / rdar://problem/45216653 and rdar://problem/45813164.
2018-11-05 23:31:32 -08:00
Maxim Moiseev
90106444d3 [stdlib] Remove a bunch of unused functions from Runtime.swift.gyb
<rdar://problem/45746339>
2018-11-05 15:03:19 -08:00
Michael Ilseman
fee2787eb6 [String] Invalidate breadcrumbs on mutation. 2018-11-05 06:48:56 -08:00
Michael Ilseman
ec6729a3a3 [String] Assertion logic and isASCII bug fix.
Fix bugs in assertion logic and properly update the isASCII bit on
RRC. RRC tests added.
2018-11-04 10:42:44 -08:00
Michael Ilseman
c04dcf3b38 [String] More efficient breadcrumb-scanning code.
Rather than rely on the UTF16View, scan between breadcrumbs by hand
for a decent 20% speedup. This code will also make it more obvious how
to slot in a vectorized solution later.
2018-11-04 10:42:44 -08:00
Michael Ilseman
948655e850 [String] Cleanups, comments, documentation
After rebasing on master and incorporating more 32-bit support,
perform a bunch of cleanup, documentation updates, comments, move code
back to String declaration, etc.
2018-11-04 10:42:42 -08:00
Karoy Lorentey
40aae6b235 [String] 32-bit platform support
Add support for 32-bit platforms for UTF-8 backed String.
2018-11-04 10:42:41 -08:00
Michael Ilseman
e6582c37ee [test] Adjust String tests for UTF-8 representation.
Adjust tests for the UTF-8 representation, in preparation for 32-bit
support. Includes UTF-8 literal update.
2018-11-04 10:42:41 -08:00
Michael Ilseman
cb0fbc6fc7 [String] 5X Faster getCharacters implementation
Rather than bounce through the UTF-16 view, implement custom
transcoding for getCharacters. This speeds it up by around 5X. Adds
tests.
2018-11-04 10:42:41 -08:00
Michael Ilseman
e2c2e479bb [test] Test the breadcrumbing String<->Cocoa interface 2018-11-04 10:42:41 -08:00
Michael Ilseman
b87bff4fac [test] Test the unique-native String RRC optimization path 2018-11-04 10:42:41 -08:00
Michael Ilseman
9b5eb23de3 [test] Fix test: add in explicit mkdir 2018-11-04 10:42:41 -08:00
Lance Parker
bacc7eecd5 fix the normalization unit tests 2018-11-04 10:42:41 -08:00
Lance Parker
7376009ccc Add benchmarks and tests for the normalized iterator (#32)
Add benchmarks and tests for the normalized iterator
2018-11-04 10:42:41 -08:00
Lance Parker
f1a35bd1c9 String comparison iterator for UTF8 strings 2018-11-04 10:42:41 -08:00
Brent Royal-Gordon
9bd1a26089 Implementation for SE-0228: Fix ExpressibleByStringInterpolation (#20214)
* [CodeCompletion] Restrict ancestor search to brace

This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.

NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.

* Remove test relying on ExpressibleByStringInterpolation being deprecated

Since soon enough, it won’t be anymore.

* [AST] Introduce TapExpr

TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:

  func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
    var copy = value
    try body(&copy)
    return copy
  }

Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.

This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.

* SE-0228: Fix ExpressibleByStringInterpolation

This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.

* [Sema] Rip out typeCheckExpressionShallow()

With new string interpolation in place, it is no longer used by anything in the compiler.

* [Sema] Diagnose invalid StringInterpolationProtocols

StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.

* [Stdlib] Fix map(String.init) source break

Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.

* [Sema] Make callWitness() take non-mutable arrays

It doesn’t actually need to mutate them.

* [Stdlib] Improve floating-point interpolation performance

This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.

This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.

* [NameLookup] Improve MemberLookupTable invalidation

In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.

This change also includes some debugging improvements for NameLookup.

* [SILOptimizer] XFAIL dead object removal failure

The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.

* Confess string interpolation’s source stability sins

* [Parser] Parse empty interpolations

Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.

Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.

* [Sema] Fix batch-mode-only lazy var bug

The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.

I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Max Moiseev
433444f02a Merge pull request #20137 from moiseev/scene-kit-mode
[overlay] Build SceneKit in Swift 4 mode
2018-11-02 09:48:28 -07:00
John McCall
abdba1d3f4 Change the integer-literal type from Int2048 to IntLiteral.
Part of SR-290.
2018-10-31 23:14:58 -04:00
Ben Cohen
dbc2e21522 Remove customization points from Sequence and Collection (#19995) 2018-10-31 18:58:00 -07:00
Slava Pestov
9499d1d346 Merge pull request #20173 from slavapestov/weak-linked
IRGen: Use @_weakLinked to test backward deployment of resilient protocols
2018-10-31 21:52:58 -04:00
Karoy Lorentey
3ae170c1c1 [stdlib] Remove SipHash from ABI-visible names
Also, eliminate the (unused) SipHash24 implementation and nest most of Hasher’s internals under Hasher itself.
2018-11-01 00:45:40 +00:00
Slava Pestov
57979d1f7c IRGen: Use @_weakLinked to test backward deployment of resilient protocols
Get the attribute working for more link entity kinds, which addresses
all the FIXME:s in the original test case.

Now the protocol resilience tests can be updated to use @_weakLinked
for all newly-added protocol requirements and default implementations.

This allows the tests to pass in the backward deployment test scenario
as well.

Eventually this will be based on availability instead of a special
attribute.

This completes <rdar://problem/29888071>.
2018-10-31 19:55:01 -04:00
Brent Royal-Gordon
4ddd82f990 Add regression test for fixed crasher (#20098)
In Swift 4.2, this example crashed. In Swift 5, it incorrectly diagnoses a type error. Eventually, it should actually succeed. For now, let's make sure we don't backslide to crashing.
2018-10-29 17:04:58 -07:00
Maxim Moiseev
27a3ebf591 [overlay] Build SceneKit in Swift 4 mode
Addresses: <rdar://problem/43534146>
2018-10-29 15:48:34 -07:00
swift-ci
9ed658b0e2 Merge pull request #20124 from DougGregor/test-for-rdar-45557325 2018-10-29 10:59:55 -07:00
Doug Gregor
3e2e81d8a3 Add already-fixed test case from rdar://problem/45557325. 2018-10-29 09:57:39 -07:00
Slava Pestov
add4185b83 AST: Fix infinite recursion with recursive same-type constraints
We diagnose and flag these in finalize(), but we can encounter one
even earlier through resolveDependentMemberTypes(). Do the same
thing there that we already do in EquivalenceClass::getTypeInContext().

Fixes <rdar://problem/45328122>, <https://bugs.swift.org/browse/SR-9022>.
2018-10-28 23:30:19 -04:00
Rintaro Ishizaki
ffbe6634ef Merge pull request #20015 from rintaro/ide-completion-rdar45275782
[CodeCompletion] Don't try to resolve generic env for extension in inactive block
2018-10-27 17:46:14 +09:00
Doug Gregor
4c47906697 [Runtime] Define type metadata for Builtin.Int1 and Builtin.Int63.
These types are used in the standard library.
2018-10-26 18:04:29 -07:00
Karoy Lorentey
f013ffe9ec [test] Add basic leak tests for key-based Dictionary.subscript variants 2018-10-26 16:20:01 +01:00
Doug Gregor
83bf9ddc25 Merge pull request #20040 from DougGregor/remove-witness-table-accessor
[ABI] Eliminate witness table accessors.
2018-10-25 22:51:52 -07:00
Doug Gregor
6abc8489ce Update Set<AnyHashable> test case that no longer crashes 2018-10-25 21:43:23 -07:00
Mark Lacey
fcdca5d7aa Merge pull request #20057 from rudkx/designated-types
Add more type checker performance tests.
2018-10-25 21:12:09 -07:00
Doug Gregor
dd154f6668 [Runtime] Rename swift_instantiateWitnessTable() -> swift_getWitnessTable()
This runtime function doesn’t always perform instantiation; it’s how we
get a witness table given a conformance, type, and set of instantiation
arguments. Name it accordingly.
2018-10-25 20:35:27 -07:00
Doug Gregor
b5bc06e552 [ABI] Eliminate witness table accessors.
Witness table accessors return a witness table for a given type's
conformance to a protocol. They are called directly from IRGen
(when we need the witness table instance) and from runtime conformance
checking (swift_conformsToProtocol digs the access function out of the
protocol conformance record). They have two interesting functions:

1) For witness tables requiring instantiation, they call
swift_instantiateWitnessTable directly.
2) For synthesized witness tables that might not be unique, they call
swift_getForeignWitnessTable.

Extend swift_instantiateWitnessTable() to handle both runtime
uniquing (for #2) as well as handling witness tables that don't have
a "generic table", i.e., don't need any actual instantiation. Use it
as the universal entry point for "get a witness table given a specific
conformance descriptor and type", eliminating witness table accessors
entirely.

Make a few related simplifications:

* Drop the "pattern" from the generic witness table. Instead, store
  the pattern in the main part of the conformance descriptor, always.
* Drop the "conformance kind" from the protocol conformance
  descriptor, since it was only there to distinguish between witness
  table (pattern) vs. witness table accessor.
* Internalize swift_getForeignWitnessTable(); IRGen no longer needs to
  call it.

Reduces the code size of the standard library (+assertions build) by
~149k.

Addresses rdar://problem/45489388.
2018-10-25 20:35:27 -07:00
Rintaro Ishizaki
07172f47c3 [CodeCompletion] Don't try to resolve generic env for extension in inactive block
Fixes code-completion crash in validateExtension().

When code completion happens, it tries to validate decl contexts. If
it's in an extension in inactivec conditional block, the extension
haven't been bound to nominal type. That used to cause crash because its
GenericParams hasn't been set.

rdar://problem/45275782
https://bugs.swift.org/browse/SR-9001
2018-10-26 10:08:51 +09:00
Mark Lacey
958ee1a82b Add more type checker performance tests.
Also move one from fast to slow based on the fact that it wasn't
representative of the original issue (which was an expression that
didn't typecheck successfully).
2018-10-25 16:21:17 -07:00
Kuba (Brecka) Mracek
925c93a37f Re-enable tsan.swift and witness_table_lookup.swift test on Linux, which is now passing after r345174 (#20036) 2018-10-25 12:47:10 -07:00
Pavel Yaskevich
70d9b2dfa3 [CSDiagnostics] Fix requirement source lookup to support initializers
Resolves: rdar://problem/45470505
2018-10-22 18:32:32 -07:00
Mark Lacey
5b4a332b0e [ConstraintSystem] Sort the designated types based on actual argument types.
In cases where we have multiple designated types, sort the types that
were designated for this operator based on any information we can
gather about actual argument types at usage sites.

We can consider extending this further in a future commit to ignore
designated types when we have concrete type information that we are
confident of.
2018-10-21 13:14:27 -07:00
Mark Lacey
9a703f584d Update a few more tests to enable -solver-enable-operator-designated-types when possible.
Add the following to all the expression type checker performance tests
that do not regress as a result:

- `-swift-version 5`
- `-solver-disable-shrink`
- `-disable-constraint-solver-performance-hacks`
- `-solver-enable-operator-designated-types`

This is a follow-up to 6de03f709f, where
these should have been included.
2018-10-21 11:47:18 -07:00
Mark Lacey
6de03f709f Update tests to enable -solver-enable-operator-designated-types when possible.
Add the following to all the expression type checker performance tests
that do not regress as a result:

- `-swift-version 5`
- `-solver-disable-shrink`
- `-disable-constraint-solver-performance-hacks`
- `-solver-enable-operator-designated-types`
2018-10-21 10:50:33 -07:00