Commit Graph

48 Commits

Author SHA1 Message Date
Doug Gregor
d92f1a3158 Inherit complete object initializers when a class supports it.
Teach name lookup to find complete object initializers in its
superclass when the current class overrides all of the subobject
initializers of its direct superclass.

Clean up the implicit declaration of constructors, so we don't rely on
callers in the type checker doing the right thing.

When we refer to a constructor within the type checker, always use the
type through which the constructor was found as the result of
construction, so that we can type-check uses of inherited complete
object initializers. Fixed a problem with the creation of
OpenExistentialExprs when the base object is a metatype.

The changes to the code completion tests are an improvement: we're
generating ExprSpecific completion results when referring to the
superclass initializer with the same signature as the initializer
we're in after "super.".

Swift SVN r14551
2014-03-01 00:51:21 +00:00
Dmitri Hrybenko
54a39dfeb8 Allow type checking qualified references to generic nominals with free type
variables

This change allows the type checker to create member references to generic
nominals with free type variables -- see tests.  This is important for code
completion, for example, swift.Dictionary.#^A^#

Fixes rdar://15980316


Swift SVN r14461
2014-02-27 14:40:28 +00:00
Doug Gregor
0bde325327 Collapse 'DynamicSelf' into 'Self'.
Swift SVN r14377
2014-02-26 05:04:05 +00:00
Joe Pamer
5c243ad71a When attempting to open a generic type parameter in the face of a semantic error (say, an invalid constraint specification on the type parameter's declaration), we likely won't have a replacement for that type. In these cases, pass on the type parameter so we can any semantic errors without crashing.
Swift SVN r14370
2014-02-26 02:06:30 +00:00
Doug Gregor
4af20816a6 Make the interface type for an initializer in a protocol return 'Self'.
Swift SVN r14352
2014-02-25 21:54:31 +00:00
Doug Gregor
6a532e05c6 Allow construction of archetype values via archetype metatypes.
Swift SVN r14325
2014-02-25 00:11:24 +00:00
Doug Gregor
0b42fcdbea Type-check construction using DynamicSelf metatype values.
Within a DynamicSelf method, we can [*] construct an object of type
DynamicSelf by calling an initializer on the metatype
value. Type-check and build a reasonable AST for this. This is the
rest of <rdar://problem/15862605>, but see the [*] below for it to
actually be useful.

[*] We're still subject to the restriction that one cannot actually
invoke an initializer on a class metatype value that is not statically
derived; that's the intent behind "virtual" initializers
<rdar://problem/15758600>.




Swift SVN r14178
2014-02-20 23:09:28 +00:00
Chris Lattner
3f7d3877a4 Re-commit r13836 with more correctness this time:
Sink the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down to
AbstractStorageDecl.  NFC.



Swift SVN r13842
2014-02-12 22:49:47 +00:00
Mark Lacey
525c9323cc Revert "since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down"
This reverts commit r13836, since it broke the build.

Swift SVN r13839
2014-02-12 20:59:24 +00:00
Chris Lattner
c23185d9ba since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down
to AbstractStorageDecl, NFC.


Swift SVN r13836
2014-02-12 19:16:40 +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
04475c6a85 Use @unchecked optionals for member references into AnyObject/AnyClass.
This eliminates the need for a number of !'s when dealing with
Objective-C APIs. Now with actual executable behavior!


Swift SVN r13483
2014-02-05 07:58:18 +00:00
Doug Gregor
7f3f5bc45a Reverted r13476 "Use @unchecked optionals for member references into AnyObject/AnyClass."
Some of the tests broke.


Swift SVN r13478
2014-02-05 05:39:49 +00:00
Doug Gregor
b37a50ec77 Use @unchecked optionals for member references into AnyObject/AnyClass.
This eliminates the need for a number of !'s when dealing with
Objective-C APIs.


Swift SVN r13476
2014-02-05 05:22:40 +00:00
Doug Gregor
bbf6f57b93 Properly handle type checking of references to DynamicSelf methods in generic classes.
Swift SVN r13154
2014-01-30 18:06:09 +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
b6210f7daf Start substituting type variables through protocol conformances.
This eliminates a class of strange type checking failures involving
generics. The actual example is from <rdar://problem/15772601>, but
this also addresses <rdar://problem/15268030> and the root problem,
<rdar://problem/15168483>.

Swift SVN r12974
2014-01-26 22:38:45 +00:00
Doug Gregor
a28a17250d Allow type substitutions to look up a member type of a type variable.
Use the just-introduced functionality to track the member types of a
type variable to allow type substitution to look up a member type of a
type variable, rather than failing to substitute. NFC yet.

Swift SVN r12972
2014-01-26 22:38:42 +00:00
Doug Gregor
be9c6f2d26 Track the member types of type variables explicitly within the constraint graph.
This eliminates the duplication of type variables that represent the member types of existing type variables. I'm unable to trigger this with a test case at the moment, but it becomes important when we begin to substitute type variables through protocol conformances.

Swift SVN r12971
2014-01-26 22:38:33 +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
471f2a577e Replace dependent types in constraints with their type variables.
Swift SVN r12807
2014-01-22 22:47:49 +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
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
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
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
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
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
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
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
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
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
Doug Gregor
256b946a83 Record protocol conformance when we start checking, rather than at the end.
As part of this, take away the poor attempt at recovering by adding an
explicit protocol conformance. The recovery mode isn't all that useful
in a system with only explicit conformance, and it messes with
diagnostics further down the line. We can bring it back later once
we're happy with explicit conformance checking.


Swift SVN r11503
2013-12-20 15:46:31 +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
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Doug Gregor
07c0793e30 Construct the type witnesses of SpecializedProtocolConformance lazily.
A SpecializedProtocolConformance intentionally contains all of the
information we need to synthesize the type witnesses from the
underlying (generic) conformance. Do so lazily rather than eagerly,
because we won't always need all of them.

As a nice side effect, we no longer need to serialize the witnesses of
these specialized protocol conformances, so we can save some space in
the Swift module file.


Swift SVN r11303
2013-12-14 06:20:44 +00:00
Doug Gregor
6fb1860f45 Replace multiple generated constraint sets with a single vector.
Swift SVN r11078
2013-12-10 16:46:46 +00:00
Doug Gregor
3755e6d556 Replace worklist deque with Active/Inactive constraint lists.
Swift SVN r11077
2013-12-10 16:36:36 +00:00
Doug Gregor
2d61bd31f8 Always use the constraint graph and worklist.
Since it takes the code in <rdar://problem/15476050> from > 10 minutes
to 4 seconds.


Swift SVN r11064
2013-12-10 01:25:56 +00:00
Doug Gregor
3040f2195b Factor our the selection of "alternative" literal type suggestions.
Swift SVN r11035
2013-12-09 19:19:21 +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
a6bd190b7c Split the core implementation of ConstraintSystem into its own file.
Swift SVN r11014
2013-12-09 14:05:35 +00:00