Commit Graph

2041 Commits

Author SHA1 Message Date
Xi Ge
5e30d0e02b sema: diagnose bad interactions between @available and @_originallyDefinedIn 2019-12-14 18:34:14 -08:00
Dan Zheng
bb1052ca3e [AutoDiff upstream] Upstream @derivative attribute type-checking. (#28738)
The `@derivative` attribute registers a function as a derivative of another
function-like declaration: a `func`, `init`, `subscript`, or `var` computed
property declaration.

The `@derivative` attribute also has an optional `wrt:` clause specifying the
parameters that are differentiated "with respect to", i.e. the differentiation
parameters. The differentiation parameters must conform to the `Differentiable`
protocol.

If the `wrt:` clause is unspecified, the differentiation parameters are inferred
to be all parameters that conform to `Differentiable`.

`@derivative` attribute type-checking verifies that the type of the derivative
function declaration is consistent with the type of the referenced original
declaration and the differentiation parameters.

The `@derivative` attribute is gated by the
`-enable-experimental-differentiable-programming` flag.

Resolves TF-829.
2019-12-12 18:18:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Brent Royal-Gordon
1df792ae9f [NFC] Convert TypeRepr to use DeclName(Loc)?
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
2019-12-11 00:45:08 -08:00
Brent Royal-Gordon
8551b32af2 [NFC] Make EnumElementPattern carry a DeclName
This has the side effect of threading compound name support through more enum pattern code, although it’s still not complete.
2019-12-11 00:45:07 -08:00
Holly Borla
edb4e70d66 Merge pull request #28600 from hborla/tuple-mismatch-diagnostics
[ConstraintSystem] Port tuple type mismatch diagnostics
2019-12-09 13:26:34 -08:00
Robert Widmann
7c46df68c7 Merge pull request #28633 from kitaisreal/classes-equatable-hashable-synthesis-diagnostics
[Type checker]: Classes `Hashable` and `Equatable` synthesis diagnostic
2019-12-09 13:16:18 -08:00
Holly Borla
94e9fd1d67 [Diagnostics] Use a generic "tuple type not convertible" error message
when there is no contextual type.
2019-12-09 11:25:32 -08:00
Kita, Maksim
00bc7f48c0 SR-11902: Fixed code review issues 2019-12-07 20:35:49 +03:00
Kita, Maksim
9963fce1f7 SR-11902: Fixed code review issues. Updated tests. 2019-12-07 15:23:31 +03:00
Kita, Maksim
7458016f22 SR-11902: Fixed code review issues 2019-12-07 14:29:10 +03:00
Kita, Maksim
30faac8124 SR-11902: Improve Error Message for Auto-synthesized Equatable Conformance on Classes
1. Added note for 'Hashable' and 'Equatable' protocol synthesis for classes.
2019-12-07 14:09:56 +03:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
swift-ci
b7d0264bc1 Merge pull request #28591 from DougGregor/nsobject-protocol-conformance 2019-12-05 13:10:59 -08:00
Doug Gregor
3fb77ea447 Provide a custom diagnostic for conformance to NSObjectProtocol
Swift classes cannot meaningfully conform to NSObjectProtocol.
Inheriting from NSObject is the appropriate fix, so suggest that.
Fixes rdar://problem/32543753.
2019-12-05 11:10:27 -08:00
Pavel Yaskevich
3c5290c78c [Diagnostics] Diagnose inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
a9f11445c0 [Diagnostics] Diagnose an attempt to assign a value to an overloaded name
Example:

```swift
struct X {
}

func X(_: Int) -> Int {
  return 42
}

X = 42
```
2019-12-03 12:07:15 -08:00
Rintaro Ishizaki
83f9a52cb8 Merge pull request #28362 from owenv/improve_trailing_closure_in_condition_diag_2
[Parse] Reapply trailing closure in condition fix and downgrade to warning
2019-11-22 17:05:48 +09:00
Xi Ge
5a862e49bd Merge pull request #28369 from nkcsgexi/originally-defined-in-attribute
AST: introduce a new attribute @_originallyDefinedIn to the AST
2019-11-21 20:26:29 -08:00
Xi Ge
aa1e4eec86 sema: check if @_originalDefinedIn attribute has duplicated entries for the same platform name 2019-11-21 17:04:00 -08:00
kelvin13
e4dc295d64 fix conflicts 2019-11-21 12:42:10 -06:00
Owen Voorhees
067a8ec42f [Parse] Downgrade trailing closure in statement condition error to a warning
In the past, this error was applied inconsistently, so diagnosing it
correctly is now a source-breaking change. Instead, diagnose it correctly,
but as a warning.
2019-11-21 08:24:46 -08:00
Robert Widmann
bed667c8e3 Merge pull request #28375 from owenv/remove-unused-diags
[Gardening] Remove unused diagnostic definitions
2019-11-20 15:46:27 -08:00
Owen Voorhees
f37c1dbaea [Gardening] Remove unused diagnostic definitions 2019-11-19 19:44:37 -08:00
Nathan Hawes
7b33254b68 Merge pull request #28226 from nathawes/assertion-fixes
Fix some SourceKit assertion hits
2019-11-19 09:50:41 -08:00
Holly Borla
eef34add12 Merge pull request #28343 from hborla/restrain-param-tuple-splat-fix
[Diagnostics] Don't apply the single parameter tuple splat fix if the parameter type is a generic parameter.
2019-11-18 18:03:51 -08:00
Holly Borla
a9a0bba31b [Diagnostics] Don't apply the single parameter tuple splat fix if the
parameter type is a generic parameter.
2019-11-18 16:19:33 -08:00
Harlan Haskins
26b20ef198 Merge pull request #28227 from keith/ks/remove-frozen-warning
Remove warning about @frozen without library evolution
2019-11-15 20:14:24 -08:00
Nathan Hawes
125c1fb03e [Sema] Avoid needing the typechecker for the IsStaticRequest request
It was being used purely to get the name of the type context for a diagnostic
message. SourceKit's syntactic-only requests were hitting an assertion when
this diagnostic was triggered because they don't set up a type checker.
2019-11-15 18:10:22 -08:00
Marc Rasi
e5e25a6c71 Merge branch 'master' of github.com:apple/swift into ast-nondiff 2019-11-15 16:41:30 -08:00
Hamish Knight
6d6feb60de [CSDiagnostics] Support static "Type." fix-it
Check whether we found a static property, and if
so, suggest inserting "Type." instead of "self.".

Resolves SR-11788.
2019-11-15 11:12:12 -08:00
Marc Rasi
f5677cbe42 add @nondiff to AnyFunctionType params 2019-11-14 16:49:22 -08:00
Keith Smiley
bf4aaacb02 Remove @frozen without library evolution warning
This warning is produced if you annotate an enum with `@frozen` but
build without library evolution enabled. The problem is that if you
only build with library evolution enabled for release builds, this
leaves you with a warning for all debug builds. The downside of this
change is that if you never build with library evolution, you may have
this unnecessary annotation without noticing.
2019-11-12 19:35:05 -08:00
Suyash Srijan
fab6ce9587 [MiscDiagnostics] Diagnose passing a non-@objc dynamic KeyPath property to KVO observe method 2019-11-08 18:52:43 +00:00
Pavel Yaskevich
6d02fb7815 Merge pull request #28057 from xedin/assign-diags
[Diagnostics] Port the rest of assignment diagnostics to the new framework
2019-11-06 00:11:08 -08:00
Hamish Knight
10d62a1e4e [CSDiagnostics] Allow non-ephemeral diag to refer to argument… (#28084)
[CSDiagnostics] Allow non-ephemeral diag to refer to argument labels
2019-11-05 17:43:39 -08:00
Suyash Srijan
3ecc13b360 Merge pull request #28015 from nexon/SR-11679-incorrect-fix-suggestion-cftypes
SR-11679: Incorrect FixIt suggestion for CFTypes
2019-11-06 01:32:55 +00:00
Hamish Knight
96e5f2a145 Allow non-ephemeral diag to refer to argument labels
Use getArgDescription to improve the diagnostic
for invalid temporary pointer conversions.
2019-11-05 13:51:53 -08:00
Pavel Yaskevich
30440d8235 [Diagnostics] Properly diagnose assignment mismatch in ambiguity cases 2019-11-05 12:38:13 -08:00
marcrasi
ce756e3189 [AutoDiff upstream] parsing for @differentiable function type (#27708)
Adds parsing for a type attribute `@differentiable`, which is optionally allowed to have argument `@differentiable(linear)`.

The typechecker currently rejects all uses of `@differentiable` with "error: attribute does not apply to type". Future work (https://bugs.swift.org/browse/TF-871 https://bugs.swift.org/browse/TF-873) will update the typechecker to allow this attribute in places where it is allowed.

Resolves https://bugs.swift.org/browse/TF-822.
2019-11-04 23:40:04 -08:00
Holly Borla
d91e4747ac Merge pull request #28073 from hborla/nil-conditional-cast
[CSGen] Add a tailored diagnostic for conditional casting from a nil literal.
2019-11-04 22:33:23 -08:00
Holly Borla
b1638ce1ab [CSGen] Add a tailored diagnostic for conditional casting from a nil literal,
and diagnose in CSGen.
2019-11-04 20:49:36 -08:00
Hamish Knight
65dda6d945 Address other review feedback 2019-11-03 08:42:26 -08:00
Hamish Knight
d0dbbf9f89 [CSDiagnostics] Add ephemeralness ambiguity notes 2019-11-03 08:42:25 -08:00
Hamish Knight
7077a68b83 [Sema] Diagnose unsound pointer conversions
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
2019-11-03 08:42:25 -08:00
Hamish Knight
92c42ec791 [AST] Add @_nonEphemeral parameter attribute
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
2019-11-03 08:40:59 -08:00
Alberto Lagos Toro
d3477ddfc4 SR-11679: Incorrect FixIt suggestion for CFTypes
Convenience inits are only allowed on classes and in extensions thereof. And in CFTypes we are not allowed to put convenince inits since swift does not support this feature yet.

This PR solve the bad fix suggestion when a user declare a init method in an extension of CF Type.

Another bug (similar to this one) that i found and became visible when i was doing the test cases for SR-116779 was the fact that if you declare a convenience init that delegates the init function in self, a fix suggestion will appear. The same suggestion that is causing troubles in SR-11679. The fix for this was removing the fix suggestion when the class kind type was CFType since if we leave it as is, it will be the same problem as SR-11679.

SR-11679: PR Feedback

Formatting the new code with clang-format and using `isa` and `cast` instead of `dyn_cast`

SR-11679: PR Feedback

Inlining `cast

SR-11679: PR Feedback

Remove semi-colon

SR-11679: PR Feedback

Remove empty line & add mark to avoid fixit.

SR-11679: PR Feedback

Remove empty line.

SR-11679: PR Feedback

Move Diagnostics Info & Remove empty lines
2019-11-01 19:54:30 -03:00
Miguel Salinas
3d9573f25d Merge branch 'master' into warn-on-empty-optionset-static-constants 2019-10-31 07:56:06 -05:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00