Commit Graph

336 Commits

Author SHA1 Message Date
Eli Friedman
7330aca582 Start propagating TypeLocs into TypeChecker::validateType.
Swift SVN r2373
2012-07-19 03:40:30 +00:00
Eli Friedman
f1f67db652 Big cleanup for how we handle computing types for functions and semantic
analysis for patterns.

Major changes:
1. We no longer try to compute the types of functions in the parser.
2. The type of a function always matches the type of the argument patterns.
3. Every FuncDecl now has a corresponding FuncExpr; that FuncExpr might not
   have a body, though.
4. We now use a new class "ExprHandle" so that both a pattern and a type
   can hold a reference to the same expression.

Hopefully this will be a more reasonable foundation for further changes to
how we compute the types of FuncDecls in generics and for the implementation
of type location information.



Swift SVN r2370
2012-07-19 02:09:04 +00:00
Eli Friedman
6a4098b102 Mess with the way we do canonicalization for ProtocolCompositionTypes in a way
that doesn't violate canonical type invariants.  It's still a little messy,
but it's consistent.  Fixes <rdar://problem/11886926>.



Swift SVN r2368
2012-07-18 01:31:40 +00:00
Doug Gregor
be55c18fcf Check that the arguments in a bound generic type conform to the
protocol requirements of that type, and capture that
protocol-conformance information in the canonical bound generic type.


Swift SVN r2322
2012-07-09 19:52:59 +00:00
Eli Friedman
a54c5493da Per discussion with Doug, add UnboundGenericType and BoundGenericType to represent generic types.
Swift SVN r2304
2012-07-04 01:17:16 +00:00
Eli Friedman
99fac3aaa8 Change MetaTypeType so that the instance type is actually a Type, not a TypeDecl*.
Swift SVN r2301
2012-07-03 23:12:19 +00:00
Eli Friedman
2268f7155d Introduce UnresolvedNominalType to represent a generic type without an argument list, and add an argument list to NominalType to represent a generic type including an argument list.
Swift SVN r2299
2012-07-03 22:15:02 +00:00
Doug Gregor
bac5470881 Collate the OneOfType*/ClassType*/StructType*/ProtocolType* members of
the various NominalDecl subclasses into a single NominalType* member
in NominalDecl. Use it to make TypeDecl::getDeclaredType() more
efficient/simpler, and simplify the ProtocolDecl/ProtocolType
interaction along the way.

No functionality change.


Swift SVN r2298
2012-07-03 21:46:52 +00:00
Doug Gregor
04ffc8c432 Introduce a new abstract type, SubstitutableType, to cover types that
can be substituted, and do some simply renaming to distance ourselves
from archetypes in these code paths.


Swift SVN r2295
2012-07-03 17:37:27 +00:00
Eli Friedman
01e7041600 Misc fixes on top of John's PolymorphicFunctionType patch.
Swift SVN r2256
2012-06-27 02:23:38 +00:00
John McCall
668f674bfa Split off a PolymorphicFunctionType from FunctionType. I am
*positive* that the behavior here is blatantly wrong in a lot
of places, but I'm going to leave it to Doug to clean up after me. :)

Swift SVN r2255
2012-06-27 00:22:15 +00:00
Doug Gregor
c079874625 Implement parsing, AST, type canonicalization, and type validation for
protocol conformance types, e.g., 'protocol<P, Q>'. A few things
people *might* want to scream about, or at least scrutinize:

  - The parsing of the '<' and '>' is odd, because '<' and '>' aren't
    tokens, but are part of the operator grammar. Neither are '>>',
    '>>>', '<>', etc., which also come up and need to be parsed
    here. Rather than turning anything starting with '<' or '>' into a
    different kind of token, I instead parse the initial '<' or '>'
    from an operator token and leave the rest of the token as the
    remaining operator.
  - The canonical form of a protocol-composition type is minimized by
    removing any protocols in the list that were inherited by other
    protocols in the list, then sorting it. If a singleton list is
    left, then the canonical type is simply that protocol type.
  - It's a little unfortunate that we now have two existential types
    in the system (ProtocolType and ProtocolCompositionType), because
    many places will have to check both. Once ProtocolCompositionTypes
    are working, we should consider whether it makes sense to remove
    ProtocolType.

Still to come: name lookup, coercions.



Swift SVN r2066
2012-05-30 00:39:08 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
8e1cd3990b Implement substitution of types, which substitutes concrete types for
archetypes. Use this substitution when checking the
variable/function/subscript witnesses during protocol conformance.

This allows us to check the conforms-to relationship for the Range
protocol as we want to express it.


Swift SVN r1945
2012-05-23 00:39:06 +00:00
Doug Gregor
b1f1e1430d Introduce NominalType as a base class of
OneOfType/StructType/ClassType/ProtocolType, an eliminate the
ridiculous chained ifs that used to check for most (or all) of these.


Swift SVN r1923
2012-05-22 00:13:59 +00:00
John McCall
38bac7c706 Add Builtin.ObjCPointer with accompanying IR-gen support and
wrap it in an 'id' type in the standard library.

Also fix a bug noticed by inspection where initWithTake for
function types wasn't entering a cleanup for the taken value.
This probably doesn't matter for existing possibilities, but
it's potentially important under exceptions.

Swift SVN r1902
2012-05-18 23:40:17 +00:00
John McCall
71c45f5212 Lion's libc++ headers do not support shared_ptr under -fno-rtti.
This is <rdar://problem/10217868>.  Apparently I'm using Lion's
libc++ headers somehow, which I should probably fix;  but since
the use of shared_ptr is just a hack until DenseMap supports
move-only types, I don't feel bad about changing it to a different
hack that avoids shared_map altogether.

Swift SVN r1897
2012-05-18 10:01:54 +00:00
Eli Friedman
099a97847d Parsing and AST support for varargs tuples.
Swift SVN r1875
2012-05-16 22:02:01 +00:00
Eli Friedman
a5a39860cd Basic parsing plus a bit more of the AST for ClassDecls.
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Eli Friedman
790687e025 Don't try to unique TupleTypes with default values.
Swift SVN r1844
2012-05-15 00:15:43 +00:00
Eli Friedman
77fa49ec2b Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
5f2344afe0 Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
guts of ProtocolType over to ProtocolDecl.


Swift SVN r1778
2012-05-08 23:28:55 +00:00
Eli Friedman
4ca443d0f5 Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
Swift SVN r1774
2012-05-08 21:09:42 +00:00
John McCall
6133630544 When type-checking a slice type, "desugar" it to a type that is
generic over the type of the base.  By "generic" I mean that it's
looked up by prepending the word "Slice" to the name of the base
type.

Swift SVN r1464
2012-04-18 08:09:10 +00:00
Chris Lattner
65b400e30d introduce a new "Builtin.RawPointer" type, which corresponds to LLVM's "i8*" type,
and is just an unmanaged pointer.  Also, introduce a basic swift.string type.

This is progress towards rdar://10923403 and strings.  Review welcome.



Swift SVN r1349
2012-04-10 00:52:52 +00:00
Doug Gregor
f370accf59 Introduce the notion of structured dependent types, such as a tuple
type with one or more elements of dependent type. Previously, an
expression such as (x, 5) would have the (unstructured) dependent
type, limiting our ability to type-check the subexpression 'x'
early. Now, if 'x' has type 'int' (for example), this expression will
now have the type (int, <<unstructured dependent type>>).

Extend coercion of a tuple to tuple type to handle coercion to
(structured) dependent tuple types, coercing element-by-element. This
code is very lightly tested and may still need to be restructured.




Swift SVN r1294
2012-03-29 16:26:04 +00:00
Doug Gregor
4cc616f2be Rename the DependentType class to UnstructuredDependentType, because
this type is only going to cover dependent types for which there is
absolutely no structure. Still no functionality change.


Swift SVN r1292
2012-03-29 14:14:48 +00:00
John McCall
1f118dbda6 Basic support for Builtin.ObjectPointer as a completely
opaque type.  Also some rudimentary support for retain/release.

Swift SVN r1214
2012-03-16 09:26:32 +00:00
Chris Lattner
71f351e0b6 fix the autoclosure bit to be properly canonicalized and preserved when building functiontypes.
Swift SVN r1190
2012-03-11 14:00:05 +00:00
Chris Lattner
145d926548 Perform sema of FunctionType's that have auto_closure behavior, building a bit in FunctionType.
Swift SVN r1187
2012-03-11 13:15:03 +00:00
John McCall
b2a2027a43 Revert r1144, r1145, and r1146. These changes (which removed ParenType
in favor of a single-element non-canonical TupleType) broke the type
system, in that supposed sugar (the TupleType) supported a different
set of operations from the canonical type.  For example, a
single-element unlabelled tuple type supports elementwise projection
(foo.$0), but the underlying element does not (or supports it
differently).

The IR-gen failure was due to a very related problem:  IR-gen
was not updated to reflect that a single unlabelled tuple element
is the same type as its element type, and therefore it was giving
different representations to these types ({ %foo } and %foo,
respectively), which broke widespread assumptions.

The removal of ParenType was done in pursuit of an AST invariant
that's not actually particularly interesting in the first place
and which, furthermore, is problematic to attain.

Swift SVN r1182
2012-03-11 09:15:21 +00:00
Chris Lattner
6641b06283 remove ParenType, which is now dead. Grouping parens are represented
as non-canonical tuple types.


Swift SVN r1147
2012-03-02 00:17:45 +00:00
Chris Lattner
2b65dcaf24 Change how we handle grouping parens. Instead of (x) being ParenType(x),
it is now a single element TupleType(x).  In order to preserve sane behavior,
we force grouping parens to be non-canonical and have them desugar down to
their underlying element type.

This does cause an IRGen testcase failure that looks like it was just working
accidentally before (though I don't really understand what is going on).  I
filed rdar://10967479 to track it.


Swift SVN r1146
2012-03-02 00:13:56 +00:00
John McCall
00b97b38af Grab-bag of materialization-related changes:
- introduce the concept of qualifiers on l-value types
  - teach overload resolution and coercion how to drop explicitness
  - require explicitness on normal [byref] arguments
  - make 'this' [byref(implicit)]
  - special-case '&' as a unary operator in the parser to make it
    produce an expression which type-checks as turning implicit l-values
    into explicit ones.

Obvious missing pieces:
  - updating LangRef
  - we should really complain about ever trying to rvalue-convert an
    explicit l-value
  - maybe qualification should play a part in overload resolution
  - we should diagnose attempts to declare unary '&' operators
  - there's a test case in expressions.swift which suggests my logic is
    slightly off

But I am out of time, and these will have to wait.

Swift SVN r1119
2012-02-22 06:43:33 +00:00
John McCall
d0f4d86f3e Use LValueType everywhere instead of the l-value value kind.
Kill off TypeJudgement.  Various fixes and improvements.



Swift SVN r1107
2012-02-06 22:47:08 +00:00
John McCall
5f1bcd7b7e Move all the side-allocated members of ASTContext to a single
side-allocation.  This is both easier to work with and extend
and slightly more efficient.



Swift SVN r1106
2012-02-02 01:13:33 +00:00
John McCall
6ff9afb6f5 Introduce LValueType.
Swift SVN r1105
2012-02-02 00:57:10 +00:00
Chris Lattner
599e4b2528 switch to using the new llvm::MutableArrayRef class, this requires llvm r148463
Swift SVN r1088
2012-01-19 06:39:07 +00:00
John McCall
ea5e37e276 Getterize uses of TupleTypeElt. I'm trying to figure out how
parameter attributes should work here.



Swift SVN r1066
2012-01-18 04:05:25 +00:00
Chris Lattner
1c42e8f6a6 rename DottedNameType to IdentifierType. It captures loc information for random uses of type names, among other things.
Swift SVN r1064
2012-01-18 01:52:28 +00:00
Chris Lattner
4f8193956d introduce DottedNameType, which will eventually be used for foo.bar in a type context.
Swift SVN r1049
2012-01-17 01:55:17 +00:00
Chris Lattner
82bf169d90 implement ModuleType::get.
Swift SVN r1040
2012-01-14 06:40:39 +00:00
Chris Lattner
173df8794d implement the construction for MetaTypeType's and plug a leak of the ParenTypes map.
Swift SVN r1002
2012-01-11 06:59:14 +00:00
John McCall
d559794e73 Introduce a new kind of sugar, ParenType. A tuple with one
anonymous member is actually one of these.

A func decl is curried over all of its parameter clauses,
as long as they're written without parentheses.  So the body
of a func is the body of the "most curried" function:
  func foo(x:int) -> (y:int) -> int {
    // This is the body of the function that takes 'y'.
    // It returns an int.
  }
  func bar(x:int) -> ((y:int) -> int) {
    // This is the body of the function that takes 'x'.
    // It returns a functon of type (y:int) -> int.
  }



Swift SVN r993
2012-01-06 04:10:32 +00:00
Chris Lattner
b737b112e7 modernize ProtocolType a bit to follow the form of OneOfType
Swift SVN r991
2012-01-05 21:51:48 +00:00
Chris Lattner
19b7a934a1 rename BuiltinFloatingPointType to BuiltinFloatType.
Swift SVN r980
2011-12-23 00:07:58 +00:00
Chris Lattner
c91c1d9db1 generalize builtin floating point types to support all of the FP types
that LLVM supports.  The standard library still only exports float and double,
but the swift core should be more general.  Yay for PPC128 :)


Swift SVN r973
2011-12-22 22:01:07 +00:00
Chris Lattner
6a51dbba34 Remove hard coded list of integer types from ASTContext, making BuiltinIntegerType have a "plus" factory method to create them like other types.
Swift SVN r966
2011-12-22 07:07:01 +00:00
Chris Lattner
98c5f5fad4 change BuiltinIntegerType to keep its width as an ivar, eliminating the
number of switches scattered through the compiler.


Swift SVN r964
2011-12-22 06:50:34 +00:00
Chris Lattner
6315b94e6b split out integer types to their own subclass of BuiltinType.
Swift SVN r932
2011-12-14 21:49:08 +00:00