Commit Graph

2202 Commits

Author SHA1 Message Date
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
a998d98924 [gardening] SILBasicBlock::splitBasicBlock() => *::split().
The BasicBlock suffix is redundant.
2016-11-25 01:14:43 -06:00
Michael Gottesman
e936de7b04 [gardening] 0 => nullptr. NFC. 2016-11-25 01:14:41 -06:00
Michael Gottesman
c3d5ace299 [gardening] Move SILBasicBlock::dropAllReferences() out of the argument list manipulation section.
I am not sure why it was put here originally, but I believe it is still there
due to bitrot.
2016-11-25 01:14:40 -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
Dave Abrahams
b6d965b7f2 Squash a noisy warning 2016-11-23 22:39:36 -08: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
Bob Wilson
6ca7872ba5 Merge remote-tracking branch 'origin/master' into master-next 2016-11-16 22:12:23 -08:00
Bob Wilson
f10ae47b9f Merge remote-tracking branch 'origin/master' into master-next 2016-11-15 17:32:28 -08:00
Erik Eckstein
26038055c2 StackPromotion: don’t move an alloc_ref above it’s operands.
fixes a SILVerifier crash: rdar://problem/29276015
2016-11-15 16:50:36 -08:00
Doug Gregor
93e7862ae5 [AST] Remove AbstractTypeParamType; NFC.
This abstract class isn't providing any value anywhere, and represents
a false distinction.
2016-11-15 13:52:22 -08:00
Michael Gottesman
a8c4cc60e8 [gardening] Rename ValueBase::getParentBB() => getParentBlock(). 2016-11-14 00:39:47 -08:00
Michael Gottesman
c6c99141b5 [gardening] Change ValueBase::{getParentBB,getFunction,getModule}() to be const methods so in the debugger one can use it with const ValueBase. 2016-11-14 00:39:41 -08:00
Michael Gottesman
f5ef3f354f [silvalue] Some small formatting fixes. 2016-11-13 23:43:05 -08:00
Huon Wilson
5a08879d06 [AST] Remove GenericSignature params from GenericEnvironment methods.
The GenericEnvironment stores a signature internally.
2016-11-11 14:57:04 -08:00
Joe Shajrawi
675820d142 [SILOptimizer] Add support for new patterns in SILCombiner 2016-11-10 15:56:57 -08:00
Michael Gottesman
dd03a9be35 Make OperandValueArrayRef::iterator a forward iterator to appease std::any_of gods. 2016-11-09 15:03:14 -07:00
Michael Gottesman
8d4aac47e8 [semantic-arc] Now that SILGen only emits qualified ownership memory operations, tighten up the verifier in functions with qualified ownership.
rdar://28685236
2016-11-09 11:37:52 -08:00
Joe Groff
e1e7e19248 SIL: Construct alloc_box insns with the type of the box.
This becomes necessary with generalized boxes, since the box type isn't derivable from a single field type.
2016-11-03 19:26:42 -07:00
Erik Eckstein
564ebc9e98 Small refactoring of SILDeclRef::mangle
Instead of passing a mangling prefix as a string, just pass the kind of mangling. This will ease the transition to the new mangling scheme.
NFC
2016-11-02 10:32:02 -07:00
Erik Eckstein
a01e9d4e41 Remove dead code in SIL linker
... which is not only dead but also broken.
NFC
2016-11-02 10:30:10 -07:00
Joe Groff
a66ab83674 Merge pull request #5574 from jckarter/nested-function-lowered-captures
SILGen: Base "currying" of functions on their lowered capture set, instead of their formal capture set.
2016-11-01 11:46:43 -07:00
Joe Groff
f81e55c44f SILGen: Base "currying" of functions on their lowered capture set, instead of their formal capture set.
This allows for slightly better codegen for nested functions that refer to other nested functions that don't transitively capture any local state, but more importantly, allows methods of local types to work while still referring to nested functions that don't capture local state, fixing rdar://problem/28015090.
2016-11-01 11:08:37 -07:00
Michael Gottesman
e2419b75fd [semantic-arc] Qualify most of the stores in SILGen as store [init].
All of these cases were trivially inits since they involved storing into
a newly created temporary allocation.

rdar://28685236
2016-10-31 15:51:26 -07:00
Michael Gottesman
05c5fcca95 [gardening] Now that the old TypeLowering::LoweringStyle::Deep is gone, rename TypeLowering::LoweringStyle::DeepNoEnum => TypeLowering::LoweringStyle::Deep. 2016-10-30 18:39:31 -07:00
Michael Gottesman
bffa7addaf [semantic-arc] Eliminate default {Load,Store}OwnershipQualification argument to SILBuilder::create{Load,Store}(...)
Today, loads and stores are treated as having @unowned(unsafe) ownership
semantics. This leaves the user to specify ownership changes on the loaded or
stored value independently of the load/store by inserting ARC operations. With
the change to Semantic SIL, this will no longer be true. Instead loads, stores
have ownership semantics that one must reason about such as copy, take, and
trivial.

This change moves us closer to that world by eliminating the default
OwnershipQualification argument from create{Load,Store}. This means that the
compiler developer cannot ignore reasoning about the ownership semantics of the
memory operation that they are creating.

Operationally, this is a NFC change since I have just gone through the compiler
and updated all places where we create loads, stores to pass in the former
default argument ({Load,Store}OwnershipQualifier::Unqualified), to
SILBuilder::create{Load,Store}(...). For now, one can just do that in situations
where one needs to create loads/stores, but over time, I am going to tighten the
semantics up via the verifier.

rdar://28685236
2016-10-30 13:07:06 -07:00
Michael Gottesman
a3ee41c5fc [semantic-arc] Enable qualified verification of {copy,destroy,retain,release}_value and strong_{retain,release}
rdar://28851920
2016-10-29 20:11:07 -07:00
Michael Gottesman
a1b5600dfc [semantic-arc] Create SILBuilder::emitDestroyValue{,AndFold}.
rdar://28851920
2016-10-29 20:11:06 -07:00
Michael Gottesman
fd760080a8 [debug-info] Add an == operator to DebugLoc.
I am going to need this for some DI changes needed for rdar://28851920.

rdar://28851920
2016-10-29 16:39:03 -07:00
Bob Wilson
b227f45b7e Merge remote-tracking branch 'origin/master' into master-next 2016-10-27 22:28:28 -07:00
Joe Groff
88ad1160a2 SILGen/IRGen: Lower protocol witness thunks for ObjC lightweight generics as pseudogeneric.
Fixes rdar://problem/28873860, where we would miscompile when lightweight generic classes were extended to conform to Swift protocols because we tried to emit parameters for the class's generic parameters for the witness entry points. Prevent this by lowering the witness into a pseudogeneric function in SILGen, and teaching IRGen to do the right thing for a witness with pseudogeneric parameters.
2016-10-26 13:45:34 -07:00
Michael Gottesman
362a556af4 [semantic-arc] SILBuilder::emit{Retain,Release}ValueOperation => SILBuilder::emit{Copy,Destroy}ValueOperation.
rdar://28851920
2016-10-25 13:12:52 -07:00
Michael Gottesman
bf40426db3 Merge pull request #5448 from gottesmm/add_is_parsingflag_to_silbuilder
[semantic-arc] Add a flag to SILBuilder called isParsing to allow for SILBuilder to ignore invariants while parsing.
2016-10-25 10:16:20 -07:00
Michael Gottesman
be95e63688 [semantic-arc] Add a flag to SILBuilder called isParsing to allow for SILBuilder to ignore invariants while parsing.
I am going to add asserts to SILBuilder to ensure that the leaf level functions
that create qualified ownership and unqualified ownership instructions assert if
one attempts to create functions with the wrong ownership qualification.

This creates problems in the parser though since we apply the ownership
qualification heuristic to SILInstructions after we have created the instruction
via SILBuilder. I could change the ownership model evaluator to have special
methods for various instructions, but I think that would introduce more
decentralized code in the Parser which I want to avoid. Instead this commit just
introduces a small isParsing flag that is set by SILParser on its SILBuilder
that will cause these invariants to be ignored. Since the bool is used in the
actual asserts themselves they are at the call site where they have an effect,
making it very clear what is going on.

rdar://28851920
2016-10-25 09:34:43 -07:00
Michael Gottesman
7f2ec618b0 [semantic-arc] Change emitCopyValue entrypoints to return the copied SILValue.
I have not updated any APIs that use the emitCopyValue entrypoints to properly
propagate forward the returned value.

The strategy for reforming the resulting value was to:

1. Return the retain_value operand in leaf cases.
2. In aggregate cases, just use reformAggregate to reform the aggregate from the
   copied leaf results.
3. In enums, since I deleted the deep code, this is the same as the leaf cases.

Once I change in a subsequent commit the actual retain_value emission to instead
be copy_value emission, then type lowering will be able to properly pair
copy_value operations.

rdar://28851920
2016-10-25 09:27:31 -07:00
Michael Gottesman
8b41745b37 [semantic-arc] Change TypeLowering APIs to use the words {Copy,Destroy}Value instead of {Retain,Release}Value. NFC.
This is an attempt to separate functional from superficial changes in the
semantic arc changes.

rdar://28851920
2016-10-24 23:49:11 -07:00
swift-ci
55f303a96b Merge pull request #5439 from gottesmm/delete_dead_code_from_typelowering 2016-10-24 20:43:29 -07:00
Michael Gottesman
5212b9ef27 [type-lowering] Delete dead code from LoweringStyle::Deep.
This code is not used anywhere in tree. If we have need for it, we can always
revert this commit.
2016-10-24 16:50:40 -07:00
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -07:00
Joe Groff
374fa57530 SILInstruction.h: friend class -> friend
NFC
2016-10-24 13:10:27 -07:00
Michael Gottesman
bb9197c7ff [semantic-arc] Move the Ownership Model Eliminator and management of SILFunction::hasQualifiedOwnership in front of SILOptions::EnableSILOwnership.
This is a NFC change, since verification still will be behind the flag. But this
will allow me to move copy_value, destroy_value in front of the
EnableSILOwnership flag and verify via SILGen that we are always using those
instructions.

rdar://28851920
2016-10-23 18:30:43 -07:00
Michael Gottesman
3eaa25bcd6 [sil] Complement ValueBase::getParentBB() with ValueBase::get{Function,Module}().
These APIs work just like getParentBB does, namely they attempt to cast
self to either SILInstruction/SILArgument and if the instance is one of
those classes, using the APIs on said classes to get the relevant
Function or Module. If the dynamic casts fail, then nullptr is returned.
2016-10-23 14:47:12 -07:00
Michael Gottesman
1b1d90fff0 [semantic-arc] Implement simple verification of the ownership qualification of copy_value, destroy_value.
rdar://28851920
2016-10-23 00:34:26 -07:00
Michael Gottesman
ab0ffa2c39 [semantic-arc] Wire up Parsing/Printing/IRGen/Serialization/Deserialization for copy_value, destroy_value.
rdar://28851920
2016-10-22 22:10:57 -07:00
practicalswift
024f1e9e9d [gardening] Fix typo in method name.
Added in a3e7bd6cad
2016-10-23 00:28:01 +02:00
Michael Gottesman
4d370a2814 [semantic-arc] When running the verifier, use the qualified ownership flag on the SILFunction to determine whether ownership is enabled or not.
Previously I was going to just set a flag and run the verifier once with that
flag enabled. Then I realized that given that the OwnershipModelEliminator is a
function pass, I really need to put the state on whether or not ownership is
enabled on functions. Now this commit refactors the verifier to use the state on
the function when determining if it should allow for ownership qualified
instructions or not in a specific function.

rdar://28685236
2016-10-21 17:42:39 -07:00
Michael Gottesman
a3e7bd6cad [semantic-arc] As staging detail, add a HasQualifiedOwnership flag on all SILFunctions.
Over the past day or so I have been thinking about how we are going to need to
manage verification of semantic ARC semantics in the pass pipeline. Specifically
the Eliminator pass really needs to be a function pass to ensure that we can
transparently put it at any stage of the optimization pipeline. This means that
just having a flag on the SILVerifier that states whether or not ownership is
enabled is not sufficient for our purposes. Instead, while staging in the SIL
ownership model, we need a bit on all SILFunctions to state whether the function
has been run through the ownership model eliminator so that the verifier can
ensure that we are in a world with "SIL ownership" or in a world without "SIL
ownership", never in a world with only some "SIL ownership" instructions. We
embed this distinction in SIL by creating the concept of a function with
"qualified ownership" and a function with "unqualified ownership".

Define a function with "qualified ownership" as a function that contains no
instructions with "unqualified ownership" (i.e. unqualified load) and a function
with "unqualified ownership" as a function containing such no "ownership
qualified" instructions (i.e. load [copy]) and at least 1 unqualified ownership
instruction.

This commit embeds this distinction into SILFunction in a manner that is
transparently ignored when compiling with SIL ownership disabled. This is done
by representing qualified or unqualified ownership via an optional Boolean on
SILFunction. If the Boolean is None, then SILOwnership is not enabled and the
verifier/passes can work as appropriate. If the Boolean is not None, then it
states whether or not the function has been run through the Ownership Model
Eliminator and thus what invariants the verifier should enforce.

How does this concept flow through the compilation pipeline for functions in a
given module? When SIL Ownership is enabled, all SILFunctions that are produced
in a given module start with "qualified ownership" allowing them to contain SIL
ownership instructions. After the Ownership Model eliminator has run, the
Ownership Model sets the "unqualified" ownership flag on the SILFunction stating
that no more ownership qualified instructions are allowed to be seen in the
given function.

But what about functions that are parsed or are deserialized from another
module? Luckily, given the manner in which we have categories our functions, we
can categorize functions directly without needing to add anything to the parser
or to the deserializer. This is done by enforcing that it is illegal to have a
function with qualified ownership and unqualified ownership instructions and
asserting that functions without either are considered qualified.

rdar://28685236
2016-10-21 17:37:02 -07:00
swift-ci
597412f39e Merge pull request #5403 from jckarter/sil-layouts 2016-10-21 14:48:29 -07:00
Joe Groff
cabaa0a51a SIL: Introduce lowered SILLayouts.
This gives us a concept we can eventually use to cache the lowered physical layout of fragile structs and classes, and more immediately, concretize the layout of closure boxes in a way that lets us represent the capture of generic environments and multiple captured values without compromising the "nominal" nature of box layouts. To start exercising the basic implementation, change the representation of SILBoxType to be in terms of a SILLayout, though avoid any immediate functionality change by preserving the single-boxed-type interface for now.
2016-10-21 14:19:56 -07:00