Commit Graph

7628 Commits

Author SHA1 Message Date
Slava Pestov
305a1e42b6 RequirementMachine: Update some tests to pass with -requirement-machine-inferred-signatures=verify 2022-03-14 12:33:18 -04:00
Slava Pestov
6a74ad7065 RequirementMachine: Drop GSB compatibility hack involving ErrorTypes
Another hack we can remove now that 'verify' mode skips checking if
there was a conflict.
2022-03-14 12:33:18 -04:00
Slava Pestov
226d2c89a0 RequirementMachine: Disable verification in a few highly-invalid compiler_crashers where it's not useful 2022-03-14 12:33:18 -04:00
Slava Pestov
a61f67a0e8 RequirementMachine: Hack to allow protocol typealiases to appear in associated type inheritance clauses
If you have something like

    protocol P {
      typealias A = C

      associatedtype T : A
    }

    class C {}

Then ::Structural resolution of 'A' in the inheritance clause will
produce a DependentMemberType 'Self.A'. Check for this case and
attempt ::Interface resolution to get the correct underlying type.

Fixes rdar://problem/90219229.
2022-03-14 12:33:18 -04:00
nate-chandler
58b414d211 Merge pull request #41781 from nate-chandler/lexical_lifetimes/di-moves-end_borrow
[DI] Fixup alloc_box borrow scope ends.
2022-03-11 13:15:47 -08:00
Nate Chandler
05e643ba04 [DI] Fixup alloc_box borrow scope ends.
After https://github.com/apple/swift/pull/40793, alloc_boxes all have
their lifetimes protected by a lexical borrow scope.  In that PR, DI had
been updated to see through begin_borrow instructions from a project_box
to a mark_uninitialized.  It did not, however, correct the end_borrow
instructions when destroy_values of mark_uninitializeds were replaced
with destroy_addrs of project_boxes.  That is done here.

In a bit more detail, in the following context

    %box = alloc_box
    %mark_uninit = mark_uninitialized %box
    %lifetime = begin_borrow [lexical] %mark_uninit
    %proj_box = project_box %lifetime

When it is not statically known whether a field is initialized, we are
replacing the instruction

      // before
      destroy_value %mark_uninit
      // after

with the following diamond

      // before
      %initialized = load
      cond_br %initialized, yes, no

    yes:
      destroy_addr %proj_box
      br bottom

    no:
      br bottom

    bottom:
      dealloc_box %box
      br keep_going

    keep_going:
      // after

Doing so is problematic, though, because by SILGen construction the
destroy_value is always preceded by an end_borrow:

      end_borrow %lifetime
      destroy_value %mark_uninit

Previously, that end_borrow remained above the

      %initialized = load

instruction in the above.  That was invalid because the the newly
introduced

      destroy_addr %proj_box

was a use of the borrow scope (%proj_box is a projection of the
begin_borrow) and consequently must be within the borrow scope.

Note also that it would not be sufficient to simply emit the diamond
before the end_borrow.  The end_borrow must come before the destruction
of the value whose lifetime it is protecting (%box), and the diamond
contains the instruction to destroy that value (dealloc_box) in its
bottom block.

To resolve this issue, just move the end_borrow instruction from where
it was to before the dealloc box.  (This is actually done by moving it to
the top of the diamond's "continue" block prior to the emission of that
dealloc_box instruction.)

rdar://89984216
2022-03-11 08:29:34 -08:00
Slava Pestov
1ff3fda53f Merge pull request #41757 from slavapestov/protocol-self-reference-fixes
Sema: Fix a couple of issues related to variance of protocol 'Self'
2022-03-09 23:07:46 -05:00
Slava Pestov
599bb79933 Sema: Generalize the 'invariant Self requirement' check to handle a related case
There are three kinds of invariant 'Self' uses here:

- 'Self' appears as the left hand side of a same-type requirement between type parameters
- 'Self' appears as a structural component of the right hand side of a concrete type requirement
- 'Self' appears as a structural component of the right hand side of a superclass requirement

My previous fix only handled the first case. Generalize it to handle all three.

Fixes rdar://problem/74944514.
2022-03-09 18:50:14 -05:00
Robert Widmann
512ebc52a6 Merge pull request #41743 from CodaFi/existential-dread 2022-03-09 15:12:29 -08:00
Robert Widmann
0aead2818c Add a Compiler Crasher
The problem is that we currenly cannot represent the generic signature of
values of type `any P<some P>`. This is because we wind up producing

<Self where Self : P, Self.T == (some P)>

What we'd like to do in the future is erase the errant (some P) with
a fresh generic parameter and keep a substitution map on the side that
records the opaque type constraint. Something like

<Self, Opaque1 where Self : P, Opaque1 : P, Self.T == Opaque1> where Opaque1 == (some P)
2022-03-09 11:49:38 -08:00
eeckstein
44a9753eea Merge pull request #41703 from eeckstein/simplify-linkage
Stabilize and simplify SIL linkage and serialization
2022-03-09 18:48:14 +01:00
Hamish Knight
187e6f3472 [test] Disable ArrayTrapsObjC.swift for backdeployment
rdar://89821303
2022-03-09 16:13:00 +00: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
Pavel Yaskevich
966f58f044 [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2022-03-08 01:13:44 -08:00
Holly Borla
70197c8557 Merge pull request #41693 from hborla/any-in-diagnositcs
[Diagnostics] Print `any` in diagnostics.
2022-03-06 10:09:12 -08:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Jonathan Grynspan
5d729845ce Merge pull request #41669 from grynspan/jgrynspan/SR-15938-imagebase-linkage
[SR-15938] Error when referencing #dsohandle in a Swift test on Windows
2022-03-04 16:35:05 -05:00
Jonathan Grynspan
34a4d66481 [SR-15938] Error when referencing #dsohandle in a Swift test on Windows 2022-03-04 12:25:49 -05:00
Slava Pestov
06dabe91ec Merge pull request #41630 from slavapestov/rqm-abstract-signatures-fixes
RequirementMachine: Fix test failures with -requirement-machine-abstract-signatures=verify
2022-03-02 22:13:45 -05:00
Slava Pestov
73faf4faec Enable -requirement-machine-abstract-signatures=on in a couple of tests
There is an edge case where the Requirement Machine produces a different
minimal signature than the GenericSignatureBuilder:

  protocol P {
    associatedtype X where X == Self
  }

  class C : P {
    typealias X = C
  }

  <T where T : P, T : C>

The GenericSignatureBuilder produces <T where T == C> and the Requirement
Machine produces <T where T : C>. The new interpretation makes more sense
with the 'concrete contraction' pre-processing pass that is done now.

The GenericSignatureBuilder's interpretation is slightly more correct,
however the entire conformance is actually invalid if the class is not
final, and we warn about it now.

I'm going to see if we can get away with this minor ABI change without
breaking anything.
2022-03-02 17:07:33 -05:00
Slava Pestov
345185f32d Sema: Fix isOverrideBasedOnType() to check protocol generic signatures
This avoids feeding invalid type parameters to the Requirement Machine
when a protocol requirement looks similar to a protocol requirement in
the inherited protocol but has an incompatible type.

Fixes https://bugs.swift.org/browse/SR-15826 / rdar://problem/89641535.
2022-03-02 14:18:15 -05:00
Slava Pestov
a9e35ed0c0 Add regression test for https://bugs.swift.org/browse/SR-14668 2022-02-25 22:32:00 -05:00
Slava Pestov
8e09ba8b45 RequirementMachine: Introduce 'concrete contraction' pre-processing pass before building rewrite system
See the comment at the top of ConcreteContraction.cpp for a detailed explanation.

This can be turned off with the -disable-requirement-machine-concrete-contraction
pass, mostly meant for testing. A few tests now run with this pass both enabled
and disabled, to exercise code paths which are otherwise trivially avoided by
concrete contraction.

Fixes rdar://problem/88135912.
2022-02-25 11:48:38 -05:00
Slava Pestov
ab6584cf05 Merge pull request #41545 from slavapestov/non-final-class-self-same-type-requirement-conformance
Sema: Warn about non-final classes conforming to protocols with a same-type requirement on 'Self'
2022-02-25 10:46:14 -05:00
Slava Pestov
561e63552f Pass -requirement-machine-protocol-signatures=off in three tests 2022-02-24 15:09:53 -05:00
Slava Pestov
c98ddb99e2 Sema: Warn about non-final classes conforming to protocols with a same-type requirement on 'Self'
This is unsound because it breaks covariance of protocol conformances
on classes. See the test case and changelog entry for details.
2022-02-24 14:23:00 -05:00
Slava Pestov
d4b303e812 Merge pull request #41533 from slavapestov/unqualified-lookup-protocol-typealias-cycle-fix
Revert "Sema: Don't resolve protocol typealiases to DependentMemberTypes"
2022-02-24 11:24:29 -05:00
Slava Pestov
54bf6adb58 Revert "Sema: Don't resolve protocol typealiases to DependentMemberTypes"
This reverts commit 1dd79ae3db.

Fixes rdar://problem/88230388.
2022-02-23 23:11:05 -05:00
Mike Ash
61cc49ed06 Merge pull request #41528 from mikeash/fix-Assert-debugPrecondition-off.swift
Mark stdlib/Assert-debugPrecondition-off.swift as REQUIRES: executable_test.
2022-02-23 16:04:57 -05: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
Mike Ash
039eb10dab Mark stdlib/Assert-debugPrecondition-off.swift as REQUIRES: executable_test. 2022-02-23 12:16:35 -05:00
Pavel Yaskevich
d7254b9100 Merge pull request #41505 from xedin/rdar88256059-test
[TypeChecker] NFC: Add a test-case for rdar://88256059
2022-02-22 09:29:35 -08:00
Guillaume Lessard
544cd889c8 Merge pull request #41503 from glessard/sr15433
[test] return early when test cannot succeed
2022-02-22 10:03:59 -07:00
Karoy Lorentey
0704746bfa Merge pull request #41445 from lorentey/unconditional-debugPrecondition
[stdlib] Add build option to enable _debugPrecondition in Release mode
2022-02-21 20:59:22 -08:00
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -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
Guillaume Lessard
4e3c1ea3ee [test] return early when test cannot succeed
- test requires Swift 5.7
- resolves rdar://89052037
2022-02-21 17:01:49 -07:00
Nate Chandler
f79f26f6ea [Test] Reenabled test.
Added flag to disable destroy hoisting to run line.  Destroy hoisting
will be disabled separately.

rdar://86271875
2022-02-21 08:05:48 -08:00
Anthony Latsis
b0043966cd Merge pull request #40269 from AnthonyLatsis/assoc-inference-system
AssociatedTypeInference: Initial refactoring of abstract type witness inference
2022-02-20 15:51:58 +03:00
Karoy Lorentey
5274295e3f [test] Update tests for new (conditional) _debugPrecondition behavior 2022-02-18 21:54:02 -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
Karoy Lorentey
7ce8544610 [StdlibUnittest] expectEqual: Use less opinionated argument names
Based on its argument names and messages, `expectEqual` and friends expects the expected value of the calculation being tested to be provided as its first argument, and the actual value as the second:

```
expectEqual(4, 2 + 2)
```

This does not always match actual use -- folks like myself find the opposite ordering far more natural:

```
expectEqual(2 + 2, 4)
```

`expectEqual` currently uses the `expected`/`actual` terminology in its failure messages, causing confusion and needless suffering.

Change `expectEqual`'s declaration and error messages to use a naming scheme that does not assume specific roles for the two arguments. (Namely, use `first`/`second` instead of `expected`/`actual`.)

An alternative way to solve this would be to use argument labels, as in `expectEqual(expected: 4, actual: 2 + 2)`, or to introduce some sort of expression builder scheme such as `expect(2 + 2).toEqual(2)`. These seem needlessly fussy and overly clever, respectively.
2022-02-16 14:00:54 -08:00
Slava Pestov
1665c57d52 Merge pull request #41381 from slavapestov/rqm-simplify-substitutions-records-projections
[RequirementMachine] Substitution simplification records projections
2022-02-16 16:08:13 -05:00
Slava Pestov
77d1063f2e Disable ArrayBridging test due to rdar://88637598 2022-02-16 14:21:43 -05:00
Alejandro Alonso
657c17fa39 Setup grapheme breaking tests 2022-02-15 17:16:36 -08:00
Alejandro Alonso
c0e1ef01f9 Fix backwards count of Indic graphemes 2022-02-15 15:28:37 -08:00
Anthony Latsis
4c68ecfdf5 TypeWitnessSystem: Add tests 2022-02-16 00:56:08 +03:00