Commit Graph

1198 Commits

Author SHA1 Message Date
John McCall
00126779d6 The world demands a common generics header, and who am I
to disagree with billions of other people?

Swift SVN r2926
2012-10-03 08:57:36 +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
578ff6631a ColonLoc -> DotLoc, to reflect the current syntax for unresolved member expressions
Swift SVN r2867
2012-09-18 21:59:21 +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
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
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
b6f6eec106 implement rdar://11935352 - accepting closures with no body expression (the closure
just returns "()").


Swift SVN r2503
2012-08-02 20:08:51 +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
bb7cdf511c Add missing doc comment.
Swift SVN r2489
2012-07-28 06:52:48 +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
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
ea6348f446 Make NewReferenceExpr inherit from ApplyExpr; this lets us delete some redundant code.
Swift SVN r2447
2012-07-25 20:55:51 +00:00
Doug Gregor
511dbfea25 When applying an operator found in a protocol, compute the effetive
base type (e.g., the archetype type, when we're in a generic function)
used to refer to that operator as a member, e.g., given

  func min<T : Ord>(x : T, y : T) {
    if y < x { return y } else { return x }
  }

'<' is found in the Ord protocol, and is referenced as

  archetype_member_ref_expr type='(lhs : T, rhs : T) -> Bool' decl=<
    (typeof_expr type='metatype<T>'))

using a new expression kind, TypeOfExpr, that simply produces a value
of metatype type for use as the base.

This solves half of the problem with operators in protocols; the other
half of the problem involves matching up operator requirements
appropriately when checking protocol conformance.


Swift SVN r2443
2012-07-25 16:04:30 +00:00
Eli Friedman
30d1f22bfb Rewrite the representation of NewReferenceExpr to make it more friendly to generics.
Generic constructors on classes should be working with this commit.



Swift SVN r2440
2012-07-25 00:49:03 +00:00
Eli Friedman
751c463a2e Rewrite the way we represent construction of value types so that it looks
more like a call.  This should be enough to get generic constructors working.



Swift SVN r2437
2012-07-24 23:43:43 +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
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
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
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
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
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
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
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
Doug Gregor
7e18b7e403 Zap the unused *Expr::createWithCopy() functions, which baked
semantics into the AST library where they don't belong. These were
made obsolete by the recent TypeCheckExpr::build(Member)?RefExpr()
refactoring.


Swift SVN r2222
2012-06-21 17:32:01 +00:00
Doug Gregor
7e61089918 Refactor the code that builds declaration reference and member
reference expressions, introducing two routines on TypeChecker
(buildRefExpr and buildMemberRefExpr) that are intended to be the sole
generators of ASTs.

Updated all but one caller for member reference expressions, the
terrible MemberLookup::createResultAST(), which still calls into the
AST library to build nodes.



Swift SVN r2219
2012-06-21 00:43:49 +00:00
Doug Gregor
38205611c3 Teach the overloaded declaration reference expression to track whether the
base of the expression is ignored, as it will be for references to
static member functions or when the base is actually of metatype
type. Then, always also one to access the type of the base, even if
it's a metatype type.

Use this information to simplify our handling of archetype member
reference expressions, which can refer to either members of the
meta-archetype or of an instance of the archetype. This allows us to
refer to an instance methodr of an archetype type (e.g., T.method) and
get back its curried form ([byref] T) -> inputs -> result.



Swift SVN r2218
2012-06-20 21:07:57 +00:00
Doug Gregor
f4bdd9ddf3 Introduce support for using static protocol functions within generics.
Swift SVN r2216
2012-06-20 17:59:03 +00:00
Doug Gregor
cf4a05f66d Eliminate SuperConversionExpr. This expression node was only really
used in the very narrow case where we were converting from one
protocol type to another (super) protocol type. However, ErasureExpr
now handles this case via its null conformance entries (for the
"trivial" cases), and can cope with general existential types where
some conversions are trivial and others are not.

The IR generation side of this is basically just a hack to inline the
existing super-conversion code into the erasure code. This whole
routine will eventually need to be reworked anyway to deal with
destination types that are protocol-conformance types and with source
types that are archetypes (for generic/existential interactions).



Swift SVN r2213
2012-06-20 16:26:48 +00:00
Doug Gregor
dd2589cb67 Teach TypeChecker::conformsToProtocol() to identify protocol
conformance when it is trivial, e.g., when the source type is an
archetype or existential type that conforms to the candidate protocol
or a protocol that implies it. In this case, we don't build a
ProtocolConformance structure (which would be uninteresting anyway).

Extend the definition of ErasureExpr to allow for null entries in the
conformance mappings, when some of the conformance is trivial. IRgen
couldn't handle multi-protocol existential types anyway, so this
change has no impact there (yet).


Swift SVN r2212
2012-06-20 15:38:46 +00:00
Doug Gregor
0741dcec2b Introduce ArchetypeSubscriptExpr to model subscripting of a value of
archetype type.


Swift SVN r2209
2012-06-20 00:27:28 +00:00
Doug Gregor
f847fe4a22 Introduce basic support for type-checking the definitions of generic
functions. This involves a few steps:

  - When assigning archetypes to type parameters, also walk all of the
  protocols to which the type parameter conforms and assign archetypes
  to each of the associated types.
  - When performing name lookup into an archetype, look into all of
  the protocols to which it conforms. If we find something, it can be
  referenced via the new ArchetypeMemberRefExpr.
  - When type-checking ArchetypeMemberRefExpr, substitute the values
  of the various associated types into the type of the member, so the
  resulting expression involves the archetypes for the enclosing
  generic method.

The rest of the type checking essentially follows from the fact that
archetypes are unique types which (therefore) have no behavior beyond
what is provided via the protocols they conform to. However, there is
still much work to do to ensure that we get the archetypes set up
correctly.



Swift SVN r2201
2012-06-19 21:16:14 +00:00
Eli Friedman
62a313977c Fix a silly copy-paste mistake.
Swift SVN r2196
2012-06-18 21:52:44 +00:00
Doug Gregor
265292805e Introduce ExistentialSubscriptExpr, which describes subscript
operations into an existential type.


Swift SVN r2194
2012-06-18 17:45:57 +00:00
Eli Friedman
032d9d3538 Default construction for classes. <rdar://problem/11619111>.
Swift SVN r2172
2012-06-08 00:31:29 +00:00
Eli Friedman
e5b4b924a1 More work on constructors. Basic testcases with "constructor" declarations appear to be working, although there's probably more work to be done. (Both old-style and new-style constructors work for the moment.)
Swift SVN r2163
2012-06-07 01:57:57 +00:00
John McCall
30f5e36dbc Semantic analysis and AST support for postfix operators.
Also prevent us from including unary operators in the
lookup results for operators written binary-style and
vice-versa.

Swift SVN r2162
2012-06-07 01:00:08 +00:00
Doug Gregor
3c2fb97bdf Introduce TypeBase::isExistentialType(), to determine whether a given
type is either a protocol type or a protocol composition type. The
long form of this query returns the minimal set of protocol
declarations required by that existential type.

Use the new isExistentialType() everywhere that we previously checked
just for ProtocolType, implementing the appropriate rules. Among other
things, this includes:
  - Type coercion
  - Subtyping relationship
  - Checking of explicit protocol conformance
  - Member name lookup

Note the FIXME for IR generation; we need to decide how we want to
encode the witnesses for the different protocols.

This is most of <rdar://problem/11548207>.


Swift SVN r2086
2012-05-31 00:26:13 +00:00
Eli Friedman
0c24d526af Add rules to verifier for CoerceExpr.
Swift SVN r2072
2012-05-30 18:23:14 +00:00
Eli Friedman
6232341e48 Revert r2068. The AST is still wrong with that fix; it only suppresses the crash.
Swift SVN r2071
2012-05-30 18:11:24 +00:00
Chris Lattner
151e02046f fix the sema crash in rdar://11546285, which happens when CoerceExpr had an
unresolvable subexpression on the first pass.  There is still a irgen crash 
on the same testcase.


Swift SVN r2070
2012-05-30 17:14:42 +00:00