Commit Graph

12650 Commits

Author SHA1 Message Date
Slava Pestov
eed84abda9 Sema: Add TVO_CanBindToNoEscape
We have a systemic class of issues where noescape types end up bound to
type variables in places that should not. The existing diagnostic for
this is ad-hoc and duplicated in several places but it doesn't actually
address the root cause of the problem.

For now, I've changed all call sites of createTypeVariable() to set the
new flag. I plan on removing enough occurrences of the flag to replicate
the old diagnostics. Then we can continue to refine this over time.
2019-04-16 23:01:33 -04:00
Slava Pestov
7d2c5e1b36 Sema: Don't 'tuple splat' parameter lists with @autoclosure parameters
Fixes <https://bugs.swift.org/browse/SR-9991>.
2019-04-16 22:10:22 -04:00
Pavel Yaskevich
2e93165040 [ConstraintSystem] Detect use of declaration with mutating getter as a key path component
Such use is currently not allowed so variables or subscripts with
mutating getters should be rejected and diagnosed.
2019-04-16 17:56:13 -07:00
Pavel Yaskevich
306507931a [CSFix] Introduce a fix for different kinds of ref failures in key path 2019-04-16 17:31:03 -07:00
Ben Langmuir
8d4447c1d7 [code-completion] Add completion for keypath dynamic member lookup
Looks into the root type of the keypath to find additional members. This
does not currently map the type of the completion to the subscript's
return type.

rdar://49029126
2019-04-16 15:37:32 -07:00
Nathan Hawes
c95252e1e5 Change from using the @_inheritedDefaultValue attribute to mark parameters with an inherited default argument to using '= super' 2019-04-16 15:21:25 -07:00
John McCall
55890896a7 Check parameter attributes. NFC because we don't have any yet. 2019-04-16 15:55:48 -04:00
Nathan Hawes
b425987e45 Add diagnostics for the new @_inheritedDefaultValue attribute 2019-04-16 11:23:23 -07:00
Nathan Hawes
9639bceded Add an attribute to inhert a param's default value from the overridden decl in module interfaces 2019-04-16 11:22:36 -07:00
Robert Widmann
f192b92799 Merge pull request #23785 from Azoy/context-cleanups
AST NFC: Minor cleanups around ASTContext
2019-04-16 13:50:35 -04:00
Pavel Yaskevich
55bc16e785 [Diagnostics] Diagnose static member reference as a key path component 2019-04-15 23:42:34 -07:00
Pavel Yaskevich
03ea5dce5a [ConstraintSystem] Detect and fix use of static members in a key path in the solver
Previously it was possible to create an invalid solution where
static members would be referenced in a key path, which is not
currently supported and would only be diagnosed while applying
such solution to AST e.g.

```swift
struct S {
  static var foo: Int = 42
}

_ = \S.Type.foo
```
2019-04-15 23:42:34 -07:00
Slava Pestov
2b5a69169a Merge pull request #23924 from slavapestov/small-csapply-cleanup
Small CSApply cleanup
2019-04-15 10:56:09 -04:00
Slava Pestov
91dffc9d44 Sema: Use AnyFunctionType::printParams() to print argument lists instead of printing a tuple type
Once the '@escaping' bit is removed from TupleTypeElt, it no longer makes
sense to print argument lists as if they were TupleTypes or ParenTypes,
since function types are '@escaping' by default inside tuples but not
in argument lists.

Instead, print ArrayRef<AnyFunctionType::Param> directly. For now this
introduces some awkward usages of AnyFunctionType::decomposeInput();
these will go away once the AST is changed to represent the argument list
as a list of expressions and not a single tuple expression.
2019-04-15 00:22:29 -04:00
Slava Pestov
7fe577fddb Sema: Clean up modeling of non-member VarDecl references
Give them substitutions just like with everything else, which
eliminates some special cases from SILGen.
2019-04-14 23:28:14 -04:00
Slava Pestov
a3c15f2f6b Sema: References to TypeDecls should always be TypeExpr
In a few corner cases we built DeclRefExpr and MemberRefExpr
for references to types. These should just be TypeExpr so that
SILGen doesn't have to deal with it.

This also fixes a bug where a protocol typealias with an
unbound generic type could not be accessed properly from
expression context, but that is just so incredibly obscure.
2019-04-14 23:28:13 -04:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Pavel Yaskevich
cd27a29a2e Merge pull request #23997 from xedin/allow-attaching-fixes-to-members-without-decl
[ConstraintSystem] Overload choice should not be required to refer to…
2019-04-12 18:36:41 -07:00
Pavel Yaskevich
374a10c55f [ConstraintSystem] Overload choice should not be required to refer to declaration to have a fix
We should be able to attach fixes to overload choices that don't
refer to declarations e.g. keypath applications which refer to
`AnyObject` is a base type.
2019-04-12 14:54:37 -07:00
Jordan Rose
d4a5740336 Merge pull request #23972 from jrose-apple/implementation-only-implementation---only
Miscellaneous cleanup and consolidation for implementation-only checking
2019-04-12 13:19:41 -07:00
Slava Pestov
1889d5aa45 Sema: Correctly simplify member types with a DynamicSelfType base
Fixes <https://bugs.swift.org/browse/SR-10434>, <rdar://problem/49779783>.
2019-04-12 01:00:19 -04:00
Jordan Rose
f61f0c0b2d Consolidate names of implementation-only checking as "exportability"
Another place where John and I used different terms.
2019-04-11 16:33:23 -07:00
Jordan Rose
326fa14f8b Don't bother checking implementation-only import use for accessors
Their associated AbstractStorageDecl is already being checked, and
will produce a better error.
2019-04-11 16:33:23 -07:00
Jordan Rose
a4606111af Adjust the implementation-only diagnostics to sound more similar
John and I had slightly different styles when adding these; better
to keep them in harmony.
2019-04-11 16:33:23 -07:00
Slava Pestov
dff3f0d134 Merge pull request #23853 from johnno1962/Self-fallback-followup
Ban Self in typealias for now
2019-04-11 16:12:44 -04:00
Brent Royal-Gordon
def1af6049 Merge pull request #23358 from brentdax/a-type-is-a-set-of-its-instances
Add static and class subscripts
2019-04-11 12:58:32 -07:00
Jordan Rose
6ea773e136 Merge pull request #23808 from jrose-apple/conformance-conformance
Implementation-only import checking for conformances
2019-04-11 08:49:56 -07:00
John Holdsworth
7ae55d3d66 Tidy up comments and final testing. 2019-04-11 12:24:38 +01:00
Pavel Yaskevich
34960788aa Merge pull request #23741 from xedin/verify-kp-subscript-hashable-via-solver
[CSSolver] Move keypath subscript index Hashable conformance verification to solver
2019-04-11 00:48:26 -07:00
Brent Royal-Gordon
7ae331dbca [NFC] Pick a few nits for Jordan 2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
473fe7027e Make sure we don’t support @objc class subscripts
Obj-C subscripts don’t work on class objects, but you can declare class methods with the appropriate names. We don’t want to half-support this. Emit an error if you try to write “@objc class subscript” and test that we don’t import the methods as subscripts.
2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
8b0e61aae0 Infer final on static subscripts 2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
0fcb09d9ce Fix description of static subscripts in errors 2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
7a41c3874b Permit subscripting types without using .self 2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
e42939d9bb Correctly apply typechecking solutions with subscripts on type instances 2019-04-10 23:09:44 -07:00
Pavel Yaskevich
439335ddb0 [Diagnostics] Extend keypath subscript index missing Hashable to support dynamic member lookup 2019-04-10 15:10:47 -07:00
Pavel Yaskevich
93f9cb1d2a [ConstraintLocator] Identify whether locator is a result of keypath dynamic member lookup or belongs to keypath subscript component 2019-04-10 13:51:19 -07:00
Pavel Yaskevich
c3460f825d [Diagnostics] Diagnose keypath subscript components with missing Hashable conformances 2019-04-10 13:51:12 -07:00
Pavel Yaskevich
c982706f0d [CSFix] Fix keypath subscript index to conform to Hashable 2019-04-10 13:51:04 -07:00
Pavel Yaskevich
3288299e1e [ConstraintSystem] Make sure that each index argument of keypath subscript is Hashable
Move checking for index Hashable conformance from CSApply (post-factum)
to the solver and use recorded conformance records complete subscript
components.
2019-04-10 13:50:34 -07:00
Jordan Rose
7006aa0b9f Check for use of implementation-only conformances in inlinable code
This includes both the types and the values (generic functions, etc)
used in the inlinable code. We get some effectively duplicate
diagnostics at this point because of this, but we can deal with that
at a future date.

Last part of rdar://problem/48991061
2019-04-10 11:09:07 -07:00
Jordan Rose
590551781a Pass a ConcreteDeclRef through for availability checking where present
This will be used in the next commit for checking conformance use in
inlinable function bodies, but for now it's No Functionality Change.
2019-04-10 11:09:07 -07:00
Jordan Rose
5c27568738 Check assoc types for conformances from implementation-only imports
Okay, strictly we're checking the "signature conformances" of a newly-
declared conformance, but that wouldn't have fit on one line. This is
making sure that we don't have a requirement on an associated type (or
on the conforming type) that can only be satisfied using a conformance
in an implementation-only import.
2019-04-10 11:09:07 -07:00
Jordan Rose
519fa00adc Check signatures for conformances from implementation-only imports
These also create a dependency on the implementation module, even if
both the type and the protocol are public. As John puts it, a
conformance is basically a declaration that we name as part of another
declaration.

More rdar://problem/48991061
2019-04-10 11:09:07 -07:00
Jordan Rose
a15dec8774 Diagnose typealiases of non-public types in inlinable functions (#23912)
...as a warning, since we didn't check this correctly in Swift 5.
For parseable interfaces, these typealiases won't work at all.
2019-04-10 09:21:44 -07:00
Pavel Yaskevich
8e5dbcfde2 Merge pull request #23921 from xedin/dynamic-member-implicit-ast
[CSApply] Mark dynamic member lookup subscript expr and its argument …
2019-04-10 01:34:37 -07:00
Pavel Yaskevich
cf09a4e536 [CSApply] Mark dynamic member lookup subscript expr and its argument as implicit
These expressions are created to model an implicit call to dynamic
member lookup endpoint, which means both of them have to be implicit.
2019-04-09 19:12:10 -07:00
Slava Pestov
d82b88cd82 Merge pull request #23907 from slavapestov/noescape-parameter-call-restriction
Re-implement "no-escape parameter call restriction" as SIL pass
2019-04-09 19:38:31 -04:00
Slava Pestov
3f58eb745b Merge pull request #23878 from slavapestov/reimplement-escaping-diagnostics
Reimplement escaping diagnostics
2019-04-09 16:40:04 -04:00
Slava Pestov
6a34ed0120 Sema: Remove NPCR diagnostics 2019-04-09 16:35:25 -04:00