Commit Graph

15871 Commits

Author SHA1 Message Date
Slava Pestov
019452f9af Sema: Diagnose unbound method references on 'super.'
This is something I noticed by inspection while working on
<https://bugs.swift.org/browse/SR-75>.

Inside a static method, 'self' is a metatype value, so
'self.instanceMethod' produces an unbound reference of type
(Self) -> (Args...) -> Results.

You might guess that 'super.instanceMethod' can similarly
be used to produce an unbound method reference that calls
the superclass method given any 'self' value, but unfortunately
it doesn't work.

Instead, 'super.instanceMethod' would produce the same
result as 'self.instanceMethod'. Maybe we can implement this
later, but for now, let's just diagnose the problem.

Note that partially-applied method references with 'super.'
-- namely, 'self.staticMethod' inside a static context, or
'self.instanceMethod' inside an instance context, continue
to work as before.

They have the type (Args...) -> Result; since the self value
has already been applied we don't hit the representational
issue.
2020-02-27 17:28:23 -05:00
Holly Borla
3cdc30ffeb [Sema] Support type erasure for dynamic replacement in function
builders.
2020-02-27 09:01:16 -08:00
Slava Pestov
00318732e1 Merge pull request #30084 from slavapestov/sr-75-prep
More Sema cleanups to prepare for curry thunks
2020-02-27 09:06:38 -05:00
Pavel Yaskevich
65ab041805 Merge pull request #29868 from omochi/fix-claimNextNamed
[ConstraintSystem] remove unused computation in claimNextNamed
2020-02-26 22:07:42 -08:00
Slava Pestov
9452c60b3b Sema: Remove CSApply's getNaturalArgumentCount() in favor of getNumCurryLevels() 2020-02-26 23:10:07 -05:00
Slava Pestov
90ee606de7 Sema: Refactor CSApply in preparation for curry thunks 2020-02-26 23:10:07 -05:00
omochimetaru
79a8a596e4 [ConstraintSystem] remove unused computation in claimNextNamed 2020-02-27 10:49:42 +09:00
Suyash Srijan
d7bba7f193 [Typechecker] Use getCalledValue() rather than using DeclRefExpr to get the function decl when checking ignored expressions (#30077) 2020-02-26 19:49:58 +00:00
Doug Gregor
031f5a4888 Merge pull request #30065 from DougGregor/function-builders-if-case-fixes
[Constraint system] Cleanups for function builders support for if let/if case let
2020-02-26 10:38:15 -08:00
Pavel Yaskevich
e70ef60ad5 Merge pull request #30067 from xedin/rdar-59741308
[ConstraintSystem] Don't attempt bindings for closure parameters/resu…
2020-02-26 10:03:58 -08:00
Doug Gregor
c58e0aa169 [Constraint system] Make sure we set expression types on StmtCondition. 2020-02-25 22:43:21 -08:00
Holly Borla
96d7434fd0 [Sema] Implement type erasure for dynamic replacement when the
dynamically replaceable function returns an opaque type.
2020-02-25 19:53:25 -08:00
Slava Pestov
2cfc2fa567 Merge pull request #30054 from slavapestov/vtable-thunk-generic-subclass-non-generic-base-class
Fix vtable thunk emission with a generic subclass of a non-generic base class
2020-02-25 22:10:03 -05:00
Pavel Yaskevich
0e88bd6890 [ConstraintSystem] Don't attempt bindings for closure parameters/result until body is opened
Let's delay attempting any bindings for type variables representing
parameters or result type of the closure until the body is "opened"
because it's impossible to infer a full set of bindings until all
constraints related to a closure have been generated.

Resolves: rdar://problem/59741308
2020-02-25 17:42:37 -08:00
Pavel Yaskevich
9ae68133ff Merge pull request #30040 from xedin/sr-11743
[ConstraintSystem] Look through l-value while checking whether dynami…
2020-02-25 17:09:45 -08:00
Hamish Knight
63e4ec6bdd Merge pull request #30038 from hamishknight/plenty-of-scope-for-requestification
Requestify scoped import validation
2020-02-25 16:40:00 -08:00
Doug Gregor
8482516412 [Constraint system] Properly deal with "as" patterns.
Teach pattern matching involving "as" patterns to work properly in
function builders. The code almost handled this, but prematurely
prechecking expressions in patterns broke it.
2020-02-25 16:29:07 -08:00
Doug Gregor
cc8db01ba9 Merge pull request #30045 from DougGregor/function-builders-if-let
[Constraint system] Support if let / if case in function builders.
2020-02-25 16:24:09 -08:00
Doug Gregor
6ad4b252ef [Constraint system] Address review comments on if patterns in function builders 2020-02-25 14:06:05 -08:00
Doug Gregor
141f3e7f07 [Constraint system] Expand SolutionApplicationTarget to StmtConditions.
Handle StmtCondition as part of SolutionApplicationTarget, so we can
generate constraints from it and rewrite directly as part of a solution,
rather than open-coding the operation in the function builder transform.
2020-02-25 13:47:26 -08:00
Slava Pestov
59cc7d7512 AST: Tighten up preconditions for getOverrideGenericSignature() 2020-02-25 16:41:28 -05:00
Hamish Knight
0c785aaa07 [NameBinding] Remove BoundImport
This was only required to represent an import that
hadn't yet had its scope validated. Now that the
validation has been requestified, we can directly
record the resulting `ImportedModuleDesc` instead.
2020-02-25 13:29:52 -08:00
Hamish Knight
ab9b6d7e11 Requestify scoped import validation
Move the validation of scoped imports into a
request, and force the request when we're
type-checking a primary file. This has the nice
bonus of no longer running the validation for
secondary files.

The use of `ModuleDecl::getTopLevelModule` also
allows us to correctly retrieve the top-level
module for a Clang submodule, rather than
potentially retrieving the Swift module in a mixed
source project.

Resolves SR-12265.
2020-02-25 13:29:52 -08:00
Rintaro Ishizaki
571d09a8a2 Merge pull request #29955 from AnthonyLatsis/operator-diag-qoi
[Parse] Improve recovery from and diagnostics for invalid operator names
2020-02-25 10:11:26 -08:00
Joe Groff
0a318a39f1 Merge pull request #29644 from jckarter/subst-function-type-shakeout
Enable substituted SIL function types
2020-02-25 09:47:10 -08:00
Doug Gregor
4830c48960 [Constraint system] Support if let / if case in function builders.
Use the generalized constraint generation and binding for patterns to
introduce support for if-let and if-case in function builders, handling
arbitrary patterns.

Part of function builder generalization, rdar://problem/50426203.
2020-02-25 09:44:06 -08:00
Doug Gregor
3f2f79a699 [Constraint system] Fold pattern variable binding into constraint gen.
Rather than re-walk the pattern to create type bindings for the variables
that show up in the pattern, assign types to each of the variables as part
of constraint generation for the pattern. Only do this in contexts
where we will need the types, e.g., function builders.
2020-02-25 08:51:56 -08:00
Doug Gregor
fe5c068ffb Merge pull request #29879 from DougGregor/constraint-system-patterns
[Constraint system] Generate constraints from patterns
2020-02-24 20:41:14 -08:00
Pavel Yaskevich
2cdd78501c [ConstraintSystem] Look through l-value while checking whether dynamic key path is recursive
Fix a crash in dynamic member lookup attempting to recursively
lookup a member on the same base type.

The problem is related to `isSelfRecursiveKeyPathDynamicMemberLookup`
which failed to look through l-value wrapping base type on each side of
the comparison, that's important because it's possible to have l-value
mismatch due to the fact that implicit call always gets l-value base
type but actual subscript which triggered dynamic lookup might be r-value.

Resolves: [SR-11743](https://bugs.swift.org/browse/SR-11743)
Resolves: rdar://problem/57091169
2020-02-24 19:38:20 -08:00
Doug Gregor
644ed76a01 [Constraint system] Prefer enum cases to static members when pattern matching. 2020-02-24 15:00:39 -08:00
Doug Gregor
6cfa0b047d [Constraint system] Don't dereference a null member locator. 2020-02-24 14:46:25 -08:00
Pavel Yaskevich
b926250c70 Merge pull request #30006 from xedin/rdar-56212087
[ConstraintSystem] Make it possible to infer subtype bindings through argument conversions
2020-02-24 14:18:35 -08:00
Joe Groff
cf0e09d9c5 Preserve conformances for upper bound constraints when lowering SILFunctionTypes 2020-02-24 12:14:21 -08:00
Joe Groff
cb9cfc3903 Map substitutions into context when resolving parsed SILFunctionTypes 2020-02-24 12:14:21 -08:00
Joe Groff
9c9bf567f7 SIL: Preserve upper bound constraints for substitutions into nominal types.
When extracting substitutions during type lowering, we can't discard protocol constraints
in positions where the substitution is for a nominal type's generic arguments, since associated
types on that protocol may affect the nominal type's ABI.
2020-02-24 12:14:21 -08:00
Doug Gregor
f6f80befe8 [Constraint system] Handle implicit tupling during pattern matching.
SE-0110 strikes again!
2020-02-24 11:45:23 -08:00
Doug Gregor
d607d3a068 [Constraint system] Custom diagnostics for failed pattern matches.
Extend the constraint system’s diagnostics with specific handling for
matching an enum element pattern that has a subpattern (i.e., to capture
associated values) against an enum case that does not have any associated
value. This brings diagnostics for the new code path on par with the existing
diagnostics of coercePatternToType.
2020-02-24 00:48:15 -08:00
Doug Gregor
dcf7ddeb3a [Constraint system] Generate constraints for EnumElement patterns.
Generate a complete set of constraints for EnumElement patterns, e.g.,

    case let .something(x, y)

Most of the complication here comes from the implicit injection of optionals,
e.g., this case can be matched to an optional of the enum type of which
`something` is a member. To effect this change, introduce a locator for
pattern matching and use it to permit implicit unwrapping during member
lookup without triggering an error.

Note also labels are dropped completely when performing the match,
because labels can be added or removed when pattern matching. Label
conflict are currently diagnosed as part of coercePatternToType, which
suffices so long as overloading cases based on argument labels is not
permitted.

The primary observable change from this commit is in diagnostics: rather
than diagnostics being triggered by `TypeChecker::coercePatternToType`,
diagnostics for matching failures here go through the diagnostics machinery
of the constraint solver. This is currently a regression, because
there are no custom diagnostics for pattern match failures within the
constraint system. This regression will be addressed in a subsequent
commit; for now, leave those tests failing.
2020-02-24 00:48:15 -08:00
Doug Gregor
08bfba79df [Constraint system] Add conversion constraint for typed patterns.
For typed patterns, the sub pattern type must be convertible to the type
provided to the pattern.
2020-02-24 00:48:15 -08:00
Doug Gregor
bea9d06a8b [Constraint system] Set the type on all patterns, not just top-level ones. 2020-02-24 00:48:15 -08:00
Doug Gregor
244a8232dd [Constraint system] Maintain paren type sugar for patterns. 2020-02-24 00:48:15 -08:00
Doug Gregor
7bef5405ec [Constraint system] “is” pattern match should open the type 2020-02-24 00:48:15 -08:00
Doug Gregor
270be17bc0 [Type checker] Drop unused parameter from coercePatternToType(). 2020-02-24 00:48:15 -08:00
Doug Gregor
8fb05af641 [Constraint solver] Give Bool patterns Bool type. 2020-02-24 00:48:14 -08:00
Doug Gregor
232f20f58d [Constraint solver] Generate constraints for “is” patterns.
Generate a checked-cast constraint for an “is” pattern, which otherwise
doesn’t change the type. This is hard to validate because checked-cast
constraints never actually fail.
2020-02-24 00:48:14 -08:00
Doug Gregor
ee90374a8f [Constraint system] Finish an unfinished comment. 2020-02-24 00:48:14 -08:00
Doug Gregor
be8b9e5ef4 [Constraint solver] Always produce optional types for '?' patterns. 2020-02-24 00:48:14 -08:00
Doug Gregor
d2b2a50772 [Constraint system] Record application targets for statement conditions.
We’ll need this to generate constraints for statement conditions within the
constraint system. This is unused boilerplate at the moment.
2020-02-24 00:48:14 -08:00
Doug Gregor
d81161aa47 Merge pull request #29851 from DougGregor/remove-performance-hacks
[Constraint solver] Remove performance hacks for pattern type computation
2020-02-23 22:46:50 -10:00
Pavel Yaskevich
96297b7e39 [CSStep] Always attempt literal bindings in diagnostic mode
In case of contextual failures such bindings could produce
better solutions with fewer fixes.
2020-02-21 17:47:39 -08:00