Commit Graph

1355 Commits

Author SHA1 Message Date
Artem Chikin
364f154fff Merge pull request #37350 from artemcm/DeployTargetIndependentAvailabilityDiagnostic
Warn about unnecessary availability independently from the deployment target
2021-05-12 15:39:45 -07:00
Artem Chikin
5146bd5191 Report unnecessary availability warnings independently from the deployment target
This change separates emission of the diagnostics like:
```
unnecessary check for 'Platform'; enclosing scope ensures guard will always be true
```
from the deployment target of the current compilation. Instead, these diagnostics will only be emitted if the enclosing scope guard is explicitly specified by the user with an `#availability` attribute.

This fixes cases like the following:
```
@available(macOS 11.0, *)
class Foo {
    func foo() {
        if #available(macOS 11.1, *) {}
    }
}
```
Compiling this with `-target x86_64-apple-macos11.2` results in:
```
warning: unnecessary check for 'macOS'; enclosing scope ensures guard will always be true
        if #available(macOS 11.1, *) {}
.../test.swift:2:7: note: enclosing scope here
class Foo {
```
Even though in source-code the enclosing scope (`Foo`) of this guard does not ensure it will always be true.
This happens because availability range is propagated by intersecting ranges top-down from the root `TypeRefinementContext`, which is defined by the deployment target, causing the availability range on class `Foo` to become `11.2`.

Users may be sharing the same piece of source-code across different projects with their own respective deployment targets which makes such target-dependent warnings confusing at some times, and not-useful at others.
We should rather have the warning simply reflect what is in the source.

Resolves rdar://77607488
2021-05-12 11:57:57 -07:00
Holly Borla
c297070106 [Diagnostics] Always use the parameter name for closure parameter diagnostics,
because the $ prefix does not indicate that the parameter is anonymous.
2021-05-11 18:30:27 -07:00
Holly Borla
ef58f6a827 [ConstraintSystem] If the contextual parameter type doesn't exist when
resolving a closure, create a new type variable for inferred property
wrapper types.
2021-05-11 18:26:22 -07:00
Slava Pestov
daceb1677a Sema: Allow unavailable conformances to be referenced from unavailable contexts
Relaxes the conformance availability check to match the Swift 5.3 behavior
with unavailable types.

Fixes rdar://problem/75430966.
2021-05-03 23:40:46 -04:00
Holly Borla
af649e7b41 Merge pull request #37143 from hborla/wrapped-parameter-mutability
[Property Wrappers] Always make sure the storage for a wrapped parameter is immutable.
2021-04-29 19:32:25 -07:00
Robert Widmann
847930bfb7 Don't Force the Interface Type While Checking Sendable
Asking for Sendable conformances on this path is going to lead to
a traversal of the stored properties of the type. If there is an
interface type computation ongoing, as is very likely the case, this
traversal can wind up causing a cycle when it forces the interface type
of a member once again.

Request only the non-structural conformances to break the cycle.

rdar://77189542
2021-04-29 13:11:32 -07:00
Holly Borla
d8b5d7d51d [Property Wrapper] For a wrapped parameter that is implementation detail,
make the backing stroage a let-constant.
2021-04-29 12:33:15 -07:00
Pavel Yaskevich
46bc3b672d Merge pull request #37115 from xedin/disable-only-in-perf
[CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
2021-04-29 10:25:16 -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
Holly Borla
0248250a51 [Property Wrappers] Fix a diagnostic crash when a parameter has a wrapped value
mismatch.

If there's an error in property wrapper application, the backing property
wrapper type request will return a null type, which would cause the compiler
to crash because most error recovery code expects ErrorType. If the wrapper
application has an error, use the interface type of the parameter instead.
2021-04-27 12:56:52 -07:00
Slava Pestov
8464afd738 Sema: Remove SourceFile::SynthesizedDecls 2021-04-21 00:07:29 -04:00
Doug Gregor
cdb7de19bf [Concurrency] References to global-actor functions have global-actor-qualified type.
When referencing a function that is on a global actor, e.g.,

    @MainActor func doSomething() -> Int

the result of that reference is a global-actor-qualified function type, e.g.,

    @MainActor () -> Int

Part of rdar://76030136.
2021-04-16 00:26:39 -07:00
Holly Borla
0445ff91c5 Merge pull request #36934 from hborla/enclosing-self-availability
[Property Wrappers] Fix availability inference for enclosing self property wrappers.
2021-04-15 21:41:46 -07:00
Holly Borla
b11f465561 [ConstraintSystem] Fix a few diagnostic bugs when an inferred property
wrapper type is a hole or a structural type.
2021-04-15 16:49:25 -07:00
Holly Borla
b774acd1f0 [Property Wrappers] If a property wrapper accessor is synthesized using the
enclosing-self subscript, infer availability from accessors on the subscript
declaration.
2021-04-15 12:44:16 -07:00
Mishal Shah
22f61df98b Use %target-cpu in the tests to support running on Apple Silicon hardware 2021-04-08 23:26:18 -07:00
Alexis Laferrière
3659e77584 Merge pull request #36683 from xymus/reenable-ioi-suggestion
[Tests] Reenable implementation-only-import-suggestion.swift
2021-04-06 10:05:18 -07:00
Holly Borla
95f8ed8807 Merge pull request #36711 from hborla/property-wrapper-availability-inference
[Property Wrappers] Fix availability inference of synthesized property wrapper setters
2021-04-06 09:30:06 -07:00
Holly Borla
e1de140dbb [Property Wrappers] Intersect the availability of the wrapped/projected value
setter with the availability of the enclosing scope when inferring the
availability of the synthesized setters for an applied property wrapper.
2021-04-01 18:11:05 -07:00
Holly Borla
ad3568e52e Merge pull request #36344 from hborla/property-wrapper-parameter-revision
[SE-0293] Implement revision #3 of property wrapper parameters
2021-03-31 15:49:01 -07:00
Alexis Laferrière
26a9442d0c [Tests] Reenable implementation-only-import-suggestion
rdar://76004923
2021-03-31 12:24:46 -07:00
Alexis Laferrière
eaa27092dc Merge pull request #36639 from xymus/fix-ioi-suggestion
[Test] Fix implementation-only-import-suggestion for Apple Silicon
2021-03-31 12:17:35 -07:00
Josh Learn
a6da8a8899 Support constant diagnostics on constructors
This change includes a fix to allow the diagnostics
for constantness in function arguments to work properly
for constructors. This change also includes some minor
code cleanup in the constantness diagnostic pass.
2021-03-31 11:06:55 -07:00
Holly Borla
a11e2455b0 [Property Wrappers] Fixes and tests for inaccessible and unavailable
parameter wrappers.
2021-03-31 09:29:46 -07:00
Mishal Shah
64d6ccd6cc Update the unsupported OS to iOS 2021-03-30 17:07:30 -07:00
Alexis Laferrière
b31571bd40 [Test] Fix implementation-only-import-suggestion for Apple Silicon 2021-03-30 11:48:42 -07:00
Arnold Schwaighofer
72d09552f7 Disable test on tvos/watchos
rdar://76004923
2021-03-30 09:17:04 -07:00
Arnold Schwaighofer
41d1de434a Disable test on ios
rdar://76004923
2021-03-30 08:51:22 -07:00
Alexis Laferrière
6bbb9f04da [Sema] Only look for PrivateFrameworks on Darwin 2021-03-26 16:33:09 -07:00
Alexis Laferrière
cf58bb7eb4 [Sema] Report public imports of private modules
Intro the concept of library access or distribution level to identify
layers of libraries and report public imports of private libraries from
public ones.

rdar://62934005
2021-03-26 16:30:15 -07:00
Josh Learn
816d186d92 Extend compile-time constantness check to support constant Ranges
Currently the function parameter constantness check for functions
annotated with @_semantics("oslog.requires_constant_argument") does
not support ranges (e.g. 0...5, 0..<5). Ranges like this are
considered binary expressions by the compiler. This change adds
support for accepting binary expressions as constant arguments
as long as both arguments to the expression are constant.

rdar://71822563
2021-03-25 11:51:44 -07:00
Erik Eckstein
78ec15cf38 tests: remove some unused FileCheck prefix options
Such tests would fail with the -allow-unused-prefixes FileCheck option.

diff --git a/test/lit.cfg b/test/lit.cfg
-run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s' % (
+run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s -allow-unused-prefixes=false' % (

It helps avoiding some wrong CHECK patterns.
I just looked briefly at some of the fails. TODO: fix remaining tests, too.

rdar://74189761
2021-03-25 15:19:30 +01:00
Holly Borla
6f4b62a93c Merge pull request #36568 from hborla/property-wrapper-constraint
[ConstraintSystem] Add a property-wrapper constraint to allow for inference of implicit property wrappers
2021-03-24 17:13:51 -07:00
Holly Borla
76c4c3dc3f [Diagnostics] Add back a dedicated fix/diagnostic for using an invalid
type as a property wrapper.
2021-03-24 11:24:21 -07:00
Holly Borla
7cd8add885 [ConstraintSystem] Add a property wrapper constraint to delay checking
if an inferred wrapper type is a property wrapper until that type is
resolved.
2021-03-24 11:24:21 -07:00
Holly Borla
f05589f6c4 [Diagnostics] Improve diagnostics for passing an invalid projected
value argument.
2021-03-24 11:24:21 -07:00
Pavel Yaskevich
6e628c4874 [CSGen] Fallback to a type variable if preferred type for placeholder is invalid
Type inside of an editor placeholder is more of a hint than anything else,
so if it's incorrect let's diagnose that and use type variable instead to
allow solver to make forward progress.

Resolves: SR-14213
Resolves: rdar://74356736
2021-03-23 18:56:21 -07:00
Alex Hoppen
fa9f3f3337 [Sema] Correctly diagnose passing tuple as only argument to function with multiple parameters
If a tuple is passed as the only argument to a function that takes two unnamed arguments, we try to diagnose the missing argument label. However, in the old diagnose code we didn’t distinguish between non-existing arguments and arguments without labels; both behaved the same.

Thus, the missing second argument in the function call would line up with the empty second argument label, not producing a diagnostic, but hitting an assertion later on.

Distinguish between the two to fix the issue.

Fixes rdar://64319340
2021-03-19 12:58:17 +01:00
Anthony Latsis
79c0d93b86 Sema: Fix dynamic Self behavior for a «super» base expression 2021-03-09 19:20:43 +03:00
Slava Pestov
9d5baaae9b Merge pull request #36327 from slavapestov/fix-storage-availability
Fix availability checking for stored properties and enum cases with associated values
2021-03-06 09:23:01 -05:00
Slava Pestov
2e1fca35e0 Merge pull request #36326 from slavapestov/witness-availability-fix
Sema: Relax witness availability check
2021-03-05 21:21:01 -05:00
Slava Pestov
511ada4a50 Sema: Ban potential unavailability on enum cases with associated values
This cannot be supported for the same reasons struct and class stored
properties with potential unavailability cannot be supported.

It is possible that some users relied on this, because it worked in
some cases where the type metadata for the potentially unavailable
type was not actually needed for anything (eg, if the type was @frozen
and trivial, or a simple class reference). If this becomes an issue
we can downgrade this to a warning.

Note that just like the previous fix for stored properties, we do
still allow writing an '@available' attribute on the enum element if
the OS version is not any newer than the deployment target. This allows
annotating APIs with the OS version where they were introduced.
2021-03-05 18:03:05 -05:00
Slava Pestov
cb9c1f93ee Sema: Allow @available on stored properties as long as its as new as the deployment target 2021-03-05 18:03:05 -05:00
Slava Pestov
c346c4fd3b Sema: Relax witness availability check
We were checking that the witness is at least as available as
the intersection of the protocol and the conforming type.

In the case where the conformance is defined in an extension,
this should actually be the intersection of the protocol and
the _availability of the extension_.

Fixes <rdar://problem/74114880>.
2021-03-05 16:58:57 -05:00
Doug Gregor
6efaf7ac0f Introduce -warn-concurrency flag to warn about concurrency issues.
To help support incremental adoption of the concurrency model, a number
of concurrency-related diagnostics are enabled only in "new" code that
takes advantage of concurrency features---async, @concurrent functions,
actors, etc. This warning flag opts into additional warnings that better
approximate the eventual concurrency model, and which will become
errors a future Swift version, allowing one to both experiment with
the full concurrency model and also properly prepare for it.
2021-03-05 10:58:54 -08:00
Holly Borla
b3d54b67fc [Property Wrappers] Don't allow parameters with attached property wrappers
in protocol requirements.
2021-02-25 18:35:14 -08:00
Holly Borla
db387273f6 [ConstraintSystem] Don't allow dollar prefixes in argument labels unless
the parameter has an attached property wrapper.
2021-02-25 18:35:14 -08:00
Holly Borla
133dec0e05 [ConstraintSystem] Implement implicit property wrapper attribute
inference for closure parameters.
2021-02-25 18:35:14 -08:00
Holly Borla
2c2d671dfa [Property Wrappers] Add an unsupported error message for property wrapper
parameters in subscript declarations.
2021-02-25 18:35:14 -08:00