Commit Graph

293 Commits

Author SHA1 Message Date
Michael Gottesman
ea1f804207 [semantic-sil] Eliminate ValueOwnershipKind::Any from SILPHIArguments in Semantic SIL.
Most of this involved sprinkling ValueOwnershipKind::Owned in many places. In
some of these places, I am sure I was too cavalier and I expect some of them to
be trivial. The verifier will help me to track those down.

On the other hand, I do expect there to be some places where we are willing to
accept guaranteed+trivial or owned+trivial. In those cases, I am going to
provide an aggregate ValueOwnershipKind that will then tell SILArgument that it
should disambiguate using the type. This will eliminate the ackwardness from
such code.

I am going to use a verifier to fix such cases.

This commit also begins the serialization of ValueOwnershipKind of arguments,
but does not implement parsing of value ownership kinds. That and undef are the
last places that we still use ValueOwnershipKind::Any.

rdar://29791263
2017-01-10 20:05:23 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
4e8ff35df5 [semantic-sil] Add ValueOwnershipKind field to SILPHIArgument and split Argument creation methods into one for SILPHIArgument and another for SILFunctionArgument.
We preserve the current behavior of assuming Any ownership always and use
default arguments to hide this change most of the time. There are asserts now in
the SILBasicBlock::{create,replace,insert}{PHI,Function}Argument to ensure that
the people can only create SILFunctionArguments in entry blocks and
SILPHIArguments in non-entry blocks. This will ensure that the code in tree
maintains the API distinction even if we are not using the full distinction in
between the two.

Once the verifier is finished being upstreamed, I am going to audit the
createPHIArgument cases for the proper ownership. This is b/c I will be able to
use the verifier to properly debug the code. At that point, I will also start
serializing/printing/parsing the ownershipkind of SILPHIArguments, but lets take
things one step at a time and move incrementally.

In the process, I also discovered a CSE bug. I am not sure how it ever worked.
Basically we replace an argument with a new argument type but return the uses of
the old argument to refer to the old argument instead of a new argument.

rdar://29671437
2016-12-18 14:48:35 -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
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00
Michael Gottesman
0a8c54d04f [gardening] Always create new SILArguments using SILBasicBlock::createArgument instead of inline placement new.
The reasoning here is the same as in e42bf07.
2016-11-25 01:14:45 -06:00
Michael Gottesman
bf6920650c [gardening] Drop BB from all argument related code in SILBasicBlock.
Before this commit all code relating to handling arguments in SILBasicBlock had
somewhere in the name BB. This is redundant given that the class's name is
already SILBasicBlock. This commit drops those names.

Some examples:

getBBArg() => getArgument()
BBArgList => ArgumentList
bbarg_begin() => args_begin()
2016-11-25 01:14:36 -06:00
Michael Gottesman
e42bf07af4 [gardening] Always create SILBasicBlocks via SILFunction::createBasicBlock.
This eliminates all inline creation of SILBasicBlock via placement new.

There are a few reasons to do this:

1. A SILBasicBlock is always created with a parent function. This commit
formalizes this into the SILBasicBlock API by only allowing for SILFunctions to
create SILBasicBlocks. This is implemented via the type system by making all
SILBasicBlock constructors private. Since SILFunction is a friend of
SILBasicBlock, SILFunction can still create a SILBasicBlock without issue.

2. Since all SILBasicBlocks will be created in only a few functions, it becomes
very easy to determine using instruments the amount of memory being allocated
for SILBasicBlocks by simply inverting the call tree in Allocations.

With LTO+PGO, normal inlining can occur if profitable so there shouldn't be
overhead that we care about in shipping compilers.
2016-11-25 01:12:49 -06: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
Francis Ricci
66dcad0d34 SIL: Avoid dereferencing sentinel nodes in ilist_iterators
The behaviour of ilist has changed in LLVM.  It is no longer permissible to
dereference the `end()` value.  Add a check to ensure that we do not
accidentally dereference the iterator.
2016-10-12 11:46:31 -07:00
Chris Lattner
51c8a81168 remove silgen support for C style for loop, now that it is always rejected in sema. 2016-04-17 15:43:39 -07:00
Dmitri Gribenko
0f36bec31f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-18 16:41:35 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Vedant Kumar
be87f04807 [Coverage] Fix the counter increment for repeat-while bodies
We need to increment the counter for repeat-while bodies immediately
after the loop body is entered. This allows us to handle "break" and
"return" statements in the repeat-while body correctly.

This also fixes an off-by-one error where we only updated the
repeat-while body counter when the loop condition evaluates to true.
2016-02-10 16:32:07 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Michael Gottesman
e25cd8860c Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
This change is needed for the next update to ToT LLVM. It can be put
into place now without breaking anything so I am committing it now.

The churn upstream on ilist_node is neccessary to remove undefined
behavior. Rather than updating the different ilist_node patches for the
hacky change required to not use iterators, just use iterators and keep
everything as ilist_nodes. Upstream they want to eventually do this, so
it makes sense for us to just do it now.

Please do not introduce new invocations of
ilist_node::get{Next,Prev}Node() into the tree.
2016-01-19 14:44:58 -06:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
Adrian Prantl
95d3851e1c Debug Info: Ensure that patterns bound in a while stmt end up in their own
debug scope.

Similar to rdar://problem/22677613

Swift SVN r31998
2015-09-16 17:51:17 +00:00
Adrian Prantl
7eccc60731 Debug Info: Ensure that patterns bound in a for stmt end up in their own
debug scope.

Similar to rdar://problem/22677613

Swift SVN r31997
2015-09-16 17:30:17 +00:00
Adrian Prantl
d1ec8a225b Debug Info: Ensure that patterns bound in a foreach stmt end up in their
own debug scope.

rdar://problem/22677613

Swift SVN r31996
2015-09-16 17:30:14 +00:00
Justin Bogner
0604d88bda InstrProf: Emit the counter for falling out of a do-catch immediately after the body
We were emitting the counter for falling out of a do block at the end
of the entire construct's scope, but this can cause us to miss the
increment if the insertion point isn't valid there. Move the increment
to immediately after we emit the body.

rdar://problem/22346924

Swift SVN r31356
2015-08-20 00:22:51 +00:00
Jordan Rose
76cf1781df [SILGen] Emit all TopLevelCodeDecls in a single scope.
This gets the cleanups right, which is important for the 'locals' that
come from top-level guard statements as well as top-level defer statements.
The former could lead to accessing destroyed memory.

rdar://problem/22064894

Swift SVN r30811
2015-07-30 19:47:54 +00:00
Joe Groff
0b1283b1c9 Have 'defer' statements cons up func decls instead of closure literals.
The defer body func is only ever fully applied, so SILGen can avoid allocating a closure for it if it's declared as a 'func', making it slightly more efficient at -Onone.

Swift SVN r30638
2015-07-25 21:28:06 +00:00
Justin Bogner
80f4156bf4 InstrProf: Fix coverage mapping for GuardStmt
We were creating a coverage mapping for GuardStmt, but we were never
incrementing its counter, so the results were quite strange. This
moves the counter to the body of the guard (instead of the
non-existent "then" clause) and increments the counter in the obvious
place.

rdar://problem/21291670

Swift SVN r29965
2015-07-08 06:13:37 +00:00
Adrian Prantl
760baa4e42 Debug Info: Fix the line table entry generated for the jump out of
a do or do-catch block to point to end of the do body rather than the
location of the "do" keyword.

<rdar://problem/21194177> line table entries for "do" happen after the body of the do is executed

Swift SVN r29239
2015-06-02 18:07:37 +00:00
Chris Lattner
8cdf88cd8c fix <rdar://problem/21088517> throw in an initializer causes bogus error
a false positive (with no location information) when an init immediately throws.


Swift SVN r28965
2015-05-23 16:03:32 +00:00
Slava Pestov
e5f1fcfad6 SILGen: Don't crash on DoCatchStmt with non-throwing body in non-throwing context
Fixes <rdar://problem/20994248>.

Swift SVN r28748
2015-05-19 04:35:50 +00:00
Slava Pestov
14dd0a4221 SILGen: Refactor emitOrDeleteBlock() to take a JumpDest rather than a BB
This allows us to invalidate the JumpDest to ensure it won't point
to a deleted block. NFC

Swift SVN r28747
2015-05-19 04:35:49 +00:00
John McCall
26a9a4d1e5 SILGen for 'rethrows'. WIP; committed to get broader testing
of an assertion.

Swift SVN r28733
2015-05-19 00:54:32 +00:00
Mark Lacey
30c52d15f4 Fix typo.
Noticed browsing code.

Swift SVN r28715
2015-05-18 18:35:51 +00:00
Slava Pestov
3f1f5b8932 Fix a nit
Swift SVN r28694
2015-05-18 00:42:07 +00:00
Slava Pestov
42d7c7251c SILGen: better diagnostic for code after break and throw
Swift SVN r28689
2015-05-18 00:26:19 +00:00
Chris Lattner
e517ad9182 Fix unreachable code handling to properly diagnose things like:
throw x 
whatever()  

as being unreachable after the throw.



Swift SVN r28680
2015-05-17 15:13:35 +00:00
Dmitri Hrybenko
0a1f7c09df Revert "Fix unreachable code handling to properly diagnose things like:"
This reverts commit 28678.  It broke the IDE/complete_exception.swift
test.

Swift SVN r28679
2015-05-17 12:27:57 +00:00
Chris Lattner
5ead9764bd Fix unreachable code handling to properly diagnose things like:
throw x
  whatever()

as being unreachable after the throw.



Swift SVN r28678
2015-05-17 05:56:02 +00:00
Slava Pestov
60eb9780a1 SILGen: fix generation of switch containing try
When emitting try_apply, don't start a new scope between adding
a cleanup and forwarding the value. This would leave behind a
dead cleanup, which would fire an assertion in emitSharedCaseBlocks().

Fixes <rdar://problem/20923654>.

Swift SVN r28572
2015-05-14 17:22:47 +00:00
Slava Pestov
cbbde4739e SILGen: remove dead diagnostics for error handling
Looks like Sema is checking all of this stuff now. NFC

Swift SVN r28571
2015-05-14 17:22:44 +00:00
Chris Lattner
3814b7003f Implement support for arbitrary pattern matching in for-each statements,
which composes straight-forwardly on top of the existing stuff for if/let
and guard.



Swift SVN r28371
2015-05-09 21:34:35 +00:00
Chris Lattner
58b63193d5 Implement support for 'where' clauses on foreach loops, part of
<rdar://problem/14482451> Allow refutable patterns & 'where' in 'for-each' loops




Swift SVN r28338
2015-05-08 23:57:01 +00:00
Chris Lattner
f35677de14 Revise SILGen of foreach loops to only drop the optional generator result value in memory when it is address-only. This leads to better -O0 performance and easier to read silgen output. This is ongoing progress towards rdar://20642198.
This recommits r28318 with a fix that simplifies away a bunch of code and a bug.



Swift SVN r28328
2015-05-08 21:26:56 +00:00
Chris Lattner
5e7a45ff70 revert r28318, it is causing a problem on perftests. I'll investigate after lunch.
Swift SVN r28321
2015-05-08 18:02:24 +00:00
Chris Lattner
f379b1e15b Revise SILGen of foreach loops to only drop the optional generator result value
in memory when it is address-only.  This leads to better -O0 performance and 
easier to read silgen output.  This is ongoing progress towards rdar://20642198.


Swift SVN r28318
2015-05-08 17:46:20 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Adrian Prantl
301aae1492 Promote the "true"-Scope of a condition to an actual lexical scope.
<rdar://problem/20394204> Scoping of if/let declarations too broad

Swift SVN r28203
2015-05-06 16:40:11 +00:00