Commit Graph

20126 Commits

Author SHA1 Message Date
Pavel Yaskevich
aef8306747 [TypeChecker] Teach declaration type-checking about LeaveClosureBodyUnchecked flag
Propagate `LeaveClosureBodyUnchecked` flag from `typeCheckASTNodeAtLoc`
down to declaration checker to skip checking closures associated with
pattern binding entry initializers. This is no-op until multi-statement
inference becomes enabled by default.
2021-12-03 11:08:04 -08:00
Pavel Yaskevich
d7984f4453 [ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location
could bw inferred from a body of a multi-statement closure (when inference
is enabled), so we need to give closure a chance to run before attemtping
a hole for such positions in diagnostic mode.
2021-12-03 10:57:42 -08:00
Pavel Yaskevich
4cd404d020 [MiscDiagnostics] Introduce a base class for diagnostic walkers
Put some common logic related to local declaration to the base
class and refactor other walkers to use it instead of `ASTWalker`.
2021-12-03 10:57:33 -08:00
Pavel Yaskevich
f258a77dfb [Sema/CodeCompletion] Leave complex closure bodies unchecked
Preserve pre SE-0326 for code completion, so it could be ported
gradually.
2021-12-03 10:57:20 -08:00
Pavel Yaskevich
dcf80e62d0 [PreCheck] Avoid patterns that appear in closures when multi-statement inference is enabled
Scope down previous check to avoid walking into patterns that appear
in multi-statement closures if the inference is enabled.
2021-12-03 10:56:55 -08:00
Pavel Yaskevich
9bd603bfc9 [Diagnostics] Apply "unhandled throw" diagnostic for for-in loop in closures
Extract diagnostic into a method and use it while type-checking
`for-in` in top-level code and in closures.
2021-12-03 10:56:32 -08:00
Pavel Yaskevich
248316536b [CSClosure] Warn about defer being the last element in the closure body 2021-12-03 10:56:07 -08:00
Pavel Yaskevich
77ab650f59 [TypeChecker/Constness] Diagnostics: Walk into multi-statement closures when inference is enabled
When multi-statement closure inference is enabled it's body is
type-checked together with enclosing context, so they could be
walked directly just like single-expressions ones.
2021-12-03 10:55:54 -08:00
Pavel Yaskevich
0e6e058e7c [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-12-03 10:54:07 -08:00
Pavel Yaskevich
46ff410a23 [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-12-03 10:53:50 -08:00
Pavel Yaskevich
b337360d63 [Sema] DebuggerTestingTransform: avoid re-using AST nodes in generated code
While building a closure to inject `checkExpect` code, clone member
references associated with assignment. Re-using AST nodes is generally
invalid. This is visible with multi-statement closure inference enabled,
because the body is type-checked together with enclosing context
and both elements end up sharing `DeclRefExpr` and `MemberRefExpr`s.
2021-12-03 10:53:40 -08:00
Slava Pestov
e087704424 Merge pull request #40382 from slavapestov/disable-rawrepresentable-enum-equal-synthesis
Sema: Narrow down the derivation of == for RawRepresentable enums to non-resilient modules
2021-12-03 13:46:11 -05:00
Doug Gregor
91fb149faf Merge pull request #40388 from DougGregor/swift-6-stricter-concurrency-checking
Swift 6 stricter concurrency checking
2021-12-03 08:40:46 -08:00
Alexis Laferrière
8bfaab95c4 Merge pull request #40380 from xymus/fix-non-linear-trc-building
[Sema] Use the most precise TRC to extend when building them lazily
2021-12-03 08:16:50 -08:00
Doug Gregor
5a6f58e686 Teach witness matching to apply minimal/strict diagnostics rules.
This downgrades some errors to warnings in Swift 5 mode, and ensures that
we diagnose all conditions in Swift 6 mode.
2021-12-02 22:24:09 -08:00
Xi Ge
dde843c04d Merge pull request #40377 from nkcsgexi/const-propery-wrapper
sema: always record fix for mismatched constness.
2021-12-02 19:21:17 -08:00
Doug Gregor
43ce118340 Simplify override isolation checking.
Improve the equality check for actor isolation to prevent differences
between "unsafe" global actor and global actor isolation from causing
inequality. The operation here is about conceptual equality, not
precise storage semantics. This allows us to simplify override
isolation checking and, likely, other places I haven't seen yet.
2021-12-02 18:26:07 -08:00
Alexis Laferrière
3401ebcf51 [Sema] Don't insert an @_spi on imports for clang SPIs
This attribute is no more needed as we now fast-track accepting all
Objective-C SPIs at access control.

rdar://85617355
2021-12-02 15:54:48 -08:00
Doug Gregor
56b565b113 Merge pull request #40371 from DougGregor/concurrency-function-type-conversions-as-warnings
Downgrade concurrency-related function type errors in existing code
2021-12-02 15:22:43 -08:00
Doug Gregor
b61d98e61c Eliminate unprincipled unsafe global actor override behavior. 2021-12-02 15:18:59 -08:00
Holly Borla
47b375fb3f Merge pull request #40361 from hborla/enable-structural-opaque-types
[SE-0328] Enable structural opaque result types.
2021-12-02 15:00:18 -08:00
Slava Pestov
2256c803a2 Sema: Narrow down the derivation of == for RawRepresentable enums to non-resilient modules
This change was originally introduced in https://github.com/apple/swift/pull/36752.

The problem occurs in the following scenario:

- New compiler with this change is used to build a dylib and swiftinterface
  file for module A, which defines a RawRepresentable enum type E.

- Module B imports module A and references == on two E instances.

- The module B is run against a dylib of module A built with the old compiler.

At this point, module B will not link (or run) because the symbol for E.==
is not present in the old dylib for A.

The only real solution here is to disable this new optimization when
building a module for -enable-library-evolution, unfortunately.

In the future, we could make the derived E.== symbol @_alwaysEmitIntoClient.
However today, synthesized declarations cannot be @_alwaysEmitIntoClient
because they do not have source text that can be emitted into the
swiftinterface file. One day, we might gain the ability to print Exprs as
source text that parses back in, at which point we could allow synthesized
declarations to be @_alwaysEmitIntoClient.

Fixes rdar://problem/84912735 and rdar://problem/82919247.
2021-12-02 17:58:16 -05:00
Alexis Laferrière
28d504dd31 [Sema] Use the most precise TRC to extend when building them lazily
This fixes an issue reported with emit-module-separately where the
compiler reports false-errors on availability.

rdar://85472278
2021-12-02 14:29:52 -08:00
Xi Ge
3377591b3c sema: always record fix for mismatched constness.
Also, this commit has added a test for using _const values in property wrapper.
2021-12-02 12:19:41 -08:00
Doug Gregor
30c5cf2ab3 In Swift 6, every context requires strict concurrency checking
This ensures, among other things, that `@_predatesConcurrency` doesn't
affect the types of entities anywhere in a module compiled in Swift 6, so
we get stricter checking throughout.
2021-12-02 11:44:10 -08:00
Doug Gregor
c0f5502269 Leverage error-to-warnings downgrades for non-ephemeral conversion diagnostics
There were slight wording changes between the warning and error
diagnostics, but they don't seem to justify the duplication here.
2021-12-02 11:12:07 -08:00
Doug Gregor
365f0afa9f Downgrade concurrency-related function type errors in existing code
When in "existing" Swift code that is Swift 5.x and has not adopted
concurrency, allow mismatches in function types that only involve
ABI-neutral concurrency changes (e.g., adding `@Sendable` or removing
a global actor) by downgrading the diagnostic to a warning. This
improves the story for incremental adoption of concurrency in an
existing code base.

As part of this, generalize the facility for downgrading an error to a
warning when performing diagnostics in the constraint solver, using the
new diagnostic behavior limits rather than duplicating diagnostics.
2021-12-02 10:33:01 -08:00
swift-ci
1b6ec37b06 Merge pull request #40363 from zoecarver/fix-mangler-leaks 2021-12-01 21:04:39 -08:00
Doug Gregor
abe099d40c Merge pull request #40360 from DougGregor/align-unavailable-sendable
Align unavailable Sendable diagnostics with the proposal for staging Sendable
2021-12-01 20:48:17 -08:00
Alexis Laferrière
b7353c9f51 [Sema] Force reporting public imports of private module as error with asserts
When running in assert mode make it an error for a public module to
publicly import a private module.
2021-12-01 18:29:27 -08:00
zoecarver
3bb9d43ead [nfc] Fix two leaks where clang::ManglerContext was not cleaned up. 2021-12-01 17:13:24 -08:00
Holly Borla
122020ee06 [Sema] Ban opaque types in parameter position. 2021-12-01 15:01:04 -08:00
Doug Gregor
f9636af015 Align unavailable Sendable diagnostics with the proposal for staging Sendable 2021-12-01 15:00:27 -08:00
Richard Wei
7150a8b362 Merge pull request #40347 from rxwei/sr15530 2021-12-01 10:25:52 -08:00
Holly Borla
50ddd7ce07 Merge pull request #36575 from hborla/simd-arithmetic-operator-partition
[ConstraintSystem] Treat arithmetic SIMD operators like other generic operators when partitioning an overload set.
2021-12-01 12:20:40 -05:00
Richard Wei
6999c8a3dc [AutoDiff] Fix crasher when type-checking mismatched derivative.
When checking the viability of an original function candidate as specified in a `@derivative` attribute, a candidate's signautre can have more generic requirements than the required signature. Such cases need to be checked and diagnosed.

Resolves SR-15530 / rdar://85845512.
2021-11-30 19:04:10 -08:00
Doug Gregor
7e375f7df6 Use new Sendable staging infrastructure consistently.
The main effect of this change is that diagnostics about Sendable
conformances now follow the same minimal/full logic used for other
Sendable diagnostics, rather than having their own separate
computation.
2021-11-30 18:22:53 -08:00
Doug Gregor
6381960eb3 Align Sendable diagnostic behavior with incremental-adoption proposal.
Determine whether a particular missing Sendable diagnostic should be
emitted as a warning or error, or even ignored entirely, based on the
emerging rules from the proposal for incremental adoption of Sendable
checking.
2021-11-30 18:22:53 -08:00
Holly Borla
9196c9ad41 [FrontendOptions] Enable structural opaque result types and remove
the -enable-experimental-structural-opaque-types frontend flag.
2021-11-30 15:41:23 -08:00
Luciano Almeida
5337b8d40f Merge pull request #40328 from LucianoPAlmeida/minor-nfc
[NFC] Remove duplicated dyn_cast
2021-11-30 19:32:18 -03:00
Evan Wilde
c57b80a3c8 Final walker cleanups
Instead of tracking the single-expression closures in a separate
structure and passing that in under the right conditions, it makes more
sense to simply set the 'Where' decl context to the single-expr closure
and use the correct declaration context to determine whether the context
is async. The reduces the number of variables that need to get plumbed
through to the actual unavailable-from-async check and simplifies the
actual check from figuring out whether we're in a single-expr closure or
in an async context.
2021-11-30 14:20:21 -08:00
Evan Wilde
d99e3318db Add implementation of _unavailableFromAsync check
The core part of the check runs as follows
 1. Are we in an async context
 2. Does the decl we're calling have the unavailableFromAsync attribute
 3. Emit a diagnostic

There are a couple challenges that muddy the implementation. First,
single-expression closures are typechecked differently than
multi-expression closures. The single-expression closure is never added
to the closure stack. We have to record it separately upon entry to
verify separately. This is necessary for `_ = { foo() }()` where `foo`
is unavailable from async, and the surrounding context is async.

The second challenge is regarding when things get typechecked. A type
must be assigned to AbstractClosureExprs to determine whether they are
an async context or not. Unfortunately, availability checking runs
before types are fully assigned in some cases. This specifically happens
when working with result builders in specific conditions. I haven't been
able to figure out how to reduce the issue further.
2021-11-30 14:20:21 -08:00
Xi Ge
4b0fc14a5e Merge pull request #40333 from nkcsgexi/enum-element-constness
sema: accept enum element reference as compile-time const value
2021-11-30 14:13:11 -08:00
Xi Ge
fdcb08ead2 sema: accept enum element reference as compile-time const value 2021-11-30 09:27:42 -08:00
Saleem Abdulrasool
349af3707d Merge pull request #40305 from compnerd/semitruck
gardening: make c++98-compat-extra-semi an error
2021-11-30 08:18:36 -08:00
nate-chandler
6fa89b7bd0 Merge pull request #40315 from nate-chandler/rdar84962693
[Sema] Made $main non-dynamic.
2021-11-30 07:43:10 -08:00
LucianoAlmeida
87498648d1 [NFC] Remove duplicated dyn_cast 2021-11-30 12:19:33 -03:00
Pavel Yaskevich
d1a906e479 Merge pull request #40321 from apple/revert-39989-more-diag-improvements-for-multi-stmt-closures
Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default"
2021-11-30 00:17:24 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Doug Gregor
2fb2871ed9 Strip concurrency-related types from mangled name of @_predatesConcurrency decls
This allows some APIs to evolve toward supporting concurrency without
breaking their ABI.
2021-11-29 15:04:07 -08:00