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.
* 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.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
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.
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.
- Remove dead `if !genericEnv` checks
- Do conformance checks for subscript indexes `InExpression`
- Use `GenericEnvironment::mapTypeOutOfContext` static method instead of null checking everywhere
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.
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>.
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.
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.
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.
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.
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.
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.
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.