Commit Graph

935 Commits

Author SHA1 Message Date
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
Joe Groff
85ad6b355e Merge branch 'master' into keypaths 2017-04-06 18:02:07 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
swift-ci
f513adada9 Merge pull request #8556 from rudkx/propagate-constraints 2017-04-05 10:22:15 -07:00
Mark Lacey
a1ceecc0ae [Constraint solver] Fix a fix-it formatting issue.
With constraint propagation enabled, we go down a different path in the
solver that results in a type with ParenType wrapped around it. Normally
in diagnostic formatting we would strip these off, but in explicitly
forming a string for a fixit, we need to do it ourself. Hits in
test/Parse/try.swift with constraint propagation enabled.
2017-04-05 08:43:08 -07:00
Joe Groff
638759ac28 SIL: Add a "keypath" instruction for summoning literal keypath objects. 2017-04-04 11:31:15 -07:00
Joe Groff
fc23781906 Sema: First pass at type-checking Swift key paths.
TODO:

- Select the KeyPath subclass corresponding to the write capability of the key path components
- Figure out an issue with unresolved solutions being chosen with contextually-typed keypaths
- Diagnostic QoI
2017-04-04 11:31:15 -07:00
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Doug Gregor
7dd1c87dd3 [SE-0160] Warn about uses of @objc declarations that used deprecated @objc inference.
When in Swift 3 compatibility mode without
`-warn-swift3-objc-inference`, warn on the *uses* of declarations that
depend on the Objective-C runtime that became `@objc` due to the
deprecated inference rule. This far more directly captures important
uses of the deprecated Objective-C entrypoints. We diagnose:

* `#selector` expressions that refer to one of these `@objc` members
* `#keyPath` expressions that refer to one of these `@objc` members
* Dynamic lookup (i.e., member access via `AnyObject`) that refers to
  one of these `@objc` members.
2017-03-31 21:22:15 -07:00
Slava Pestov
19b12aa3b1 Sema: Fix convenience init delegation to a convenience init in a generic base class
While in the constraint system, the delegation is modeled as
returning an instance of the derived class, in the AST we type
the reference as returning an instance of the base class, and
insert a downcast, because in SILGen we're calling the base
class initializer which is typed as returning the base class.

This bit of fixup logic wasn't happening if the base class was
generic, and so we were not inserting the cast, which would
crash in SILGen with an assert.

Fixes <rdar://problem/31000248>.
2017-03-26 00:00:53 -07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
Mark Lacey
abfd19c5b1 [Constraint solver] Update LiteralExpr::shallowClone to set types in type map.
It was getting types from the type map, but not setting them in it.
2017-03-15 00:16:54 -07:00
Mark Lacey
041a25ecf1 [Constraint solver] More progress on the constraint solver type map. 2017-03-14 21:56:13 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
swift-ci
6ee6378e5d Merge pull request #8029 from rudkx/more-cs-typemap 2017-03-10 18:42:47 -08:00
Mark Lacey
b592260cdd [Constraint solver] More updates for using the constraint solver type map. 2017-03-10 18:16:09 -08:00
swift-ci
36f465e947 Merge pull request #8027 from rudkx/cache-some-types 2017-03-10 17:15:03 -08:00
Mark Lacey
3f8e1fec4a [Constraint solver] Cache a the types of a few AST nodes we create.
Another small step toward moving to using the side map for all types in
the constraint solver.
2017-03-10 16:51:03 -08:00
Joe Groff
eb40d4303b Sema: Add a stdlib-internal _openExistential helper.
Leverage the "special type-checking semantics" hack to pass an opened existential down to an arbitrary subexpression. Please don't use this.
2017-03-10 13:41:00 -08:00
Slava Pestov
e62c238bc9 AST: Remove unused overload of GenericSignature::getSubstitutions() 2017-03-08 13:54:31 -08:00
Doug Gregor
ce718eeb54 Merge branch 'master' into normal-conformance-requirement-signature 2017-03-01 20:38:20 -08:00
Doug Gregor
ec4bf005af [AST] Eliminate unnecessary #includes of AST/ProtocolConformance.h. 2017-03-01 08:22:39 -08:00
Joe Groff
fc16cb5dda Sema: Let .foo patterns fall back to being ExprPatterns if they don't match an enum case.
This lets you match `case .foo` when `foo` resolves to any static member, instead of only a `case`, albeit without the exhaustiveness checking and subpattern capabilities of proper cases. While we're here, adjust the type system we set up for unresolved patterns embedded in expressions so that we give better signal in the error messages too.
2017-02-28 21:51:39 -08:00