Commit Graph

9116 Commits

Author SHA1 Message Date
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
Mark Lacey
84209778bd [CS] Dump the number of viable solutions with -debug-constraints. 2017-07-19 15:20:59 -07:00
Robert Widmann
fd7c1f8bc0 Merge pull request #10889 from CodaFi/the-bit-ter-pill
Consistently Pass Parameter Flags
2017-07-19 13:14:50 -07:00
Robert Widmann
d019485e36 Address review comments 2017-07-19 12:38:23 -07:00
Robert Widmann
2968b03312 Merge pull request #11048 from CodaFi/optional-illusion
[NFC] Adjust return type of getTypeOfExpressionWithoutApplying
2017-07-19 10:45:27 -07:00
Robert Widmann
7a97e46203 Switch interface type computation to use params and bits 2017-07-19 09:49:32 -07:00
Robert Widmann
c8a1e5e9ec Make TypeCheckPattern keep track of parameter mutability
A temporary hack to keep track explicitly when type checking a pattern decides to flip a parameter from 'owned' to 'inout'.
2017-07-19 09:49:32 -07:00
Robert Widmann
5dfe3364a2 Redo a hack in CSDiag
Turns out keeping the "mutability classifier" only affects one diagnostic.
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
707e6de9a4 Merge pull request #10436 from slavapestov/gut-resolve-type-in-context
Remove DeclContext walk from resolveTypeInContext()
2017-07-19 01:10:55 -07:00
Pavel Yaskevich
4d2ace6ff0 Merge pull request #11049 from xedin/rdar-32431736-fix
[QoI] Fix position of the fix-it related to raw representable conversion
2017-07-18 23:12:37 -07:00
Pavel Yaskevich
2bec75e069 [QoI] Fix position of the fix-it related to raw representable conversion
Part of the fix-it for conversion from optional to raw representable
was inserted at the incorrect position which produces invalid expression.

Resolves: rdar://problem/32431736
2017-07-18 22:13:20 -07:00
Slava Pestov
ee68ff4170 Sema: Use foundDC in resolveTypeInContext()
Now that we remember the DeclContext of lookup results when
doing unqualified lookup, we don't have to walk parent contexts
again to find this DeclContext.

This means that unqualified lookup is now the "single source of
truth" for what names are visible and why.
2017-07-18 22:11:29 -07:00
Slava Pestov
737174fe9f AST: Add a DeclContext field to ComponentIdentTypeRepr
Plumb this through and set it appropriately, but don't use it
for anything yet.
2017-07-18 22:10:33 -07:00
Slava Pestov
5592d3cca8 Sema: Change lookupUnqualifiedType() to return a LookupResult
This will allow callers of lookupUnqualifiedType() to know what
DeclContext a lookup result came from.
2017-07-18 22:09:55 -07:00
Slava Pestov
7db4c9075c AST: Change LookupResultEntry to store a DeclContext instead of a base ValueDecl
Storing a DeclContext allows us to distinguish type
members from extension members just by looking at the
lookup result.
2017-07-18 22:09:55 -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
Robert Widmann
c42f4eabc6 Remove a latent Optional<Type> from independent expr checking 2017-07-18 19:35:28 -07:00
Robert Widmann
8249593433 Merge pull request #11047 from CodaFi/who-cleans-the-cleanser
[NFC] Merge ExprCleaner and ExprCleanser
2017-07-18 19:33:57 -07:00
Robert Widmann
ebfb3e8fd5 [NFC] Merge ExprCleaner and ExprCleanser
The distinction was made between these two because of rdar://25341015,
wherein we needed a diagnostic that could detect the shadowing of
global functions by calls in protocols that don't match any
of the protocol's members.

This used to function by hoping that we had an argument tuple type lying
around after type checking.  The expr cleaner would re-write that
type into the AST and we would look up based on it.  Now that we write
Type() into the AST on failure, we must instead type check the
component parts of the argument themselves to form a tuple
type to make the lookup.
2017-07-18 18:15:37 -07:00
Harlan
b9f468e79a [NFC] Remove Syntax's dependency on Sema (#10984)
* Move LegacyASTTransformer and SyntaxASTMapping to AST

* Fix import in swift-syntax-format

* Update swift-syntax-test
2017-07-18 16:58:18 -07:00
Robert Widmann
296492e4d1 Merge pull request #10941 from CodaFi/im-in-ur-member-base
Never Bind to ErrorType
2017-07-18 14:14:19 -07:00
John McCall
dcc65ca39e Fix the fix-it for replacing C-style for loops, enhance it to handle
inclusive ranges, and actually add a test to catch future regressions.

rdar://33329301
2017-07-18 00:46:51 -04:00
Robert Widmann
509e66f171 Merge pull request #11015 from CodaFi/bottom-feeding
Lower Never-typed patterns to unreachable
2017-07-17 19:39:25 -07:00
Robert Widmann
3292e6bc99 Lower Never-typed patterns to unreachable
Cuts off a crash in SILGen for switches over uninhabited types.
We can take this a step further and extend the definition of
"uninhabited" to product types with uninhabited components.
2017-07-17 18:59:15 -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
swift-ci
33de7991ae Merge pull request #11014 from rudkx/enable-type-map 2017-07-17 15:15:21 -07:00
Mark Lacey
96ff76cf83 [CS] Use the type map in eraseOpenedExistentials. 2017-07-17 14:18:49 -07: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
swift-ci
ea5b362f9a Merge pull request #11002 from rudkx/enable-type-map 2017-07-17 11:06:43 -07:00
Mark Lacey
4d28791880 Fix up comment for typeCheckExpression. 2017-07-17 09:45:55 -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
Pavel Yaskevich
9e9a4fae19 [ConstraintSolver] NFC: remove excessive conformance logging from ConstraintSystem 2017-07-16 16:46:12 -07:00
swift-ci
058d1adef1 Merge pull request #10996 from rudkx/enable-type-map 2017-07-16 12:49:38 -07:00
Mark Lacey
9e4523a463 [CS] Use ConstraintSystem::getType. 2017-07-16 12:19:52 -07:00
swift-ci
3b53ef9d19 Merge pull request #10993 from rudkx/enable-type-map 2017-07-16 00:43:18 -07:00
Mark Lacey
fff29b1bb6 Update CSDiag to hold ConstraintSystems by reference. 2017-07-16 00:18:27 -07:00
swift-ci
ff8787a736 Merge pull request #10992 from rudkx/enable-type-map 2017-07-15 18:09:00 -07:00
Mark Lacey
5e32b13d6b Remove CleanupIllFormedExpressionRAII from preCheckExpression.
It erases type variables, but none can exist at this point.
2017-07-15 12:51:07 -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
Mark Lacey
59aee35208 Merge pull request #10979 from rudkx/fix-rdar31127419
[Constraint system] Properly infer types for collections of vars.
2017-07-14 18:46:47 -07:00
Mark Lacey
524b7f2a78 [Constraint system] Properly infer types for collections of vars.
When we saw lvalue- or inout-types we were not appropriately looking at
the underlying types when performing a join. As a result we would infer
Any in cases where we should have inferred a common supertype.

rdar://problem/31127419
2017-07-14 17:12:01 -07:00
Slava Pestov
a39b5eb53b Sema: Move preCheckExpression() out of solveForExpression()
There are two "RAII cleaners" here:

- CleanupIllFormedExpressionRAII cleans up the Expr in its final state
- ExprCleanser walks the Expr before it is mutated and collects
  sub-expressions, then cleans those up after

The subtle difference comes into play if we started to apply the
solution (which can fail, leaving the AST in an inconsistent state)
or if preCheckExpression() modified the AST.

The latter case was causing an ASan failure because we were not
cleaning up type variables in new nodes introduced by
preCheckExpression().

Fix this by moving the preCheckExpression() call out of
solveForExpression(), so that if solveForExpression() is called
with TypeCheckExprFlags::SkipApplyingSolution, we don't mutate the
AST at all.

Sigh...

Fixes <rdar://problem/33277279>.
2017-07-14 16:46:51 -07:00
Pavel Yaskevich
e5a2c7c7dc [QoI] Improve fix-it when renamed method has contextual member lookup argument
Currently we generate incorrect fix-it in situations where we
have contextual member lookup as one of the arguments.

Resolves: rdar://problem/32526620
2017-07-14 12:15:29 -07:00
Jordan Rose
970f020488 [CMake] Sema depends on Serialization these days. (#10968)
Specifically, it uses SerializedASTFile::getLanguageVersionBuiltWith
to improve diagnostics. Not having this has led to failures on Linux,
where linking order matters.
2017-07-14 10:42:56 -07:00
Itai Ferber
7fd5a82408 Merge pull request #10930 from itaiferber/synthesized-member-lookup
Expose synthesized members in AST lookups
2017-07-13 20:15:30 -07:00
Itai Ferber
e86428559a Expose synthesized members in AST lookups
Some types and members are synthesized by derived protocol conformances
(e.g. the CodingKeys member type or init(from:)/encode(to:) members
from Decodable/Encodable conformance) — however, they are not visible
in AST lookup if they have not been synthesized.

Exposes a LazyResolver callback for performing member synthesis where
relevant during qualified lookups to synthesize these members on demand
when needed.
2017-07-13 13:27:08 -07:00