Commit Graph

118 Commits

Author SHA1 Message Date
Hugh Bellamy
b39895b0a5 Fix incorrect format specifiers passed to snprintf in Sema 2017-03-26 15:48:02 +07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
5d8bfb09e7 Re-apply "Playground Transform: Fix assertion failure in generic code" (#6747)
This regression was introduced in the following commit:
<6cbb494ad2>

Fixes <rdar://problem/29935266>.
2017-01-11 19:47:20 -08:00
Arnold Schwaighofer
dbab7257bf Revert "Playground Transform: Fix assertion failure in generic code" 2017-01-11 09:02:38 -08:00
Slava Pestov
d38c65dff5 Playground Transform: Fix assertion failure in generic code
This regression was introduced in the following commit:
<6cbb494ad2>

Fixes <rdar://problem/29935266>.
2017-01-10 16:23:12 -08:00
Slava Pestov
7731d4c6cb Sema: Remove some unnecessary calls to getCanonicalType() 2017-01-08 21:01:13 -08:00
practicalswift
83f250312b [gardening] Add override where appropriate 2017-01-07 20:17:16 +01:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Maxwell Swadling
cf6cb5f74d Ran clang format on InstrumenterSupport.h and PlaygroundTransform.cpp 2016-12-19 10:58:46 -08:00
Maxwell Swadling
77caeefe10 Adopted InitExpr->getType()->getAs<LValueType>
This means the desugared type is used instead.
2016-12-19 10:56:41 -08:00
Maxwell Swadling
8ee55b3719 Fixed array size of buffer and added comment. 2016-12-19 10:56:41 -08:00
Maxwell Swadling
214efbfc3c Added a new AST Walker that instruments the AST to provide callbacks that simulate a program counter
Based off the PlaygroundTransform, this new ASTWalker leaves calls to __builtin_pc_before and __builtin_pc_after before and after a user would expect a program counter to enter a range of source code.
2016-12-19 10:56:40 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
b4d11338ec AST: Push ValueDecl::{has,get,set}Type() down to VarDecl
After recent changes, this asserts on all decls that are not VarDecls,
so we can just enforce that statically now. Interestingly, this turns
up some dead code which would have asserted immediately if called.

Also, replace AnyFunctionRef::getType() with
AnyFunctionRef::getInterfaceType(), since the old
AnyFunctionRef::getType() would just assert when called on
a Decl.
2016-12-01 19:28:13 -08:00
Slava Pestov
6cbb494ad2 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-29 03:05:25 -07:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
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