Commit Graph

1602 Commits

Author SHA1 Message Date
Chris Lattner
6b93fc2034 simplify code now that getGetter/SetterType have been hoisted
to AbstractStorageDecl, NFC.


Swift SVN r12575
2014-01-20 15:37:20 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
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
2014-01-18 19:42:02 +00:00
Chris Lattner
b4735381d0 Plumb the DeclContext of the use site down to the "doesVarDeclMemberProduceLValue"
function.  Pretty soon, whether something is an lvalue or not will depend on who is
asking.


Swift SVN r12507
2014-01-17 22:14:02 +00:00
Doug Gregor
4d6fc894be Propagate nil returned from a self.init or super.init call.
What we actually do here will likely change depending on how we want
to handle error propagation in general, but for now it suffices to
propagate the nil via an early exit.

Swift SVN r12440
2014-01-17 00:17:15 +00:00
Doug Gregor
133bb13848 Always assume that the result of calling self.init or super.init is of the appropriate subclass type.
Eliminates some Swift-side checking for a memory safety problem that
can only originate in Objective-C.

Swift SVN r12413
2014-01-16 19:58:09 +00:00
Doug Gregor
30a34e5a56 Lower the rebinding of 'self' in a super.init call to a cast when it can't fail.
Swift-rooted class hierarchies don't permit the replacement of "self",
so it's guaranteed that the 'self' returned from a 'super.init'
invocation is identical to the previous self. Elide the unconditional
checked downcast (that manifests as a call to
swift_dynamicCastClassUnconditional in the runtime) by putting in the
moral equivalent of a bitcast.

For Objective-C-rooted hierarchies, 'self' can be replaced, so memory
safety dictates that we use the unconditional checked downcast. Note
that this path is still unsafe against nil returns.

Swift SVN r12401
2014-01-16 06:01:22 +00:00
Doug Gregor
3a6db8292e Revert "Introduce the self_downcast SIL instruction to downcast the result of super.init."
We need to model the difference between Objective-C- and Swift-rooted
class hierarchies in SIL. IRGen is too late to handle nil returns.

This reverts commit 549db981ea0136a67aee3029aefe18a05d3c8833.

Swift SVN r12400
2014-01-16 06:01:21 +00:00
Doug Gregor
d19065048b Introduce the self_downcast SIL instruction to downcast the result of super.init.
No functional difference from the unconditional checked downcast we
had before, but this gives IRGen the chance to specialize the
implementation.

Swift SVN r12382
2014-01-16 04:24:56 +00:00
Doug Gregor
e5adce56ad Clarify SILGen lowering of the self-rebinding expression. NFC
Swift SVN r12377
2014-01-16 01:40:03 +00:00
Chris Lattner
1b6c2e321e change a few "createCopyValue"'s to "emitCopyValue" so that trivial types
don't get copyvalues.  This is mostly to make sure that only Typelowering and
silcloner are calling createCopyValue.


Swift SVN r12365
2014-01-16 00:27:32 +00:00
Chris Lattner
e180f9b601 Properly handle the case when a member_ref_expr on an rvalue struct
causes an abstraction change.


Swift SVN r12354
2014-01-15 22:19:03 +00:00
Chris Lattner
eacb823fd5 fix rdar://15821990 - Don't emit default value for type var in instance init() body.
Swift SVN r12319
2014-01-15 05:31:43 +00:00
Chris Lattner
fe41a8ad6b Closures over address-only let decls: these will often be captured
by box (which is not "Constant" closure kind) because partial_apply
can't handle copy-in semantics.


Swift SVN r12278
2014-01-14 04:47:58 +00:00
John McCall
817e80bde5 Implicit conversions for UncheckedOptional.
rdar://15189000
rdar://15189009

Swift SVN r12260
2014-01-13 23:15:03 +00:00
Doug Gregor
57d278a9bd Given -.cxx_construct the proper return type; it returns self.
Initialization via .cxx_construct is now functional.


Swift SVN r12255
2014-01-13 21:55:49 +00:00
Doug Gregor
5664bee5fb Mark 'self' as uninitialized in the ivar initializer (-.cxx_construct).
This ensures that DI will initialize the ivars rather than assigning
to them.


Swift SVN r12246
2014-01-13 21:22:06 +00:00
Doug Gregor
c6b880a9b7 Definite initialization for initializers relying on a separate ivar initializer.
When we decide to emit a separate ivar initializer method (via the
Objective-C entry point -.cxx_construct), we no longer initialize the
ivars within the initializer. This only happens for derived classes,
so teach DI about uninitialized 'self' values that require a
super.init call but don't require the ivars to be initialized.



Swift SVN r12240
2014-01-13 19:41:16 +00:00
Chris Lattner
7db7d4a813 Three changes:
- 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
2014-01-13 17:24:40 +00:00
Doug Gregor
ea209da4be When needed, emit a Objective-C .cxx_construct method to initialize stored properties.
When a class that will be allocated by the Objective-C runtime also
requires all of its stored properties have initial values, move that
complete initialization of the object into -.cxx_construct, which is
invoked by the runtime after +alloc.

Definite initialization doesn't like the resulting initializers (which
don't initialize any of their ivars) at all, so no end-to-end testing yet.

Swift SVN r12229
2014-01-13 16:31:23 +00:00
Chris Lattner
cab4e1caf6 emit debug_value for class constructors that don't need a box (i.e. root classes).
We don't need it for value constructors or derived classes, since those have an
allocation for self that carries debug info.


Swift SVN r12214
2014-01-12 07:16:14 +00:00
Chris Lattner
76bea38d3e emit debug_value for 'self' in class destructors of all sorts, and
rename emitDestructorProlog -> emitSelfDecl, since that is what it 
does.


Swift SVN r12213
2014-01-12 06:44:11 +00:00
Doug Gregor
6957209b84 Add a note indicating that we shouldn't emit ivar initialization in ObjC initializers.
Swift SVN r12212
2014-01-12 04:49:26 +00:00
Doug Gregor
fc7dfb2fae Start emitting .cxx_construct methods for Objective-C-derived classes.
When we're using Objective-C's memory allocation, emit .cxx_construct
methods whenever we have instance variables with in-class
initializers. Presently, these methods are just empty stubs.

Swift SVN r12211
2014-01-12 04:31:52 +00:00
Doug Gregor
7950fc2df6 Only emit the Objective-C entry point for the ivar destroyer (-.cxx_destruct).
The Swift entry point will never be referenced by anything, so don't
bother generating it.

Swift SVN r12207
2014-01-12 00:50:12 +00:00
Doug Gregor
3524a79fa0 Emit .cxx_destruct for destruction of ivars in Objective-C-derived classes.
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
2014-01-12 00:17:42 +00:00
Doug Gregor
34113ffee4 Emit both Swift and Objective-C entry points for -dealloc.
The Swift entry point is required for the Swift metadata, while the
Objective-C entry point goes into the Objective-C metadata. As part of
this, stop emitting the destroying destructor for classes that use
Objective-C allocation: it won't work anyway.

Swift SVN r12199
2014-01-11 04:37:39 +00:00
Doug Gregor
1b746bc3b5 Move the creation of deallocating destructors from IRGen to SILGen.
This is the first (and only) use of the dealloc_ref instruction.

Swift SVN r12145
2014-01-10 22:32:55 +00:00
Doug Gregor
7b0783f985 Move the "gather all substitutions" operation into the AST. SILGen also needs it.
Swift SVN r12142
2014-01-10 22:32:51 +00:00
Doug Gregor
2bf20ccbc3 Add the ClassDecl::getDestructor() convenience method.
Swift SVN r12140
2014-01-10 22:32:49 +00:00
Chris Lattner
f5466ab2b6 ding, dong, MaterializeExpr is dead.
Swift SVN r12125
2014-01-10 17:55:00 +00:00
Doug Gregor
5f1b8618f4 Make the SILDeclRef for a destroying destructor store a DestructorDecl.
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
2014-01-10 17:33:57 +00:00
Doug Gregor
8d2142dcd0 Tweak the "uses Objective-C allocation" predicate.
We use Objective-C allocation for classes whose root was defined in
Objective-C. Any Swift class whose root is defined in Swift will use
Swift's allocation routines instead.

Plus some minor cleanup in advance of implementing -dealloc.


Swift SVN r12104
2014-01-09 23:09:59 +00:00
Chris Lattner
b87dd57079 implement SILGen and parser support for 'type' let's, implementing rdar://15767586.
General compiler support is missing for 'type' properties on classes, and lets don't
work either, but at least we have a nice diagnostic now.
also, rename static -> type in a few internal diagnostic names.



Swift SVN r12102
2014-01-09 22:42:24 +00:00
Doug Gregor
3f09a9891d Add an [objc] bit to the alloc_ref instruction to indicate when to use Objective-C's +allocWithZone:.
Swift SVN r12099
2014-01-09 21:35:55 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
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
2014-01-09 08:58:07 +00:00
Doug Gregor
622c2f6ce8 Destroy instance variables after chaining to the superclass destructor.
This is the dual of our initialization story: delay the destruction of
instance variables until after the execution of the superclass
destructor, so that memory safety is preserved even if the superclass
destructor calls a method on teh subclass.

Swift SVN r12089
2014-01-09 05:59:33 +00:00
Doug Gregor
68bcb0d2af Move emission of instance variable initial values from Sema to SILGen.
Hacking up ASTs to perform this emission was always gross; move it
over to SILGen. No functionality change.

Swift SVN r12067
2014-01-08 21:38:23 +00:00
Sean Callanan
f3e81ec9d2 Values produced by the debugger client are
lvalues.  (They're all addresses.)  We need to
mark the resulting ManagedValues as lvalues as
well, so that SILGen emits loads for them
correctly.


Swift SVN r12066
2014-01-08 21:34:23 +00:00
Joe Groff
b2f0b90ba2 SIL: Switch to SILFunctionType interface types in easy-to-reach places.
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
2014-01-08 04:48:29 +00:00
Doug Gregor
23fff50b69 Use UTF-16 string literals when the (builtin) string literal type supports it.
Make the compiler fully support both UTF-8 and UTF-16 string
literals. A (standard-library-defined) string type (such as String)
that wants UTF-16 string literals should conform to the
BuiltinUTF16StringLiteralConvertible protocol; one that wants UTF-8
string literals should conform to the BuiltinStringLiteralConvertible
protocol.

Note that BuiltinUTF16StringLiteralConvertible inherits from
BuiltinStringLiteralConvertible, so a string type that wants UTF-16
string literals also has to implement support for UTF-8. The UTF-16
entry point is preferred when the compiler knows that UTF-16 is
supported. This only tends to happen when we have a generic parameter
that is required to conform to StringLiteralConvertible, e.g.,

  func f<T: StringLiteralConvertible>() {
    var t: T = "Hello, World!" // uses UTF-8 entry point
  }

because the UTF-8 entry point is the only one guaranteed to be available.



Swift SVN r12014
2014-01-07 22:55:07 +00:00
Joe Groff
530e948cb2 SIL: Rename 'enum_data_addr' to 'init_enum_data_addr'.
Emphasize the fact that this address is only intended for initialization. When we split destructive_switch_enum_addr, there will be another similar instruction for destructively taking the payload out of an already-initialized enum.

Swift SVN r12000
2014-01-07 18:40:00 +00:00
Joe Groff
44fb729830 SIL: Use only interface types in the verifier.
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
2014-01-07 06:50:20 +00:00
Chris Lattner
408011ae59 Implement silgen and DI support for delegating initializers
in value types.


Swift SVN r11982
2014-01-07 06:04:59 +00:00
Chris Lattner
7e69153d14 merge the MUI flags for delegating self: there is no need to
differentiate the 'derived' and 'base' cases for delegating
initializers.  One is better than two.


Swift SVN r11981
2014-01-07 05:39:21 +00:00
Doug Gregor
b0440645c8 Diagnose attempts to both delegate to a peer and chain to a superclass initializer.
While we're here, cache the result of looking for delegation or
chaining calls within ConstructorDecl. Only Sema and SILGen for the
body of the constructor care, so we don't serialize this
information. Rather, we have a faster-path to recompute it should
someone ask again after it was cached.


Swift SVN r11969
2014-01-07 01:00:49 +00:00
Chris Lattner
6406e54138 teach silgen to produce the right mark_unintialized tags for delegating inits.
Swift SVN r11964
2014-01-06 23:33:06 +00:00
Chris Lattner
f4d12a2b6e teach SILGenFunction::manageBufferForExprResult about address-only let buffers, so that
we don't emit a shadow copy in some cases where we didn't realize we successfully emitted
into our buffer.


Swift SVN r11948
2014-01-06 20:37:45 +00:00
Chris Lattner
5c5c7829da Rework SILGen of address-only let declarations. Previously, we would just drop them
into heap boxes like var decls.  Now we drop them into stack temporaries like rvalues.

No semantic change goes with this.



Swift SVN r11939
2014-01-06 19:42:50 +00:00
Doug Gregor
5f1e886907 Wrap delegating initialization ('self.init' calls) in RebindSelfInConstructorExpr.
As with chaining initialization ('super.init' calls), wrapping the
delegating initialization in RebindSelfInConstructorExpr ensures that
'self' gets overwritten by the result of delegation.

Note that I'd much prefer that RebindSelfInConstructorExpr be
introduced by the type checker (not the parser). That cleanup will
follow.



Swift SVN r11932
2014-01-06 18:25:29 +00:00
Chris Lattner
dcd8581f6c Fix RValueEmitter::visitDeclRefExpr to do the right thing when SGFContext
specifies a destination to plop the loaded decl into.  This isn't actually
being used, just something I noticed in flight.


Swift SVN r11910
2014-01-04 21:11:29 +00:00