Commit Graph

1378 Commits

Author SHA1 Message Date
Doug Gregor
600c967563 [Constraint application] Remove a bogus assertion.
THe constraint solver validates that any conditional requirements have
been satisfied; we don't need to fail here.
2017-11-14 16:23:20 -08:00
Joe Groff
4b401e257a Merge pull request #12835 from jckarter/key-path-type-checking
Sema: Fixes for KeyPath type checking.
2017-11-14 13:10:44 -08:00
Joe Groff
73d2e9a47f Sema: Fixes for KeyPath type checking.
When testing KeyPathApplication constraints, we would keep going after rejecting a concrete KeyPath application by trying PartialKeyPath and AnyKeyPath, even though that's not what we want, since any key path application expression can type check with an AnyKeyPath. We would then miscompile by building the AST such that we applied the mismatched key path expression directly to the base. We also didn't handle expressions where the base was a subtype of the key path's base type correctly—the conversion means the base can't be written through in this situation, and we hardcoded the concrete-to-existential case instead of handling general conversions. Fix these problems, and add an AST verifier for KeyPathApplicationExprs to help catch problems in the future. Fixes SR-6300 | rdar://problem/35368903.
2017-11-09 11:57:23 -08:00
Greg Titus
20a488225a Merge pull request #12642 from gregomni/6204
[Sema] Don't suggest adding 'as' in a pattern matching context where it will do no good.
2017-11-07 10:02:58 -08:00
Slava Pestov
4eef3615ee Sema: coerceToRValue() never returns nullptr 2017-10-31 20:22:41 -07:00
Davide Italiano
330fb1ce2f [gardening] Remove some unused variables. NFCI. 2017-10-30 15:19:55 -07:00
gregomni
55edab880f Don't suggest adding 'as' in a pattern matching context where it will do no good. 2017-10-26 15:51:59 -07:00
Slava Pestov
b39a6eda1d Sema: Coerce base to rvalue when calling a DeclViaBridging overload kind
This code path is only used for a special purpose hack to make
NSString members available on String. Since it is rarely
exercised, it was broken.
2017-10-24 20:45:49 -07:00
Slava Pestov
31176d713a Sema: Only validate all members of a class if we access one of its members
... Or if we subclass it, or define an extension of it.
2017-10-22 20:05:01 -07:00
Greg Titus
abb6156eb9 Merge pull request #12553 from gregomni/6198
[Sema] When subscripting with a keypath, check for the path being an IUO.
2017-10-21 16:42:27 -07:00
gregomni
a76d74b6d4 When subscripting with a keypath, check for the path being an IUO. 2017-10-21 16:12:28 -07:00
David Zarzycki
835906c543 [Sema] NFC: Simplify type coercion of ClosureExprs
* If we have an updatable ClosureExpr, then both fromEI.isAutoClosure()
  and toEI.isAutoClosure() must be false because the type system ensures
  that normal closures and functions do not convert to auto-closures.
* If we have a throwing ClosureExpr, then fromEI.throws() and
  toEI.throws() must be true, otherwise an erroneous throwing to
  non-throwing closure/function conversions would be possible. From a
  different perspective, updating the 'throws' bit would make sense if
  overloading on 'throws' wasn't possible.
2017-10-16 16:48:08 -04:00
gregomni
0188e1cb65 Incorrect condition here resulted in incorrectly trying to optional-wrap for an optional chain to optional lvalue. 2017-10-15 15:31:06 -07:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Huon Wilson
8e50a1666f [AST&Sema] Add assertions for conditional conformances.
These are just places that may need updating for conditional
conformances, and so having them flag eagerly will help in future.
2017-10-10 20:17:41 -07:00
Huon Wilson
945f723d59 [AST] Compute conditional requirements in a conformance.
This allows determining which requirements make a conformance conditional; as
in, which requirements aren't known as part of the type itself.

Additionally, use this to assert that a few builtin protocols aren't
conditionally-conformed-to, something we won't support for now.
2017-10-10 20:17:39 -07:00
Joe Groff
d3a2a0ff82 Sema: Coerce the type of the index expression in a key path component to match the subscript decl's index type.
Fixes SR-6062 | rdar://problem/34835322.
2017-10-05 14:33:21 -07:00
Slava Pestov
a1aaa4e141 Sema: Remove a bogus assertion
Fixes <rdar://problem/32727557>.
2017-09-28 13:06:58 -07:00
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Joe Groff
875435de53 Merge pull request #11957 from jckarter/key-path-subscript-review
Code updates from review on #11953
2017-09-17 20:12:59 -07:00
Robert Widmann
e310ab3e3c Coerce the base of existential keypath applies
We can wind up in a situation where the base of a keypath
application is concrete but is being applied to a keypath
with an existential source type.  Coerce the base to the
intended type if necessary when building the final subscript
expression.

Resolves SR-5878.
2017-09-17 16:52:49 -04:00
Joe Groff
6ccc96cf67 Code updates from review on #11953
- Remove dead `if !genericEnv` checks
- Do conformance checks for subscript indexes `InExpression`
- Use `GenericEnvironment::mapTypeOutOfContext` static method instead of null checking everywhere
2017-09-15 15:43:59 -07:00
Joe Groff
a67f9ca3e5 Sema: Require indexes in key path subscript components to be Hashable.
And save the conformance to be captured when we form the KeyPath object.
2017-09-15 09:59:51 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Greg Parker
0af574a7be [AST] Rename DefaultArgumentKind::Nil to NilLiteral.
This avoids a conflict with #define Nil in objc/objc.h.
2017-08-31 21:55:45 -07:00
Slava Pestov
e506d92a0a Sema: Fix crash when ternary operator is applied to an lvalue of IUO type
Note that the bug was in Sema, but I added a SILGen test, since
that's an easy way to ensure the AST is valid.

Unfortunately the AST verifier does not perform many checks when
we emit diagnostics; adding the test case to an existing Sema test
would not catch regressions.

Fixes <rdar://problem/31595572>.
2017-08-19 00:18:40 -04:00
Robert Widmann
9e13fcb69f [NFC] Refactor CSApply's ExprWalker a bit and propagate closure checking errors
There is exactly one place where the 'skipClosures' needs to be
honored, and that is when applying the solution.

Also, teach typeCheckClosureBody to propagate failures
outward instead of ignoring them.
2017-08-10 15:29:12 -07:00
Joe Groff
a689b34945 Merge pull request #11061 from jckarter/static-key-path-error
Sema: Don't allow key path literals to refer to static members.
2017-07-19 16:14:50 -07:00
Joe Groff
605804cd17 Sema: Don't allow key path literals to refer to static members.
This is theoretically supportable some day, but isn't implemented today. Fixes rdar://problem/33318422 | SR-5453.
2017-07-19 15:27:43 -07:00
Robert Widmann
d019485e36 Address review comments 2017-07-19 12:38:23 -07:00
Robert Widmann
7a97e46203 Switch interface type computation to use params and bits 2017-07-19 09:49:32 -07:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -07:00
Slava Pestov
83684eb08a Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration;
we can remove one. Soon, it will change to store a base
declaration context, instead.
2017-07-18 22:09:19 -07:00
John McCall
bd43d74561 Merge pull request #11024 from rjmccall/variadic-subscripts
Fix a pair of bugs with variadic subscripts
2017-07-17 19:58:14 -04:00
John McCall
63594f1e10 Fix a SILGen bug with variadic subscripts that I recently introduced
and a CSApply bug with variadic tuple subscripts that I did not.

The SILGen bug was exposed by the source-compat test suite as part
of rdar://33341584.
2017-07-17 18:52:17 -04:00
Joe Groff
e2dc62b207 Merge pull request #11004 from jckarter/iuo-key-path
Handle IUO unwraps in key paths.
2017-07-17 12:02:30 -07:00
Joe Groff
69a290edda Handle IUO unwraps in key paths.
In the type checker, we need to recognize when a member lookup succeeded through an IUO unwrap, and insert the implicit optional-unwrap component into the key path. In the standard library, we need to cope with the fact that IUO is still a first-class type with unique type metadata in a few places. Fix for rdar://problem/33230845.
2017-07-17 11:21:36 -07:00
Mark Lacey
715cfdd7f4 Merge pull request #10999 from rudkx/enable-type-map
Change typeCheckExpression() to return Type.
2017-07-17 00:56:41 -07:00
Mark Lacey
3d387dd906 Change typeCheckExpression() to Type.
Doing this allows us to return ErrorType in some circumstances where we
want to communicate that we don't have a usable type rather than writing
ErrorType directly into the type of the expression root, avoiding a
mutation of the expression tree in a failure case.
2017-07-16 23:43:13 -07:00
John McCall
716dd08a51 Always build the coercion as the sub-expression of a CoerceExpr.
Previously, we sometimes built optional injections and evaluations
on the outside.  NFC, but it makes the bridging peephole a lot simpler.
2017-07-15 01:12:55 -04:00
John McCall
928afc6ab8 Merge pull request #10866 from rjmccall/bridging-rework
Substantially rework how SILGen handles bridging
2017-07-11 15:40:23 -04:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Joe Groff
51672d3bbf Sema: Allow KeyPath and KeyPathApplicationExprs to re-type-check during failure diagnosis.
Fixes SR-5034 | rdar://problem/32488872.
2017-07-10 16:43:34 -07:00
Joe Groff
6ad01d63f6 Sema: Feed argument label and constraint locator info from key path subscript components into getCalleeDeclAndArgs.
Fixes SR-5189 | rdar://problem/32713662.
2017-07-10 14:55:08 -07:00
Mark Lacey
6eb71e4d51 [Constraint system] A few more type map updates. 2017-07-09 13:24:42 -07:00
Joe Groff
04453d1ddc Merge pull request #10810 from jckarter/keypath-apply-lvalue
Sema: Coerce [keyPath:] index to rvalue.
2017-07-07 13:50:08 -07:00
Joe Groff
a3c6dbc469 Sema: Coerce [keyPath:] index to rvalue.
Fixes SR-5384 | rdar://problem/33160409.
2017-07-07 10:31:32 -07:00
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Joe Groff
3c82e981f9 KeyPaths: Add support for optional chaining/forcing components.
rdar://problem/31768715
2017-06-26 09:40:31 -07:00
Joe Groff
8548693c9a Sema: Ensure the array type for variadic tuple shuffles is always set.
We neglected to set it on one path (a scalar-to-tuple conversion path currently only taken by subscript applications). Change TupleShuffleExpr's constructor to take it as an argument so this mistake is harder to make in the future. Fixes SR-5264 | rdar://problem/32860988.
2017-06-20 16:38:52 -07:00