Commit Graph

22435 Commits

Author SHA1 Message Date
Eli Friedman
0f4d49385c Remove SourceLoc from ArraySliceType.
Swift SVN r2425
2012-07-24 06:29:36 +00:00
Doug Gregor
ce1c30f531 Switch the representation of archetype types so that it encodes when
an archetype is a nested type of another archetype. No functionality
change (yet).


Swift SVN r2416
2012-07-23 21:54:31 +00:00
Doug Gregor
a70818d513 Clamp down on same-type requirements that end up equating two generic
parameters together, e.g.,

  func f<T, U requires T == U>()

It's possible that we will allow this in the future.


Swift SVN r2413
2012-07-23 21:37:57 +00:00
Doug Gregor
7777cb22fe Clamp down on the types specified in requirements clauses a bit. The
subject of a conformance constraint (e.g., T : Foo) and both types of
a same-type constraint need to be generic parameters of nested types
thereof. The latter actually prohibits code like, e.g.,

  func f<R : Range requires R.Element == Int>()

which is something we may very well want to bring back into the
language in the future.


Swift SVN r2411
2012-07-23 21:13:33 +00:00
Doug Gregor
b6b094301f Eliminate the ridiculous string manipulation in the handling of
potential archetypes, replacing it with a 'parent' pointer that allows
a potential archetype to figure out its full name and its depth by
walking the parent chain. No actual functionality change.


Swift SVN r2409
2012-07-23 17:44:20 +00:00
John McCall
0eb93abb96 Add the ability to metaprogram nominal type declarations.
Swift SVN r2403
2012-07-23 07:35:21 +00:00
John McCall
39479b20ae Group all the builtin types together to allow some amount
of re-use.

Swift SVN r2394
2012-07-22 07:59:45 +00:00
John McCall
88679dbd2f Add a TypeVisitor class.
Swift SVN r2392
2012-07-22 07:59:32 +00:00
John McCall
da8c01938e Reorg, monster comment.
Swift SVN r2391
2012-07-22 07:59:22 +00:00
Eli Friedman
c6901f6a6c Initial parsing/AST for generic constructors.
Swift SVN r2387
2012-07-20 23:07:40 +00:00
John McCall
3950a6af41 Generic calls status code dump activate!
Swift SVN r2386
2012-07-20 21:59:14 +00:00
Eli Friedman
e6917fbc51 Add support for "new" with classes with non-default constructors. <rdar://problem/11917082>.
Swift SVN r2384
2012-07-20 21:37:08 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Doug Gregor
5e13507a9d Introduce the archetype builder, which collects the requirements
placed on generic parameters and associated types within the generic
parameter clause, expands those requirements out to form the complete
set of requirements, then assigns archetypes for each of the generic
parameters and their nested types (recursively).


Swift SVN r2379
2012-07-19 23:36:15 +00:00
Eli Friedman
671522000d Change diagnostic text to be a bit less confusing.
Swift SVN r2378
2012-07-19 23:23:32 +00:00
Eli Friedman
e592e07f2e Compute full SourceRanges for Decls.
Swift SVN r2376
2012-07-19 22:27:13 +00:00
Eli Friedman
7330aca582 Start propagating TypeLocs into TypeChecker::validateType.
Swift SVN r2373
2012-07-19 03:40:30 +00:00
Eli Friedman
361f931a16 Start propgating TypeLocs from the parser into the AST.
Swift SVN r2372
2012-07-19 02:54:28 +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
Doug Gregor
27e3a03525 Implement parsing, AST, and basic validation of requires clauses
within generic parameter clauses, e.g.,

  func f<T requires T : P1, T : P2>() {}




Swift SVN r2369
2012-07-18 23:36:56 +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
Eli Friedman
6b4a248f04 Parsing and AST support for destructors on classes.
Swift SVN r2348
2012-07-12 01:26:02 +00:00
Eli Friedman
43e7559310 Add GenericSubscriptExpr to represent subscripting into a generic type.
Swift SVN r2336
2012-07-10 23:39:46 +00:00
Eli Friedman
0aee5f30d5 A few misc fixes for constructing generic types. Add a WIP implementation of Slice<T>.
Swift SVN r2334
2012-07-10 21:56:43 +00:00
Doug Gregor
d684a74ada Implement builtin 'sizeof' and 'alignof' for everthing except archetypes.
Swift SVN r2330
2012-07-10 18:35:48 +00:00
Eli Friedman
bc5bb8e9f9 Fix the computation of the type of the elements of a generic oneof.
Swift SVN r2327
2012-07-10 03:25:08 +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
99784ebf3d Build ASTs correctly for unqualified references to metatype members of a generic type.
Swift SVN r2318
2012-07-07 01:18:15 +00:00
Doug Gregor
693ea406cc Tighten up the checking for the use of '&' when passing an argument to
a [byref] parameter. We were far too lax in checking this before.


Swift SVN r2314
2012-07-06 21:43:24 +00:00
Eli Friedman
960b0bfd35 Move most type lookup from name-binding into TypeChecker::validateType. Use this to make type resolution more powerful, so we can resolve members of types like S<Int>
and Int[].

Type resolution for types named in ExtensionDecls remains a part of name-binding; it has to use more restrictive rules because we can't perform general member lookup until
we've resolved all the types named in ExtensionDecls.



Swift SVN r2313
2012-07-06 01:51:09 +00:00
Eli Friedman
6258942b30 Explicitly specify whether we're performing type lookup to the name lookup code, rather than deducing it from the translation phase.
Swift SVN r2312
2012-07-06 01:06:46 +00:00
Eli Friedman
ab7d855a40 Fix a couple places where we weren't calling validateType early enough.
Swift SVN r2311
2012-07-06 00:55:28 +00:00
Eli Friedman
b067da1104 Add GenericMemberRefExpr to represent a reference to a member of a generic type.
Add a couple other misc pieces necessary for semantic analysis of members of
generic types.  We're now up to the point where we can actually construct a
useful AST for small testcases.



Swift SVN r2308
2012-07-05 20:45:31 +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
Doug Gregor
ad2fa39eaa Treat deducible generic parameter types as unresolved types, because
they need to be substituted away for any type containing them to be
useful. A nice side-effect of this is that we'll actually properly
walk into the source type when a generic function returns, e.g., a
tuple type that involves type parameters not resolved by the input
arguments.


Swift SVN r2302
2012-07-03 23:23:25 +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
b07b05937a Rework our approach to deduction of generic parameters during overload
resolution. When we see a polymorphic function type, we substitute
"deducible generic parameter" types for each of the generic
parameters. Coercion then deduces those deducible generic parameter
types. This approach eliminates the confusion between the types used
in the definition (which must not be coerced) and the types used when
the generic function is referenced (which need to be coerced).

Note that there are still some terrible inefficiencies in our handling
of these types.



Swift SVN r2297
2012-07-03 21:30:49 +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
2774d7c015 Parsing for generic types in a type context.
Swift SVN r2293
2012-07-03 02:13:45 +00:00
Eli Friedman
4555345440 Add basic parser/AST support for defining generic types.
Swift SVN r2292
2012-07-03 01:34:58 +00:00
Eli Friedman
a1a182e3d9 Initial implementation of member operators. Known limitations: currently only works for operators on structs/classes, the lookup rules aren't completely settled,
and we don't actually check whether it's reasonable to declare a given operator as a member.



Swift SVN r2277
2012-06-29 00:47:33 +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
cf5eb59956 Extend SpecializeExpr with information about the types used to replace
each primary archetype along with the protocol conformance records for
each of the requirements placed on that archetype.


Swift SVN r2250
2012-06-26 00:10:23 +00:00
Doug Gregor
a13c05ff24 Distinguish between 'primary' archetypes, which are type parameters on
which other archetypes (such as associated types) are based. Give
primary archetypes an index, to help with recording substitutions in
the near future.


Swift SVN r2239
2012-06-25 20:04:34 +00:00
Doug Gregor
827e87cac3 Switch the representation of the list of protocols to which an
archetype conforms from a list of Types (each of which is existential)
to the minimized, sorted list of protocol declarations as used by
canonical protocol composition types. This stable list is more
suitable for IR generation.


Swift SVN r2238
2012-06-25 18:37:52 +00:00
Doug Gregor
34f3e7c4c0 Introduce rudimentary generic argument deduction as part of expression
coercion. Overload resolution uses this argument deduction when
dealing with generic functions, to determine when we can invoke a
generic function. When a generic function is selected, we create a
SpecializeExpr wrapping the DeclRefExpr to the generic function.

This is sufficient to type-check calls to simple things like a call to

  func identity<T>(x : T) -> T { return x }

with a value of known type. However, it's missing far too many pieces
to enumerate.



Swift SVN r2230
2012-06-23 00:05:00 +00:00
Doug Gregor
bcbbe7e9d4 Introduce SpecializeExpr, an implicit conversion that will be used to
specialize a generic function with a given set of substitutions to
produce a new, concrete type. This node is not yet used.


Swift SVN r2226
2012-06-22 18:58:21 +00:00
Eli Friedman
ab2998431c Simplify our handling of tuple elements in the AST and Sema.
Swift SVN r2224
2012-06-21 21:30:57 +00:00