Commit Graph

28382 Commits

Author SHA1 Message Date
Doug Gregor
c86b40f8bb Implement type coercion of an overloaded declaration reference that is
not being called directly. We previously had a simplistic
implementation that required exact type matches; loosen this to simply
require coercion, as well as diagnosing ambiguities/lack of suitable
candidates.


Swift SVN r1316
2012-04-03 14:44:51 +00:00
Doug Gregor
2bf38b5713 Fix an issue where we were failing to type-check calls to
single-parameter functions with a literal argument. The argument
therefore had unstructured dependent type, and there was no reason to
reject it in the first place.


Swift SVN r1313
2012-04-03 00:04:24 +00:00
Eli Friedman
94244131f7 Remove ElementRefDecl and DeclVarName. Add the replacement, PatternBindingDecl. Use proper pattern parsing for variable declarations. Uniformly use PatternBindingDecl for variable initialization. Adapt type-checking and IRGen for this new style of variable declaration. <rdar://problem/11124980>.
Swift SVN r1312
2012-04-02 23:49:28 +00:00
Doug Gregor
29b4a21b78 Rename TypeChecker::convertToType() to TypeChecker::coerceToType(), so
that we're slightly-more-consistently using the term 'coerce' to refer
to this process.


Swift SVN r1311
2012-04-02 23:32:12 +00:00
Doug Gregor
79ed496d87 Implement filtering of overload sets based on argument and destination
types. Use this simple overload resolution scheme in both type
checking and type coercion, simplifying both code paths a bit.

There is one significant semantic change here: we allow overload
resolution to operate on (structured) dependent arguments, which
allows for more overload filtering before we come in with the type
coercion hammer. For example, we can now properly type-check

  var x : int32;
  x + 0;



Swift SVN r1310
2012-04-02 23:22:01 +00:00
Doug Gregor
77ec9a62b1 Make more of SemaCoerce's members private
Swift SVN r1309
2012-04-02 21:46:14 +00:00
Doug Gregor
bfe7ff2168 Extend the AST walker that performs type coercion to have two modes:
one that performs the coercion on the AST and produces diagnostics for
any problems, and one that simply determines whether the coercion
would succeed. The former already existed (as
TypeChecker::convertToType), while an approximation of the latter was
already implemented as Expr::getRankOfConversionTo(). Unifying these
code paths addresses several issues:

  - Lots of redundancy in the code for computing these two properties,
    which causes bugs. For example, Expr::getRankOfConversionTo()
    wasn't able to handle literals (!).
  - Determining whether a conversion is possible will need the full
    power of the type checker, e.g., to deal with closures in cases
    like:

      func f(g : (int, int) -> int);
      func h() { f({$1 + 0}); }

    Although this is not handled correctly now.

I have opted not to adopt Clang's ImplicitConversionSequence (or
InitializationSequence) design, which computes a record of the steps
needed to perform the conversion/coercion and later applies those
steps, because we don't need that complexity yet. If we start
introducing more implicit conversions into the language, we'll revisit
this decision.



Swift SVN r1308
2012-04-02 21:43:15 +00:00
Doug Gregor
2c3b36a8b9 Only call applyTypeToLiteral() from within the type-coercion code.
Swift SVN r1302
2012-04-02 20:33:54 +00:00
Doug Gregor
4980219fab Add a "diagnose()" method to SemaCoerce for coercion-related
diagnostics, rather than going directly to the type checker's similar
method.


Swift SVN r1301
2012-04-02 17:53:45 +00:00
Doug Gregor
02b250c821 Actually create ImplicitThisTupleElementExpr expressions when we don't
have the location of the '.'. Prior to this,
ImplicitThisTupleElementExpr was completely unused.


Swift SVN r1300
2012-03-30 21:28:07 +00:00
Doug Gregor
3299d8b176 Eliminate BinaryExpr::getArgTuple(). The argument to a binary
expression will always be a two-element tuple, but it may not always
be a tuple literal. In the near future, it could also be a tuple
shuffle.



Swift SVN r1299
2012-03-30 18:37:02 +00:00
Chris Lattner
cb1d2cacbe implement a new CanType subclass of Type, for use when we known that we have a canonical type.
Unlike Type, it implements equality operators.  It is returned by Type->getCanonicalType().

This adopts it in the minimal places required to get the build to work, it would also be nice
to switch IRGen to canonical types and use it there.


Swift SVN r1298
2012-03-29 20:33:20 +00:00
Doug Gregor
c76edd6643 Remove Expr::setDependentType(); it's not really documenting anything,
and with structured dependent types, many more setType() calls
actually would have to be setDependentType() to be documenting.


Swift SVN r1297
2012-03-29 18:57:18 +00:00
Doug Gregor
5c6b3dfdb1 Use unstructured dependent types in a few more places
Swift SVN r1296
2012-03-29 18:02:15 +00:00
Doug Gregor
e6bb114428 Don't null out the subexpression of a grouping parentheses expression
if there's an error.


Swift SVN r1295
2012-03-29 16:34:01 +00:00
Doug Gregor
f370accf59 Introduce the notion of structured dependent types, such as a tuple
type with one or more elements of dependent type. Previously, an
expression such as (x, 5) would have the (unstructured) dependent
type, limiting our ability to type-check the subexpression 'x'
early. Now, if 'x' has type 'int' (for example), this expression will
now have the type (int, <<unstructured dependent type>>).

Extend coercion of a tuple to tuple type to handle coercion to
(structured) dependent tuple types, coercing element-by-element. This
code is very lightly tested and may still need to be restructured.




Swift SVN r1294
2012-03-29 16:26:04 +00:00
Doug Gregor
4cc616f2be Rename the DependentType class to UnstructuredDependentType, because
this type is only going to cover dependent types for which there is
absolutely no structure. Still no functionality change.


Swift SVN r1292
2012-03-29 14:14:48 +00:00
Doug Gregor
22371781a5 Introduce TypeBase::isDependentType(), and use it rather than checks
against the DependentType class. No functionality change.


Swift SVN r1291
2012-03-29 14:03:57 +00:00
Doug Gregor
f697dfc62c Unbreak CMake build
Swift SVN r1290
2012-03-29 13:55:07 +00:00
Eli Friedman
29f3fca950 First iteration of CaptureAnalysis.
Swift SVN r1284
2012-03-29 00:24:03 +00:00
Doug Gregor
8f8ae8a77c Unbreak CMake build.
Swift SVN r1280
2012-03-28 16:49:40 +00:00
Eli Friedman
cbad8bf2ad Fix crash with "!=" overloads. <rdar://problem/11115904>.
The way that overload resolution works for the testcases in test/statements.swift is still wrong, but that's a different issue.



Swift SVN r1270
2012-03-27 01:55:07 +00:00
Eli Friedman
d2bbf81245 Zap AnonClosureArgExpr.
Swift SVN r1269
2012-03-27 01:03:15 +00:00
Chris Lattner
01dbc43a95 unify code for diagnosing overload sets resolved to no candidates.
Swift SVN r1258
2012-03-25 03:58:53 +00:00
Chris Lattner
f7f5894acf Implement overload set pruning based on whether a call happens in a unary
or binary context.  This allows us to discard binary "-" candidates when in
a unary context.  This is enough to resolve the last ambiguity, implementing
<rdar://problem/11088443> The expression "-1" always has type int



Swift SVN r1257
2012-03-25 03:51:58 +00:00
Chris Lattner
f78a4e0be5 implement a bit of context sensitive overload set resolution, resolving some fixme's
in name-binding and making progress towards 11088443


Swift SVN r1256
2012-03-25 03:28:17 +00:00
Eli Friedman
a940cdd22b Compute capture lists for FuncExprs and ImplicitClosureExprs.
Swift SVN r1254
2012-03-23 22:06:21 +00:00
Chris Lattner
744bf2d970 unify the call handling code into a single visitApplyExpr implementation,
move it out of line.


Swift SVN r1253
2012-03-22 16:53:05 +00:00
Eli Friedman
80b55617ba Start of computing captures for CapturingExprs in the AST; only works for ExplicitClosureExprs so far. Per previous discussion, anything which can be captured goes through the relevant codepath in Parser::actOnIdentifierExpr.
Swift SVN r1251
2012-03-22 02:37:57 +00:00
Eli Friedman
ea17adc3ec Completely switch over IRGen for closures to use the standard prologue/epilogue emission.
Swift SVN r1250
2012-03-22 01:04:05 +00:00
Eli Friedman
61c2a9ea18 Fix error-checking for UnresolvedMemberExpr coercion. Some minor improvements for coercion and lvalues. Converting dependent types still has a lot of issues.
Swift SVN r1249
2012-03-21 05:13:40 +00:00
Eli Friedman
fdc45c7611 Store the VarDecls and Patterns for AnonClosureArgExpr and ExplicitClosureExpr in the AST.
It might be possible to save some memory by breaking the AnonClosureArgExpr linked list during type-checking... not sure if that's worthwhile.



Swift SVN r1248
2012-03-20 21:43:36 +00:00
Eli Friedman
618cfc4b21 Build VarDecls and a Pattern for the paramters for an explicit closure. Not used yet.
Swift SVN r1242
2012-03-20 01:24:52 +00:00
Eli Friedman
d39a7abe36 Implement CapturingExpr. In addition to unifying the hierarchy between FuncExpr and ClosureExpr, this introduces a DeclContext for ClosureExprs. <rdar://problem/11076715>
Swift SVN r1240
2012-03-20 01:08:04 +00:00
John McCall
1a4b945a14 Flag in a ValueDecl whether it's ever been used as an
l-value or a heap l-value, except to immediate convert
it to an r-value or a non-heap l-value.

Swift SVN r1237
2012-03-19 08:28:42 +00:00
John McCall
2fd608ae4d Add basic parsing and type-system support for the byref(heap)
qualifier, making sure that variables end up so-qualified by
default.  Add a RequalifyExpr to capture the act of adding
qualifiers (to form a supertype) to an l-value.

Swift SVN r1236
2012-03-19 06:55:23 +00:00
Chris Lattner
8aafdda9f6 after an epic refactoring fest, finally implement ivar/method lookup in methods, resolving rdar://10682135.
There are still problems in the field of name lookup, but this is progress at least.


Swift SVN r1235
2012-03-19 06:08:57 +00:00
Chris Lattner
388eb650aa move construction of ast for dot syntax out to NameLookup. No functionality change.
Swift SVN r1234
2012-03-19 06:01:09 +00:00
Chris Lattner
ce717d2c7c teach IRGenFunction::emitIgnored to handle expressions of module and metattype type.
Teach Expr::getSemanticsProvidingExpr to look through DotSyntaxBaseIgnoredExpr.
Start generating DotSyntaxBaseIgnoredExpr for all dot syntax exprs where the base is
ignored (e.g. "Builtin.mul_i32"), which preserves a lot more source location information
and is general goodness for the AST.


Swift SVN r1232
2012-03-19 05:33:29 +00:00
Chris Lattner
4e4c1bf417 rename DotSyntaxPlusFuncUseExpr -> DotSyntaxBaseIgnoredExpr
to properly represent its newly generalized role.  It is formed
for things like "swift.print" where swift is a module type and is
evaluated and ignored.


Swift SVN r1230
2012-03-19 05:23:39 +00:00
Chris Lattner
e7cd357065 reimplement TypeChecker::semaUnresolvedDotExpr in terms of the new
MemberLookup class.


Swift SVN r1229
2012-03-19 05:16:19 +00:00
Chris Lattner
92f3d6a431 checkpoint, nothing useful here.
Swift SVN r1228
2012-03-19 05:15:59 +00:00
Chris Lattner
f986dbaf95 Add a new file to handle name lookup tasks, implement a bunch of
stuff that will eventually be centralized "dot" lookup mechanics.


Swift SVN r1227
2012-03-18 01:17:32 +00:00
Chris Lattner
1ecef669b4 elimiante TC member.
Swift SVN r1226
2012-03-18 01:16:17 +00:00
Chris Lattner
1884e4943f refactor some code out of Sema into AST.
Swift SVN r1225
2012-03-17 23:07:00 +00:00
John McCall
1f118dbda6 Basic support for Builtin.ObjectPointer as a completely
opaque type.  Also some rudimentary support for retain/release.

Swift SVN r1214
2012-03-16 09:26:32 +00:00
Eli Friedman
595676abf7 Limit the number of potential getLogicValue() calls for a conditional to 2. Per Chris's comments.
Swift SVN r1208
2012-03-13 21:58:53 +00:00
Chris Lattner
60d9b2a570 intermediate progress on rdar://10682135, nothing particularly useful so far.
Swift SVN r1207
2012-03-11 23:57:09 +00:00
Chris Lattner
0cccfe9299 rename the Walker class to ASTWalker to match ASTVisitor.
Swift SVN r1201
2012-03-11 16:28:50 +00:00
Chris Lattner
636ba08a4d eliminate some manual forwarding that is now redundant.
Swift SVN r1198
2012-03-11 14:56:58 +00:00