Commit Graph

2202 Commits

Author SHA1 Message Date
Arnold Schwaighofer
a87f34372e Rename SILFunction::entryBB to getEntryBlock 2016-12-20 07:51:55 -08:00
Arnold Schwaighofer
474e3967d9 Add a entryBB accessor to SILFunction 2016-12-20 07:24:02 -08:00
Michael Gottesman
4931161929 [semantic-sil] Implement the dataflow checker behind the -enable-semantic-sil flag.
This commit includes the dataflow verifier and plugs in the use checker into the
dataflow verifier.

Some specific checks in the use checker need revision, but I for today
this is good enough. As I go through SILGen I am going to fix them.

rdar://29671437
2016-12-18 22:55:03 -08:00
Michael Gottesman
ef6462de47 [semantic-sil] Add the SILOwnershipUseVerifier behind the -enable-semantic-sil flag
This is the first verifier for SemanticSIL. The verifier is very simple and
verifies that given a SILValue V, V->getOwnershipKind() returns an ownership
kind compatible with all of V's user instructions.

This is implemented by adding a new method to SILInstruction:

    SILInstruction::verifyOperandOwnership()

This method creates an instance of the visitor OwnershipCompatibilityUseChecker
and then has the instance visit this.

The OwnershipCompatibilityUseChecker is a SILInstructionVisitor that for a given
instruction verifies that the given SILInstruction's operand SILValue's produce
ValueOwnershipKind that are compatible with the SILInstruction. The reason why
it is implemented as a visitor is to ensure that a warning is produced if a new
instruction is added and a method on the OwnershipCompatibleUseChecker isn't
added.

Keep in mind that this is just the first verifier and the full verifier (that
also verifies dataflow) is built on top of it. The reason why this separate API
to the use verifier is exposed is that exposing the checker enables us to place
an assert in SILBuilder to diagnose any places where SIL ownership is violated
immediately when the violation occurs allowing for an easy debugging experience
for compiler writers. This assert is a key tool that I am going to be using to
make SILGen conform to the SIL Ownership Model.

Again, this will be behind the -enable-semantic-sil flag, so normal development
will be unaffected by this change.

rdar://29671437
2016-12-18 21:04:26 -08: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
Michael Gottesman
0d2b8abc1c Merge pull request #6357 from gottesmm/split_sil_argument
[semantic-sil] Reify the split in SILArgument in between function and block arguments via subclasses.
2016-12-18 02:20:07 -08:00
Michael Gottesman
19f0f6e686 [semantic-sil] Reify the split in SILArgument in between function and block arguments via subclasses.
For a long time, we have:

1. Created methods on SILArgument that only work on either function arguments or
block arguments.
2. Created code paths in the compiler that only allow for "function"
SILArguments or "block" SILArguments.

This commit refactors SILArgument into two subclasses, SILPHIArgument and
SILFunctionArgument, separates the function and block APIs onto the subclasses
(leaving the common APIs on SILArgument). It also goes through and changes all
places in the compiler that conditionalize on one of the forms of SILArgument to
just use the relevant subclass. This is made easier by the relevant APIs not
being on SILArgument anymore. If you take a quick look through you will see that
the API now expresses a lot more of its intention.

The reason why I am performing this refactoring now is that SILFunctionArguments
have a ValueOwnershipKind defined by the given function's signature. On the
other hand, SILBlockArguments have a stored ValueOwnershipKind. Rather than
store ValueOwnershipKind in both instances and in the function case have a dead
variable, I decided to just bite the bullet and fix this.

rdar://29671437
2016-12-18 01:11:28 -08:00
practicalswift
a3ce1601ca [gardening] Fix typos. 2016-12-18 09:58:19 +01:00
swift-ci
7b1f753c31 Merge pull request #6345 from practicalswift/gardening-20161217 2016-12-17 14:46:43 -08:00
practicalswift
8f0330e424 Merge pull request #6347 from practicalswift/namespace-normalization
[gardening] Normalize end-of-namespace comments
2016-12-17 23:14:28 +01:00
practicalswift
ed0098a5c6 [gardening] Use correct header formatting. 2016-12-17 22:33:09 +01:00
practicalswift
ddedf240ec [gardening] Use correct Swift URLs. 2016-12-17 22:33:09 +01:00
practicalswift
9d0b2abfc2 [gardening] Normalize end-of-namespace comments 2016-12-17 22:29:07 +01:00
Michael Gottesman
cd59d96292 Merge pull request #6342 from gottesmm/some_small_fixes
[sil-ownership] Fix some cases in SILValue::getOwnershipKind().
2016-12-17 12:45:13 -08:00
swift-ci
268c2b668d Merge pull request #6325 from practicalswift/gardening-20161216 2016-12-17 09:19:24 -08:00
Michael Gottesman
a178ac97e0 [sil-ownership] Fix some cases in SILValue::getOwnershipKind().
I fixed a few things. Now I am finally hitting cases where we have
guaranteed/owned arguments, so I really need to do the SILGen work. But this was
a good first step.

rdar://29671437
2016-12-17 01:23:52 -08:00
Joe Groff
c10cae2830 Merge pull request #6333 from jckarter/capture-box-generic-context
SIL: Lower captures to boxes with an appropriate generic context.
2016-12-16 20:49:32 -08:00
Joe Groff
4444d83756 SIL: Lower captures to boxes with an appropriate generic context.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
2016-12-16 20:23:25 -08:00
Michael Gottesman
d4fb21d50f [semantic-sil] Define ValueOwnershipKind SILValue::getOwnershipKind().
The implementation will rely on a SILVisitor to ensure that we properly handle
all relevant cases. Right now, there are only stubs and we assert in all of
them.

rdar://29671437
2016-12-16 17:00:54 -08:00
Michael Gottesman
57d3f848a6 [semantic-sil] Define ValueOwnershipKind enum.
This enum models the various froms of ownership semantics that a specific
SILValue can have.

rdar://29671437
2016-12-16 16:50:49 -08:00
Michael Gottesman
e7c4065987 [semantic-sil] Add a new visitor called SILBuiltinVisitor.
I am going to use this to ensure that I am properly handling all Builtin cases.
The intrinsic cases from LLVM are simpler and can be handled at a high level
(namely that all ownership uses are trivial since LLVM has no concept of
ownership.

rdar://29671437
2016-12-16 16:47:39 -08:00
practicalswift
16d6dce62e [gardening] Fix recently introduced typos. 2016-12-16 21:42:09 +01:00
Michael Gottesman
6213550239 [semantic-sil] Create copy_unowned_value.
This was in the first high level ARC instruction proposal, but I have not needed
it until now. The use case for this is to ahandle strong_retain_unowned (which
takes in an unowned value, asserts it is still alive, performs a strong_retain,
and returns the @owned value). This @owned value needs a destroy_value.

rdar://29671437
2016-12-14 19:22:24 -08:00
Michael Gottesman
bf3116d105 [semantic-sil] Expose support for getting SILResultInfo from an ApplyInstBase.
We just never needed this information before. And I need it now for the SIL
Ownership Verifier to cleanly get the result info so I can determine the
ownership convention of an ApplyInstBase's return value.

rdar://29671437
2016-12-14 17:24:38 -08:00
Joe Groff
b6823b930b SIL: Change SILType::subst to be SubstitutionMap-based.
This simplifies the SILType substitution APIs and brings them in line with Doug and Slava's refactorings to improve AST-level type substitution. NFC intended.
2016-12-14 14:33:32 -08:00
Bob Wilson
deddf19aae Merge remote-tracking branch 'origin/master' into master-next 2016-12-13 10:23:03 -08:00
Arnold Schwaighofer
7194613b2d Merge pull request #6229 from aschwaighofer/fix_existential_metatype_memory_effect
The address form of existential_metatype does read from memory
2016-12-12 16:50:37 -08:00
Michael Gottesman
66cff7e37e [semantic-arc] Add StoreBorrowInst and BeginBorrowInst. 2016-12-12 13:06:18 -08:00
Arnold Schwaighofer
6f881b1d0e The address form of existential_metatype does read from memory
rdar://29625413
2016-12-12 12:56:51 -08:00
Joe Groff
3871cda205 Push SILBoxType::getFieldType into SIL and make it take a SILModule.
Applying nontrivial generic arguments to a nontrivial SIL layout requires lowered SILType substitution, which requires a SILModule. NFC yet, just an API change.
2016-12-09 16:21:13 -08:00
Joe Groff
585ccd59c1 Remove SILBoxType::getBoxedType.
Move the few remaining usages to getFieldType. Removing the old API lets us progress in fully adopting nontrivial layouts in SILGen.
2016-12-09 11:10:03 -08:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -08:00
Joe Groff
13bb6c649a SIL: Remove AllocBoxInst::getElementType().
There's no longer a single element type to speak of. Update uses to either iterate all box fields or to assert that they're working with a single-field box.
2016-12-02 16:37:34 -08:00
Joe Groff
9b858a7431 SIL: Remove the ElementType from DeallocBoxInst's representation.
This was made redundant by typed boxes, and the type operand was already removed from textual SIL, but the field was never removed from the instruction's in memory representation. It becomes wrong in the face of compound boxes with layout.
2016-12-02 15:19:43 -08:00
Joe Groff
277608a69b Print and parse SILBoxTypes with a new syntax.
Use a syntax that declares the layout's generic parameters and fields,
followed by the generic arguments to apply to the layout:

  { var Int, let String } // A concrete box layout with a mutable Int
                          // and immutable String field
  <T, U> { var T, let U } <Int, String> // A generic box layout,
                                        // applied to Int and String
                                        // arguments
2016-12-02 13:44:22 -08:00
Joe Groff
0ca4a374d5 Move SILLayout from SIL to AST.
Trying to contain it in SIL doesn't really work if we want to be able to print or parse SIL box types, since the type parser and printer doesn't otherwise depend on the SIL module.
2016-12-02 12:23:45 -08:00
Bob Wilson
ae3db7c88e Update for llvm r281167: changes to ilist_iterator template arguments.
(cherry picked from commit 97e415ce2a)
2016-12-01 10:47:07 -08:00
Bob Wilson
2c21ef586d Update to match llvm r279473: remove ilist_*sentinel_traits.
(cherry picked from commit 391e7d8b60)
2016-12-01 10:46:38 -08:00
Bob Wilson
26a62b912a Update to match llvm r278513: share code for embedded sentinel traits.
Nothing at all should be changing here, this is just rearranging code.

(cherry picked from commit 9964697f22)
2016-12-01 10:42:59 -08:00
Slava Pestov
835472b14f AST: Remove PolymorphicFunctionType 2016-11-29 03:05:35 -07:00
Robert Widmann
fe586fafd7 Merge pull request #5960 from practicalswift/doxygen-fixes
[gardening] Use proper doxygen comments (///)
2016-11-28 19:04:41 -05:00
Michael Gottesman
c8e119b159 [gardening] Standardize include guard in SILSuccessor.h
We always use all caps.
2016-11-28 12:53:40 -08:00
practicalswift
7d412572e6 [gardening] Use proper doxygen comments (///) 2016-11-28 21:25:30 +01:00
Michael Gottesman
38ec08f45f [gardening] Standardize SILBasicBlock successor/predecessor methods that deal with blocks rather than the full successor data structure to have the suffix 'Block'.
This was already done for getSuccessorBlocks() to distinguish getting successor
blocks from getting the full list of SILSuccessors via getSuccessors(). This
commit just makes all of the successor/predecessor code follow that naming
convention.

Some examples:

getSingleSuccessor() => getSingleSuccessorBlock().
isSuccessor() => isSuccessorBlock().
getPreds() => getPredecessorBlocks().

Really, IMO, we should consider renaming SILSuccessor to a more verbose name so
that it is clear that it is more of an internal detail of SILBasicBlock's
implementation rather than something that one should consider as apart of one's
mental model of the IR when one really wants to be thinking about predecessor
and successor blocks. But that is not what this commit is trying to change, it
is just trying to eliminate a bit of technical debt by making the naming
conventions here consistent.
2016-11-27 12:32:51 -08:00
Michael Gottesman
6a50566a75 [gardening] Use proper doxygen style by inserting a newline between brief and longer comment.
Also a little bit of copy editing.
2016-11-27 11:58:20 -08:00
Michael Gottesman
804df7cac9 [gardening] Standardize a bit of code style. NFC.
In this file, by and large we use 'Type *'.

This file converts a couple of places where we use 'Type*' => 'Type *'.
2016-11-27 11:58:20 -08:00
Michael Gottesman
edce501b71 [gardening] Eliminate unneeded 'public' from inheritance declaration of a struct.
structs always inherit publicly.
2016-11-27 11:58:20 -08:00
Michael Gottesman
529eec30b7 [gardening] Use const_cast rather than implement SILBasicBlock::getSingleSuccessor() twice for const/non-const. 2016-11-27 11:58:20 -08:00
Michael Gottesman
5a1650f0c5 [gardening] doxygenify file level comment. NFC. 2016-11-27 11:58:20 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00