Commit Graph

298 Commits

Author SHA1 Message Date
Joe Groff
66a2b6a0e2 SILGen: Purge misuses of pre-exploded RValue constructor.
The RValue(ArrayRef<ManagedValue>, CanType) constructor was intended as a semi-private interface for building an RValue from a pre-exploded array of elements, but was (understandably) widely being misused as a general ManagedValue-to-RValue constructor, causing crashes when working with tuples in various contexts where RValue's methods expected them to be exploded. Make the constructor private and update most improper uses of it to use the exploding RValue constructor, or to use a new `RValue::withPreExplodedElements` static method that more explicitly communicates the intent of the constructor. Fixes rdar://problem/29500731.
2016-12-05 14:55:59 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -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
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
Huon Wilson
cc5529f9f4 Run git-clang-format. 2016-11-11 15:02:28 -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
Michael Gottesman
34ec32bc14 [semantic-arc] Handle the rest of the unqualified mem opts in SILGen.
Keep in mind that these are approximations that will not impact correctness
since in all cases I ensured that the SIL will be the same after the
OwnershipModelEliminator has run. The cases that I was unsure of I commented
with SEMANTIC ARC TODO. Once we have the verifier any confusion that may have
occurred here will be dealt with.

rdar://28685236
2016-11-09 11:37:52 -08:00
Michael Gottesman
2ccc251888 [semantic-arc] In SILGen always assign a copy_value's argument to its result.
This ensures that ownership is properly propagated forward through the use-def
graph.

This was the work that was stymied by issues relating to SILBuilder performing
local ARC dataflow. I ripped out that local dataflow in 6f4e2ab and added a
cheap ARC guaranteed dataflow pass that performs the same optimization.

Also in the process of doing this work, I found that there were many SILGen
tests that were either pattern matching in the wrong functions or had wrong
CHECK lines (for instance CHECK_NEXT). I fixed all of these issues and also
expanded many of the tests so that they verify ownership. The only work I left
for a future PR is that there are certain places in tests where we are using the
projection from an original value, instead of a copy. I marked those with a
message SEMANTIC ARC TODO so that they are easy to find.

rdar://28685236
2016-11-06 23:17:17 -08:00
Michael Gottesman
3e5c4326fe [semantic-arc] Remove all uses of SILBuilder::*AndFold in SILGen and TypeLowering.
I am removing these usages of this API since it conflicts with SILGen's want to
hold onto copy_value return values for ownership propagation purposes. If any of
the copy_value are folded, the reference that SILGen holds onto will be
invalid.

rdar://28685236
2016-11-06 23:17:17 -08:00
Joe Groff
512a0d7bcf SILGen: Pass down right substitutions when getting a read-only local property.
Fixes rdar://problem/28933116.
2016-11-02 13:45:57 -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
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
9507093b17 [semantic-arc] Change SILGen to only use copy_value, destroy_value.
rdar://28851920
2016-10-29 20:11:07 -07:00
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Slava Pestov
2068c5d5e6 AST: Refactor GenericParamList::getForwardingSubstitutions() to use GenericSignature::getSubstitutions(), NFC
This is the first, and most trivial, usage of the new
GenericSignature::getSubstitutions() method.

Note that getForwardingSubstitutions() now takes a
GenericSignature, which is slightly awkward.

However, this is in line with our goal of 'hollowing out'
GenericParamList by removing knowledge of the finalized
generic requirements.

Also, there is now a new getForwardingSubstitutionMap()
function, which returns an interface type substitution
mapping. This is used in the new getForwardingSubstitutions()
implementation, and all also be used elsewhere later.

Finally, in the SILFunction we now cache the forwarding
substitutions, instead of re-computing them every time.
I doubt this makes a big difference in performance, but
it's a simple enhancement and every little bit helps.
2016-08-22 10:45:49 -07:00
Joe Groff
3a8520be56 SILGen: Partial codegen for property behaviors with DI initialization.
If a behavior has storage that can be initialized out-of-line, generate code in SILGen that uses stores to mark_uninitialized_behavior for eventual analysis by DI.

This is incomplete, particularly, it's missing code generation of glue thunks for accessors that require reabstraction, but I wanted to make sure the progress here didn't bitrot.
2016-06-14 20:10:22 -07:00
Slava Pestov
98a0e73b02 AST: Merge BoundGenericType::getSubstitutions() with TypeBase::gatherAllSubstitutions(), NFC 2016-06-13 00:57:09 -07:00
Joe Groff
77719a5ef0 SILGen: Evaluate loaded lvalues in a writeback scope.
emitLValue always has to occur in a writeback scope, even if the lvalue isn't formally accessed until later, because some lvalue productions immediately access their parent lvalue expression (namely optional chaining expressions). Fixes rdar://problem/26642478.
2016-06-07 12:51:32 -07:00
Slava Pestov
e7f0ca0ebf Sema: Synthesize materializeForSet for lazy properties
Fixes <rdar://problem/25707968>.
2016-04-13 20:07:37 -07:00
Roman Levenstein
2e77b3990b Add [nonatomic] attribute to all SIL reference counting instructions. 2016-04-06 01:52:43 -07:00
Michael Ilseman
d7581d1b36 Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member 2016-03-23 13:05:57 -07:00
Joe Groff
aec7be3930 SILGen: Handle C functions imported as property accessors. 2016-03-18 13:23:40 -07:00
Slava Pestov
c27d22d6a5 SILGen: Remove unused method, NFC 2016-03-14 20:58:32 -07:00
Slava Pestov
bc1fc73b2a Sema: Simpler materializeForSet return type, NFC
The function pointer is a thin function and possibly polymorphic,
so it does not really have an AST type. Instead of pretending it has
an AST type, just return a RawPointer and remove some casts in the
process.
2016-03-14 13:01:03 -07:00
Slava Pestov
cfebe49e90 SILGen: Allow direct calls to materializeForSet defined in a protocol extension
Now that we apply the callback with the correct generic signature, the
assert can go away. It was being triggered if the protocol extension was
defined in a different resilience domain; otherwise we prefer direct
access anyway.

Note that materializeForSet now has to be able to re-abstract Self when
invoking the callback, since we might have to go from a thin metatype
to a thick metatype.
2016-03-14 13:01:03 -07:00
Slava Pestov
2ee4fd6b2a SILGen: Decouple "should use materializeForSet" from "materializeForSet was synthesized"
We will sometimes emit materializeForSet for resilience, even if
it is not the preferred method for inout accesses of the property
or subscript.

To avoid having SILGen behavior depend on whether Sema synthesized
a materializeForSet or not, add a more precise predicate. The
general idea as I understand it, is that we want to use
materializeForSet if we do not have perfect information about the
implementation of the property or subscript, due to polymorphism
or resilience.
2016-03-14 13:01:03 -07:00
Slava Pestov
0c870a35aa SILGen: Cast the materializeForSet callback to the correct type when applying it
We don't want to perform substitutions when we call the materializeForSet
accessor itself, since the return value is a polymorphic thin function,
and its calling convention is not compatible with a concretely-typed
function value in the case where 'Self' is an abstract type parameter.

With this change, the materializeForSet declaration still has an AST type
for the callback in its return value, but since this AST type makes no
sense in reality it would be better to just return a RawPointer instead,
removing some unnecessary code from CodeSynthesis.cpp. This will be
cleaned up in a subsequent patch.
2016-03-11 11:27:06 -08:00
Ben Langmuir
73e8193fc6 Revert "SILGen: Cast the materializeForSet callback to the correct type when applying it"
This reverts commit 194c170d0e.
2016-03-10 11:37:52 -08:00
Slava Pestov
194c170d0e SILGen: Cast the materializeForSet callback to the correct type when applying it
We don't want to perform substitutions when we call the materializeForSet
accessor itself, since the return value is a polymorphic thin function,
and its calling convention is not compatible with a concretely-typed
function value in the case where 'Self' is an abstract type parameter.

With this change, the materializeForSet declaration still has an AST type
for the callback in its return value, but since this AST type makes no
sense in reality it would be better to just return a RawPointer instead,
removing some unnecessary code from CodeSynthesis.cpp. This will be
cleaned up in a subsequent patch.
2016-03-09 22:55:53 -08:00
Slava Pestov
41971fec99 SILGen: Introduce MaterializedLValue abstraction
This is used when materializing an LValue to share state between
the read and write phases of the access, replacing the 'temporary'
and 'extraInfo' parameters that were previously being passed around.

It adds two new fields, origSelfType and genericSig, which will be
used in an upcoming patch to actually apply the callback with the
current generic signature.

This will finally allow us to make use of materializeForSet
implementations in protocol extensions, which is a prerequisite
for enabling resilient default implementations of property and
subscript requirements.
2016-03-09 16:33:22 -08:00
Slava Pestov
08196c9f9a SILGen: Better type safety in SILGenApply.cpp, NFC 2016-03-07 17:05:06 -08:00
Slava Pestov
924e4c4e13 SILGen: Clean up lvalue re-abstraction a bit
When we emit calls to getters and setters with emitApply(), the call
emission code ends up re-abstracting the result of a getter or the
parameter to a setter.

As a result, getOrigFormalType() was incorrect for logical path
components. This was worked around by only adding an OrigToSubst
path component to an lvalue if the last path component was physical.

This caused a problem in the following case:

1) There was an abstraction difference between the storage of the
   protocol requirement and the storage of the protocol witness

2) There was an abstraction difference between the storage of the
   protocol witness, and the fully-substituted type of the witness

An example is when the witness is in a protocol extension, and uses
'Self' or some other associated type which is concrete and loadable
in the conformance.

Fix this properly by splitting up getStorageTypeData() into two
functions, one used when adding physical path components and another
one used for logical.

As a result, we can now give the correct abstraction pattern to
logical path components.
2016-03-07 17:05:06 -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
Daniel Duan
efe230774b [AST] rename some isXXX methods to getAsXXX
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
2016-02-11 16:23:40 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Slava Pestov
56b03642ac SILGen: Targeted fix for MaterializeForSet use
If we're accessing a field of a struct, ignore materializeForSet;
it will only have been synthesized if the struct conforms to a
protocol, and we don't want the presence of a conformance to
affect generated code.

A more principled fix would change the SILGen logic to use a
materializeForSet if it would have been synthesized anyway,
asserting that it was synthesized in that case. I'll clean this
up in the 'master' branch once these fixes settle.
2016-01-20 01:50:17 -08:00
Slava Pestov
df38bd1764 SILGen: More interface type abstraction pattern goodness, NFC 2016-01-18 23:17:17 -08:00
Slava Pestov
249242b08d SILGen: Always open-code materializeForSet
This improves MaterializeForSetEmitter to support emission
of static materializeForSet thunks, as well as witnesses.

This is now done by passing in a nullptr as the conformance
and requirement parameters, and adding some conditional code.

Along the way, I fixed a few limitations of the old code,
namely weak/unowned and static stored properties weren't
completely plumbed through. There was also a memory leak in
addressed materializeForSet, the valueBuffer was never freed.

Finally, remove the materializeForSet synthesis in Sema since
it is no longer needed, which fixes at least one known crash
case.
2016-01-11 19:53:16 -08:00
Slava Pestov
b70e4d2aad SILGen: Split off SILGenMaterializeForSet.cpp from SILGenLValue.cpp, NFC
In order to fix some other issues that came up with materializeForSet
and resilience, I had to bite the bullet and finish off John's code
for open-coding materializeForSet emission in SILGen. This patch
makes the subsequent changes easier to review.
2016-01-10 17:06:19 -08:00
Slava Pestov
6af7f95a5a We don't need to plumb a resilience expansion through mangling, NFC
I'm going to be adding deployment target info ResilienceExpansion
soon so removing unnecessary usages helps reduce the amount of
work there.
2016-01-07 08:15:26 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
021a186c23 Fix typos. 2015-12-28 18:30:15 +01:00
Nadav Rotem
07d4558c1c [Mangler] Change the Swift mangler into a symbol builder.
This commit changes the Swift mangler from a utility that writes tokens into a
stream into a name-builder that has two phases: "building a name", and "ready".
This clear separation is needed for the implementation of the compression layer.

Users of the mangler can continue to build the name using the mangleXXX methods,
but to access the results the users of the mangler need to call the finalize()
method. This method can write the result into a stream, like before, or return
an std::string.
2015-12-25 21:40:25 -08:00
Nadav Rotem
6fa6ca563e [Mangler] Rename some of the mangler methods. NFC. 2015-12-24 14:35:33 -08:00
Nadav Rotem
b5e4197d33 [Mangler] Fix all of the places where users of the Mangler access the underlying buffer.
This commit fixes all of the places where users of the Mangler write to the stream that's used by the Mangler. The plan is to make the Mangler buffered, and this means that users can't assume that the mangler immediately writes the mangled tokens to the output stream.
2015-12-22 22:47:35 -08:00
Slava Pestov
8e0e2b4ea2 SIL: Nuke TypeConverter::getEffectiveGenericParamsForContext(), NFC 2015-12-20 16:57:23 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
John McCall
bdb4b896a2 Move ObjC-compatible unowned references to the new runtime
functions.

Take the code for the old, broken reference-counting
implementation and delete it with prejudice.
2015-12-08 16:20:32 -08:00
Joe Groff
b1667ec705 SIL: Introduce a new @inout_aliasable parameter convention.
Modeling nonescaping captures as @inout parameters is wrong, because captures are allowed to share state, unlike 'inout' parameters, which are allowed to assume to some degree that there are no aliases during the parameter's scope. To model this, introduce a new @inout_aliasable parameter convention to indicate an indirect parameter that can be written to, not only by the current function, but by well-typed, well-synchronized aliasing accesses too. (This is unrelated to our discussions of adding a "type-unsafe-aliasable" annotation to pointer_to_address to allow for safe pointer punning.)
2015-12-08 14:35:47 -08:00