Commit Graph

577 Commits

Author SHA1 Message Date
Pavel Yaskevich
c03e8b5544 Merge pull request #41899 from xedin/rdar-90419017
[Diagnostics] Ignore type mismatches related to synthesized arguments
2022-03-25 14:47:52 -07:00
Pavel Yaskevich
9d413b3668 Merge pull request #41939 from xedin/rdar-87407899
[Diagnostics] Fix out-of-bounds index while fixing argument mismatch
2022-03-22 22:46:54 -07:00
Pavel Yaskevich
b6c2b3edff [Diagnostics] Fix out-of-bounds index while fixing argument mismatch
Although the overload choice has two parameters, it doesn't
mean that there are exactly two arguments passed to it.

Resolves: rdar://87407899
2022-03-21 14:57:50 -07:00
Kavon Farvardin
9b1fcedf2f backtrack on part of SE-327 dealing with default-value exprs
This effectively reverts 6823744779

The blanket removal of isolation in default-value expressions had
unintented consequences for important workflows. It's still
a problem that needs to be addressed, but we need to be more precise
about the problematic situations.
2022-03-18 18:41:05 -07:00
Pavel Yaskevich
fc83c6fa68 [Diagnostics] Ignore type mismatches related to synthesized arguments
The main issue is the absence of the argument itself.

Resolves: rdar://90419017
2022-03-18 14:54:15 -07:00
Pavel Yaskevich
10324641f9 [TypeChecker] NFC: Restrict multi-statement closure + simd test-case to macOS
Resolves: rdar://90445018
2022-03-17 12:10:31 -07:00
Pavel Yaskevich
839b483f1b Merge pull request #41824 from xedin/rdar-85516390
[CSDiagnostics] Contextual failure could result in optional chain hav…
2022-03-16 10:33:39 -07:00
Pavel Yaskevich
5331e276d5 Merge pull request #41730 from xedin/se-0326-solve-pattern-bindings-via-conjunctions
[SE-0326] Re-enable multi-statement closure inference by default
2022-03-15 13:21:03 -07:00
Pavel Yaskevich
6fb5c3042b [CSDiagnostics] Contextual failure could result in optional chain having non-optional type
Fixes a crash during diagnostics by not assuming that optional chain
would always produce an optional type, which is not true because in
error scenarios it could get assigned an invalid type from context.

Resolves: rdar://85516390
2022-03-15 13:14:48 -07:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Pavel Yaskevich
5c3fb222e1 [CSClosure] Explode pattern binding declarations into conjunctions
`one-way` constraints disable some optimizations related to component
selection because they imply strict ordering. This is a problem for
multi-statement closures because variable declarations could involve
complex operator expressions that rely on aforementioned optimizations.

In order to fix that, let's move away from solving whole pattern binding
declaration into scheme that explodes such declarations into indvidual
elements and inlines them into a conjunction.

For example:

```
let x = 42, y = x + 1, z = (x, test())
```

Would result in a conjunction of three elements:

```
x = 42
y = x + 1
z = (x, test())
```

Each element is solved indepedently, which eliminates the need for
`one-way` constraints and re-enables component selection optimizations.
2022-03-08 21:37:40 -08:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Pavel Yaskevich
c22649e050 Merge pull request #41504 from xedin/rdar-84580119
[CSDiagnostics] Look through l-value conversions when mismatch is in …
2022-02-23 09:16:38 -08:00
Pavel Yaskevich
874d0fbe8f [TypeChecker] NFC: Add a test-case for rdar://88256059 2022-02-21 16:34:53 -08:00
Pavel Yaskevich
bf820c5dab [CSDiagnostics] Look through l-value conversions when mismatch is in subscript setter
`repairFailures` needs a special case when l-value conversion is
associated with a result type of subscript setter because otherwise
it falls through and treats result type as if it's an argument type,
which leads to crashes.

Resolves: rdar://84580119
2022-02-21 16:32:25 -08:00
Slava Pestov
1784aee148 Add '-requirement-machine-protocol-signatures=verify -requirement-machine-inferred-signatures=verify' to a few validation tests 2022-02-17 19:40:58 -05:00
Philippe Hausler
e675b310f8 [SE-0329] Clock/Instant/Duration (#40609)
* [WIP] Initial draft at v2 Clock/Instant/Duration

* Ensure the literal types for _DoubleWide are able to be at least 64 bits on 32 bit platforms

* static cast timespec members to long

* Remove runtime exports from clock functions

* Export clock functions in implementations as they are in headers

* Clean up internal properties by adding leading underscores, refine availability to a TBD marker macro, and break at 80 lines to match style

* Shift operators to concrete Instant types to avoid complexity in solver resolution

* Adjust diagnostic note and error expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Update stdlib/public/Concurrency/TaskSleep.swift

Co-authored-by: Karoy Lorentey <klorentey@apple.com>

* [stdlib][NFC] Remove trailing whitespace

* [stdlib] Remove _DoubleWidth from stdlib's ABI

* [stdlib] Strip downd _DoubleWidth to _[U]Int128

* Additional adjustments to diagnostic notes and errors expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Disable type checker performance validation for operator overload inferences (rdar://33958047)

* Decorate Duration, DurationProtocol, Instant and clocks with @available(SwiftStdlib 9999, *)

* Restore diagnostic ambiguity test assertion (due to availability)

* Add a rough attempt at implementing time accessors on win32

* Remove unused clock id, rename SPI for swift clock ids and correct a few more missing availabilities

* remove obsolete case of realtime clock for dispatch after callout

* Use the default implementation of ~ for Int128 and UInt128

* Ensure diagnostic ambiguitiy applies evenly to all platforms and their resolved types

* Restore the simd vector build modifications (merge damage)

* Update to latest naming results for Instant.Duration

* Updates to latest proposal initializers and accessors and adjust encoding/decoding to string based serialization

* Update availability for Clock/Instant/Duration methods and types to be 5.7

* Correct *Clock.now to report via the correct runtime API

* Ensure the hashing of Duration is based upon the attoseconds hashing

* Avoid string based encoding and resort back to high and low bit encoding/decoding but as unkeyed

* Adjust naming of component initializer to use suffixes on parameters

* Duration decoding should use a mutable container for decoding

* fix up components initializer and decode access

* Add platform base initializers for timespec and tiemval to and from Duration

* Add some first draft documentation for standard library types Duration, DurationProtocol and InstantProtocol

* Another round of documentation prose and some drive-by availability fixes

* InstantProtocol availability should be 5.7

* Correct linux timeval creation to be Int and not Int32

Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2022-02-17 09:32:46 -08:00
Slava Pestov
5fa5ff7ce1 RequirementMachine: Update tests for protocol typealiases 2022-02-13 09:50:16 -05:00
Kavon Farvardin
13dd3d9ecf have the inferred isolation for properties change only in Swift 6
This patch delays the removal of redundant isolation for inferred
global-actor isolation to Swift 6 too, since we only warn about it
changing in Swift 5. Otherwise, only isolation that is a byproduct
of inference no longer needs an await, which will probably confuse
people.

This change is with respect to SE-327, which argues that the
non-static stored properties of ordinary structs do not need
global-actor isolation.
2022-02-04 14:43:12 -07:00
Kavon Farvardin
19bdfb1172 In a property-wrapper, global-actor isolation remains on wrappedValue
If a struct is a property-wrapper, then global-actor isolation
still applies to the `wrappedValue`, even if it's a stored property.
This is needed in order to support the propagation of global-actor
isolation through the wrapper, even when the programmer has opted
to use a stored property instead of a computed one for the
`wrappedValue`. Since this propagation is a useful pattern, I think
this exception is reasonable.
2022-02-04 14:41:49 -07:00
Pavel Yaskevich
48ffeddbc7 [CSApply] Result coercion check should always use resolved type
`shouldCoerceToContextualType` used `solution.getType(ASTNode)`
which returns a type that has type variables in it. To properly
check whether result type needs a coercion it has to be resolved
first which is done via `solution.getResultType(ASTNode)`.

Resolves: rdar://88285682
2022-01-31 14:42:27 -08:00
Pavel Yaskevich
3b381f7876 [TypeChecker] NFC: Add a slow perf test related to operator >= 2022-01-13 12:13:16 -08:00
Pavel Yaskevich
fe9224d6a8 [TypeChecker] NFC: Add a test-case for mixed SwiftUI + multi-statement closures
This test-case used to crash with multi-statement closure inference
enabled in result builder contexts.
2021-12-26 21:16:27 -08:00
Pavel Yaskevich
f642c3efc8 [PreCheck] Don't use value declared in closure as outer candidate if it's validated
With multi-statement closure inference enabled "outer candidates"
hack needs to be careful with its use of `isInvalid()` because some
of the declarations lookup finds might be coming from a multi-statement
closure that being type-checked, such declarations have to be avoided
as candidates, otherwise calling `isInvalid` on them results in a circular
type-checking.

Resolves: rdar://85843677
2021-12-06 16:47:56 -08:00
Pavel Yaskevich
9649e74490 Merge pull request #40335 from xedin/atmpt-3-fix-flaky-test
[TypeChecker] NFC: Scope down per test-case for rdar://74035425
2021-11-30 15:47:15 -08:00
Kuba (Brecka) Mracek
34b45cbcc2 Add a crash reproducer for rdar://85843677 (#40327) 2021-11-30 13:50:49 -08:00
Pavel Yaskevich
053c874047 [TypeChecker] NFC: Scope down per test-case for rdar://74035425
Remove some literals from the test-case to prevent it from randomly
failing in some CI configurations.

Resolves: rdar://85267603
2021-11-30 10:29:57 -08:00
Pavel Yaskevich
14939cf467 [CSGen] Rework nil-coalescing operator handling in LinkedExprAnalyzer
Allow `LinkedExprAnalyzer` to capture `??` operator and walk into
its arguments because they could have valuable type information,
but don't attempt to favor or link operators if `??` is present in a chain.

Resolves: rdar://85277993
2021-11-16 18:00:11 -08:00
Pavel Yaskevich
5422bb884c [TypeChecker] NFC: Allow perf test-case for rdar://74035425 to run only on macOS
Resolves: rdar://85267603
2021-11-10 14:59:11 -08:00
Holly Borla
b3ad77f21c [Test] Add a few more + operands to a type checker perf test to exhibit
exponential behavior.

Binding value types early allows the previous version of this test
to compile, but the performance still doesn't scale with a few more
operands in the + chain.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
4799acfb20 [CSBindings] Attempt a type variable early if it's constrained by a struct/enum type
If a type variable has a subtype binding which came from a conversion/subtype/equality
constraint to a struct or enum (expect to `AnyHashable`, `Unsafe{Mutable}RawPointer`),
attempt it early because that type is the only choice which is not going to fail such
constraint.

For example, in cases like `$T argument convertible to Int` type variable could
only be bound to `Int`, `Int!`, or `@lvalue Int` to satisfy that constraint, so
it would make sense to attempt to bind it to `Int` early if it doesn't represent
a result of a member lookup (that's how IUO and/or `@lvalue` could be inferred)`
and doesn't have any direct disjunction associated with it e.g. for coercion or
optional matching.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
609841710f [ConstraintLocator] Allow simplification of constructor member with overloaded base
`init` calls to redeclared types would end up diagnosed as ambiguity,
so locator simplification needs to account for the fact that "base"
of constructor might be overloaded type reference.

Resolves: rdar://84879566
2021-11-05 16:44:07 -07:00
Pavel Yaskevich
573ae9bcac Merge pull request #40047 from xedin/rdar-83056143
[Diagnostics] A tailored diagnostic for Double<->CGFloat conversion via optional chaining
2021-11-04 16:14:58 -07:00
Pavel Yaskevich
ba9f6a24dd [TypeChecker] NFC: Add a test-case for rdar://83666783 2021-11-03 20:54:10 -07:00
Pavel Yaskevich
d72871c0e3 [Diagnostics] Coercion warning shouldn't assume that IUO is always optional
In situations like `_ = ... as! Bool!` the `to` type could either
be represented by an optional (default) or unwrapped. Coercion warnings
cannot assume that `to` (even though its IUO) is always represented
as an optional type.

Resolves: rdar://83072606
2021-11-02 13:42:11 -07:00
Holly Borla
4fc5830d10 [Test] Complicate a "fast" type checker test to make it slow.
This test only happened to be under the constraint system thresholds,
but the performance was not fast. Add a few operands to the + chain,
and disable shrink to push the solver past the performance thresholds.
2021-10-21 15:43:30 -07:00
Pavel Yaskevich
55a75ed89b [TypeChecker] NFC: Add a test-case for rdar://80630127 2021-10-14 13:07:12 -07:00
Holly Borla
2032da0443 [Test] Add type checker performance tests using description(with:) and
count(where:).
2021-09-22 13:33:44 -07:00
Pavel Yaskevich
20431b9dc6 [ConstraintSystem] Fix incorrect type-check of IUO pattern bindings
Patterns associated with `PatternBindingDecl`s have to be type-checked
in pattern binding context. Not doing so might result in spurious errors.
2021-09-02 10:17:09 -07:00
Pavel Yaskevich
c1269883b8 [ConstraintSystem] Allow IUO types to be unrelated while forming a disjunction
Detect situations when type of a declaration hasn't been resolved yet
(one-way constraints would use a type variable to represent a type of IUO pattern),
and use additional type variable and a constraint to represent an
object type of a future optional type.

Resolves: SR-14893
Resolves: rdar://80271666
2021-08-30 11:59:43 -07:00
Frederick Kellison-Linn
16a4031c32 [tests] Update tests with modified diagnostics 2021-08-19 14:53:34 -04:00
Pavel Yaskevich
befe4bd2ab Revert "[CSGen] Don't apply one-way requirement to typed patterns" 2021-07-20 14:35:49 -07:00
Pavel Yaskevich
b60c82610c Merge pull request #38328 from xedin/rdar-79657350
[Diagnostics] Diagnose ambiguous solutions with warnings like regular…
2021-07-09 22:52:36 -07:00
Pavel Yaskevich
66b1149abd [CSGen] Don't apply one-way requirement to typed patterns
Typed patterns are represented by a name and a fixed contextual
type, let's not use intermediary type variable and one-way constraint
as its type because that variable would be bound right away to
contextual type. Also setting type of a variable declaration
to a type variable when contextual type is IUO doesn't play well
with overload resolution because it expects an optional type for
declarations with IUO attribute.

Resolves: rdar://80271666
2021-07-09 14:50:17 -07:00
Pavel Yaskevich
d1e12785ed [Diagnostics] Diagnose ambiguous solutions with warnings like regular ambiguities
If solutions either have no fixes at all or all of the are warnings,
let's use `diagnoseAmbiguity` to diagnose such cases as-if there are
no fixes at all.

Resolves: rdar://79657350
2021-07-08 22:06:12 -07:00
Pavel Yaskevich
d08b2d5930 Merge pull request #37957 from xedin/rdar-79414045
[TypeChecker] NFC: Make test-case for rdar://19737632 more complex
2021-06-28 10:04:29 -07:00
Holly Borla
30ec896bcd [NFC] Add a fast type checker test for rdar://74853403. 2021-06-25 11:23:44 -07:00
Pavel Yaskevich
9733fb7562 Merge pull request #38045 from xedin/rdar-79268378
[Diagnostics] Adjust `Self` conformance check to find non-decl overload choices
2021-06-23 12:19:28 -07:00
Alex Hoppen
e5dc347df7 Merge pull request #37964 from ahoppen/pr/solutions-scoring
[Sema] Use different solution vectors for `ComponentStep`s created by `DependentComponentSplitterStep`
2021-06-23 18:56:06 +02:00
Pavel Yaskevich
be6e2fad8c [Diagnostics] Adjust Self conformance check to find non-decl overload choices
Use `findSelectedOverloadFor` instead of `findResolvedMemberRef`
to cover cases where member is found via base type unwrap, otherwise
conformance constraint would be re-inserted but never re-attempted
which results in a compiler crash.

Resolves: rdar://79268378
2021-06-22 15:32:51 -07:00