Commit Graph

1081 Commits

Author SHA1 Message Date
Allan Shortlidge
903e68b289 NFC: Test derived Comparable conformances for enums with unavailable cases.
Also, add a FIXME to track improving the diagnostics when derivation of a
Comparable conformance is blocked by unavailable enum cases.
2023-07-31 17:26:34 -07:00
Allan Shortlidge
7996c5b30c Sema: Avoid decoding unavailable enum elements in derived Codable conformances.
The compiler derived implementations of `Codable` conformances for enums did
not take enum element unavailability into account. This could result in
unavailable values being instantiated at runtime, leading to a general
violation of the invariant that unavailable code is unreachable at runtime.
This problem is possible because synthesized code is not type checked; had the
conformances been hand-written, they would have been rejected for referencing
unavailable declarations inside of available declarations.

This change specifically alters derivation for the following declarations:
- `Decodable.init(from:)`
- `Encodable.encode(to:)`
- `CodingKey.init(stringValue:)`

Resolves rdar://110098469
2023-07-26 22:48:25 -07:00
Holly Borla
b746a034c4 [Distributed] Avoid cascading diagnostics when actorSystem is declared
explicitly.
2023-07-17 14:21:52 -07:00
Slava Pestov
1957bd6065 Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context' 2023-06-09 17:44:42 -04:00
Pavel Yaskevich
3b1f392d0a Merge pull request #65785 from angela-laar/fix-covariant-erasure-for-constrained-existentials
Fix covariant erasure for constrained existentials
2023-05-18 16:58:45 -07:00
Angela Laar
a9f1096839 [Generic Signature] Unify generic upper bound functions
Opened existentials should be erased to the dependent upper bound
if the dependent member can be reduced to a concrete type. This
allows the generic signature to support parameterized protocol types
and bound generic class types by producing a more specific constraint
instead of just a plain protocol or class.
2023-05-17 15:33:50 -07:00
Slava Pestov
e9e6a51c82 Unconditionally enable variadic generic types now that SE-0398 has been accepted 2023-05-15 23:32:52 -04:00
Anthony Latsis
3f629315a9 Merge pull request #65731 from AnthonyLatsis/always-print-any
ASTPrinter: Turn on explicit `any` printing for everything and remove the option to disable it
2023-05-16 03:27:36 +03:00
Angela Laar
5c818b3fd4 [Constraint System] Fix covariant erasure for constrained existentials
Constrained existentials should be type erased to an upper bound that is dependent on other type parameters.
2023-05-15 16:17:59 -07:00
Slava Pestov
4318a36be6 Sema: Availability checking for variadic generic types 2023-05-12 22:50:25 -04:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Slava Pestov
290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00
Slava Pestov
58822544bc RequirementMachine: Use Requirement::checkRequirement() to desugar conformance requirements 2023-04-05 23:42:17 -04:00
Slava Pestov
e635dd3a3a Sema: Generic parameter packs cannot witness associated type requirements 2023-04-05 23:42:16 -04:00
Allan Shortlidge
5da4e2df40 Sema: Allow unavailable decls to witness requirements in more conformances.
In https://github.com/apple/swift/pull/63898 conformance requirement
typechecking was relaxed to allow unavailable decls to witness conformance
requirements as long as the conforming nominal was also unavailable. However,
only nominals that were directly marked unavailable were accepted. Nominals
that are declared in unavailable scopes should also be allowed to have
unavailable wintesses.

Resolves rdar://107052715
2023-03-22 12:37:51 -07:00
Ellie Shin
ef321c9fd2 Allow @usableFromInline and @inlinable to package decls
Add tests for packgae inline
Add more package acl tests

Resolves rdar://104617133
2023-03-16 11:21:11 -07:00
Michael Gottesman
40449a6987 [move-only] Emit a clearer message around deinits.
Specifically:

1. Fix the error message so that when we say you can't have a deinit that a
deinit can be on a noncopyable type along side a class or an actor.

2. Even though we already error on @objc enums and say they cannot be
noncopyable, we did not emit an error on the deinit saying that @objc enums
cannot have a deinit. I put in a nice to have error just to make it even
clearer.

rdar://105855978
rdar://106566054
2023-03-12 14:47:34 -07:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Allan Shortlidge
9521764b18 Sema: Allow unavailable protocol witnesses in unavailable nominals or extensions.
Resolves rdar://99451416
2023-02-28 13:54:35 -08:00
Allan Shortlidge
b3403ff9fc Sema: Improve derived conformance diagnostics for actors.
Previously, actor declarations were identified by the diagnostics as classes.
2022-11-08 19:33:32 -08:00
Anthony Latsis
0ab77fb849 Gardening: Migrate test suite to GH issues (file names): decl 2022-09-18 17:54:58 +03:00
Anthony Latsis
4ee63da498 Gardening: Migrate test suite to GH issues: decl/protocol 2022-08-30 04:08:00 +03:00
Holly Borla
8713d78704 [PrintOptions] Print explicit 'any' in SIL. 2022-08-18 01:15:12 -04:00
Anthony Latsis
05fca9905d Merge pull request #59357 from AnthonyLatsis/cond-conf-overridden-assoc
ConformanceChecker: Don't record a type witness for an overridden associated type if...
2022-07-19 22:39:06 +03:00
Konrad `ktoso` Malawski
728c007fb9 [Distributed] Implement witnesses for sync or non-throw dist reqs
[Distributed] generic and inner test; without one edge case

[Distributed] fix distributed_thunk test; unsure about those extra hops, could remove later

[Distributed] Remove type pretending in getSILFunctionType; it is not needed

It seems our constant replacement in the earlier phases is enough, and
we don't need this trick at all.

[Distributed] Use thunk when calling cross-actor on DA protocols
2022-07-04 19:02:11 +09:00
Slava Pestov
63ac80ba30 Merge pull request #59786 from slavapestov/associated-type-inference-protocol-extension-fix
Sema: Check conditional requirements in inferTypeWitnessesViaValueWitnesses()
2022-06-29 20:47:18 -04:00
Slava Pestov
4473363844 Sema: Check conditional requirements in inferTypeWitnessesViaValueWitnesses()
Otherwise, a conditional conformance could not rely on a default
implementation in a protocol extension.

Fixes rdar://problem/91451771.
2022-06-29 12:54:07 -04:00
Becca Royal-Gordon
8c9a6ce0b4 Increase determinism of selector conflict errors
Refactor ObjC conflict diagnosis code to sort conflict data more thoroughly, filter out unwanted declarations earlier, and just generally behave in ways that are more likely to work correctly.

This change increases the determinism of the ordering of diagnostics and the selection of the “correct” declaration that the others are considered to conflict with, increasing my confidence that the diagnostics will work correctly in untested corner cases or if the compiler is refactored so that declarations are recorded in a different order. It also adds a new selection rule—@objc without vs. with explicit selector—that I believe will slightly improve the diagnostics we produce. And it replaces a lot of really dodgy-looking logic that may have only worked reliably when a conflict involved exactly two methods.
2022-06-28 18:15:54 -07:00
Konrad `ktoso` Malawski
22b20afce6 [Distributed] make witness be the distributed thunk 2022-06-27 17:08:55 +09:00
Anthony Latsis
15acfa9a5b Merge pull request #59535 from AnthonyLatsis/close-issues-1
Add regression tests to close some issues
2022-06-23 20:43:51 +03:00
Anthony Latsis
f6b39ae6ae Add regression test to close #52883 2022-06-22 22:17:33 +03:00
Konrad `ktoso` Malawski
60ef959fc0 adjust last tests 2022-06-22 09:43:45 +09:00
Anthony Latsis
85bb2e8df7 ConformanceChecker: Don't record a type witness for an overridden associated type if
the conformance to the corresponding inherited protocol
- originates in a superclass
- originates in a different module
- and the current conformance have mismatching conditional requirements

This can turn out badly in two ways:
- Foremost, we must not *alter* conformances originating in superclasses
  or other modules. In other cases, we may hit an assertion in an attempt
  to overwrite an already recorded type witness with a different one.
  For example, the recorded type witness may be invalid, whereas the
  other one---valid, and vice versa.
- If the current conformance is more restrictive, this type witness may
  not be a viable candidate for the overridden associated type.
2022-06-16 19:07:10 +03:00
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
de2394db4f Merge pull request #59246 from AnthonyLatsis/local-conformance-operator
Sema: Fix operator function witness lookup for local adoptees
2022-06-07 03:31:48 +03:00
Anthony Latsis
7a11b43058 Merge pull request #59271 from AnthonyLatsis/sr-2063
Add regression tests to close several fixed issues
2022-06-06 21:50:41 +03:00
Anthony Latsis
94796e03ff Add regression test to close #52588 2022-06-06 20:04:42 +03:00
Anthony Latsis
927d09915b Add regression test to close #52024 2022-06-06 05:39:54 +03:00
Anthony Latsis
0e9a3cb70a Add regression test to close #45389 2022-06-05 21:17:36 +03:00
Anthony Latsis
0772f68601 Sema: Fix operator function witness lookup for local adoptees
Operator function witnesses are looked up globally. However, an additional, qualified lookup is warranted if the conforming type is declared in a local context.
2022-06-04 14:03:43 +03:00
Doug Gregor
904a2ff64c Allow unavailable conformances to non-Sendaable protocols during contraction
Refusing to acknowledge unavailable conformances at this point in the
requirement machine doesn't allow us to make use of unavailable
conformances from unavailable contexts, something which code currently
depends on. Limit the new filtering behavior to `Sendable` conformances
where we need them, as a narrow fix for this regression. We'll revisit
the approach here later.

Fixes rdar://94154905.
2022-06-02 13:24:37 -07:00
Anthony Latsis
b2e2bab7e0 DiagnosticEngine: Print any in 'aka' types 2022-05-29 21:55:31 +03:00
Doug Gregor
c9c50b4ae0 [Requirement machine] Ignore unavailable conformances on superclass constraints.
When determining whether a superclass conforms to a particular protocol,
skip unavailable conformances. This way, we don't minimize away a
constraint that might only apply to subclasses of the specified
superclass.

Fixes rdar://91853658.
2022-05-27 13:09:15 -07:00
Pavel Yaskevich
ec0b836401 [CSFix] Check for constrained associated types via generic signature
Instead of checking for presence of `where` clause, let's use
requirement signature and check whether any of the requires are
anchored on a particular associated type.
2022-05-26 12:06:49 -07:00
Pavel Yaskevich
773ea6b10c [TypeChecker] Require a coercion if result of protocol member access would loose information
Accessing members on the protocol could result in existential opening and subsequence
result erasure, which requires explicit coercion if there is any loss of generic requirements.
2022-05-25 16:07:06 -07:00
Slava Pestov
ac74b845e5 Merge pull request #58513 from AnthonyLatsis/se-309-sil-opt
SE-0309: SILOptimizer fixes & reenable executable tests
2022-05-20 16:38:05 -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
Anthony Latsis
5dc483472c Supplement, relocate and reenable SE-0309 executable tests 2022-05-02 14:20:04 +03:00
Holly Borla
ccbfdbebea Merge pull request #42558 from hborla/se-0309-require-any
[Sema] Require `any` for SE-0309 existential types.
2022-04-22 13:37:22 -07:00