Commit Graph

805 Commits

Author SHA1 Message Date
Slava Pestov
0254c0ee7c RequirementMachine: Fix handling of unavailable Sendable conformances in concretizeNestedTypesFromConcreteParent()
We can't just ignore unavailable conformances because the
generic signature we're computing might itself be attached
to an unavailable declaration.

Until we get a proper fix, only drop unavailable conformances
to Sendable here.

Fixes rdar://problem/94305457.
2022-06-10 17:46:40 -04:00
Anthony Latsis
4bcb3713d0 Add regression test to close #56100 2022-06-05 21:59:10 +03:00
Doug Gregor
686655b61f Update expected diagnostics 2022-05-27 14:46:30 -07:00
Robert Widmann
663722d892 Parameterized Existential Types Are Enabled By Default
See https://forums.swift.org/t/accepted-se-0353-constrained-existential-types/57560
2022-05-25 09:50:36 -07:00
swift-ci
997ace439c Merge pull request #58562 from AnthonyLatsis/sr13589
Add regression test for #56024 crasher
2022-05-24 00:40:37 -07:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Slava Pestov
f39372b33d RequirementMachine: Turn off redundant requirement warnings by default and add -warn-redundant-requirements frontend flag 2022-05-10 01:49:56 -04:00
Slava Pestov
0111618c50 RequirementMachine: Perform concrete contraction on protocol requirement signatures 2022-05-09 21:21:35 -04:00
Robert Widmann
930827aeb2 Ban Nested some Types in Existentials
We would like to leave room in the language for `some` types in existential
constraints a la `any P<some Q>` to resolve as a part of the requirement
signature of a future generalized existential type. To that end, usages of
`some` types nested anywhere in the arguments of an existential will fail to
resolve.

rdar://92758884
2022-05-04 19:21:32 -07:00
Anthony Latsis
d470eaadad Add regression test for #56024 crasher 2022-05-01 06:21:48 +03:00
Alex Hoppen
f652a9d01a Merge pull request #42295 from ahoppen/pr/add-fixed-test-cases
[IDE][Sema] Add test cases for issues no longer occurring in the stress tester
2022-04-27 11:32:44 +02:00
Alex Hoppen
e0205f7586 [Sema] Add test case for SR-15497
SR-15497 is no longer happening in the stress tester. Add its test case to the test suite.

rdar://85602946
2022-04-22 09:50:24 +02:00
nate-chandler
45ec725e43 Merge pull request #42485 from nate-chandler/rdar85526916
[SILGen] Use opaque AP for ObjC-async returns.
2022-04-20 16:43:02 -07:00
Nate Chandler
4aff98ffb5 [SILGen] Use opaque AP for ObjC-async returns.
Previously, the AbstractionPattern that was used for the value
"returned" (i.e. via a completion handler) from ObjC mostly (but not
quite always) was "type".

The generated completion handler correctly (because this is required in
order to call _resumeUnsafeContinuation) reabstracted the block (e.g.
from @convention(block) to @substituted <T> () -> @out T for <()>).  The
callee of the ObjC function, however, loaded the function from the block
as if it were not reabstracted (e.g. () -> ()).

On most platforms, that happened to work.  On arm64e, that difference in
types caused in a difference in pointer signing, resulting in a failure
at runtime.

rdar://85526879
rdar://85526916
2022-04-20 10:42:45 -07:00
Anton Korobeynikov
121e28051a Force escaping all thin functions. Ensure types are always unique. 2022-04-20 10:34:45 +02:00
Saleem Abdulrasool
36c951d31e Revert "[DebugInfo] Ignore noescape bit for all @convention(c) pointers" 2022-04-19 18:09:23 -07:00
Anton Korobeynikov
b2dc6e5228 Unbreak the test 2022-04-18 22:43:57 +02:00
Slava Pestov
1bf248e374 Enable parameterized protocols by default, and add new staging flag for parameterized existentials 2022-04-06 17:30:10 -04:00
Slava Pestov
094130b9c7 RequirementMachine: Diagnose redundant concrete conformance requirements
A conformance requirement on a concrete type parameter is redundant if the
concrete type conforms to the protocol.

The replacement path for the conformance rule is based on a concrete
conformance rule introduced by the property map. Since the concrete
conformance rule is not associated with a requirement ID, this would
normally muffle the redundancy warning, because we don't want to
suggest removing a rule that depends on a non-redundant, non-explicit
rule.

However, concrete conformance rules don't actually appear in the
minimal signature, so skip them when computing the set of non-redundant,
non-explicit rules to ensure that the original conformance requirement
is still diagnosed as redundant.
2022-04-05 21:12:51 -04:00
Slava Pestov
8c47cd75fd Sema: The primary associated type list references existing associated types instead of declaring new ones 2022-04-03 22:03:49 -04:00
Anthony Latsis
62a2c9e265 Merge pull request #42137 from AnthonyLatsis/objc-optional-keypath
SILGen: Handle key paths with `@objc optional` property and subscript components
2022-04-02 13:53:25 +03:00
Slava Pestov
4068c9d707 Pass -requirement-machine-{protocol,inferred}-signatures=verify in remaining tests that fail due to diagnostics 2022-04-01 23:55:34 -04:00
Anthony Latsis
7b26e293ef Add regression test for https://bugs.swift.org/browse/SR-16076 2022-04-01 20:22:36 +03:00
Slava Pestov
01fea564fb RequirementMachine: Skip emitting diagnostics containing ErrorTypes 2022-04-01 01:04:54 -04:00
Slava Pestov
b4b873332f Update -requirement-machine-* flags in various tests
- Don't pass 'verify' since it's now the default
- Update tests where diagnostics changed in a correct way to pass 'on' instead
- Delete compiler_scale/explicit_requirements_perf.swift since it's not testing anything with the requirement machine
2022-03-31 15:57:36 -04:00
Slava Pestov
8ea633850c Add regression test for https://bugs.swift.org/browse/SR-10792 2022-03-29 23:01:48 -04:00
Slava Pestov
d40e30db27 Merge pull request #42017 from slavapestov/rqm-rule-length-heuristic
RequirementMachine: Tweak rule limit non-termination heuristic
2022-03-25 11:44:27 -04:00
Anthony Latsis
38e48ac15d TypeWitnessSystem: Disable by default 2022-03-25 08:45:54 +03:00
Slava Pestov
7d0215e6e0 RequirementMachine: Tweak rule limit non-termination heuristic
Add the length of the longest *initial* rule to the rule length limit
before comparing.

Fixes https://bugs.swift.org/browse/SR-16024.
2022-03-25 01:00:49 -04:00
Slava Pestov
2f727d6b47 RequirementMachine: Opaque archetype support (sort of)
Complete support is behind a flag, because it can result in a non-convergent
rewrite system if the opaque result type has a recursive conformance of its
own (eg, `some View` for SwiftUI's View protocol).

Without the flag, it's good enough for simple examples; you just can't have
a requirement that mentions a nested type of a type parameter equated to
the concrete type.

Fixes rdar://problem/88135291, https://bugs.swift.org/browse/SR-15983.
2022-03-17 17:45:59 -04: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
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
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
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
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
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08: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
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
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
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
Anthony Latsis
4c68ecfdf5 TypeWitnessSystem: Add tests 2022-02-16 00:56:08 +03:00