Commit Graph

561 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
c1bac12bb6 [CSSimplify] Fix warning check to account that "from" might be less optional than "to" type
While checking whether compiler needs to produce a checked cast warning,
account for the fact that "from" could be less optional than "to" e.g.
`0 as Any?`, so the difference has to be stored as a signed integer
otherwise it's going to underflow and result in a crash or infinite
recursion in the diagnostics.

Resolves: rdar://79523605
2021-06-21 16:38:04 -07:00
Alex Hoppen
c3ce40ddb6 [Sema] Use different solution vectors for ComponentSteps created by DependentComponentSplitterStep
Currently all `ComponentSteps` created by `DependentComponentSplitterStep` share the same `Solutions` vector. Because of this, the `ComponentStep`s might modify solutions created by previous `ComponentStep`s. Use different `Solutions` vectors for each `ComponentStep` to avoid sharing information between the `ComponentStep`s.

The concrete manifestation in the added test case is that the `Bar` overload gets added to `Solutions`, it’s score gets reduced by its `ComponentStep` original score, then the `Foo` overload gets added to `Solutions` and both solutions have their score decreased by the `OriginalScore` of `Foo`’s `ComponentStep`, causing `Bar`’s score to underflow.

Fixes rdar://78780840 [SR-14692]
2021-06-18 15:17:11 +02:00
Pavel Yaskevich
b83e250a37 [TypeChecker] NFC: Make test-case for rdar://19737632 more complex
Test-case as-is is producing conversion failure on Apple Silicon

Resolves: rdar://79414045
2021-06-16 15:56:04 -07:00
Pavel Yaskevich
8ab8b2e3e9 [CSApply] Load l-value before wrapping it in try expression
Just like `try?` other types of try - `try` and `try!` have to load
the value before using it.

Resolve: rdar://78102266
2021-05-24 10:23:32 -07:00
Pavel Yaskevich
6126bc06e0 [TypeChecker] NFC: Complicate perf test-case expression by adding more operators
This test has become flaky in different configurations due to a varying
number of available operator overloads, let's use more operators to make
sure that it's "too complex" regardless of configuration.

Resolves: rdar://77656775
2021-05-07 11:04:19 -07:00
Arnold Schwaighofer
b8b5edbf5c Disable test type_checker_perf/slow/rdar19737632.swift
It failed on a bot.

rdar://77656775
2021-05-07 08:10:05 -07:00
Pavel Yaskevich
2898b50b7f Revert "Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"" 2021-05-04 11:19:33 -07:00
Pavel Yaskevich
b12d57afac Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …" 2021-05-03 11:55:25 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
a21f323c16 Merge pull request #36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2021-04-26 12:19:55 -07:00
Pavel Yaskevich
71372bce67 [Diagnostics] Switch to use contextual purpose associated with locator
`ContextualFailure` is the main beneficiary of additional information
associated with `ContextualType` element because it no longer has to
query solution for "purpose" of the contextual information.

Resolves: rdar://68795727
2021-04-26 09:51:25 -07:00
Pavel Yaskevich
593bbab880 [TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts and ObjC literals
`PreCheckExpression` already skips calls, make sure that invalid subscripts,
dynamic subscript, ObjC literals preserve paren/tuple for an index/argument.

Resolves: rdar://61749633
2021-04-16 11:40:19 -07:00
Nate Chandler
1e45d161ab [Test] Disable a test on Linux at swift_test_mode_optimize_none.
Per @xedin, it's fine to leave this test disabled here.
2021-04-14 13:58:03 -07:00
Pavel Yaskevich
a4ced48946 [TypeChecker] NFC: Adjust "fast" test-case message to accommodate Amazon Linux 2 2021-04-13 10:32:25 -07:00
Pavel Yaskevich
ceeee459b4 Merge pull request #36631 from xedin/conformance-perf-experiment
[Perf][CSSimplify] Transfer conformance requirements of a parameter to an argument
2021-04-12 13:13:56 -07:00
Pavel Yaskevich
62c5e18710 [TypeChecker] NFC: Make test-case for rdar://74035425 more complex to avoid flaky behavior 2021-04-09 10:37:29 -07:00