Commit Graph

1378 Commits

Author SHA1 Message Date
Slava Pestov
9275dd67ff Sema: Open-code a usage of SubscriptDecl::getIndicesInterfaceType()
Also add a FIXME, since its wrong.
2018-08-27 21:15:38 -07:00
Greg Titus
c95cfc6f69 Merge pull request #18950 from gregomni/rvalue-as-lvalue
[Diagnostics] Adding assignments directly to CS and diagnosing from there.
2018-08-26 11:12:57 -07:00
Robert Widmann
661c30f93e Merge pull request #18963 from CodaFi/its-not-unusual-to-be-unused-by-anyone
[NFC] Silence a bunch of Wunused-variable diagnostics
2018-08-25 09:24:44 -07:00
gregomni
821f63fe98 Make assignments and assignment failure diagnoses directly in the CS.
More specific diagnoses for assigning to read-only keypaths.
'computeAssignDestType' is dead code now.
ConstraintFix shouldRecordFix()
2018-08-24 20:39:03 -07:00
Slava Pestov
7b41a7a63e Sema: Simplify ExprRewriter::coerceTupleToTuple()
We don't get default arguments or varargs here anymore.
2018-08-24 16:53:32 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Pavel Yaskevich
8fa8852f9e Merge pull request #18894 from xedin/switch-to-use-cs-in-new-diags
[Diagnostics] Switch to using `ConstraintSystem` directly in new diagnostics infra
2018-08-22 10:36:25 -07:00
John McCall
a30d91e3cb Implement vararg expansion well enough to support argument forwarding.
I needed this for materializeForSet remission, but it makes inherited
variadic initializers work, too.

I tried to make this a reasonable starting point for a real language
feature.  Here's what's still missing:

- syntax
- semantic restrictions to ensure that the expression isn't written in
  invalid places or arbitrarily converted
- SILGen support for expansions that aren't the only variadic argument

rdar://16331406
2018-08-22 06:46:08 -04:00
Pavel Yaskevich
3eeab38606 [Diagnostics] NFC: Attach ConstraintSystem to ConstraintFix directly
There is no longer any reason to attach solution to `ConstraintFix`
because solution applied to the constraint system before any of the
related fixes are diagnosed, so instead let's attach `ConstraintSystem`
to `ConstraintFix` directly, because it would have all of the required
information.
2018-08-22 00:07:34 -07:00
Greg Titus
32eacc5e80 Merge pull request #18608 from gregomni/rvalue-as-lvalue
[ConstraintSystem] New FailureDiagnostic for rvalues that should be lvalues
2018-08-18 11:43:23 -07:00
gregomni
aeb96274d2 Apply the solution to the CS before diagnosing solution fixes. 2018-08-18 08:38:16 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
5e0a7fdab9 [Name lookup] Teach shadowing to avoid validating decls until needed.
Rather than validating the signature of any declaration found by
name lookup, first check whether there is a collision on the full name
of the declaration. This should result in fewer declaration validations.
2018-08-14 02:19:13 -07:00
Pavel Yaskevich
0926808726 Merge pull request #18664 from xedin/cs-improve-fix-interface
[ConstraintSystem] Replace `Fix` with richer `ConstraintFix` interface
2018-08-14 00:13:01 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Pavel Yaskevich
e631a37ef6 [ConstraintSystem] Replace Fix with ConstraintFix throughout solver 2018-08-13 18:10:27 -07:00
Slava Pestov
f2ae23a2ab AST: Remove TupleType::getElementForScalarInit()
This is a legacy holdover from when tuple types had default
arguments, and also the constraint solver's matching of function
types pre-SE-0110.

Well, move the last live usage to CSDiag, where it can die a slow
painful death over time. The other usages were not doing anything.
2018-08-11 22:26:44 -07:00
Rintaro Ishizaki
3bff834f22 Merge pull request #18625 from rintaro/rdar43057058
[CSGen] Rework SanitizeExpr
2018-08-11 08:23:09 +09:00
Rintaro Ishizaki
cfeae64712 [AST] Add reference to original expression in MakeTemporarilyEscapableExpr
This is needed to restore original call expression in SanitizeExpr.
2018-08-10 18:19:53 +09:00
Pavel Yaskevich
6d64b1c8a5 [Diagnostics] Some diagnostics possible only when locator is resolved down to expression 2018-08-09 22:23:31 -07:00
Pavel Yaskevich
e2cde5acc2 [Diagnostics] Port 'missing optional unwrap' diagnostic to new abstraction 2018-08-09 17:47:06 -07:00
Pavel Yaskevich
d72c204bad [Diagnostics] Port member access on optional base diagnostic to new abstraction 2018-08-09 17:03:20 -07:00
Pavel Yaskevich
a564042fdc [Diagnostics] Port missing explicit conversion to new abstraction 2018-08-09 17:01:54 -07:00
Pavel Yaskevich
9f9904b65d [Diagnostics] Port missing & diagnostic to new abstraction 2018-08-09 13:57:57 -07:00
Pavel Yaskevich
f5aa0d9c75 [Diagnostics] Port missing force downcast diagnostic to new abstraction 2018-08-09 11:56:19 -07:00
Pavel Yaskevich
157dc719e0 [Diagnostics] Port implicitly escaping to type conversion diagnostics to new abstraction 2018-08-09 11:05:33 -07:00
Slava Pestov
8d4b8e31aa Sema: Remove ScalarToTuple conversion
This either became dead shortly after the removal of Swift 3
compatibility mode from the constraint solver, or even earlier.

Note that the code completion test change is actually correct
because (Any) -> () is not convertible to () -> () in the
language.
2018-08-08 10:18:52 -07:00
Slava Pestov
b581c63e6b AST: Remove TypeBase::getRValueObjectType()
This would look through one-element tuples, which is no longer necessary.
2018-08-08 10:18:52 -07:00
Joe Groff
cf664b2654 Merge pull request #18552 from jckarter/array-of-class-bridging
Sema: Apply metatype-to-object conversions even without restriction hints.
2018-08-08 09:43:24 -07:00
Joe Groff
0f085dc5ec Sema: Apply metatype-to-object conversions even without restriction hints.
In some cases, such as when pushing a collection conversion down to per-element conversions, we'll coerce a subtype metatype to AnyObject, as in:

```
func f(_: [AnyObject]) {}
f([NSString.self, NSObject.self]) // Type checks as [NSObject.Type] converted to [AnyObject]
```

and only record the restriction kinds used in the indirect steps NSString -> NSObject and NSObject.Type -> AnyObject without recording the jump from NSString.Type to AnyObject. coerceToType ought to apply this subtyping rule even without such a hint, though, since the restriction kind is intended only as an optimization. Fixes rdar://problem/42666956 .
2018-08-07 18:14:31 -07:00
Slava Pestov
528c632f8d Sema: Fix two unused variable warnings 2018-08-06 23:22:16 -07:00
Pavel Yaskevich
776485878f [ConstraintSystem] NFC: Move new diagnostics into separate files - Diagnostics.(h|cpp) 2018-08-06 13:08:47 -07:00
Pavel Yaskevich
d201e552e5 [Diagnostics] Move re-labeling diagnostic to use new abstraction 2018-08-04 16:52:45 -07:00
Pavel Yaskevich
5750b07daa [ConstraintSystem] Add new FailureDiagnostic abstraction
Aim of this new diagnostic abstraction is to encapsulate each
individual failure into its own class with some shared base.
Good example of this - diagnostics related to generic requirement
failures, where each kind (conformance, same-type etc.) has
some specific logic e.g. diagnostic message but the all share
the same traits like affected declaration/requirement.
2018-08-04 11:25:54 -07:00
Pavel Yaskevich
0f9f4e99ce [ConstraintSystem] NFC: Move getOverloadChoice{IfAvailable} to Solution
Since information comes from `Solution` anyway, it's good to have
that logic localized, but it's also useful for diagnostics based on
fixes attached to solutions.
2018-08-03 20:50:54 -07:00
Pavel Yaskevich
913f3710c6 Merge pull request #18484 from xedin/diag-req-failures-via-fixes
[ConstraintSystem] Diagnose missing conformance requirements via "fixes"
2018-08-03 19:23:06 -07:00
Pavel Yaskevich
e4da7a1167 [ConstraintSystem] Look through metatype of base while diagnosing conformance failures
Having `.Type` in `requires conformance` diagnostic is unnecessary.
2018-08-03 14:42:07 -07:00
Pavel Yaskevich
9d50122e75 [ConstraintSystem] NFC: Fix typo in FixKind::AddConformance name 2018-08-03 14:33:19 -07:00
gregomni
a37229e40a Omit recording conversion restrictions in a solution that apply can just as easily figure out itself from the shape of the types. 2018-08-03 11:02:04 -07:00
Pavel Yaskevich
6dfa8f21eb [ConstraintSystem] Try to dig out parameter position only if apply expr is available
While trying to diagnose missing conformances don't attempt
to lookup parameter position if the parent apply expression
is not available, which could happen when fixes are produced
as part of the sub-expression diagnostics.
2018-08-02 21:51:21 -07:00
Pavel Yaskevich
29e34e66e7 [ConstraintSystem] Diagnose missing conformance requirements via "fixes"
If fixes are allowed let solver record missing protocol conformance
requirements and assume that `conformsTo` constraint is successfully
solved, this helps to diagnose such errors without involving
heavy-weight expression based diagnostics.

Resolves: rdar://problem/40537858
2018-08-02 16:40:34 -07:00
gregomni
5faa8bf4d1 Don't offer force-unwrap of the base as a possible fixit for optional
member access if optional chaining is sure to be valid.
2018-07-27 13:56:24 -07:00
Doug Gregor
76eb767b97 [Type checker] Request nominal layout for the result types of function calls.
Once you’ve called a function and retrieved a result, IRGen will want
layout information for the result type. Make sure that the type checker
precomputes it.
2018-07-26 15:46:29 -07:00
Pavel Yaskevich
a9ebaef2e5 Merge pull request #18227 from xedin/diagnose-missing-labels-using-fixes
[ConstraintSystem] Use fixes to diagnose missing/extraneous/incorrect argument labels
2018-07-26 12:01:28 -07:00
Pavel Yaskevich
dfad872cea [ConstraintSystem] Attempt to apply fixes in AST walker order
This makes sure that the diagnostics appear in the stable order
which is closer to what users would expect e.g. evaluation
order, otherwise, because disjunctions are currently attempted
based on their size, ordering of error messages produced by
applying fixes is completely arbitrary.
2018-07-25 13:32:16 -07:00
Pavel Yaskevich
62eccd53ad [ConstraintSystem] Use fixes to diagnose missing argument labels
Let the solver disregard missing argument labels and record correct
ones, so such problem could be diagnosed later on iff there were no
other more serious failures.
2018-07-24 22:11:56 -07:00
Brent Royal-Gordon
0be713b5a0 [Sema] Add arg parens to two generated calls 2018-07-22 19:33:56 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00