Commit Graph

12848 Commits

Author SHA1 Message Date
John McCall
04a10f08bb Fix the mangling of generic types, change the mangling of
non-generic nominal types to encode the type kind, and add
substitutions for certain very common standard types while
we're at it.  Sorry, Howard.

Swift SVN r2455
2012-07-25 22:42:13 +00:00
John McCall
f7aca3f7fb Progress towards generic types.
Swift SVN r2454
2012-07-25 22:42:07 +00:00
Eli Friedman
83a29c9cff Fix a small FIXME related to static methods in witness tables.
Swift SVN r2451
2012-07-25 21:27:59 +00:00
Doug Gregor
64130a82ad When checking protocol conformance for an operator requirement,
perform global operator lookup and match those operators. We can now
type-check a proper 'min' function that uses '<'.


Swift SVN r2449
2012-07-25 21:10:48 +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
2834352a73 Fix a bug emitting the definition of a generic constructor on a class.
NewReferenceExprs referencing generic constructors still don't work;
I'm having trouble following how the code is supposed to work.



Swift SVN r2441
2012-07-25 01:23: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
235255cdc8 A couple minor tweaks to my last commit.
Swift SVN r2439
2012-07-24 23:53:25 +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
28d9744843 Fix mangling for local functions in a getter/setter.
Swift SVN r2435
2012-07-24 21:01:53 +00:00
Eli Friedman
58247ec603 Fix IRGen bug with local functions. <rdar://problem/11935459>.
Swift SVN r2434
2012-07-24 20:47:13 +00:00
John McCall
1be602a010 The return type passed to the call emitter needs to be the substituted
return type, not the original.  We were getting away with it
as long as we had a final address, but we won't always have
a final address, as in this test case, where we're ignoring the
result.

Swift SVN r2421
2012-07-24 02:38:57 +00:00
Eli Friedman
fec6ff2d07 Disable performStoreOnlyObjectElimination because it's causing leaks (and the leaks are blocking Howard's work).
Swift SVN r2412
2012-07-23 21:21:27 +00:00
Doug Gregor
b405157742 Fix comment
Swift SVN r2406
2012-07-23 15:42:35 +00:00
John McCall
7426712f74 Split out the cases for BoundGenericType, but keep punting
for now.

Swift SVN r2404
2012-07-23 07:35:29 +00:00
John McCall
ed38caaa04 Support generic return types, as long as they don't differ
by abstraction from the concrete return type.

This basically gets generic calls working totally as long
as there's no remapping required.

Swift SVN r2402
2012-07-23 07:06:28 +00:00
John McCall
555aa807b6 Dig into the formal type of a generic callee for the
call sites, since that's what we want to target for
substitution and witness-argument emission.

Swift SVN r2401
2012-07-22 10:05:24 +00:00
John McCall
a9b9c9c7f0 Collect CallSites in the CalleeSource. Closing in
actually getting a generic call to work.

Swift SVN r2400
2012-07-22 10:05:18 +00:00
John McCall
f16898b0e4 Extract the rvalue-under-substitutions code out into its own file.
Swift SVN r2399
2012-07-22 08:00:16 +00:00
John McCall
536ac7b01e Restructure differsByAbstraction to use SubstTypeVisitor.
Swift SVN r2398
2012-07-22 08:00:11 +00:00
John McCall
83505931f3 Basic argument passing as long as re-mapping isn't required.
Swift SVN r2397
2012-07-22 08:00:06 +00:00
John McCall
baae407f27 New kind of visitor for visiting substituted types.
Swift SVN r2396
2012-07-22 07:59:57 +00:00
John McCall
f254c4abb4 Add a little checker for whether something is a dependent type.
Swift SVN r2395
2012-07-22 07:59:52 +00:00
John McCall
b2b4a2a614 Add IRGen's inevitable specialization of the TypeVisitor class.
Swift SVN r2393
2012-07-22 07:59:40 +00:00
John McCall
da8c01938e Reorg, monster comment.
Swift SVN r2391
2012-07-22 07:59:22 +00:00
John McCall
3950a6af41 Generic calls status code dump activate!
Swift SVN r2386
2012-07-20 21:59:14 +00:00
John McCall
e67466d164 Reorganize how we collect substitutions for callees,
and convert the code that was drilling into function
expressions into an ASTVisitor.

Swift SVN r2385
2012-07-20 21:59:09 +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
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
29b3994cca Add a new entry point for allocating classes. This API probably isn't really
right, but we need something in the meantime to make the optimizer understand
that there could be non-trivial destructors involved.



Swift SVN r2366
2012-07-17 23:25:02 +00:00
Eli Friedman
c9cb594eb3 IRGen for destructors. (This code is likely to change a lot once we design classes properly, but it should be a decent start.)
Swift SVN r2365
2012-07-17 22:41:23 +00:00
John McCall
3b30fbfc36 Support multiple protocols on a generic parameter.
Swift SVN r2363
2012-07-17 06:20:38 +00:00
John McCall
b1d5c33e19 Support for trivial protocol compositon types.
Swift SVN r2362
2012-07-17 06:20:29 +00:00
Eli Friedman
77751012d2 Switch over constructors so that they return a value instead of being a
method to initialize the members.  This doesn't matter so much
for structs (the generated IR is essentially equivalent except for
small structs), but on classes, we don't want to make "new X" generate
code that knows about metadata/destructors/etc for the class X.

Also, make sure classes always have a constructor.  (We haven't really
discussed the rules for implicitly declared constructors, so for now,
the rule is just "generate an implicit constructor if there is no
explicit constructor".  We'll want to revisit this when we actually
design object construction.)



Swift SVN r2361
2012-07-17 00:32:28 +00:00
John McCall
7d8231e22a Test basic functionality for protocol composition types.
Swift SVN r2357
2012-07-14 06:51:07 +00:00
John McCall
7a9a8e92ea Another big drop of code to support protocol composition
types.  Mostly untested.  As part of this, I changed the
order in which we emit erasures:  now we evaluate the
operand in-place and only then write the protocols in.
This makes it slightly more likely that a generic
optimization will be able to devirtualize.

Swift SVN r2356
2012-07-14 06:51:01 +00:00
John McCall
b86d764397 Add some basic structures for protocol composition types.
Swift SVN r2355
2012-07-14 06:50:53 +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
3d85d78651 Add a missing call to Initialization::markInitialized in GenInit. <rdar://problem/11851415>.
Swift SVN r2345
2012-07-11 21:45:21 +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
Doug Gregor
2da3c6c251 Virtualize TypeInfo::getSizeAndAlignment() and teach it to query the
value witness for archetypes. Builtin alignof/sizeof now work properly
for archetypes.


Swift SVN r2331
2012-07-10 19:08:14 +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
728f948a79 Make Builtin.load, Builtin.init, and Builtin.assign generic functions.
This is most of what is necessary to implement UnsafePointer<T>; we also
will need Builtin.sizeof eventually.



Swift SVN r2325
2012-07-09 23:55:03 +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
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
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
Eli Friedman
ff6f882362 Change the convertFromStringLiteral convention to be a bit more efficient:
add an alternate entry-point called convertFromASCIIStringLiteral which is called for
string literals which contain only ASCII codepoints, and add an optional byteLength
argument for the conversion.  <rdar://problem/11764780>.

I've also tentatively changed swift.String to use the new convention; Dave,
please review.



Swift SVN r2290
2012-07-02 23:00:29 +00:00