Commit Graph

2516 Commits

Author SHA1 Message Date
John McCall
0224e93a2b Only look through UncheckedOptional<T> on explicit accesses.
Add .Some and .None members.

Swift SVN r12951
2014-01-25 03:07:30 +00:00
Dave Zarzycki
6eba6ceeeb Zap accumlated unused variable warnings in non-assert builds
Swift SVN r12861
2014-01-23 08:11:37 +00:00
Dave Abrahams
d58caea0cd Revert "Zap accumlated warnings in non-assert builds"
This reverts r12850, which broke the build for me.

Swift SVN r12856
2014-01-23 06:47:29 +00:00
Dave Zarzycki
17eb84d9c6 Zap accumlated warnings in non-assert builds
Swift SVN r12850
2014-01-23 05:45:24 +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
Chris Lattner
8ad44c16a2 fix rdar://15877337 - let properties in structs are always accessed through
rvalue bases.


Swift SVN r12745
2014-01-22 17:31:51 +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
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Doug Gregor
9179fa28ed TypeCheckFlags -> TypeResolutionFlags and s/TC_/TR_/g, NFC.
Swift SVN r12584
2014-01-20 16:51:42 +00:00
Chris Lattner
b4735381d0 Plumb the DeclContext of the use site down to the "doesVarDeclMemberProduceLValue"
function.  Pretty soon, whether something is an lvalue or not will depend on who is
asking.


Swift SVN r12507
2014-01-17 22:14:02 +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
Doug Gregor
25d705f019 Rename the pattern coerceToType to coercePatternToType, switch to options.
Swift SVN r12342
2014-01-15 20:24:17 +00:00
Doug Gregor
7fdfe68a9d Be defensive when doing a metatype conversion.
Swift SVN r12285
2014-01-14 15:17:39 +00:00
Dave Abrahams
e149bd8e21 Revert "Diagnose metatype conversions we can't handle yet."
This reverts commit r12265, which caused test expr/delayed-ident/static_var.swift to fail.

Swift SVN r12271
2014-01-14 03:00:12 +00:00
Doug Gregor
d0c4ab11d7 Diagnose metatype conversions we can't handle yet.
It's better than crashing <rdar://problem/15777610>.


Swift SVN r12265
2014-01-14 01:14:58 +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
1ca9f79f55 simplify coerceObjectArgumentToType - we now no longer coerce
rvalues to lvalues, so this can be dramatically simplified.


Swift SVN r12124
2014-01-10 17:47:27 +00:00
Chris Lattner
f6a08290bc switch archetype bases over to the new world order where ArchetypeMemberRef
takes the archetype as an rvalue, not an lvalue.  This defines away the need
for MaterializeExpr at sema time, reusing the existing temporary mechanics in
SILGen.  This also opens future optimizations.


Swift SVN r12123
2014-01-10 17:41:38 +00:00
Chris Lattner
0013ceea39 Rework how existential member references (i.e., calls to protocol methods)
to non-@mutating methods work in the AST: now the base expression is 
always computed as an rvalue, instead of computing them as an lvalue.  The 
optimization that we were accidentally getting before is now explicitly 
modeled, and the non-optimized case is now handled by standard temporary 
emission in SILGen instead of with MaterializeExpr.  The upshot of this 
carefully choreographed step is that there is no change in generated code (!).

Archetype member references still need to be switched over to this new
scheme (at which point materializeexpr is dead), and the optimization 
needs to be replicated for 'let' bases (at which point arguments 
becoming 'let' is only gated on debug info).



Swift SVN r12120
2014-01-10 07:26:30 +00:00
Doug Gregor
23fff50b69 Use UTF-16 string literals when the (builtin) string literal type supports it.
Make the compiler fully support both UTF-8 and UTF-16 string
literals. A (standard-library-defined) string type (such as String)
that wants UTF-16 string literals should conform to the
BuiltinUTF16StringLiteralConvertible protocol; one that wants UTF-8
string literals should conform to the BuiltinStringLiteralConvertible
protocol.

Note that BuiltinUTF16StringLiteralConvertible inherits from
BuiltinStringLiteralConvertible, so a string type that wants UTF-16
string literals also has to implement support for UTF-8. The UTF-16
entry point is preferred when the compiler knows that UTF-16 is
supported. This only tends to happen when we have a generic parameter
that is required to conform to StringLiteralConvertible, e.g.,

  func f<T: StringLiteralConvertible>() {
    var t: T = "Hello, World!" // uses UTF-8 entry point
  }

because the UTF-8 entry point is the only one guaranteed to be available.



Swift SVN r12014
2014-01-07 22:55:07 +00:00
Doug Gregor
fc00bf6076 Parsing and semantic analysis for delegating initializers.
Swift SVN r11921
2014-01-06 16:33:08 +00:00
Chris Lattner
54ea11d5de fix 'unapplied rvalue member' detection to work in the face of rvalue archetype bases.
Swift SVN r11909
2014-01-04 21:09:13 +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
b61a6fd946 Rework AST and SILGen of properties and subscripts to take advantage of the new mutability model.
- Change the AST for get/set functions to take self @inout only when they 
  are @mutating.  Setters default to @mutating, but can be explicitly marked 
  @!mutating. Getters default to not mutating, but can be marked @mutating.  
  This causes self to follow.
- Change sema to handle semantic analysis of a.y (and subscripts) based on
  whether the computed type of a allows mutation (which is when 'a' is an 
  lvalue, or both the getter and setter are non-mutating).  When both of
  these conditions fail, 'a.y' has rvalue type, and is thus non-mutable.
- Rework silgen of lvalues to handle this: now properties and subscripts 
  can have rvalues as bases, which means that all the lvalue machinery needs 
  to be able to handle the full generality of base expressions (which is 
  what my recent patches have been paving the way towards).
- Rework silgen of rvalues to similarly handle rvalue bases.
- Rework silgen of both to handle the case where the AST has found a base
  expression that is an lvalue, but where only a non-mutating getter or
  setter is needed.  Right now, we just emit a load of the lvalue, but
  it would result in better code to not require the base be an lvalue at 
  all (todo).

The upshot of all of this is that we are doing *much* less AST-level 
materialization (MaterializeExpr goes down), we generate a lot better SIL
out of SILGen in many cases, and 'self' being an rvalue in properties and
subscripts means that we correctly reject code like the examples in
test/Sema/immutability.swift.



Swift SVN r11884
2014-01-04 04:27:51 +00:00
Doug Gregor
285007a6e0 Don't introduce a conditional cast from AnyObject to AnyObject.
Fixes <rdar://problem/15246190>.

Swift SVN r11874
2014-01-03 22:54:35 +00:00
Doug Gregor
1ee513e7e8 Use Builtin.Word for array lengths, string literal lengths, etc.
This eliminates a number of 64-bit integer/64-bit pointer assumptions
in the type checker and SILGen.


Swift SVN r11863
2014-01-03 18:53:01 +00:00
Joe Groff
8bebb084e6 Rename 'RequirementKind::ValueWitnessMarker' to 'WitnessMarker'.
It's witnessing protocol requirements, not values, and "value witness" has a particular meaning in IRGen.

Swift SVN r11814
2014-01-02 17:47:40 +00:00
Chris Lattner
bcc46aef5d now that super is playing nicely with the type system, all the old code
I originally wrote to turn "loadexpr(declrefexpr(letdecl))" is dead, remove
it.  Let decls are now always rvalues, so they never are loaded.


Swift SVN r11804
2014-01-01 22:58:09 +00:00
Chris Lattner
c73bfe2530 rework sema and silgen of SuperRefExpr. The most notable change is that it
is no longer an lvalue, since it doesn't make sense to assign to super.

This eliminates a bunch of special cases and simplifies things.



Swift SVN r11803
2014-01-01 22:51:10 +00:00
Chris Lattner
5e39e8f47f remove "adjustInOutForReference", the change from @inout(T) to @lvalue(T) on
reference to an @inout argument is now handled by getUnopenedTypeOfReference,
just like all the other translations.



Swift SVN r11802
2014-01-01 21:43:53 +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
d2a33362dc Fix getRValueType() to not strip off @inout types, only @lvalue types.
- Introduce a new TypeBase::getInOutObjectType() that strips off @inout types
- Switch stuff that is calling getRValueType() to call getInOutObjectType()
  when they are stripping @inout, not @lvalue (this is primarily around
  stuff working with self)
- Update testcases, some diagnostics improve around & handling.

This fixes rdar://15708430 and rdar://15729093.



Swift SVN r11794
2014-01-01 18:56:44 +00:00
Chris Lattner
366d3c173c rework base object computation and application to apply data members
to to @lvalue bases instead of @inout bases, and make the verifier
check that the right type is being used consistently.

Before:

            (member_ref_expr type='@lvalue (E0, E1)' ...
               (address_of_expr implicit type='@inout ZipGenerator2<E0, E1>'
                 (declref_expr implicit type='@lvalue ZipGenerator2<E0, E1>'

After:

                  (member_ref_expr type='@lvalue (E0, E1)' ...
                    (declref_expr implicit type='@lvalue ZipGenerator2<E0, E1>' 



Swift SVN r11792
2014-01-01 17:40:07 +00:00
Chris Lattner
468ead25a6 allow 'var' and 'let' to appear in patterns (not just matching patterns).
This allows them to appear in argument lists of functions, enabling behavior
like this:

func test_arguments(a : Int, var b : Int, let c : Int) {
  a = 1  // ok (for now).
  b = 2  // ok.
  c = 3  // expected-error {{cannot assign to the result of this expression}}
}



Swift SVN r11746
2013-12-30 21:48:06 +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
4ae0c72dec rework coerceObjectArgumentToType to make its assumptions more explicit and to only
build MaterializeExpr with an implicit lvalue type.  In the case when materialization
is still needed, we now produce addressof(materializeexpr(rvalue)) instead of producing
materializeexpr(rvalue) with @inout type.

Verify this in the AST verifier.


Swift SVN r11717
2013-12-29 17:38:58 +00:00
Chris Lattner
eb576ba2cd Now that lvalue types are more squared away, RequalifyExpr is completely
dead.  Remove it.


Swift SVN r11710
2013-12-29 05:06:54 +00:00
Chris Lattner
78f765f5f8 simplify adjustLValueForReference: now it *only* changes @inout arguments to be
implicit lvalues when referenced, so it can be simplified.


Swift SVN r11709
2013-12-29 04:52:58 +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
60cfcf74e9 - delete a dead function from the AST verifier,
- fix some logic in the type checker that only works on
  implicit lvalues to be explicit about that.
- update some comments



Swift SVN r11707
2013-12-28 23:55:33 +00:00
Chris Lattner
6f7d15dda0 the 'self' argument of a mutable value type method should be @inout(implicit), not @inout.
Swift SVN r11704
2013-12-28 22:56:41 +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
5a053ac85a - fix the ASTDumper to propertly dump closure_expr's.
- mark closure arguments (both explicit and $0's) as immutable
- Adjust the stdlib (one place) and some tests to cope with this.
- Remove some special case logic in sema for lvalue qualifying
  anonymous closure exprs, which is now the wrong thing to do.




Swift SVN r11674
2013-12-27 21:01:00 +00:00
Chris Lattner
9462fca05c Several NFC changes:
- In AST/Decl.cpp, simplify by always setting isMutating to true for 
   ctors/dtors, since mutability only means something to struct/enum 
   methods anyway.
 - in DeclContext.cpp, continue to lvalue qualify the 'self' of protocol 
   methods, this is currently dead.
 - in CSApply, fix logic for some value-type member processing stuff
   to properly handle methods that have a self which is not lvalue 
   qualified. Not exercised yet.


Swift SVN r11650
2013-12-26 01:42:51 +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
a792065c57 continue rvalue world domination. Switch get-only subscript expressions to produce
rvalues instead of non-modifiable lvalues.


Swift SVN r11634
2013-12-25 21:34:52 +00:00
Chris Lattner
57ae77dd32 Fix subscripts on rvalues: for now, just materialize the base of the
subscript to an lvalue.



Swift SVN r11624
2013-12-24 21:29:36 +00:00
Chris Lattner
b92c57fd3e Extend MemberRefExpr in a fairly substantial way: now it is ok, when applied to a
struct rvalue, to produce a struct element directly, without converting the rvalue
to an lvalue.

This means that it no longer materializes an lvalue when applied to a let declaration
or other rvalue.  For example, this testcase:

struct X { var a,b : Int} 
func g() -> X { return X(1,2) }

func f() {
  let a = g().a
}

used to sema into:

       (load_expr implicit type='Int'
          (member_ref_expr type='@inout (implicit, nonsettable)Int' decl=t.(file).X.a@t.swift:2:16
            (materialize_expr implicit type='@inout (implicit)X'
              (call_expr type='X'

and silgen into:

  %1 = function_ref @_TF1t1gFT_VS_1X : $@thin () -> X // user: %2
  %2 = apply %1() : $@thin () -> X                // user: %4
  %3 = alloc_stack $X                             // users: %7, %5, %4
  store %2 to %3#1 : $*X                          // id: %4
  %5 = struct_element_addr %3#1 : $*X, #a         // user: %6
  %6 = load %5 : $*Int64

It now sema's into:
        (member_ref_expr type='Int' decl=t.(file).X.a@t.swift:1:16
          (call_expr type='X'

and silgens into:

  %1 = function_ref @_TF1t1gFT_VS_1X : $@thin () -> X // user: %2
  %2 = apply %1() : $@thin () -> X                // user: %3
  %3 = struct_extract %2 : $X, #a

I think I'm finally starting to grok Doug's crazy typechecker magic.



Swift SVN r11599
2013-12-23 06:24:55 +00:00
Chris Lattner
31ca8889cd eliminate TypeChecker::transformType, replacing it with Type::transform.
Swift SVN r11502
2013-12-20 05:43:26 +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