Commit Graph

12650 Commits

Author SHA1 Message Date
Pavel Yaskevich
42e0f21409 [CSDiagnostics] Improve requirement failure source detection
If affected declaration is a static or instance memeber (excluding
operators) and failed requirement is declared in other nominal type
or extension, diagnose such problems as `in reference` instead of
claiming that requirement belongs to the member itself.
2019-02-08 15:05:42 -08:00
Pavel Yaskevich
0d0c132ecd [Sema] NFC: Add accessors to check whether locator is type or conditional requirement 2019-02-08 15:04:44 -08:00
Brent Royal-Gordon
6d8dbfa0f1 [NFC] Style/assertion/test design improvements 2019-02-08 14:17:38 -08:00
Jordan Rose
19c1765187 Remove unnecessary work from availability fix-its
As near as I can tell, this was always going to start with
DeclarationToSearch and then end up with DeclarationToSearch, since
it's already a declaration (and we already checked for null earlier).
No test changes observed either.
2019-02-08 11:39:32 -08:00
Jordan Rose
722cb836f5 Extend transitive availability checking to initial value expressions
Because initial value expressions aren't actually considered /within/
the VarDecl or PatternBindingDecl they're initializing, the existing
logic to search for availability attributes wasn't kicking in, leading
to errors when a conditionally-unavailable value was used in an
initial value expression for a conditionally-unavailable binding. Fix
this by walking the enclosing type or extension to find the appropriate
PatternBindingDecl.

https://bugs.swift.org/browse/SR-9867
2019-02-08 11:39:32 -08:00
Pavel Yaskevich
6fd1600534 [ConstraintSystem] Diagnose conditional requirement failures via fixes
Extend existing `RequirementFailure` functionality to support
conditional requirement failures. Such fixes are introduced
only if the parent type requirement has been matched successfully.

Resolves: rdar://problem/47871590
2019-02-08 11:16:54 -08:00
Pavel Yaskevich
dfac0d8323 [CSDiagnostics] Augment RequirementFailure to support conditional requirements 2019-02-08 11:14:41 -08:00
Ding Ye
0f493a68b3 [Sema] Improve diagnostics for access level of protocol witness in extension. (#22235)
If the access level of a protocol witness does not satisfies a requirement,
the compiler suggests marking it as the required level.  This is not suitable
when the witness is in an extension whose specified access level is less than
the required level, since the fixit fights with other warnings in this case.
This patch identifies such case and produces improved diagnostics.

Resolves: SR-9793
2019-02-08 09:31:01 -08:00
Slava Pestov
dffa29fd0d AST: Remove a few uses of FunctionType::Param::getOldType() 2019-02-07 23:46:31 -05:00
Slava Pestov
12fa026f99 Sema: Use AbstractStorageDecl::getValueInterfaceType() in a couple of spots 2019-02-07 23:46:31 -05:00
Slava Pestov
e18a61c3b4 Sema: Remove unused parameter from getTypeOfReference() 2019-02-07 23:46:31 -05:00
Slava Pestov
71ff168ad5 Sema: Add a couple more counters 2019-02-07 23:46:31 -05:00
Bob Wilson
4dc2eaccdc [master-next] After LLVM r344359, Timer names with slashes do not work.
The code in TimerGroup::printJSONValue asserts that the name does not need
to be quoted. Perhaps we can get this fixed, but for now at least, rename
a Timer that has a forward slash in its name.
2019-02-07 17:54:44 -08:00
Pavel Yaskevich
2ea00c3815 Merge pull request #22442 from xedin/diagnose-construction-using-non-cost-metatype
[ConstraintSystem] Detect invalid implicit ref to initializer on non-…
2019-02-07 17:30:49 -08:00
Pavel Yaskevich
f2abfc547a [ConstraintSystem] Add requirement kind to conditional conformance requirement locator 2019-02-07 13:51:20 -08:00
Jordan Rose
c8acb7e4c2 @objc extension makes even 'private' members '@objc' (#22436)
This regressed in a8fb416f9e, when we started using a helper function
in more places.

rdar://problem/47869562
2019-02-07 10:10:38 -08:00
Pavel Yaskevich
1d42e16ad2 [ConstraintSystem] Detect invalid implicit ref to initializer on non-const metatype
Situations like:

```swift
struct S {}
func foo(_ s: S.Type) {
  _ = s()
}
```

Used to be diagnosed in solution application phase, which means that
solver was allowed to formed an incorrect solution.
2019-02-07 00:17:07 -08:00
Pavel Yaskevich
6754b86507 Merge pull request #22379 from xedin/rdar-47787705
[ConstraintSystem] Detect invalid initializer references early
2019-02-06 17:16:20 -08:00
Pavel Yaskevich
9a1e92ec0a [AST] Add getDecl parameter to Expr::isTypeRerefence
So it could be extended to support not yet fully type-checked
AST when used by constraint system solver.
2019-02-05 18:09:51 -08:00
Pavel Yaskevich
0a07619992 Merge pull request #22348 from xedin/cleanup-autoclosure-diags
[Sema] Extract @autoclosure diagnostics from type resolver
2019-02-05 16:05:44 -08:00
Pavel Yaskevich
7f262a7003 [Sema] Extract @autoclosure diagnostics from type resolver
Since @autoclosure attribute is associated with declarations
it makes more sense to move diagnostics to where type of the
parameter has been completely resolved. This also helps to support
parameters with typealiases pointing to function types without
any extra logic in the resolver.
2019-02-05 10:57:05 -08:00
Pavel Yaskevich
e8c8c0b705 [CSApply] Remove obsolete diagnoseInvalidDynamicConstructorReferences 2019-02-05 10:52:52 -08:00
Pavel Yaskevich
0595cefab3 [CSDiagnostics] Add diagnostics for two kinds of incorrect initializer reference
- Attempting to construct class object using metatype value via
  non-required initializer

- Referencing initializer of protocol metatype base

Both of the diagnostics are used by `AllowInvalidInitRef` fix.
2019-02-05 10:28:41 -08:00
Pavel Yaskevich
1d8cee9cb4 [ConstraintSystem] Detect invalid initializer references early
Currently invalid initializer references are detected and
diagnosed in solution application phase, but that's too
late because solver wouldn't have required information while
attempting to determine the best solution, which might result
in viable solutions being ignored in favour of incorrect ones e.g.

```swift
protocol P {
  init(value: Int)
}

class C {
  init(value: Int, _: String = "") {}
}

func make<T: P & C>(type: T.Type) -> T {
  return T.init(value: 0)
}
```

In this example `init` on `C` would be preferred since it
comes from the concrete type, but reference itself is invalid
because it's an attempt to construct class object using
metatype value via non-required initalizer.

Situations like these should be recognized early and invalid
use like in case of `C.init` should be ranked lower or diagnosed
if that is the only possible solution.

Resolves: rdar://problem/47787705
2019-02-05 10:25:36 -08:00
Doug Gregor
de2b75c1c1 Merge pull request #22370 from DougGregor/lazy-known-protocol-kind
[AST] Lazily compute ProtocolDecl::getKnownProtocolKind()
2019-02-05 06:49:42 -08:00
Doug Gregor
d19d2f2490 [AST] Lazily compute ProtocolDecl::getKnownProtocolKind()
Rather than eagerly doing a bunch of name lookups to establish the known
protocol kind, lazily match the ProtocolDecl to the list of known
protocols as-needed. This eliminates a bunch of up-front unqualified
name lookups when spinning up a type checker.
2019-02-04 21:25:48 -08:00
Brent Royal-Gordon
5da6668b8a Refactor availability-checking code to handle more cases
Moves a lot of it into helper functions and types so it doesn’t disrupt the main flow of the code so much. Also makes it handle always-unavailable and obsolete cases (by skipping them).
2019-02-04 15:54:23 -08:00
Slava Pestov
14bbab4d56 Merge pull request #22259 from pschuh/s-3
BooleanLiteralExpr now is lowered directly into SIL.
2019-02-04 18:06:59 -05:00
Jordan Rose
aabcabfdf3 Merge pull request #21983 from KingOfBrian/bugfix/SR-964-As-Member-master
[Sema] Report unused newValue when getter is accessed in custom setter
2019-02-04 14:46:33 -08:00
Brent Royal-Gordon
d2d1211b51 Further improve AvailabilityWalker changes
Access context more quickly; document each flag’s purpose; perform a faster test before a slower one.
2019-02-04 13:50:46 -08:00
swift-ci
4ee879eb54 Merge pull request #22342 from DougGregor/type-checker-state-removal 2019-02-04 08:13:51 -08:00
Doug Gregor
1b4b7390ba [Type checker] Remove some pointless cached state from the type checker.
We can retrieve these standard library declarations from the ASTContext
easily enough, and the interface type is already cached, so do that.
2019-02-03 22:32:20 -08:00
David Ungar
520b801bf0 Merge pull request #21177 from davidungar/A-exp-dep-graph-12-10-18
First cut at graph-based fine-grained experimental dependencies.
2019-02-03 21:15:17 -08:00
Doug Gregor
47f9dd10fb Merge pull request #22291 from DougGregor/name-lookup-archetype-anchor-rdar47605019
[Type checker] Ensure that we record archetype anchors.
2019-02-01 09:54:16 -08:00
Doug Gregor
8210f0521d [Type checker] Ensure that we record archetype anchors.
When we aren't going through proper resolution of an associated type
of 'Self', at least record an archetype anchor. Narrow fix for
rdar://problem/47605019.
2019-01-31 22:43:42 -08:00
Pavel Yaskevich
b6c1ac0038 Merge pull request #22267 from xedin/rdar-47492691
[ConstraintSystem] Decouple `designated types` feature from Swift ver…
2019-01-31 15:54:47 -08:00
Pavel Yaskevich
6449e47e2c Merge pull request #22231 from theblixguy/fix/SR-9760
[Typechecker] Fix an issue with @escaping when used with a generic function
2019-01-31 15:38:25 -08:00
Pavel Yaskevich
0b29d9d4e6 [ConstraintSystem] Decouple designated types feature from Swift version
`selectApplyDisjunction` only makes sense in conjunction with
designated types feature because it's going to prioritize disjunctions
with arguments which are known to conform to literal protocols.

Prioritization like that is harmful without designated types feature
because it doesn't always lead to better constraint system splits,
and could prioritize bigger disjunctions which harms chances to
short-circuit solving.

Resolves: rdar://problem/47492691
2019-01-31 11:48:35 -08:00
Parker Schuh
d8bff8ddc9 BooleanLiteralExpr now is lowered directly into SIL.
Instead of constructing calls to ExpressibleByBooleanLiteral.init(booleanLiteral: ...) in CSApply.cpp, just
annotate BooleanLiteralExpr with the selected constructor and do the actual construction during SILGen.

For context, StringLiteralExpr and NilLiteralExpr already behave this way.
2019-01-31 09:56:00 -08:00
Suyash Srijan
be6dc7c84a [typechecker] handle typealias inside protocols when used with @escaping 2019-01-30 17:51:02 +00:00
John McCall
8be4ec32e6 Protocol requirement overrides must match in mutating-ness.
Without this change, SILGen will crash when compiling a use of the
derived protocol's requirement: it will instead attempt to use
the base protocol's requirement, but the code will have been
type-checked incorrectly for that.

This has a potential for source-compatibility impact if anyone's
using explicit override checking for their protocol requirements:
reasonable idioms like overriding a mutating requirement with a
non-mutating one will no longer count as an override.  However,
this is arguably a bug-fix, because the current designed intent
of protocol override checking is to not allow any differences in
type, even "covariant" changes like making a mutating requirement
non-mutating.  Moreover, we believe explicit override checking in
protocols is quite uncommon, so the overall compatibility impact
will be low.

This also has a potential for ABI impact whenever something that
was once an override becomes a non-override and thus requires a
new entry.  It might require a contrived test case to demonstrate
that while using the derived entry, but it's quite possible to
imagine a situation where the derived entry is not used directly
but nonetheless has ABI impact.

Furthermore, as part of developing this patch (earlier versions of
which used stricter rules in places), I discovered a number of
places where the standard library was unintentionally introducing
a new requirement in a derived protocol when it intended only to
guide associated type deduction.  Fixing that (as I have in this
patch) *definitely* has ABI impact.
2019-01-30 01:33:09 -05:00
Pavel Yaskevich
2e0c6db871 Merge pull request #22186 from xedin/rdar-47586626
[TypeChecker] Drop @autoclosure attribute from invalid parameters
2019-01-29 14:24:24 -08:00
Pavel Yaskevich
005abcc3e9 Merge pull request #22212 from xedin/rdar-47550715
[TypeChecker] Classify `nil` literal and `.none` as non-contriburing to throws
2019-01-29 13:04:10 -08:00
Pavel Yaskevich
43670cb897 [TypeChecker] Classify nil literal and .none as non-contriburing to throws
Original fix for SR-9102 stripped throws bit from the function types
nested inside optionals before attempting bindings, that doesn't
work with e.g. default parameter values because conversions from
throwing and non-throwing functions are only allowed in subtype
relationship but function types nested inside optionals are going
to be equated.

So this patch takes an alternative approach and attempts to pattern
match `nil` literal and `.none` use and classify argument as
non-contributing to throws.

Resolves: rdar://problem/47550715
2019-01-29 10:27:37 -08:00
Jordan Rose
15056ed695 Remove mistaken early exit from access checking
Warnings should not result in early exits because we might end up
missing an error!
2019-01-28 18:26:43 -08:00
Jordan Rose
3c740e4f2e Don't fix access of an 'open' decl in a 'public' extension
This is reasonable to diagnose with a warning, but dropping the 'open'
down to 'public' isn't the right fix, because now it's not a valid
override. The declaration has to get moved to another extension instead,
or the extension has to not set a default access level.

This turned out to be a source compat issue because the same logic
that emits the fix-it also updates the access of the member, which
then resulted in "must be as accessible as the declaration it
overrides" in the /same/ build. It's not immediately clear what caused
this; probably something's just being validated in a different order
than it was before. The change makes sense either way.

Stepping back, it's weird that a warning would change how the compiler
saw the code, and while we could check for 'override' explicitly, we
can't know if the member might be satisfying a protocol requirement.
Better to just not guess at the right answer here.

rdar://problem/47557376&28493971
2019-01-28 18:25:06 -08:00
Jordan Rose
1f06cd7e6d Tweak diagnostic for a high-access member in a low-access extension
Before: declaring a public instance method in a private extension
After: 'public' modifier conflicts with extension's default access of
       'private'
2019-01-28 18:24:12 -08:00
Brent Royal-Gordon
a6c23790f9 Add #available guards to init(rawValue:)
When a case has an @available(currentPlatform, introduced: x.y) attribute, the auto-derived init(rawValue:) will now include a “guard #available(currentPlatform x.y, *) else { return nil }” check to prevent the new case from being returned.

This requires a targeted hack to disable @available(introduced:) checks in auto-derived init(rawValue:) implementations; the availability checker is SourceLoc-based, so it can’t tell that the synthesized `guard` covers the use of the case. I’m not happy about that, but fixing the deeper problem is a much larger task than I can take on in one day.
2019-01-28 17:34:54 -08:00
Pavel Yaskevich
9da67c1897 [TypeChecker] Drop @autoclosure attribute from invalid parameters
While forming/validating parameters make sure that the type is indeed
a function type before marking it as `autoclosure` based on type
representative attributes, because parser doesn't change attributes
even after the error has been found and diagnosed.

Resolves: rdar://problem/47586626
2019-01-28 17:01:05 -08:00
Brent Royal-Gordon
c48be0072e [NFC] Refactor diagnoseDeclAvailability() flags
The function took three random boolean parameters; there’s about to be a fourth. This wasn’t going to scale.
2019-01-28 16:42:23 -08:00