Commit Graph

15871 Commits

Author SHA1 Message Date
Pavel Yaskevich
26357eedcb Merge pull request #30742 from LucianoPAlmeida/fixme-obsolete
[TypeChecker] Remove obsolete check for load expr on typeCheckExpr
2020-04-01 00:05:17 -07:00
Ivan Smetanin
3dacbed891 Add new error diagnostic for escaping optional closures 2020-04-01 08:57:48 +03:00
Slava Pestov
52c11c78d1 Sema: Property wrapper storage wrappers ($foo) inherit 'final' bit from original property
Otherwise, we would generate inconsistent vtable layouts for classes
with static properties that have attached wrappers. The reason is that
we normally force synthesis of the backing storage and storage wrapper
for each instance property wrapper as part of computing the lowered
stored properties.

However, there was no such forcing for static properties. But since a
static stored property (with an attached wrapper or otherwise) must be
'final', the real fix is to just ensure that the 'final' bit propagates
to the storage wrapper as well.

The backing storage property was already always final, so the issue
did not arise there.

Fixes <rdar://problem/59522703>, <https://bugs.swift.org/browse/SR-12429>.
2020-03-31 23:42:34 -04:00
Luciano Almeida
90ff5c5d68 [TypeChecker] Remove obsolete check for load expr on typeCheckExpr 2020-03-31 23:49:41 -03:00
Robert Widmann
aa0bf50323 Merge pull request #30723 from CodaFi/dependendable-dependencies
[Evaluator] Online Request-Based Incremental Dependency Tracking
2020-03-31 18:13:05 -07:00
Pavel Yaskevich
fdc535a691 [ConstraintSystem] Don't include self-recursive dynamic member results as "inaccessible"
Solver has to keep track of excluded dynamic member results while
performing lookup because otherwise, in diagnostic modem it might
include such results as inaccessible.

Resolves: rdar://problem/61084565
2020-03-31 16:20:20 -07:00
Robert Widmann
42cfc7eb58 Add "Legacy" to the manual referenced name tracker 2020-03-31 16:16:53 -07:00
Robert Widmann
8c69814f5c Define Dependency Sinks
Convert most of the name lookup requests and a few other ancillary typechecking requests into dependency sinks.

Some requests are also combined sinks and sources in order to emulate the current scheme, which performs scope changes based on lookup flags. This is generally undesirable, since it means those requests cannot immediately be generalized to a purely context-based scheme because they depend on some client-provided entropy source. In particular, the few callers that are providing the "known private" name lookup flag need to be converted to perform lookups in the appropriate private context.

Clients that are passing "no known dependency" are currently considered universally incorrect and are outside the scope of the compatibility guarantees. This means that request-based dependency tracking registers strictly more edges than manual dependency tracking. It also means that once we fixup the clients that are passing "known private", we can completely remove these name lookup flags.

Finally, some tests had to change to accomodate the new scheme. Currently, we go out of our way to register a dependency edge for extensions that declare protocol conformances. However, we were also asserting in at least one test that extensions without protocol conformances weren't registering dependency edges. This is blatantly incorrect and has been undone now that the request-based scheme is automatically registering this edge.
2020-03-31 16:16:53 -07:00
Suyash Srijan
95f0651cbb [Diagnostics] Emit a warning when an immutable decodable property has an initial value (#30218)
* [Diagnostics] Emit a warning when an immutable decodable property has an initial value

* [Sema] Use Decl::diagnose instead of Diags.diagnose

* [AST] Remove property name from 'decodable_property_will_not_be_decoded' diagnostic

* [Test] Update tests

* [Test] Update existing codable tests
2020-03-31 23:16:08 +01:00
Pavel Yaskevich
f95cabb745 [ConstraintSystem] Allow sequence element mismatch fix to produce new holes
Type on the right-hand side of the element conversion/pattern match
should be allowed to have holes to be able to diagnose failures with
structurally incompatible types.

Resolves: rdar://problem/60832876
2020-03-30 17:48:46 -07:00
Robert Widmann
92c8a65f09 Drop references to name binding as a phase
A lot of places appear to mean "name lookup".  A few places meant "import resolution".
2020-03-29 18:51:09 -07:00
Hamish Knight
d2434e1bf7 NFC: Rename NameBinding to ImportResolution 2020-03-29 18:43:58 -07:00
Hamish Knight
e8cbe76cba NFC: Fix NameBinding indentation 2020-03-29 18:43:58 -07:00
Hamish Knight
71882996ca [CS] Adjust applied overload simplification
Currently `simplifyAppliedOverloads` depends on
the order in which constraints are simplified,
specifically that a lookup constraint for a
function gets simplified before the applicable
function constraint. This happens to work out
just fine today with the order in which we
re-activate constraints, but I'm planning on
changing that order.

This commit changes the logic such that it it's no
longer affected by the order in which constraints
are simplified. We'll now run it when either an
applicable function constraint is added, or a new
bind overload disjunction is added. This also
means we no longer need to run it potentially
multiple times when simplifying the applicable fn.
2020-03-29 18:33:59 -07:00
Hamish Knight
ee3e694527 [CS] Explore additional bindings for fixes (#30686)
[CS] Explore additional bindings for fixes
2020-03-29 08:47:16 -07:00
Hamish Knight
b4c13c2c55 [CS] Adjust assessRequirementFailureImpact
- In `simplifyConformsToConstraint`, pass the LHS
type regardless of whether it is a type variable.

- Add the `choiceImpact` onto the impact for
adding a stdlib conformance.

- Treat Any and AnyObject as standard library
types.
2020-03-28 17:03:42 -07:00
Hamish Knight
dc4b089b9f [CS] Don't fix an _OptionalNilComparison argument
We should only be attempting such overloads for
nil literal args.

Resolves SR-12426.
2020-03-28 17:03:42 -07:00
Hamish Knight
b517aa13ef [CS] Explore additional bindings for fixes
Previously we could skip default literal or
supertype bindings if we had already found a solution
with fixes, which could lead us to miss bindings
that produce better diagnostics.

Tweak the logic such that we continue exploring if
we're in diagnostic mode.

Resolves SR-12399.
2020-03-28 17:03:41 -07:00
Anthony Latsis
3d26b07883 Merge pull request #30421 from AnthonyLatsis/derived-conf-override-compl
CodeCompletion: Include derived requirements on override completion lookup
2020-03-29 02:00:32 +03:00
Pavel Yaskevich
24bbce142f Merge pull request #30701 from LucianoPAlmeida/diagnose-key-path-refer-init
[Diagnostics] Diagnose key path referring to init method
2020-03-28 15:37:20 -07:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
Anthony Latsis
41fe367a7e [CodeCompletion] Don't skip derived conformance members on override completion lookup 2020-03-28 23:59:18 +03:00
Luciano Almeida
faba29a55f [Diagnostics] Diagnose key path reference to initializer methods. 2020-03-28 16:32:08 -03:00
Suyash Srijan
f724d1ff85 [SE-0280] Enum cases as protocol witnesses (#28916)
* [Typechecker] Allow enum cases without payload to witness a static get-only property with Self type protocol requirement

* [SIL] Add support for payload cases as well

* [SILGen] Clean up comment

* [Typechecker] Re-enable some previously disabled witness matching code

Also properly handle the matching in some cases

* [Test] Update typechecker tests with payload enum test cases

* [Test] Update SILGen test

* [SIL] Add two FIXME's to address soon

* [SIL] Emit the enum case constructor unconditionally when an enum case is used as a witness

Also, tweak SILDeclRef::getLinkage to update the 'limit' to 'OnDemand' if we have an enum declaration

* [SILGen] Properly handle a enum witness in addMethodImplementation

Also remove a FIXME and code added to workaround the original bug

* [TBDGen] Handle enum case witness

* [Typechecker] Fix conflicts

* [Test] Fix tests

* [AST] Fix indentation in diagnostics def file
2020-03-28 10:44:01 +00:00
Hamish Knight
31e46b3a23 [CS] Fix a locator path element
This locator is for Dictionary's Value generic
parameter.
2020-03-27 15:13:24 -07:00
Hamish Knight
234270c941 [CS] NFC: Tweak addExplicitConversionConstraint
Have it take a RememberChoice_t instead of an
'allowFixes' bool, as the parameter no longer
really corresponds to fixes.
2020-03-27 15:13:24 -07:00
swift-ci
2d8bca0cb7 Merge pull request #30679 from CodaFi/repetez-repartee 2020-03-27 14:46:54 -07:00
Doug Gregor
85762c30f5 Merge pull request #30663 from DougGregor/property-wrapper-default-init-infer-type
[Property wrappers] Allow default initialization to infer a type.
2020-03-27 13:46:47 -07:00
Robert Widmann
d7e9738a05 [NFC] Implement CheckRedeclarationRequest
Use the request evaluator to formalize the fact that this function
should be evaluated once per decl in the primary.
2020-03-27 12:27:09 -07:00
Hamish Knight
5af04d35b4 Move operator lookup tables onto SourceLookupCache (#30587)
Move operator lookup tables onto SourceLookupCache
2020-03-27 12:04:11 -07:00
ematejska
9f0f92fa29 [AutoDiff upstream] Upstream @transpose attribute type-checking. (#30664)
The `@transpose` attribute registers a function as the transpose of another
function-like declaration: a `func`, `init`, `subscript`, or `var` computed
property declaration.

The `@transpose` attribute also has an optional `wrt:` clause specifying the
linearity parameters, i.e. the parameters that are transposed with respect to.
The linearity parameters must conform to the `Differentiable` protocol and
satisfy `Self == TangentVector`.

If the `wrt:` clause is unspecified, the linearity parameters are inferred to be
all parameters that conform to `Differentiable` and that satisfy
`Self == TangentVector`.

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

Resolves TF-830.
2020-03-27 11:22:21 -07:00
Pavel Yaskevich
94fdce791d Merge pull request #30658 from xedin/rdar-60901494
[ConstraintSystem] Don't check `-disable-availability-checking`
2020-03-27 10:44:27 -07:00
Hamish Knight
4e42f033a5 Switch operator lookup over to using SourceLookupCache
Switch the direct operator lookup logic over to
querying the SourceLookupCache, then switch the
main operator lookup logic over to calling the
direct lookup logic rather than querying the
operator maps on the SourceFile.

This then allows us to remove the SourceFile
operator maps, in addition to the logic from
NameBinding that populated them. This requires
redeclaration checking to be implemented
separately.

Finally, to compensate for the caching that the old
operator maps were providing for imported results,
turn the operator lookup requests into cached
requests.
2020-03-27 09:45:33 -07:00
Robert Widmann
1f904ca86d Merge pull request #30669 from CodaFi/consteval
[NFC] A Handful of Sweeping Evaluator Cleanups
2020-03-27 09:43:28 -07:00
Dan Zheng
28315487dc [AutoDiff upstream] Serialize derivative function configurations. (#30672)
Serialize derivative function configurations per module.

`@differentiable` and `@derivative` attributes register derivatives for
`AbstractFunctionDecl`s for a particular "derivative function configuration":
parameter indices and dervative generic signature.

To find `@derivative` functions registered in other Swift modules, derivative
function configurations must be serialized per module. When configurations for
a `AbstractFunctionDecl` are requested, all configurations from imported
modules are deserialized. This module serialization technique has precedent: it
is used for protocol conformances (e.g. extension declarations for a nominal
type) and Obj-C members for a class type.

Add `AbstractFunctionDecl::getDerivativeFunctionConfigurations` entry point
for accessing derivative function configurations.

In the differentiation transform: use
`AbstractFunctionDecl::getDerivativeFunctionConfigurations` to implement
`findMinimalDerivativeConfiguration` for canonical derivative function
configuration lookup, replacing `getMinimalASTDifferentiableAttr`.

Resolves TF-1100.
2020-03-27 06:40:27 -07:00
Dan Zheng
bbe86e908d [AutoDiff upstream] Add Differentiable protocol derived conformances. (#30671)
Add `AdditiveArithmetic` derived conformances for structs and classes, gated by
the `-enable-experimental-differentiable-programming` flag.

Structs and classes whose stored properties all conform to `Differentiable` can
derive `Differentiable`:

- `associatedtype TangentVector: Differentiable & AdditiveArithmetic`
  - Member `TangentVector` structs are synthesized whose stored properties are
    all `var` stored properties that conform to `Differentiable` and that are
    not `@noDerivative`.
- `mutating func move(along: TangentVector)`

The `@noDerivative` attribute may be declared on stored properties to opt out of
inclusion in synthesized `TangentVector` structs.

Some stored properties cannot be used in `TangentVector` struct synthesis and
are implicitly marked as `@noDerivative`, with a warning:

- `let` stored properties.
  - These cannot be updated by `mutating func move(along: TangentVector)`.
- Non-`Differentiable`-conforming stored properties.

`@noDerivative` also implies `@_semantics("autodiff.nonvarying")`, which is
relevant for differentiable activity analysis.

Add type-checking and SILGen tests.

Resolves TF-845.
2020-03-27 06:40:04 -07:00
marcrasi
f6562d3a67 [AutoDiff upstream] differentiable function conversion pipeline (#30660)
Add the `@differentiable` function conversion pipeline:

- New expressions that convert between `@differentiable`,
  `@differentiable(linear)`, and non-`@differentiable` functions:
  - `DifferentiableFunction`
  - `LinearFunction`
  - `DifferentiableFunctionExtractOriginal`
  - `LinearFunctionExtractOriginal`
  - `LinearToDifferentiableFunction`
- All the AST handling (e.g. printing) necessary for those expressions.
- SILGen for those expressions.
- CSApply code that inserts these expressions to implicitly convert between
  the various function types.
- Sema tests for the implicit conversions.
- SILGen tests for the SILGen of these expressions.

Resolves TF-833.
2020-03-27 01:27:39 -07:00
Pavel Yaskevich
c99c9b95d0 [ConstraintSystem] Switch availability check to use correct API
Use `TypeChecker::checkDeclarationAvailability` instead of `isDeclAvailable`,
that is a proper API endpoint which does flag checking before calling
`isDeclAvailable` internally.
2020-03-27 00:43:09 -07:00
marcrasi
eae4c5eece [AutoDiff upstream] @differentiable function type sema (#30648)
Add type checking for `@differentiable` function types:
- Check that parameters and results conform to `Differentiable`.
- Implicitly conform parameters and results whose types are generic parameters
  to `Differentiable`.
- Upstream most of the differentiable_func_type_type_checking.swift test from
  `tensorflow` branch. A few function conversion tests have not been added
   because they depend on the `@differentiable` function conversion pipeline.

Diagnose gracefully when the `Differentiable` protocol is unavailable because
`_Differentiation` has not been imported.

Resolves TF-823 and TF-1219.
2020-03-26 23:28:02 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
f2a1abc5dd [NFC] Refactor Side-Effecting Requests to be Explicitly so
Introduce evaluator::SideEffect, the type of a request that performs
some operation solely to execute its side effects. Thankfully, there are
precious few requests that need to use this type in practice, but it's
good to call them out explicitly so we can get around to making them
behave much more functionally in the future.
2020-03-26 22:55:20 -07:00
Pavel Yaskevich
4af4a3d901 Merge pull request #30656 from apple/revert-29845-trailing-closure-position
Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter"
2020-03-26 17:30:51 -07:00
Robert Widmann
4accf59a3b Merge pull request #30618 from CodaFi/protocol-adoption-program
[NFC] Add LookupConformancesInContextRequest
2020-03-26 17:18:55 -07:00
Pavel Yaskevich
81dbec09fb [ConstraintSystem] Don't check -disable-availability-checking
Checking for `-disable-availability-checking` in
`ConstraintSystem::isDeclUnavailable` caused a regression with
obsolete/introduced checking. Let's rely on
`DeclAttributes::isUnavailable` and `TypeChecker::isDeclAvailable`
to do the right thing instead.

Resolves: rdar://problem/60898369
2020-03-26 16:13:32 -07:00
Doug Gregor
d282e3c1e9 [Property wrappers] NFC rename initialValue -> wrappedValue where appropriate
wrappedValue is the new name, and we only support initialValue for backward
compatibility with earlier revisions of the property wrappers proposal.
2020-03-26 15:16:28 -07:00
Doug Gregor
5ac8d769fd [Property wrappers] Allow default initialization to infer a type.
Property wrappers are allowed to infer the type of a variable, but this
only worked when the property wrapper was provided with an explicit
initialization, e.g.,

    @WrapsAnInt() var x   // infers type Int from WrapsAnInt.wrappedValue

However, when default initialization is supported by the property wrapper,
dropping the parentheses would produce an error about the missing type
annotation

    @WrapsAnInt var x

Make this second case behave like the first, so that default initialization
works consistently with the explicitly-specified version.
Fixes rdar://problem/59471019.
2020-03-26 13:44:08 -07:00
Doug Gregor
38964fc360 [Type checker] Remove dead code to compute pattern checking options. 2020-03-26 12:48:47 -07:00
Holly Borla
febcbf6d1c Merge pull request #30655 from hborla/missing-conformance-operator-ref
[Diagnostics] Support diagnosing references to operators without argument application
2020-03-26 11:13:12 -07:00
Robert Widmann
4de729fffc [NFC] Add LookupConformancesInContextRequest
Add a request to lookup all implied conformances for use while
typechecking the primary. This provides a cache-point for
evaluator-based dependency tracking.
2020-03-26 10:26:25 -07:00