Commit Graph

21693 Commits

Author SHA1 Message Date
Doug Gregor
13d8eed15c Add a verifier for ReturnStmt.
Swift SVN r2947
2012-10-08 19:03:51 +00:00
Doug Gregor
9927f761de Improve debug dumping for overloaded expressions ever so slightly.
Swift SVN r2918
2012-10-02 15:01:07 +00:00
Eli Friedman
77c0114186 Make sure TupleType::get never returns an invalid TupleType.
Finishes off <rdar://problem/12337042>.

Also, fix constraint application so that test/Constraints/closures.swift
doesn't explode with the above fix.



Swift SVN r2888
2012-09-21 01:54:26 +00:00
Eli Friedman
d8b84d6cd0 Add ScalarToTupleExpr to represent an implicit conversion from a scalar to a tuple. Part of <rdar://problem/12337042>.
Swift SVN r2887
2012-09-21 00:45:33 +00:00
Doug Gregor
ce334c03ce When dumping an overloaded declaration reference or member reference
expression, just dump out the types of each of the options, rather
than the full, recursive definitions.


Swift SVN r2884
2012-09-20 22:12:42 +00:00
Doug Gregor
95830d4db0 Clean up some type computations in the application of a constraint
system to an expression, and fix a bogus check in the verifier.


Swift SVN r2881
2012-09-20 20:46:37 +00:00
Doug Gregor
42b1ab6fbd Introduce a LangOptions class to capture various type-checker-tweaking flags. For now, introduce bits to enable the constraint solver and to enable debugging of the constraint solver, and use those to eliminate the "useConstraintSolver" bit that was threaded through too much of the type checker.
Swift SVN r2836
2012-09-12 20:19:33 +00:00
Doug Gregor
693318642d Remove the "type checker cannot handle well-typed expressions" error,
since we're now applying solved constraints to an expression to
produce a well-typed expression. The resulting expressions are now
returned and run through the verifier, so deal with some of the
byref(implicit) fallout.


Swift SVN r2835
2012-09-12 02:14:13 +00:00
Doug Gregor
5dfd6e8f2d Implement support for allocating a new array within the
constraint-based type checker.


Swift SVN r2808
2012-08-29 22:32:47 +00:00
Doug Gregor
029f7329c5 Re-introduce the notion of implicit lvalues, to be used within the
constraint-based type checker. We now model the address-of operator
with the constraint

  [byref] T1 < T2

where T1 is a fresh variable and T2 is the type of the subexpression
of &. 

Note that there's a little hack in the constraint generator that
strips off the 'heap' qualifier when performing constraint-based type
checking, because we're not actually using it for overloading (merely
as an aid for IRgen) and it causes some trouble in the modeling of the
address-of operator.

We can now properly reject code such as

  swap(a, b)

which should be

  swap(&a, &b)



Swift SVN r2797
2012-08-28 18:21:27 +00:00
Ted Kremenek
a5ec0af7e8 Rename 'BraceStmt::elements()' to 'getElements()' to match Swift
naming style for accessors.

Swift SVN r2742
2012-08-24 14:17:28 +00:00
Doug Gregor
fa474ee750 Implement simplification of conversion constraints for user-defined
conversions. We limit the relationship between the result of the
conversion and the actual expected type to a subtyping relationship,
which effectively limits us to applying a single user-defined
conversion function (rather than a chain of such conversions).

Later, we can consider extending this to a chain of conversion
functions, but that will require us to cope with cyclic conversions
and minimizing conversion sequences (e.g., if A -> B -> C and A -> C
are both possible, we should prefer A -> C).


Swift SVN r2730
2012-08-23 23:25:02 +00:00
Doug Gregor
8015fcecf8 Implement subtyping of classes in the constraint-based type checker.
Swift SVN r2724
2012-08-23 21:55:57 +00:00
John McCall
e7b9ae47fa Defer to the value witness when moving an archetype. This
is really a deficiency in TypeInfo::initializeWithTake, which
is now virtual and not implemented in TypeInfo anymore.  This
fixes rdar://problem/12153619.

While I'm at it, fix an inefficiency in how we were handling
ignored results of generic calls, and add 4 new builtins:
  Builtin.strideof is like sizeof, but guarantees that it
  returns a multiple of the alignment (i.e., like C sizeof,
  it is the appropriate allocation size for members of an
  array).
  Builtin.destroy destroys something "in place";  previously
  this was being simulated by moving and ignoring the result.
  Builtin.allocRaw allocates raw, uninitialized memory, given
  a size and alignment.
  Builtin.deallocRaw deallocates a pointer allocated with
  Builtin.allocRaw;  it must be given the allocated size.

Swift SVN r2720
2012-08-23 05:21:31 +00:00
Doug Gregor
9d315ae72a Keep track of whether a given type involves a type variable.
Swift SVN r2705
2012-08-22 00:24:22 +00:00
Eli Friedman
eb1689710f Delete isa, cast, and dyn_cast on Type. Hopefully, this will lead to fewer stupid mistakes.
Swift SVN r2691
2012-08-20 22:15:10 +00:00
Doug Gregor
b4c91a34a0 Whether a canonical type has been constructed for a given type is not
a reliable way to track whether a particular type has been
validated. Instead, add some bits to the type to indicate which stage
of checking it has received. I hate it, but it works and I don't know
of a better way to ensure that types get validated. This subsystem
will need to get rearchitected at some point (ugh).

Reduce the number of places where we build new BoundGenericTypes,
since they need to be validated fully to get substitutions, and then
introduces a number of validateTypeSimple() calls to validate types in
places where we know the validation will succeed, but we need that
information regardless.


Swift SVN r2681
2012-08-18 00:09:56 +00:00
Doug Gregor
8d583f412b Add a verifier to check that bound generic types always have
substitution information, but keep it turned off because it fails
everywhere :(


Swift SVN r2673
2012-08-17 18:12:15 +00:00
Eli Friedman
bef302d2ee Initial attempt at implementing semantic analysis of overriding for classes.
Still a lot of missing pieces, but it mostly works.



Swift SVN r2633
2012-08-15 01:21:35 +00:00
Doug Gregor
0d7afbe5e0 Introduce an almost completely untested implementation of constraint
generation from an expression that has not been type-checked. One can
see the constraints introduced by an expression by using

  :dump_constraints <expression>

within the REPL. We're still missing several major pieces of
constraint generation:
  - We don't yet "open up" references to polymorphic types
  - We don't print out the child constraint systems in the dump, so
  it's not at all obvious what happens within overloading (and I'm not
  convinced I like my representation anyway)
  - There are no tests whatsoever
  - Member constraints are still very, very weird



Swift SVN r2624
2012-08-13 22:59:41 +00:00
Eli Friedman
9e06964c8a Make the TypeLoc constructor which takes just a type private, and expose a
static method to call it, to make it more explicit what is happening.  Avoid
using TypeLoc::withoutLoc for function definitions; instead, just use an empty
TypeLoc.



Swift SVN r2606
2012-08-10 02:09:00 +00:00
Eli Friedman
6781f56cfd Start of support for class inheritance.
Swift SVN r2598
2012-08-09 21:56:05 +00:00
Ted Kremenek
479077e354 Remove individual element setters from BraceStmt, and just use MutableArrayRef and ArrayRef to access its elements.
Swift SVN r2586
2012-08-08 05:06:33 +00:00
Eli Friedman
95cb2d6af2 Add builtins to convert between arbitrary retainable pointers,
Builtin.ObjectPointer, and Builtin.RawPointer.  I don't really like the way
these builtins are defined (specifically, the part where messing up
gives a mysterious IRGen error), but it's workable. <rdar://problem/11976323>.



Swift SVN r2585
2012-08-08 00:40:07 +00:00
Eli Friedman
b01b27c9c0 A few misc tweaks to -ast-dump for decls.
Swift SVN r2579
2012-08-07 22:52:11 +00:00
Doug Gregor
011e9da1ef When we're specializing, we need to know how many levels of generic
parameters we're substituting. This is either "all levels" (when we're
substituting a specific base type in a member access) or "the
innermost level" (when we're substituting after deducing from a use or
application of a polymorphic function).


Swift SVN r2576
2012-08-07 22:04:31 +00:00
Chris Lattner
5184be484f Finish off rdar://12017658 - func() expression should support type inference of argument types.
This implements inference of return types, per the discussion today.



Swift SVN r2572
2012-08-07 05:12:32 +00:00
Doug Gregor
531583e2d1 Implement support for nested generics in the AST and type
checker. There are a few related sets of changes here:

  - Generic parameter lists have a link  to their "outer" generic
  parameter lists, so its easy to establish the full generic context
  of an entity.
  - Bound and unbound generic types now carry a parent type, so that
  we distinguish between, e.g., X<Int>.Inner<Int> and
  X<Double>.Inner<Int>. Deduction, substitution, canonicalization,
  etc. cope with the parent type.
  - Opening of polymorphic types now handles multiple levels of
  generic parameters when needed (e.g., when we're substituting into
  the base).

Note that the generics module implied by this representation restricts
what one can do with requirements clauses in nested generics. For
example, one cannot add requirements to outer generic parameters or
their associated types, e.g., this is ill-formed:

  struct X<T : Range> {
    func f<U requires T.Element : Range>() {}
  }

The restriction has some precedent (e.g., in C#), but could be
loosened by rearchitecting how we handle archetypes in nested
generics. The current approach is more straightforward.


Swift SVN r2568
2012-08-06 19:02:06 +00:00
John McCall
0c9252412a Print the injection function of a NewArrayExpr when
dumping it.

Swift SVN r2531
2012-08-03 08:10:40 +00:00
Chris Lattner
b3f4547a9b use contextual type information to infer the argument types for func exprs
without fully typed patterns.  This is the first half of rdar://12017658,
the second half is to infer return types.



Swift SVN r2528
2012-08-03 05:03:46 +00:00
Eli Friedman
0bfcfbfb8a Change the type of ConstructorDecls to be of the form metatype<T> -> () -> (). Change a bunch of stuff to compensate. Get rid of ConstructorRefExpr, which is no longer used.
Swift SVN r2526
2012-08-03 03:58:44 +00:00
Chris Lattner
51b4f35b9f fix -parse-dump to not crash on pattern_binding_decls that don't have a type yet.
This occurs in "var u8, u8_1 : StringByte"



Swift SVN r2521
2012-08-03 01:18:01 +00:00
Doug Gregor
532737205b Improve checking of protocol-conformance requirements for generic
types in a few ways:
  - Actually check the extra requirements placed on associated types,
  e.g., "T.Element : Ordered"
  - Actually encode/store the protocol conformance information for a
  BoundGenericType in the same way that we do for SpecializeExpr,
  GenericMemberRefExpr, and GenericSubscriptExpr. Yay, consistency.
  - Move the storage for the protocol conformance information into a
  DenseMap in the ASTContext indexed by canonical BoundGenericType, so
  it doesn't require inline storage in BoundGenericType.


Swift SVN r2517
2012-08-03 00:41:32 +00:00
Doug Gregor
3eed1fbafd Generalize the substitution of a "base type" into a reference to a
member of a oneof/struct/class/extension to support types nested
within generic classes, e.g., Vector<Int>.ElementRange. 

Most importantly, nominal types are no longer inherently canonical. A
nominal type refers to both a particular nominal type declaration as
well as its parent, which may be non-canonical and will vary. For
example, the variance in the parent makes Vector<Int>.ElementRange and
Vector<Float>.ElementRange different types. 

Introduce deduction and substitution for nominal types. Deduction is
particular interesting because we actually do allow deduction of T
when comparing X<T>.Inner and X<Int>.Inner, because (unlike C++) there
is no specialization to thwart us.



Swift SVN r2507
2012-08-02 21:22:44 +00:00
Doug Gregor
e27d65f199 Introduce a "parent' context into oneof, struct, and class types. The
parent context encodes the generic arguments for outer generic types,
so that X<Int>.Nested and X<Float>.Nested are distinct types.


Swift SVN r2502
2012-08-01 23:20:36 +00:00
Doug Gregor
c1229e72a8 Give the methods, constructors, and destructors of a nested type a
polymorphic type when that type is nested within a generic type. The
type-checker still isn't ready to use these declarations in a sane way.



Swift SVN r2501
2012-08-01 21:16:06 +00:00
Ted Kremenek
81169fc0aa Reduce 'threading' of show colors logic through AST printer API, computing it in one central place.
Swift SVN r2499
2012-07-31 05:10:49 +00:00
Ted Kremenek
c03dce396b Hack up some initial support for coloring -ast-dump to make this easier to read.
Swift SVN r2498
2012-07-31 01:00:55 +00:00
Eli Friedman
76e6aa41b0 Change the computed type for OneOfElementDecls in OneOfs: for an Optional<T>, the OneOfElementDecl for Some now has type <T>(metatype<Optional<T>>) -> (T) -> Optional<T>, and the OneOfElementDecl for None has type <T>(metatype<Optional<T>>) -> Optional<T>.
The IRGen test is turned off because of another call-related IRGen crash (specifically, an indirect call of an indirect call crashes).



Swift SVN r2497
2012-07-30 23:31:23 +00:00
Eli Friedman
84e858da4e Fix static member functions so a member of type T has type "metatype<T> -> () -> ()" instead of "() -> ()".
This is much more convenient for IRGen, and gives us a reasonable representation for a static
polymorphic function on a polymorphic type.

I had to hack up irgen::emitArrayInjectionCall a bit to make the rest of this patch work; John, please
revert those bits once emitCallee is fixed.



Swift SVN r2488
2012-07-28 06:47:25 +00:00
Doug Gregor
3e5666d88c Introduce a set of substitutions into generic subscript
expressions. All accesses to members of generic types should now get
appropriate specialization information.


Swift SVN r2484
2012-07-27 19:11:07 +00:00
Doug Gregor
f66ca78037 Introduce a set of substitutions into GenericMemberRefExpr, so that we
have a record of how the member is being specialized for the given
context. To do this, I also had to patch up the DeclContext for
template parameters.


Swift SVN r2483
2012-07-27 18:49:09 +00:00
Doug Gregor
3173d17983 Generic class types, both bound and unbound, have reference semantics.
Swift SVN r2478
2012-07-27 07:18:32 +00:00
Doug Gregor
f4f176dd27 Give the static methods of a generic type polymorphic type,
always. One step closer to representational sanity.


Swift SVN r2477
2012-07-27 07:05:03 +00:00
Doug Gregor
ea4cb398ed Destructors of generic class types have polymorphic function
type. This has remarkably little effect on type checking, because the
destructors themselves are never referenced by the AST after initially
type-checking them.


Swift SVN r2474
2012-07-27 06:38:32 +00:00
Doug Gregor
f4ced2028d Make the constructors of generic types polymorphic function types,
including the weird implicit one-of element declarations that end up in struct
types. Teach overload resolution and the type-checking of
ConstructorRefExprs how to specialize these polymorphic function types.


Swift SVN r2473
2012-07-27 06:33:04 +00:00
Doug Gregor
17422d5bee The type of an instance method in a generic class is actually a
polymorphic function type. For example, given

  struct X<T> {
    func f(a : T) -> Int { }
  }

The type of X.f is

  <T> (this : [byref] X<T>) -> (a : T) -> Int

If we have a call to f, e.g.,

  var xi : X<Int>
  xi.f(5)

it will be represented as X.f specialized to type

  (this : [byref] X<Int>) -> (a : Int) -> Int

and then called with 'xi' (DotSyntaxCallExpr) and finally 5
(ApplyExpr). The actual deduction of arguments is not as clean as I'd
like, generic functions of generic classes are unsupported, static
functions are broken, and constructors/destructors are broken. Fixes
for those cases will follow.



Swift SVN r2470
2012-07-27 00:24:32 +00:00
Doug Gregor
9e8633ac41 Encode and pass all of the archetypes, including derived archetypes,
in SpecializeExpr, so that we have complete substitution and
protocol-conformance information. On the IR generation side, pass
witness tables for all of the archetypes (again, including derived
archetypes) into generic functions, so that we have witness tables for
all of the associated types.

There are at least two major issues:

  (1) This is a terribly inefficient way to pass witness tables for
  associated types. The witness tables for associated types should be
  accessible via the witness tables of their parent. However, we need
  more information in the ASTs here, because there may be additional
  witness tables that will need to be passed for requirements that are
  placed on the associated type by the generic function itself.

  (2) Something about my test triggers a void/non-void verification failure
  in the witness build for an instance function whose abstracted form
  returns an associated type archetype and whose concrete form returns
  an empty struct. See the FIXME in the test.



Swift SVN r2464
2012-07-26 17:52:04 +00:00
Doug Gregor
67c2354d28 When building archetypes, gather all of the archetypes (both primary
and derived) so they can be stored within the generic parameter list
for use 'later'.

More immediately, when we deduce arguments for a polymorphic function
type, check that all of the derived archetypes conform to all of the
protocol requirements, stashing that protocol-conformance information
in the coercion context (also for use 'later'). From a type-checking
perspective, we now actually verify requirements on associated types
such as the requirement on R.Element in, e.g.,

  func minElement<R : Range requires R.Element : Ordered>(range : R)
         -> R.Element



Swift SVN r2460
2012-07-26 00:24:05 +00:00
Eli Friedman
688138482d Complete the implementation of a basic Vector<T>.
Swift SVN r2457
2012-07-25 22:51:46 +00:00