Commit Graph

443 Commits

Author SHA1 Message Date
Joe Groff
f40dfce918 IRGen: Implement SuperConstructorRefCallExprs.
Recognize super.constructor calls in IRGen and generate them as calls to the superclass initializing constructor. Note that super.constructor code still won't execute just yet because classic IRGen doesn't generate initializing constructors.

Swift SVN r3859
2013-01-24 21:58:36 +00:00
Joe Groff
e6d3c3e00c Parser: Parse 'super' expressions.
Set up AST nodes for 'super.<identifier>', 'super.constructor', and 'super[<expr>]' expressions, and implement parsing for them without any sema or backend support.

Swift SVN r3847
2013-01-23 21:24:28 +00:00
Doug Gregor
59ab9d1954 Split superclass-to-archetype downcasts into their own expression node.
Swift SVN r3537
2012-12-18 23:48:19 +00:00
Doug Gregor
96583a726b Introduce ArchetypeToSuperExpr for implicit archetype-to-superclass conversions.
The IR generation for this conversion is different from
derived-to-base conversions, because converting from an archetype to
its superclass type means projecting the buffer and then performing
the conversion.


Swift SVN r3462
2012-12-13 00:16:05 +00:00
Doug Gregor
f3857df469 Implement an AST pretty-printer for declarations, under -print-ast.
Swift SVN r3431
2012-12-10 23:21:49 +00:00
Joe Groff
96bba4e567 AST: Dump captures in AST dump for CapturingExpr.
Swift SVN r3356
2012-12-05 00:18:23 +00:00
Doug Gregor
dc7dcc7fc5 Implement explicit (unchecked!) downcasting for class types.
This introduces support for the syntax

  Derived(baseObj)

to downcast from a class type to one of its subclasses. This still
needs more language design and implementation work, including:
  - This overloads the X(y) syntax again, which already means either
  "coerce y to type X, performing implicit conversions if necessary"
  or "construct a value of type X from y". It's no actually ambiguous,
  because the first case won't apply for downcasts and the second case
  is limited to value types, but it makes me wonder whether we want a
  different syntax for the first case.

  - We need this to be a checked cast, but don't have the runtime
    infrastructure to do so yet. I've left this as a FIXME.

However, the Objective-C importer is fairly useless because everything
that creates an object returns an "id", "id" maps to "NSObject", and
then the type system doesn't let you get from NSObject back to the
type you care about. So, this lets you explicitly do the cast.



Swift SVN r3279
2012-11-28 16:59:27 +00:00
Doug Gregor
b632ef6ba0 Introduce an abstract ExplicitCastExpr, for explicit type casts.
No functionality change: the only subclass is CoerceExpr, for cases
where the user has forced an expression to a given type, e.g., Int32(17).


Swift SVN r3278
2012-11-28 15:44:14 +00:00
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
Eli Friedman
b62d47a2e5 Rewrite the way we build capture list so we don't miss capturing "this". <rdar://problem/12583581>.
Swift SVN r3093
2012-10-30 22:33:18 +00:00
John McCall
c8f53e3535 Add a MetatypeConversionExpr for doing derived-to-base
conversions on metatypes;  at runtime it has no effect,
since those conversions are always trivial.  Fix a number
of bugs involving the conversion of metatypes, in both
typecheckers.

Swift SVN r3055
2012-10-25 10:21:44 +00:00
John McCall
2f8f05615e Rename TypeOfExpr / TypeOfInst to MetatypeExpr / MetatypeInst.
Introduce a '.metatype' form in the syntax and do some basic
type-checking that I probably haven't done right.  Change
IR-generation for that and GetMetatypeExpr to use code that
actually honors the dynamic type of an expression.

Swift SVN r3053
2012-10-24 07:54:23 +00:00
Chris Lattner
db2beefaa2 Start implementing support for varargs tuple shuffles (thus, support
for varargs).  This is incomplete, but we can already lower this:

  var va2 : (Int...) = (1,2,3)

to this CFG:

  %15 = tuple (%4, %9, %14)
  %16 = alloc_array element type=Int, 3
  %17 = tupleelement %16, 1
  %18 = tupleelement %15, 0
  %19 = store %18 -> %17 [initialization]
  %20 = index_lvalue %17, 1
  %21 = tupleelement %15, 1
  %22 = store %21 -> %20 [initialization]
  %23 = index_lvalue %17, 2
  %24 = tupleelement %15, 2
  %25 = store %24 -> %23 [initialization]

Next, we need to call the injection function to turn an initialized heap 
allocation into Slice<T>... which requires a bunch of generic support.

To get this far, this patch:
- Introduces index_lvalue for indexing over array elements (striding lvalues)
- Introduces alloc_array.
- Renames RequalifyInst to TypeConversionInst and generalizes it to handle
  FunctionConversionExpr.



Swift SVN r2988
2012-10-12 00:40:38 +00:00
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
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
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
6781f56cfd Start of support for class inheritance.
Swift SVN r2598
2012-08-09 21:56:05 +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
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
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
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
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
5b0b5494a2 Update AST dumping for recent change to FuncDecl representation.
Swift SVN r2442
2012-07-25 01:42:11 +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
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
e592e07f2e Compute full SourceRanges for Decls.
Swift SVN r2376
2012-07-19 22:27:13 +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
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
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
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
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
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