Commit Graph

3502 Commits

Author SHA1 Message Date
Doug Gregor
e27d65f199 Introduce a "parent' context into oneof, struct, and class types. The
parent context encodes the generic arguments for outer generic types,
so that X<Int>.Nested and X<Float>.Nested are distinct types.


Swift SVN r2502
2012-08-01 23:20:36 +00:00
Doug Gregor
c1229e72a8 Give the methods, constructors, and destructors of a nested type a
polymorphic type when that type is nested within a generic type. The
type-checker still isn't ready to use these declarations in a sane way.



Swift SVN r2501
2012-08-01 21:16:06 +00:00
Ted Kremenek
81169fc0aa Reduce 'threading' of show colors logic through AST printer API, computing it in one central place.
Swift SVN r2499
2012-07-31 05:10:49 +00:00
Ted Kremenek
c03dce396b Hack up some initial support for coloring -ast-dump to make this easier to read.
Swift SVN r2498
2012-07-31 01:00:55 +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
f4f176dd27 Give the static methods of a generic type polymorphic type,
always. One step closer to representational sanity.


Swift SVN r2477
2012-07-27 07:05:03 +00:00
Doug Gregor
ea4cb398ed Destructors of generic class types have polymorphic function
type. This has remarkably little effect on type checking, because the
destructors themselves are never referenced by the AST after initially
type-checking them.


Swift SVN r2474
2012-07-27 06:38:32 +00:00
Doug Gregor
f4ced2028d Make the constructors of generic types polymorphic function types,
including the weird implicit one-of element declarations that end up in struct
types. Teach overload resolution and the type-checking of
ConstructorRefExprs how to specialize these polymorphic function types.


Swift SVN r2473
2012-07-27 06:33:04 +00:00
Doug Gregor
17422d5bee The type of an instance method in a generic class is actually a
polymorphic function type. For example, given

  struct X<T> {
    func f(a : T) -> Int { }
  }

The type of X.f is

  <T> (this : [byref] X<T>) -> (a : T) -> Int

If we have a call to f, e.g.,

  var xi : X<Int>
  xi.f(5)

it will be represented as X.f specialized to type

  (this : [byref] X<Int>) -> (a : Int) -> Int

and then called with 'xi' (DotSyntaxCallExpr) and finally 5
(ApplyExpr). The actual deduction of arguments is not as clean as I'd
like, generic functions of generic classes are unsupported, static
functions are broken, and constructors/destructors are broken. Fixes
for those cases will follow.



Swift SVN r2470
2012-07-27 00:24:32 +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
Doug Gregor
72e69d5420 Teach each archetype type to keep track of its nested types, so that
type substitution for a nested type reference (Foo.Bar.Wibble) whose
substituted parent reference (Foo.Bar) yields an archetype can simply
look for the appropriate nested type in the archetype. 

This allows us to eliminate the hideous ASTContext::AssociatedTypeMap
and simply the archetype builder.


Swift SVN r2438
2012-07-24 23:52:04 +00:00
Eli Friedman
c6901f6a6c Initial parsing/AST for generic constructors.
Swift SVN r2387
2012-07-20 23:07:40 +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
Doug Gregor
c5a1edd1b8 Revert r2372, which is breaking some tests.
Swift SVN r2375
2012-07-19 21:32:22 +00:00
Eli Friedman
fca009f280 TypeLoc-related cleanup: add FIXMEs to the places in validateType that need to
compute sub-TypeLocs, and fix the places that don't need them not to reuse the
parent TypeLoc.



Swift SVN r2374
2012-07-19 04:01:59 +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
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
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
Eli Friedman
5ff5b40159 Misc pieces of Sema for destructors.
Swift SVN r2350
2012-07-12 02:23:49 +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
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
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
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
Eli Friedman
4555345440 Add basic parser/AST support for defining generic types.
Swift SVN r2292
2012-07-03 01:34:58 +00:00
Doug Gregor
31d1f40cb8 The type of the 'this' parameter for a protocol method is [byref]
This, not [byref] ProtocolType. Fix this in semantic analysis, and
update IR generation accordingly.


Swift SVN r2217
2012-06-20 20:47:03 +00:00
Doug Gregor
bf71eeb26d Include the generic parameter list of a function declaration in the
FuncDecl AST, and use it for local name lookup.


Swift SVN r2198
2012-06-18 23:49:40 +00:00
Eli Friedman
2eb6261838 Don't try to capture TypeDecls in local functions.
Swift SVN r2180
2012-06-08 23:51:02 +00:00
Eli Friedman
2880b0afda Address Doug's review comments on constructors.
Swift SVN r2176
2012-06-08 19:59:55 +00:00
Eli Friedman
f1ffa870a3 A few adjustments to AST/Sema for ConstructorDecls, and starting IRGen.
Swift SVN r2160
2012-06-06 00:53:44 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Doug Gregor
9abd2340bc Allow an 'inheritance' clause on typealiases, specifying what
protocols the underlying type of the type alias shall conform to. This
isn't super-motivating by itself (one could extend the underying type
instead), but serves as documentation, makes typealiases provide the
same syntax as other nominal types in this regard, and will also be
used to specify requirements on associated types.


Swift SVN r2133
2012-06-04 16:15:47 +00:00
Doug Gregor
d41e39a363 Sink the 'inherited' members for the various nominal types down into
TypeDecl; TypeAliasDecl will get this ability soon.


Swift SVN r2132
2012-06-04 15:56:29 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +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
Doug Gregor
74436a3120 Introduce the implicit 'This' type into protocols, which refers to the
type T that conforms to the given protocol. 'This' is modeled simply
as an associated type.



Swift SVN r1953
2012-05-23 14:45:55 +00:00
Eli Friedman
5e206bc10f Rename DistinctTypeDecl to NominalTypeDecl.
Swift SVN r1882
2012-05-17 01:54:15 +00:00
Doug Gregor
245d2a46f2 Parse an 'inheritance' clause on extensions, oneofs, structs, and
classes, with the same syntax as we have on protocols. This
inheritance specifies explicit conformance to a protocol.

Later, we can allow a class definition to have a single class type
within this list, when we introduce class inheritance.



Swift SVN r1862
2012-05-15 23:39:19 +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
79c3276b07 AST representation for ClassDecls.
Swift SVN r1858
2012-05-15 21:53:38 +00:00
Eli Friedman
6f045aad2f Throw the switch to use "var" syntax to declare members of structs. This also means we no longer build an implicit extension for every struct decl. Everything seems to be working, but please yell if this breaks anything.
Swift SVN r1851
2012-05-15 03:27:13 +00:00
Doug Gregor
ec674b3bce Make the implicit 'this' argument [byref] rather than
[byref(implicit)], and rely on type coercion for the implicit object
argument to deal with the implicitness. This is one half of
<rdar://problem/11215969>. 

The other half of <rdar://problem/11215969> requires us to invent some
syntax to allow increment/decrement/assignment to operate on lvalues
without requiring one to write '&'. There are two distinct ideas
gaining traction here:

  - Adding an [assignment] attribute to these operators, which tells
    us both that use of the operators is a statement (not an
    expression) and that the byref argument (either on the left, or
    the only argument).

  - Allowing operators to be written as member functions, so that they
    get the same treatment as "a.b".

The former seems like the better option.



Swift SVN r1819
2012-05-12 00:19:22 +00:00
Doug Gregor
a49d6c88c8 Introduce a conversion-to-supertype expression to capture conversions
from a protocol to a protocol it inherits. This is a far simpler
operation that the general type-erasure expression, so generate this
AST when we can.


Swift SVN r1813
2012-05-11 17:25:14 +00:00
Eli Friedman
01a18f6c7a Use VarDecls to represent struct members, and MemberRefExprs to represent member access in structs. Eliminate the horrible hack which was LookThroughOneOfExpr.
Swift SVN r1808
2012-05-11 03:08:15 +00:00
Doug Gregor
70bfc235b8 Implement protocol inheritance, e.g.,
protocol Document { var title : String }
  protocol Versioning { func bumpVersion() }
  protocol VersionedDocument : Document, Versioning { }

This commit covers the basic functionality of protocol inheritance, including:
  - Parsing & AST representation
  - Conforming to a protocol also requires conforming to its inherited
  protocols
  - Member lookup into a protocol also looks into its inherited
  protocols (results are aggregated; there is no name hiding)
  - Teach ErasureExpr to maintain lvalueness, so we don't end up
  performing a silly load/erase/materialize dance when accessing
  members from an inherited protocol.




Swift SVN r1804
2012-05-11 00:00:50 +00:00