Commit Graph

25 Commits

Author SHA1 Message Date
Chris Lattner
0e8f0d6bfc fix <rdar://problem/20679379> DI crashes on initializers on protocol extensions
DI makes the assumption that the type of self in an initializer is always
derived from a nominal type.  Now that you can put an initializer body on a
protocol, this isn't true anymore, so teach it about this.



Swift SVN r27714
2015-04-24 23:51:40 +00:00
Chris Lattner
3a7d8df92b fix <rdar://problem/19259730> Using mutating methods in a struct initializer with a let property is rejected
while we're at it, improve the QoI for actually-invalid mutating method calls in struct initalizers.


Swift SVN r24030
2014-12-19 06:52:37 +00:00
Chris Lattner
e2da1224d6 generalize and clean up the logic in LetValueInitialization to be easier to follow,
paving the way for future progress.


Swift SVN r23875
2014-12-12 01:14:43 +00:00
Chris Lattner
674a50df2f refactor how "getPathStringToElement" in DI works, to clean it up and simplify
clients.  NFC except for slightly better diagnostic in .sil testcases.  


Swift SVN r23809
2014-12-09 17:51:06 +00:00
Chris Lattner
cb8a65e831 Clean up the semantics of 'let' properties in a number of ways:
- We switch to a model where let properties may be "initialized", but never
  reassigned.  Specifically, immutable properties in structs/classes may have
  an init value specified in their declaration (but can then never be reset
  in any init implementation) or not (in which case they must be initialized 
  exactly once on all paths through every init.  This makes a lot more sense 
  for immutability, defines several problems away, and provides a path to
  supporting things like (rdar://16181314)

- We now *never* default initialize an immutable property.  Formerly
  we would default initialize optional let properties to nil, but this
  isn't actually useful, and allows an error of omission with let 
  properties.  

This resolves: <rdar://problem/19035287> let properties should only be initializable, not reassignable
and possibly other radars.





Swift SVN r23779
2014-12-08 20:59:53 +00:00
Chris Lattner
a2df9c650e reapply r22223 with a testcase update:
Dramatically improve DI diagnostics in initializers fixing rdar://18414728.

As one small example of the improvement, where an initializer like this:

class Foo {
    var path:String? {
        return "boo"
    }
    
    let aaaaa:String
    
    init() {
        if let p1 = path {

used to  produce the error: "error: variable 'self.aaaaa' used before being initialized" on path,
we now produce:

x.swift:9:21: error: use of 'self' in property access 'path' before all stored properties are initialized
        if let p1 = path {
                    ^
x.swift:6:9: note: 'self.aaaaa' not initialized
    let aaaaa:String
        ^

which is more useful.





Swift SVN r22238
2014-09-23 23:17:29 +00:00
Dmitri Hrybenko
5de6540670 Revert "Dramatically improve DI diagnostics in initializers fixing rdar://18414728."
This reverts commit r22223.

Swift SVN r22233
2014-09-23 21:52:04 +00:00
Chris Lattner
88750f6ff3 Dramatically improve DI diagnostics in initializers fixing rdar://18414728.
As one small example of the improvement, where an initializer like this:

class Foo {
    var path:String? {
        return "boo"
    }
    
    let aaaaa:String
    
    init() {
        if let p1 = path {

used to  produce the error: "error: variable 'self.aaaaa' used before being initialized" on path,
we now produce:

x.swift:9:21: error: use of 'self' in property access 'path' before all stored properties are initialized
        if let p1 = path {
                    ^
x.swift:6:9: note: 'self.aaaaa' not initialized
    let aaaaa:String
        ^

which is more useful.



Swift SVN r22223
2014-09-23 19:28:36 +00:00
Chris Lattner
c16cdf656d implement support for cleaning up early returns from class initializers that
are delegating and/or derived.


Swift SVN r21623
2014-09-01 06:14:10 +00:00
Joe Groff
71379f5bad SILGen: Explicitly mark uninitialized locals with mark_uninitialized, and have DI only consider mark_uninitialized storage.
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
2014-01-31 22:50:21 +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
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
Chris Lattner
3a970678a1 implement definite initialization enforcement for delegating class
initializers.


Swift SVN r11980
2014-01-07 05:31:33 +00:00
Chris Lattner
3f6ce3f888 introduce new flavors of MarkUninitializedInst to model delegating ctors to DI.
Swift SVN r11961
2014-01-06 23:13:41 +00:00
Chris Lattner
7c41f9e2d7 more diagnostic QoI improvements, refer to properties, not ivars.
Swift SVN r11094
2013-12-10 21:29:04 +00:00
Chris Lattner
4b24b7f567 Two more QoI improvements to DI diagnostics. For enums,
diagnose failure to initialize with:
  "return from enum initializer method without storing to 'self'"
instead of:
  "variable 'self' used before being initialized"

For partially initialized super.init() calls, emit:
  "super.init not called on all paths leading to use of base object 'SomeClass'"
instead of:
  "use of base object 'SomeClass' before super.init call to initializes it on some paths"

... which didn't make any sense.



Swift SVN r11075
2013-12-10 04:52:56 +00:00
Chris Lattner
12db3b2880 Implement support for validating super.init invariants.
This builds on the infrastructure we have for liveness tracking, by tracking
the "super.init'd" state as another faux memory object that has a liveness.
Each escape/base class use requires super.init to have happened, and super.init
requires super.init to NOT have happened.  This gives us pretty great QoI,
full fidelity to the model, and is pretty simple.

This implements:
<rdar://problem/15579247> We need to validate super.init() invariants in initializers




Swift SVN r11073
2013-12-10 04:15:29 +00:00
Chris Lattner
8a5d66dc9d Start improving "DI for init methods" diagnostics. New additions:
t.swift:10:5: error: instance variable 'self.y' not initialized at super.init call
    super.init()
    ^
<unknown>:0: note: variable defined here
t.swift:15:5: error: use of base object 'SomeClass' before super.init call initializes it
    x = 17 
    ^

instead of:

variable 'self.y' captured by a closure before being initialized

for each of them.  <unknown> is in the crosshairs next.



Swift SVN r11036
2013-12-09 21:37:39 +00:00
Chris Lattner
51acb02bfb Element analysis applies to more than just tuple elements now,
just refer to them as elements of the memory object, not as 
tuple elements.


Swift SVN r10813
2013-12-04 23:22:14 +00:00
Chris Lattner
468e143d50 Rework MemoryUseCollector to individually collect struct field members
as individual elements when processing the 'self' decl in a struct
init method.  This isn't exercised yet.


Swift SVN r10809
2013-12-04 23:09:47 +00:00
Chris Lattner
5a878c2185 Move tuple flattening functions into DIMemoryObjectInfo
now that they fit there.


Swift SVN r10782
2013-12-04 17:27:47 +00:00
Chris Lattner
6fdb5f9ce1 introduce a new abstraction for handling the memory object being
analyzed, and use it as common currency between the element use
collector and its clients.  Element collection is about to become
more nuanced.  NFC.


Swift SVN r10781
2013-12-04 17:07:29 +00:00
Chris Lattner
c4f9cd1576 Make a function static.
Swift SVN r10780
2013-12-04 16:33:50 +00:00
Chris Lattner
78e5e9879e move the ElementUseCollector out of DefiniteInitialization.cpp
Swift SVN r10720
2013-12-02 01:04:56 +00:00
Chris Lattner
92594b9b5a DI is over 3000 lines of code now, and should be split into two
separate passes.  Start splitting some utility functions out,
and rearranging code a bit.  While I'm at it, rename some bits
to make more sense now that their purpose has settled.


Swift SVN r10719
2013-12-02 00:55:08 +00:00