Commit Graph

776 Commits

Author SHA1 Message Date
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
Eli Friedman
e63a471347 Fix value name-binding so it correctly performs member lookup for expressions which aren't inside a member function.
Swift SVN r2004
2012-05-25 23:42:40 +00:00
Eli Friedman
6abecd43cb Minor cleanup.
Swift SVN r2003
2012-05-25 22:38:22 +00:00
Eli Friedman
95838dca5d Move the SequenceExpr transformation from the expression pre-check into the main expression type-checking visitor.
Swift SVN r2002
2012-05-25 22:27:50 +00:00
Eli Friedman
2947962120 Fix getLoc() for DotSyntaxCallExpr.
Swift SVN r1999
2012-05-25 21:22:41 +00:00
Doug Gregor
0062c84351 Introduce ExistentialMemberRefExpr for references to the members of
values of existential type, e.g.,

  var x : Printable
  x.print()

Existential member references reify the type of the implicit object
argument (implicitly, because we have no way of expressing this in the
type system), and replace the types of any other archetypes
with existential types that (don't, but will eventually) conform to
the protocols to which the archetypes conform.



Swift SVN r1963
2012-05-23 23:06:34 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
c68c9da1b6 Introduce ThisApplyExpr, an ApplyExpr meant for the various forms of
application expressions that provide a 'this' parameter to a
method. There will eventually be more than just DotSyntaxCallExpr, to
capture the other syntactic (and implicit) forms.


Swift SVN r1924
2012-05-22 00:25:40 +00:00
Doug Gregor
a9906ad38f Introduce support for implicit user-defined conversions.
A user-defined conversion function is an instance method that accepts
an empty tuple and returns a value of the type we're converting to,
has the [conversion] attribute, and is named __conversion. The last of
these restrictions is a temporary hack to work around our inability to
perform a lookup across all extensions for "every function with the
conversion attribute", and shouldn't last too long.

As in C++, we only get one user-defined conversion function. Unlike in
C++, a constructor is not (and cannot) be a conversion function.

Introduce NSString <-> String conversion functions, but leave the
runtime implementations as stubs for Dave to fill in.



Swift SVN r1921
2012-05-21 23:36:16 +00:00
Eli Friedman
6e69e27975 Kill ScalarToTupleExpr, which is no longer in use.
Swift SVN r1881
2012-05-17 01:50:48 +00:00
Eli Friedman
d4750d9014 Finish off the semantic analysis of vararg tuples.
Swift SVN r1880
2012-05-17 01:44:27 +00:00
Eli Friedman
7614b53e9f Semantic analysis, part 1b.
Swift SVN r1878
2012-05-17 00:58:53 +00:00
Eli Friedman
33f20a14e0 Add NewReferenceExpr, for allocating class objects.
Swift SVN r1867
2012-05-16 01:36:03 +00:00
Doug Gregor
056ba286eb Implement subtyping rules that allow one to convert a function type to
another function type, so long as the source is a subtype of the
target. The subtyping relation is fairly obvious, allowing parameter
renaming, qualification conversions for lvalue types, and
protocol-conformance conversions (at the top level of function
types). It is a strict subset of the allowed type coercions.

The representation of FunctionConversionExpr is temporary. It will
need to account for the capture of the source of the conversion in the
trivial-trivial case.



Swift SVN r1839
2012-05-14 19:10:22 +00:00
Doug Gregor
59db25658a Ban the use of SuperConversionExpr to produce lvalues, since that is,
in general, not sound. For the limited cases where we did use this
expression kind on lvalues (member access or instance method
invocations on a superprotocol), leave the conversion to the client of
their respective AST nodes (MemberRefExpr, DotSyntaxCallExpr). We may
decide to enrich these ASTs in the future with more information about
the conversion path, but it's not clear that it's actually useful
information for, e.g., IRgen.


Swift SVN r1830
2012-05-14 15:38:27 +00:00
Eli Friedman
2a78055566 Second attempt at <rdar://problem/11228914>.
Swift SVN r1820
2012-05-12 00:49:12 +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
3e7b52d025 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.



Swift SVN r1797
2012-05-10 18:55:30 +00:00
Doug Gregor
88b214d020 Revert r1792; it's missing a file :(
Swift SVN r1795
2012-05-10 17:13:44 +00:00
Doug Gregor
f4f2f9f570 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.


Swift SVN r1794
2012-05-10 16:15:34 +00:00
Chris Lattner
2d99b7cca0 switch LiteralExpr::classof to a range-based check, as suggested by Doug.
Swift SVN r1756
2012-05-05 22:43:21 +00:00
Eli Friedman
f75e305a20 Add ScalarToTupleExpr to represent an implicit conversion from a scalar to a tuple, with or without default arguments. Make Sema and IRGen work with them.
I'm not completely sure this is the representation we want, but it isn't much code to rip out if we decide to represent it some other way.

While I'm in the area, also fix a case where tuple->tuple conversion wasn't working.



Swift SVN r1748
2012-05-05 00:50:06 +00:00