Commit Graph

767 Commits

Author SHA1 Message Date
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Joe Pamer
18f3bf67b0 More progress towards getting same-type constraints working correctly.
Swift SVN r16023
2014-04-07 21:31:52 +00:00
Joe Pamer
b9fdfe3063 Begin softening some restrictions on self-recursive constraints on associated types. This will prevent cases of infinite recursion while building archetypes.
Swift SVN r16022
2014-04-07 21:31:50 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
4bb68502a7 Take more steps towards allowing associated types referenced within constraints to conform to concrete types. This allows me to lift some restrictions I added a couple of weeks ago, and addresses rdar://problem/16333042 and rdar://problem/16284599.
(These changes also address the type-check aspects of rdar://problem/16369105, but there are still some SIL generation issues that I need to work through before I can call that work done.)

Swift SVN r15337
2014-03-21 21:44:59 +00:00
Joe Pamer
d91482ca66 Fix some issues with type parameter resolution.
In a couple of cases, we weren't properly extracting the correct archetype type from generic type parameters.  This was causing various crashes and strange errors throughout the system.  (See rdar://problem/16296421, rdar://problem/16273217, rdar://problem/16329242)

Swift SVN r15213
2014-03-18 23:52:07 +00:00
Joe Pamer
53c69a956f Fix validation of implicit 'self' variable declarations on methods with recursive associated types as constraints. In these cases, the compiler should not crash while type checking member accesses on 'self'. (rdar://problem/16281468)
Swift SVN r14934
2014-03-11 23:42:59 +00:00
Joe Groff
24e9fed6db Sema: Don't create locators with null archetypes.
And remove a stray assert(false) that shouldn't be there that I noticed by inspection.

Swift SVN r14903
2014-03-11 01:56:35 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Joe Pamer
e05e04ab0e Address more feedback for r14800
Swift SVN r14807
2014-03-08 00:03:57 +00:00
Joe Pamer
6fe2917646 John gave me some style advice on r14800 - this change folds in his feedback.
Swift SVN r14803
2014-03-07 23:25:23 +00:00
Joe Pamer
dce0673db1 We should avoid fixing type variables to optional types that wrap the type variable itself. When solving for the type variable, this will lead to the creation of a constraint where the variable is adjacent to itself. Such constraints are not permitted and will cause the compiler to crash. (rdar://problem/15727642)
Swift SVN r14800
2014-03-07 22:47:48 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Joe Pamer
3684658771 When resolving generic type aliases within protocols, the type aliases themselves may be modeled as substitutions, and not strictly as type variables. Not accounting for this lead to rdar://problem/16228026 and rdar://problem/16228058, wherein the compiler could crash if the open type alias was referenced from within a generic type instantiation.
Swift SVN r14746
2014-03-06 19:47:41 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Chris Lattner
11bedff2f3 the swift.Slice type got removed a long time ago, being replaced with
what is now Swift.Array.  Update various internal stuff to refer to
Array instead of Slice.  NFC.


Swift SVN r14567
2014-03-02 06:21:37 +00:00
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