Commit Graph

28404 Commits

Author SHA1 Message Date
Doug Gregor
ba56d2c0b1 Implement support for lookup of members of the current
oneof/struct/protocol within a static method. The lookup is performed
on the metatype (as one would get when using qualified syntax
Type.member). Add tests to verify that this provides proper
overloading behavior.

As a drive-by, actually set the type of the implicit 'this' variable
during name binding for a non-static method.



Swift SVN r1394
2012-04-11 18:22:53 +00:00
Doug Gregor
13aa703185 Explicitly define a move constructor for SemaCoerce::CoerceDiagnostic,
for compilers that don't implement the rules for implicitly defining
one (e.g., Xcode 4.3 Clang).


Swift SVN r1392
2012-04-11 16:58:44 +00:00
Doug Gregor
7e9b7da0ca Remove the general diagnostic-suppression mechanism. Instead,
introduce a simple suppression mechanism into the type-coercion code,
which is the only place we should need it.


Swift SVN r1388
2012-04-11 14:31:40 +00:00
Eli Friedman
361481835c Introduce a notion of module scope declarations; use it where appropriate instead of checking for a local declcontext.
Swift SVN r1380
2012-04-11 02:52:40 +00:00
Ted Kremenek
352453a53b Revert "Fix a bunch of "has virtual functions but non-virtual destructor" warnings"
Swift SVN r1376
2012-04-11 00:02:16 +00:00
Ted Kremenek
8a61ea1fd0 Fix a bunch of "has virtual functions but non-virtual destructor" warnings
Swift SVN r1373
2012-04-10 23:53:46 +00:00
Doug Gregor
ee0a2d2184 Robustify the lookup of members within a metaclass ever so slightly,
by not allowing name lookup to return find struct or tuple members
(which make swift crash).


Swift SVN r1370
2012-04-10 23:34:27 +00:00
Doug Gregor
a3c34c5dbd Introduce an AST node (OverloadedMemberRefExpr) that represents dot
syntax when name lookup finds multiple candidates. Overload resolution
is then used to select the best candidate and map the overloaded
member reference expression down to DotSyntaxCallExpr or
DotSyntaxBaseIgnoredExpr, as appropriate.

This implements part of <rdar://problem/11071641>, so that simple
overload resolution works, but there is still a bit of cleanup to do.



Swift SVN r1366
2012-04-10 22:52:41 +00:00
Eli Friedman
6348a5a372 A bit of minor hacking to get print("hello") working.
Swift SVN r1355
2012-04-10 02:06:33 +00:00
Eli Friedman
bb597c7a37 Minor cleanup.
Swift SVN r1354
2012-04-10 01:47:45 +00:00
Chris Lattner
5650d08ddf implement parsing, AST, and sema support for simple strings,
no irgen yet.


Swift SVN r1351
2012-04-10 01:25:51 +00:00
Chris Lattner
65b400e30d introduce a new "Builtin.RawPointer" type, which corresponds to LLVM's "i8*" type,
and is just an unmanaged pointer.  Also, introduce a basic swift.string type.

This is progress towards rdar://10923403 and strings.  Review welcome.



Swift SVN r1349
2012-04-10 00:52:52 +00:00
Doug Gregor
c24d6ec8c4 Factor OverloadSetRefExpr into an abstract base class covering the
notion of a reference to a set of declarations. Introduce one derived
class, OverloadedDeclRefExpr, which covers the only case we currently
handle for overload resolution [*]: a direct (unqualified) reference
to an overloaded set of entities. Future subclasses should handle,
e.g., overloaded member references such as a.b or a.b.c.

[*] Ugly hacks for static methods notwithstanding


Swift SVN r1345
2012-04-09 17:16:11 +00:00
Doug Gregor
6379980cea Pull the lvalue-to-rvalue conversion into the type coercion
logic. This eliminates spurious diagnostics when attempting to coerce
(for overload resolution) between lvalues and rvalues. Also, improve
error recovery and diagnostics when dealing with an incorrect '&' in
the source.


Swift SVN r1344
2012-04-09 15:41:45 +00:00
Chris Lattner
fbfb76a515 rename 'plus' methods to 'static' methods, resolving:
<rdar://problem/10718220> Need a better name than 'plus' for "static" functions



Swift SVN r1340
2012-04-06 17:50:43 +00:00
John McCall
72c423fee4 Fix a bug where we were failing to mark the variable associated with a heap l-value
as heap, and add a test case to verify that we release the owner of the reference.

Swift SVN r1339
2012-04-06 07:07:34 +00:00
Doug Gregor
2a2059db45 Provide a more specialized diagnostic (+ tests) when coercion fails
to resolve an overloaded reference that is not called.


Swift SVN r1335
2012-04-05 21:15:43 +00:00
Doug Gregor
0f3584acd6 Downgrade integer overflow diagnostic to a warning, and don't let it
have any effect on overload resolution.


Swift SVN r1329
2012-04-05 19:59:14 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Eli Friedman
22b7cd05f5 Some minor incremental improvements for module import. Allow explicitly importing Builtin, and implicitly import swift for any module which doesn't explicitly import Builtin or swift. Fixes <rdar://problem/11185519>.
Swift SVN r1323
2012-04-04 21:56:40 +00:00
Doug Gregor
5cf0a09e1a Allow type coercion from one function type to another function type,
so long as the input and result types are equivalent modulo renaming
of labels. This conversion is a no-op.


Swift SVN r1318
2012-04-03 17:51:41 +00:00
Doug Gregor
9c4f9b3cd4 Remove some uninteresting FIXMEs in the type-coercion code
Swift SVN r1317
2012-04-03 14:59:19 +00:00
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