Commit Graph

2383 Commits

Author SHA1 Message Date
John McCall
99ae104980 Protocol conformance is a subtyping relationship, no
matter whether the target type is a class existential.

The subtype relation should form a lattice and be intrinsically
reversible; everything else is a conversion.

Swift SVN r14027
2014-02-18 02:27:29 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Doug Gregor
7a3b17a238 Look through @unchecked_option for function application.
Swift SVN r13475
2014-02-05 04:51:38 +00:00
Doug Gregor
b22321d89b Allow invocation of a DynamicSelf-returning method on an existential.
As part of this, rewrite the check to use interface types. It's
cleaner and more efficient.

Swift SVN r13353
2014-02-03 15:27:55 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Doug Gregor
bb7e07cab2 Remove outdated FIXME.
Swift SVN r12897
2014-01-24 04:13:11 +00:00
John McCall
e088646f9b The value-to-optional and optional-to-optional conversions
are subtype conversions.

Swift SVN r12843
2014-01-23 03:05:06 +00:00
John McCall
59ffc88fa7 When ranking constraint solutions, consider anything that causes
a function conversion to be bad.

This encourages the type-checker to place conversions within
closures rather than outside; the test case here crashed in
SIL verification because of that.  (Yes, that means that there's
an underlying problem still when the function conversion is
required; that's tracked by rdar://15875305.)  But in general,
function conversions are likely to be expensive, and it's good
to avoid them when possible.

The setup work to add SK_FunctionConversion was accidentally
committed as part of r12813.

Swift SVN r12839
2014-01-23 01:28:48 +00:00
John McCall
5c6b022cbe Track whether a constraint locator is part of a function
conversion, and use the same process to optimize isSimple()
as an afterthought.

Swift SVN r12813
2014-01-22 23:22:55 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +00:00
John McCall
9c415a3bed Remove the TrivialSubtype conversion kind and implement
its basic logic in libAST, which both makes it easier to
implement and makes it possible to use in the places that
should care about it, i.e. in IR-gen and SIL-gen.

Per Doug, none of the places that were introducing
trivial-subtype constraints really needed to do so rather
than just using subtype constraints.

Swift SVN r12679
2014-01-22 00:19:56 +00:00
Chris Lattner
16db07a5a2 revert r12277 now that subscriptdecls in protocol have getter/setters. NFC.
Swift SVN r12666
2014-01-21 22:47:15 +00:00
John McCall
7be7c20a27 Implicitly look through UncheckedOptional<T> when it's the
base of a member access or subscript.

Swift SVN r12345
2014-01-15 21:00:59 +00:00
Chris Lattner
5c23e3568c Fix a crash on subscript decls in protocols.
Swift SVN r12277
2014-01-14 04:33:45 +00:00
John McCall
817e80bde5 Implicit conversions for UncheckedOptional.
rdar://15189000
rdar://15189009

Swift SVN r12260
2014-01-13 23:15:03 +00:00
Chris Lattner
fb640dfc21 start removing Materialization logic from the type checker:
- MaterializeExpr can never be formed in an argument list (but 
  still can as the base object) so remove that case from CSApply.
- LValues never exist *inside* of tuples, so remove code related
  to that.



Swift SVN r11889
2014-01-04 05:36:11 +00:00
Chris Lattner
847cc6b739 add some more testcases, have sema reject (with a poor QoI error) invalid code
where a mutating getter is used on an rvalue.  This previously crashed silgen
because the rvalue has no address to pass @inout.


Swift SVN r11887
2014-01-04 04:51:13 +00:00
Chris Lattner
be58684653 further detangle @inout and @lvalue types, making the code more specific
and simpler.


Swift SVN r11801
2014-01-01 21:35:31 +00:00
Chris Lattner
988270a066 eliminate the code copied and pasted from shouldTryUserConversion:
just call it instead.


Swift SVN r11791
2014-01-01 06:47:32 +00:00
Chris Lattner
f30dd51763 fix rdar://15735537: __conversion function not found in protocol if marked @mutating
- shouldTryUserConversion was not looking through @lvalue to determine if 
  the underlying type had a __conversion member, so we were only trying user
  conversions on lvalues through an lvalue-to-rvalue conversion.
- Similarly, fix the similar-but-different filter in tryUserConversion to look through
  lvalues as well.

This causes the QoI of some conversion diagnostics to get worse (the dreaded "does 
not type check error") because there are now two possible conversions instead of one 
in some cases and the diagnostics of the type checker doesn't handle this case well.


Swift SVN r11789
2014-01-01 06:40:48 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Chris Lattner
18a9193452 Redesign how @inout propagation works in the typechecker:
- Switch all the 'self' mutable arguments to take self as @inout, since
   binding methods to uncurried functions expose them as such.
 - Eliminate the subtype relationship between @inout and @inout(implicit),
   which means that we eliminate all sorts of weird cases where they get
   dropped (see the updated testcases).
 - Eliminate the logic in adjustLValueForReference that walks through functions
   converting @inout to @inout(implicit) in strange cases.
 - Introduce a new set of type checker constraints and conversion kinds to properly
   handle assignment operators: when rebound or curried, their input/result argument
   is exposed as @inout and requires an explicit &.  When applied directly (e.g. 
   as ++i), they get an implicit AddressOfExpr to bind the mutated lvalue as an
   @inout argument.

Overall, the short term effect of this is to fix a few old bugs handling lvalues.
The long term effect is to drive a larger wedge between implicit and explicit 
lvalues.


Swift SVN r11708
2013-12-29 04:38:26 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
d7621b5a7b Remove the concept of a "nonsettable lvalue": Now everything that is
nonsettable is represented as an rvalue.  Yay for one less concept in
the AST.


Swift SVN r11640
2013-12-25 22:20:01 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Chris Lattner
42d0fdadcf - Introduce the ability for attributes to be inverted with !.
- Switch @mutable to be a tri-state attribute that is invertable with @!mutable.
- Move the semantic form of 'mutable' to being a bit on FuncDecl instead of
  something in DeclAttrs.  The former is a binary bit, the later is a tristate
  which differentiates between "not present", "present and set" "present and inverted".
- Diagnose some invalid uses of @mutable, e.g. on class methods.
- Make setters default to mutable, and allow them to be switched with @!mutable.



Swift SVN r11439
2013-12-18 21:38:53 +00:00
Chris Lattner
51862b91fd rename the inout decl attribute (not the type attribute) to @mutating.
Swift SVN r11416
2013-12-18 04:44:56 +00:00
Chris Lattner
b11903a6fc Reject calls to inout methods on rvalues and 'let' values.
Many thanks to Doug for helping with the constraint solver magic.


Swift SVN r11391
2013-12-17 21:15:44 +00:00
Doug Gregor
61318e33f0 Compute potential bindings with the help of the constraint graph.
Rather than performing a two-pass walk over all of the constraints in
the system to attach them to type variables, use the existing type
variable -> constraints mapping in the constraint graph to make this a
faster single-pass process. Also clarify the type bindings a little
bit. Improves type checking time for the standard library by ~3%.



Swift SVN r11098
2013-12-10 23:25:37 +00:00
Doug Gregor
79f8175e0b Solver: Keep track of a solution's score as we're computing it.
No functionality change here; just staging for some future optimizations.


Swift SVN r11028
2013-12-09 17:12:07 +00:00
Doug Gregor
5bb053c0dd Fix renamed file names
Swift SVN r11017
2013-12-09 14:20:33 +00:00
Doug Gregor
ee545e9f68 Rename TypeCheckConstraintsFoo.cpp to CSFoo.cpp.
It's more idiomatic and easier to type.


Swift SVN r11015
2013-12-09 14:09:54 +00:00