Commit Graph

1659 Commits

Author SHA1 Message Date
Mark Lacey
12926eb667 [Constraint solver] More type map updates.
More updates to read and write types from a side table in the constraint
solver and only write back into expressions when we've finished type
checking an expression.

We still write directly into expressions, and will continue to do so
until all of the code has been updated.
2017-05-31 00:36:09 -07:00
Pavel Yaskevich
9c1e9756e4 Merge pull request #9971 from xedin/sr-4301
[QoI] Fix crash when constructing existential metatype without '.init'
2017-05-29 23:16:45 -07:00
Pavel Yaskevich
29b8f5615d [QoI] Fix crash when constructing existential metatype without '.init'
Resolves: SR-4301.
2017-05-29 22:08:50 -07:00
Jordan Rose
4468ad2028 [Sema] Preparations for removal of getName on ValueDecl (#9972)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 22:36:39 -07:00
Joe Groff
8022266404 Merge pull request #9933 from jckarter/partial-key-path-application
Support application of AnyKeyPath/PartialKeyPath.
2017-05-26 08:45:55 -07:00
Joe Groff
cdc7a5c945 Support application of AnyKeyPath/PartialKeyPath.
rdar://problem/32237567
2017-05-25 15:51:22 -07:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
d8234bace6 Sema: Fix double type checking of lazy initializer expressions
If a lazy var has no declared type, we have to type check the
initializer to get a type before we can build the getter.

Then, the initializer is type checked as part of the getter
again.

Use the new SkipApplyingSolution flag when type checking for
the first time. We still end up doing redundant work, but by
not applying the solution we avoid feeding invalid AST nodes
back into the constraint solver.

This fixes some bad diagnostics and crashes.

Fixes <https://bugs.swift.org/browse/SR-2616> and
<rdar://problem/28313602>.
2017-05-24 17:21:28 -07:00
Slava Pestov
451600ce4b Merge pull request #9824 from slavapestov/more-member-reference-simplification
More member reference simplification
2017-05-24 16:13:58 -07:00
Joe Groff
a6fb6d6f15 Sema: Don't crash when key path literals appear in PartialKeyPath context.
And make an attempt to use the constraint system's contextualType to bind type information; this makes things better but doesn't seem to be a complete solution for contextually typing key paths.
2017-05-24 11:31:01 -07:00
Slava Pestov
55c4542db6 Sema: Small cleanup in CSApply 2017-05-24 00:21:40 -07:00
Joe Groff
9157372431 Merge pull request #9840 from jckarter/already-checked-key-path
Sema: Don't crash when type-checking a KeyPathExpr that's already type-checked.
2017-05-23 15:11:51 -07:00
Joe Groff
2425258593 Sema: Don't crash when type-checking a KeyPathExpr that's already type-checked.
This can come up when re-checking a larger expression for diagnostics. Fixes SR-4965.
2017-05-23 14:00:32 -07:00
Slava Pestov
a6dfcd52cf Sema: Remove OverloadChoiceKind::TypeDecl, which was never used 2017-05-23 02:10:02 -07:00
Mark Lacey
88077c33bf Merge pull request #9842 from rudkx/fix-rdar32215763
Make getWitnessType() return Type() for ErrorType.
2017-05-22 15:51:09 -07:00
Mark Lacey
ceacfb4c53 Make getWitnessType() return Type() for ErrorType.
None of the clients of this care about distinguishing between immediate
failures in getWitnessType() vs. earlier errors that result in
getWitnessType() returning ErrorType, so simplify the interface by
having it always return Type() if there is a problem.

Update the clients that were not already checking for null result to do
so.

Fixes rdar://problem/32215763.
2017-05-22 14:33:00 -07:00
Joe Groff
879397008c Sema: Don't crash when recovering type errors from malformed keypath expressions.
It's particularly likely someone will try to type `\(foo)`, which looks like a string interpolation segment, outside of a string literal, so give that case a special diagnostic. Fixes rdar://problem/32315365.
2017-05-22 10:42:40 -07:00
Mark Lacey
b8cc015113 Fix some issues in handling of withoutActuallyEscaping.
We need to strip inout/lvalue before casting the second parameter's type
to FunctionType.

There were also some verification issues and the fact that we weren't
allowing already-escaping closures to be passed to it (which is not
useful, but shouldn't result in an error and really awful
diagnostic). We can potentially look at diagnosing this with a warning
at some point in the future.

Fixes rdar://problem/32239354.
2017-05-17 17:13:47 -07:00
Slava Pestov
03ebba50be Sema: Fix lvalue access of class existential payloads
Now that SILGen can correctly lower lvalue accesses of
class existential payloads, remove a hack in Sema that
was simply doing the wrong thing.

Fixes <rdar://problem/31858378>.
2017-05-15 20:14:48 -07:00
Joe Groff
faa6bc72f0 Sema: Reject unimplemented key path components during resolveKeyPathExpr.
This is a bit more robust and user-friendly than hoping more brittle recovery in SILGen or IRGen for unsupported components kicks in. rdar://problem/32200714
2017-05-15 16:10:59 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Huon Wilson
4fc27a1f3e Merge pull request #9150 from huonw/keypath-syntax
Implement \ syntax for Swift key paths.
2017-05-03 06:22:47 +10:00
Doug Gregor
66b11cbc3d [SE-0160] Make deprecated @objc inference warnings opt-in.
The warnings about deprecated @objc inference in Swift 3 mode can be a
bit annoying; and are mostly relevant to the migration workflow. Make
the warning emission a three-state switch:

* None (the default): don't warn about these issues.
* Minimal (-warn-swift3-objc-inference-minimal): warn about direct
  uses of @objc entrypoints and provide "@objc" Fix-Its for them.
* Complete (-warn-swift3-objc-inference-complete): warn about all
  cases where Swift 3 infers @objc but Swift 4 will not.

Fixes rdar://problem/31922278.
2017-05-01 16:25:50 -07:00
Huon Wilson
07c5ab8fb2 Implement \ syntax for Swift key paths.
This introduces a few unfortunate things because the syntax is awkward.
In particular, the period and following token in \.[a], \.? and \.! are
token sequences that don't appear anywhere else in Swift, and so need
special handling. This is somewhat compounded by \foo.bar.baz possibly
being \(foo).bar.baz or \(foo.bar).baz (parens around the type), and,
furthermore, needing to distinguish \Foo?.bar from \Foo.?bar.

rdar://problem/31724243
2017-05-01 16:06:15 -07:00
Slava Pestov
3130c3cbd7 AST: Remove an overload of GenericSignature::getSubstitutions() 2017-04-28 13:26:02 -07:00
Slava Pestov
7a3f12f327 Sema: Small fix to get class property access working on subclass existentials
This is tested in the next commit. This code path is about to
get more cleanup shortly to fix a miscompile with class
existentials (not just subclass existentials; an old problem),
so I'm not too concerned with adding the new conditinals here.
2017-04-27 16:08:32 -07:00
Slava Pestov
e7d9d00119 Sema: Remove a bit of dead code from CSApply 2017-04-27 16:06:54 -07:00
John McCall
7bb263161a Fix a semantic bug in CSApply's optional-to-optional application.
Implicit conversions from T?? to U?? would map nil to some(nil) instead of nil.
2017-04-26 17:24:17 -04:00
John McCall
338825e73d Fix the emission of r-value pointer conversions to delay the
conversions and extend lifetimes over the call.

Apply this logic to string-to-pointer conversions as well as
array-to-pointer conversions.

Fix the AST verifier to not blow up on optional pointer conversions,
and make sure we SILGen them correctly.  There's still an AST bug
here, but I'll fix that in a follow-up patch.
2017-04-26 14:15:44 -04:00
Joe Groff
3d178be169 Merge pull request #8875 from jckarter/keypaths
Keypaths
2017-04-21 17:51:17 -07:00
Joe Groff
d5cdf658da KeyPaths: Generate _kvcKeyPathString for ObjC-compatible keypaths. 2017-04-21 16:56:17 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Joe Groff
517c45aa3d Followups from merging master 2017-04-19 20:58:52 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Doug Gregor
8584e97408 [AST] Sink ProtocolConformance::getWitness() down into NormalProtocolConformance.
NormalProtocolConformance has the only correct implementation of this
functionality. Instead, providing a safer getWitnessDecl() that
doesn't promise substitutions that are incorrect (and not actually
used by any clients).
2017-04-18 23:35:24 -07:00
Joe Groff
a6cd471c2b IRGen/stdlib: Instantiate non-generic computed key path components. 2017-04-18 21:51:12 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
374db66e8b Merge pull request #8685 from slavapestov/subclass-existentials-silgen
Preliminary SILGen support for subclass existentials (SE-0156)
2017-04-12 11:44:23 -07:00
Arnold Schwaighofer
69e6f07167 Merge pull request #8701 from aschwaighofer/wip_ast_silgen_const_string_literal
AST/SILGen support for constant string literals
2017-04-12 09:52:18 -07:00
Slava Pestov
e2d81a11cb Sema: Fix bug in buildMemberRef() with subclass existentials
Make sure we use the right 'self' type in various places. When
calling a Self-returning class method on a subclass existential,
the following has to happen correctly:

- The existential is opened to produce an archetype with a superclass
  constraint.

- The archetype is upcast to a class type to produce the 'self'
  parameter for the call.

- The method call returns a value with the same type as the 'self'
  parameter.

- The return value is downcast to the opened archetype.

- The opened archetype is converted back to an existential.

Some SILGen tests in an upcoming patch exercise this code path.
2017-04-12 00:07:27 -07:00
Mark Lacey
9bd79299f3 Merge pull request #8699 from rudkx/appease-the-warning-gods
Fix unused variable warnings in release build.
2017-04-11 23:40:21 -07:00
Slava Pestov
2281ff0c1c Sema: Fix another crash with tuple to Any conversion
An earlier patch fixed the case where some tuple elements
were lvalue types. However this only looked into tuples
nested one level deep, when a more correct fix checks the
lvalue recursive property of the type.
2017-04-11 14:26:11 -07:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Mark Lacey
e1d727d76d Fix unused variable warnings in release build. 2017-04-11 10:37:51 -07:00
Slava Pestov
2e5b3b6dfc Sema: Update constraint solver for subclass existentials 2017-04-10 17:05:45 -07:00
Slava Pestov
9c3b514c7e AST: New getExistentialLayout() method on TypeBase and CanType
This consolidates calculations which need to look at every
protocol in an existential type. Soon we will also have to
deal with superclass constrained existentials, so start
updating call sites that look at all protocols to use the
new ExistentialLayout and correctly handle a class constraint
as well.

Also, eventually I will kill off the AnyObject protocol and
model it as a protocol composition with no protocols or
superclass, but the requiresClass() flag set.

This is not quite modeled this way yet and AnyObject still
exists, but the new abstraction is a step in the right
direction.
2017-04-10 17:04:37 -07:00
Slava Pestov
ed4c681aae Sema: Simplify Solution::computeSubstitutions()
Don't pass in the opened type; instead have the caller call
simplifyType() if needed. Also, make computeSubstitutions()
bail out if there's no generic signature, which allowed
unifying several generic vs non-generic code paths.

Hopefully there is enough short circuiting in there now that
we're not doing any extra work in the non-generic case.
2017-04-10 17:04:36 -07:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00
Michael Gottesman
6578661521 [gardening] Cleanup control flow in computeCallLevel to reduce indentation level. 2017-04-08 17:37:37 -07:00
Michael Gottesman
5c14ec1e8e [gardening] Refactor out computation of a callee's level into its own helper function.
ExprRewriter::coerceCallArguments is a huge function that is difficult to reason
about. This just moves an obvious subroutine into a real subroutine.
2017-04-08 17:37:37 -07:00