Commit Graph

149 Commits

Author SHA1 Message Date
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Sean Callanan
d30b364e24 [PlaygroundTransform] Don't log the results of functions that return ().
The fix for missing logging for += accidentally made us log ALL functions that
return (), not just the ones that happen to touch inout parameters.  That's not
really desirable, and resulted from a missing testcase.

This fixes the problem and adds a testcase.

<rdar://problem/27995558>
2016-08-24 17:43:57 -07:00
Sean Callanan
b80e4c530e [PlaygroundTransform] Instrument mutations of inout vars by class methods.
+= is now a class method, which means the playground transform ignores it.  This
is undesirable, and we have ways to instrument methods that mutate inout
parameters the way += does.  I have just made it so that if we see a method call
and we can't instrument the mutation of the base of the method call, we still
instrument the inout argument if there is one.

Also added a test case.
2016-08-18 12:56:21 -07:00
Doug Gregor
604adff1bd [SE-0111] Capture argument labels directly in CallExpr.
Yet another step on the way to SE-0111, capture the argument labels
(and their locations) directly in CallExpr, rather than depending on
them being part of the tuple argument.
2016-07-25 23:14:41 -07:00
Doug Gregor
fdcf45b497 [AST] Introduce factory methods to create CallExprs.
Introduce several new factory methods to create CallExprs, and hide
the constructor. The primary reason for this refactor is to start
moving clients over to the factory method that takes the call
arguments separately from the argument labels. Internally, it
repackages those arguments into a TupleExpr or ParenExpr (as
appropriate) so the result ASTs are the same. However, this will make
it easier for us to tease out the arguments themselves in the
implementation of SE-0111.
2016-07-25 13:27:35 -07:00
Saleem Abdulrasool
c553628964 Use sizeof for buffer lengths in snprintf
Rather than duplicating the constant value, use the `sizeof` operator to have
the value propogate from the static buffer allocation.  Any standards conforming
implementation of `snprintf` will null-terminate the output unless the buffer is
NULL (a zero-sized buffer is passed to the call).  On Windows, where this is not
the case, the function is named `_snprintf` which ensures that we do not
accidentally end up with the incorrect behaviour.
2016-06-15 17:41:16 -07:00
Doug Gregor
ee85891d11 Revert "[Type checker] Be more rigorous about extracting argument labels from calls."
This reverts commit 3753d779bc. It's
causing some type-inference problems I need to investigate.
2016-06-03 10:21:27 -07:00
Doug Gregor
3753d779bc [Type checker] Be more rigorous about extracting argument labels from calls.
Whenever we have a call, retrieve the argument labels from the
argument structurally and associate them with the callee. We were
previously doing this as a separate AST walk (which was unnecessary),
so fold that into constraint generation for a CallExpr. We were also
allowing weird ASTs to effectively disable this information: tighten
that up and require that CallExprs always have a ParenExpr, TupleExpr,
or (as a temporary hack) a TypeExpr whose representation is a
TupleTypeRepr as their argument prior to type checking. This gives us
a more sane AST to work with, and guarantees that we aren't losing
label information.

From the user perspective, this should be NFC, because it's mostly AST
cleanup and staging.
2016-06-02 17:15:51 -07:00
Sean Callanan
a0fa099f1a [PlaygroundTransform] embed source ranges in data packets before sending them.
<rdar://problem/25043276>
2016-04-15 16:47:11 -07:00
Jordan Rose
377829b3e6 Revert "Change the playground transform instrumenter such that it provides the logging calls direct access to the source locations"
This reverts commit fe3b8993e9.
2016-04-05 14:17:51 -07:00
Enrico Granata
fe3b8993e9 Change the playground transform instrumenter such that it provides the logging calls direct access to the source locations 2016-04-05 14:14:43 -07:00
Michael Gottesman
7361e35bb9 Revert "Putting white spaces in between if/while clauses and braces." 2016-04-01 22:00:25 -07:00
Ge Sen
7dd61bdfa9 [gardening] Put white spaces in between if/while clauses and braces where it is missing.
For instance:

'if (foo){' => 'if (foo) {'
2016-04-02 08:22:23 +08:00
Dmitri Gribenko
a9f8d97d3e Replace 'unsigned int' with 'unsigned'
'unsigned' is more idiomatic in LLVM style.
2016-02-27 16:20:27 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Xi Ge
77b7180f1a Rename CodeCompletionTypeChecking.h to IDETypeChecking.h since it's used by more clients now. NFC 2016-02-04 11:09:21 -08:00
Adrian Prantl
ecd47e0a81 PlaygroundTransform: Use a global TmpNameIndex to avoid having multiple
temporaries with the same name in the same scope.

rdar://problem/24318554
2016-01-27 14:12:15 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Arsen Gasparyan
be738abb7c Fix else code style 2015-12-22 11:13:26 +03:00
Sean Callanan
8a0b1a7244 Updated PlaygroundTransform to call a function after print() is called.
We no longer try to change the print() statement.  I updated the tests, too.

<rdar://problem/22079705> ER: PlaygroundTransform support for print() API


Swift SVN r30891
2015-07-31 23:39:47 +00:00
Sean Callanan
1d9cdbbfeb PlaygroundTransform now forwards print() arguments to $builtin_print() exactly.
We put the argument to be printed (so not the stream or the appendNewline:) into
a temporary variable to avoid type-checking nastiness.  I also made the test
case considerably more comprehensive.

<rdar://problem/21905513> [Swift submission] playgrounds need to handle print with weird arguments


Swift SVN r30457
2015-07-21 18:30:51 +00:00
Chris Lattner
59f912ac3c Speculatively change PlaygroundTransform to stop using FreeTypeVariableBinding::GenericParameters,
there are two possible situations here:

1) This code never runs on invalid code, in which case this argument does nothing.
2) This code does run on invalid code, and the type checker would crash as 
   TypeCheckExpr attempted to apply the solution.

This causes no regressions on the playground logger testsuite, but I'm not really confident
in this so I'll chat with Sean.



Swift SVN r30182
2015-07-14 00:52:59 +00:00
Chris Lattner
3edd82837f remove the isDiscarded bool from TypeChecker::solveForExpression
and getTypeOfExpressionWithoutApplying and change typeCheckExpression
to take it as a single-entry OptionSet, in prep for getting other 
options.  NFC.


Swift SVN r30121
2015-07-11 22:06:45 +00:00
Sean Callanan
872a1c8592 Sequester expressions the PlaygroundTransform adds, isolating type-check errors.
We had a bit of back-and-forth over how to handle type-check errors in added
expressions.  Obviously all added expressions *should* type-check -- but we
don't want the compiler (and, by extension, the XPC playground service) crashing
when they don't.  So the ErrorTypes from failed type-checks must not leak into
existing code.

In this solution, we use a convenience class (Added) that wraps an expression.
It marks expressions we've constructed -- and we're only allowed to type-check
Added<Expr*>s.  (This isn't fully enforced -- you could still have Added<Expr*>s
that refer to existing Expr*s) but adding this and plumbing it through caught
most of the problems.

I also added checks to various places that weren't checking whether type
checking succeeded.  In one case where we were emitting a source location for
one element in a TupleExpr but not emitting source locations for the others
(which caused dumping to assert) I eliminated that source location.

Finally I added several test cases.  These cases used to crash; one of them
works perfectly now and I've XFAILed the other two.

<rdar://problem/20444876>


Swift SVN r29842
2015-07-01 17:53:06 +00:00
Ted Kremenek
57265acbfc Revert "Updated the playground transform's error handling. Specifically, we now report type-checking errors in added instrumentation to llvm::errs() and try to restore the ASTs to their former state."
This reverts commit r29798.

This commit was breaking the iOS bots.

Swift SVN r29800
2015-06-30 03:50:56 +00:00
Sean Callanan
789eff28e1 Updated the playground transform's error handling.
Specifically, we now report type-checking errors in
added instrumentation to llvm::errs() and try to
restore the ASTs to their former state.

As Jordan points out, this requires a better and
more full solution, involving some form of AST
cloning or doing the playground transform at the
SIL level.  I have left in a TODO to that effect.

<rdar://problem/20444876>


Swift SVN r29798
2015-06-30 00:46:45 +00:00
Sean Callanan
814a2d6623 Don't build temporary variables of InOutType.
This only appears in the print logging for now.
I've got to figure out a way of transforming
print() calls without building temporary variables
left and right.

<rdar://problem/21412489>


Swift SVN r29683
2015-06-25 20:01:24 +00:00
Sean Callanan
eb1ea2aca0 Harden the PlaygroundTransform against type-checking
errors.  These errors are now printed to errs() and
the data they produce is not used, avoiding crashes
later in SILGen when we encounter ErrorTypes.

<rdar://problem/20444876>
<rdar://problem/21321078>
...


Swift SVN r29674
2015-06-25 17:38:13 +00:00
Sean Callanan
eb8c9ac5e7 Handle "do { }" statements in playgrounds. Also
added a testcase.

<rdar://problem/21473935>


Swift SVN r29649
2015-06-25 00:43:48 +00:00
Chris Lattner
1b49bc31f8 improve coding style: remove unneeded llvm:: qualifications,
use isa instead of dyn_cast when ignoring the results, etc. NFC.


Swift SVN r29507
2015-06-19 05:45:04 +00:00
Sean Callanan
b2c6f4e5d5 Added support for do-catch blocks to the playground
transform.  Also added a testcase.

<rdar://problem/21196212> Some results don't show in sidebar -- why?


Swift SVN r29247
2015-06-02 20:03:23 +00:00
Sean Callanan
33b0079a95 Made the PlaygroundTransform instrument the print()/
debugPrint() APIs correctly.  PlaygroundLogger implements
APIs that always take a boolean as their second argument.
If print()/debugPrint() are called with just one argument,
we add "true" as the second argument and replace the call
with a call to the appropriate PlaygroundLogger API.

Also modified the testcase to verify that this is happening
correctly, including when the boolean argument comes from a
more complicated expression.

<rdar://problem/21084145> [Swift integration] Playground AST rewrites not updated for latest Swift standard library changes


Swift SVN r28946
2015-05-23 02:07:25 +00:00
Ben Langmuir
69fdca43da Fix assertion failure code completing after nil literal
We were asserting (and doing the wrong thing) when trying to code
complete
    nil #^HERE^#

The issue is that we tried to apply a solution to the expression that
contained free type variables (converted to generic parameters). This
trips us up when we expect the new type to conform to protocols. In code
completion we generally only need the type of the expression, so this
commit switches to getting that more explicitly.  That said, this did
cause us to drop non-API parameter names in call patterns after an
opening '(' in some cases (covered by rdar://20962472).

Thanks to Doug for suggesting this solution!

rdar://problem/20891867

Swift SVN r28584
2015-05-14 22:22:37 +00:00
Sean Callanan
032eefaed9 Make the PlaygroundLogger be able to deal with
all the strange and wonderful new ways of printing
things.  Also addeed a testcase.

Note: this does not yet pass information about
which version (print vs. debugPrint) is called and
whether a newline is desired or not; that will be
in a future commit once the PlaygroundLogger
support for that is in a build.

<rdar://problem/20859024>


Swift SVN r28518
2015-05-13 18:12:16 +00:00
John McCall
35fc1a090c Track whether an ApplyExpr throws in the AST.
Verify that this bit is set during type-checking on
every ApplyExpr, and fix the remaining locations where
we weren't doing coverage testing on expressions; most
of these were harmless, but it's better to be safe.

Swift SVN r28509
2015-05-13 07:11:44 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Chris Lattner
c6aa041fb9 Add parser/ast/sema/sourcekit/etc support for 'unless' statement.
SILGen support still missing.



Swift SVN r27961
2015-04-30 05:55:11 +00:00
Chris Willmore
c7c7388cf2 Change do-while to repeat-while.
Change all uses of "do { ... } while <cond>" to use "repeat" instead.
Rename DoWhileStmt to RepeatWhileStmt. Add diagnostic suggesting change
of 'do' to 'repeat' if a condition is found afterwards.

<rdar://problem/20336424> rename do/while loops to repeat/while & introduce "repeat <count> {}" loops

Swift SVN r27650
2015-04-23 22:48:31 +00:00
Chris Willmore
d3a977d824 <rdar://problem/20402026> Remove scope entry/exit log entries
Don't emit scope entry/exit logging code in instrumentation for
playgrounds if -playground-high-performance option is passed.

Swift SVN r27046
2015-04-06 22:09:20 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Chris Lattner
8521916b86 change PatternBindingDecl to be created with a static "create" method instead
of using its ctor directly.  NFC, this is in prep for other changes coming.


Swift SVN r26174
2015-03-16 00:44:52 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Dmitri Hrybenko
b15c0bd01c PlaygroundTransform: don't overflow an Int on 32-bit platforms
Swift SVN r24787
2015-01-28 05:22:41 +00:00
Dmitri Hrybenko
acc4baf2eb Don't use reserved names in PlaygroundTransform
Swift SVN r23989
2014-12-17 20:26:33 +00:00
Dmitri Hrybenko
721b9637ee Revert "Clang-format the PlaygroundTransform.cpp file"
This reverts commit r23984 because I don't have enough free time to
convince everyone that a consistent coding style is a good thing.

Swift SVN r23988
2014-12-17 20:26:32 +00:00
Dmitri Hrybenko
0a6dcd98a0 Revert "Don't use reserved names in PlaygroundTransform"
This reverts commit r23985 because it depends on r23984, which I'm
reverting.

Swift SVN r23987
2014-12-17 20:26:30 +00:00