Most of the complexity here is teaching SILGen how to handle closed-over direct
accesses to observing properties, since all of the getter/setter/willSet/didSet
members of the property are actually full closures when in a function body.
We generate correct but really terrible code here, since the setter captures the
willset/didset members themselves. I'm not worrying about the performance of
this construct though, functionality is what matters.
Swift SVN r13778
We still glue the generic params of the requirement to the generic params of the conformance, but now we do it without relying on TypeLowering.
Swift SVN r13771
Pass the context generic params for a reabstraction thunk down to getOrCreateReabstractionThunk from the enclosing function, where it can either use them to define a new thunk or ignore them if it has an equivalent thunk already. Tweak the mangling of reabstraction thunks to use the generic signature with decontextualized "from" and "to" types instead of the generic param list.
Swift SVN r13763
- purge @inout from comments in the compiler except for places talking about
the SIL argument convention.
- change diagnostics to not refer to @inout
- Change the astprinter to print InoutType without the @, so it doesn't show
up in diagnostics or in closure argument types in code completion.
- Implement type parsing support for the new inout syntax (before we just
handled patterns).
- Switch the last couple of uses in the stdlib (in types) to inout.
- Various testcase updates (more to come).
Swift SVN r13564
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.
Thanks Jordan for helping work out the serialization changes needed.
Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.
Swift SVN r13485
Specialization and devirtualization can produce legitimate direct references to them from outside, and at least in the short term all conformances will be public.
Swift SVN r13287
Have SILGen mark all variables bound from pattern bindings without initializers (and *only* ones without initializers) with mark_uninitialized [var] pseudo instructions. On the DI end, *only* consider mark_uninitialized instructions for DI analysis. This has many benefits:
- DI doesn't waste time analyzing locals that are trivially initialized in the original source code.
- DI doesn't try to mangle canonical SIL that has been inlined from transparent functions, which may have been optimized into a form DI isn't written to understand.
While we're here, fix an issue with DCE where it would try to kill unused MarkUninitialized instructions. Although MarkUninitialized has no side effects, it still is semantically important to raw SIL, and can't be killed.
Chris did most of the work here; I just finished updating tests and fixing bugs.
Swift SVN r13247
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.
Thanks Jordan for helping work out the serialization changes needed.
Swift SVN r13036
properties have accessors, we have an amazing property: everything that we
want to form a getter or setter for ... really has one! I suspect many things
can be simplified now, but the first on the chopping block is
StorageDecl::getGetterType (and its three friends) which is now always exactly
just getGetter()->getType().
Swift SVN r12983
mostly to get the brokenness inherent in their current representation out
of my way.
The biggest part of this is that properties in protocols are now always
represented as Computed VarDecls. If you write "var x : Int" in a protocol,
you get an getter FuncDecl. If you write "var x : Int { get}" you get the same
thing. If you write "var x : Int { get set }" then you get a getter and setter
prototype associated with the vardecl.
This then readjusts the various hacks that sort of pass through such things
in SILGen and IRGen, so that we have the same level of hacky support for properties
in protocols.
From the functionality perspective, this enables the { get set } syntax described
in rdar://15827219, and means that "var x : Int" is uniformly treated as read-only
(it was treated as mutable in some cases before). Properties in protocols are
still quite broken though.
Swift SVN r12981
This patch:
- Changes sema to set the "IsDirectPropertyAccess" on MemberRefExprs
in inits/destructors that should be done directly because they are
on the local object.
- Removes the "SGF.AlwaysDirectStoredPropertyAccess" bool in SILGen,
which was the source of the problem above and was otherwise problematic.
This will get a bit simpler when -enable-new-objc-properties rolls out.
Swift SVN r12967
If all of the bindings in a pattern column are 'let' bindings, don't box the binding. If there is any 'var' in the column, conservatively fall back to binding a box. Factor out the logic for producing an initialization for a variable into an new emitInitializationForVarDecl method that SILGenPattern can use. Add a 'copyInto' method to RValue that can bind a copy of an rvalue to an Initialization.
This doesn't use Chris's new +0 ManagedValue optimization yet, so we end up with an extra copy_value when the value is bound that might still be avoidable.
Swift SVN r12903
- Strength reduce the interface to LogicalPathComponent::getMaterialized
to now just return a SILValue for the address. The full "Materialize"
structure hasn't been needed since MaterializeExpr got removed.
- Move 'struct Materialize' out of SILGen.h into SILGenLValues.cpp now
that it is only used for logical property materialization.
- Drop the dead 'loc' argument on DeallocStackCleanup. The location is
already specified when the cleanup is emitted.
Swift SVN r12827
with two kinds, and some more specific predicates that clients can use.
The notion of 'computed or not' isn't specific enough for how properties
are accessed. We already have problems with ObjC properties that are
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.
NFC.
Swift SVN r12593
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.
Swift SVN r12536
move OverriddenDecl and usesObjCGetterAndSetter() up to it.
This allows usesObjCGetterAndSetter to subsume the logic
for subscript decls as well.
Swift SVN r12535
1) Revert my change to give DeclContext a dump method, it confuses the debugger.
2) Refactor SILGen::requiresObjCPropertyEntryPoints out to
VarDecl::usesObjCGetterAndSetter.
Swift SVN r12526
- constify the Initialization::getAddressOrNull/hasAddress functions.
- Teach the initialization logic that 'let' initializations can be
split into tuple subelements by address (i.e. i
getSubInitializationsForTuple works on them) when the let decl has
a backing memory allocation.
- Teach LetValueInitialization to produce a backing memory object
for address-only tuple arguments, since they are passed as multiple
SILArguments and need some place in memory to reassemble them.
The collection fixes a bad miscompilation where the RValue logic emitted
a temporary (through getSingleValue) which we then accidentally lifetime
extended for the duration of the argument. This led to bad things when
the temporary got destroyed too early.
Thanks to MichaelG for helping narrow down this problem, it initially looked
like a sil optimizer bug.
Swift SVN r12234
RValue::forwardInto. While this isn't directly related to my
current problem, it is obvious goodness. This avoids materializing
"as a single value" the argument values, which means that we don't
create a temporary holding the value when we have tuple elements,
allowing us to generate more efficient code (particularly for
address-only tuple).
Swift SVN r12233
so merge them. ArgumentInitVisitor is very very similar to
InitializeTupleValues, so start using RValue::forwardInto in
ArgumentInitVisitor for some cases instead of duplciating logic. This
gives ArgumentInitVisitor some extra magic for lets which I'll be using
in a bit.
Swift SVN r12231
Doing so makes it plain that the empty tuple case doesn't need to
synthesize a tupleinst to return. Eliminating this gets rid of the
weird dead empty tuple you may have seen get dropped in the prolog
of functions taking no arguments.
Also, push around RValue handling a bit in ArgumentInitVisitor, NFC
for this part.
Swift SVN r12230
The Objective-C runtime executes the .cxx_destruct method after the
last -dealloc has executed when destroying an object, allowing the
instance variables to remain live even after the subclass's
destructor/-dealloc has executed, which is important for memory
safety. This fixes the majority of <rdar://problem/15136592>.
Note that IRGenModule::getAddrOfIVarDestroyer() contains an egregious
hack to find the ivar destructor SIL function via a linear
search. We need a better way to find SIL functions that we know exist,
because LinkEntity does not suffice.
Swift SVN r12206
Right now I unconditionally generate these, because silgen doesn't have
easy access to whether "-g" is passed or not. We can either make SILGen
know about this, or we can have optimizations strip these uses out.
Opinions welcome!
As an example, something like:
protocol P { func bonk() }
func foo(let a : Int, let b : P) -> Int {
let x = a
b.bonk()
return x
}
compiles into:
sil @_TF1t3fooFT1aSi1bPS_1P__Si : $@thin (Int64, @in P) -> Int64 {
bb0(%0 : $Int64, %1 : $*P):
debug_value %0 : $Int64 // let a // id: %2
debug_value_addr %1 : $*P // let b // id: %3
debug_value %0 : $Int64 // let x // id: %4
%5 = project_existential %1 : $*P to $*@sil_self P // user: %7
%6 = protocol_method %1 : $*P, #P.bonk!1 : $@cc(witness_method) @callee_owned (@inout Self) -> () // user: %7
%7 = apply %6(%5) : $@cc(witness_method) @callee_owned (@inout Self) -> ()
destroy_addr %1 : $*P // id: %8
return %0 : $Int64 // id: %9
}
Swift SVN r12193
Because Objective-C doesn't have the notion of a destroying
destructor, this is a matter of cleanliness rather than
correctness. Still, it's better not to lie.
Swift SVN r12160
SILDeclRef was previously storing the ClassDecl for this case, because
semantic analysis didn't guarantee that a DestructorDecl was always
present. It is now, and this representation makes more sense.
Swift SVN r12122
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.
There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.
Swift SVN r12115
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.
Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.
Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.
Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration. This computation should really take
advantage of the relationship between modules, but currently
it does not.
Swift SVN r12090
In nongeneric contexts, or contexts where we only care about the indirectness of parameters or have already substituted the generic parameters for a function, the interface types are interchangeable, so just switch over.
Swift SVN r12044
Treat the interface types of SILFunctionTypes as the canonical representation in the verifier. Do a bunch of supporting and annoyingly irreducible work to enable this:
- Stop trying to uncurry generic parameter lists during type lowering and preserve the structure of AST GenericParamLists. This makes mapping dependent types into contexts easier.
- Properly walk generic parameter lists at all depths when grooming substitution vectors for use with substGenericArgs interfaces.
- Reseat the generic parameter lists created for protocol_method results so that we don't expect the outer Self archetype to be unbound; it's provided by the extra data of the result.
- Hack SILFunctionType serialization never to use a decl reference when serializing its generic param list. When this happens, we get incorrect archetypes. This is a gross hack, but when we're able to jump all the way to interface types, it can go away.
Putting these ducks in a row nicely un-XFAILs TextFormatting.swift.
Swift SVN r11989