Commit Graph

125 Commits

Author SHA1 Message Date
Nadav Rotem
f5549dce0f A small cleanup suggested by Chris. NFC.
Swift SVN r20657
2014-07-28 23:38:12 +00:00
Nadav Rotem
a09e0d58ba DI: Handle 'assert' instructions in the SelfInit state.
rdar://17746401



Swift SVN r20646
2014-07-28 21:46:55 +00:00
Chris Lattner
d214e1a75c fix <rdar://problem/17686667> If super.init is implicitly inserted, DI diagnostics have no location info
This has two changes:
 - In the case when we have an invalid source loc, DI will default to emitting diagnostics
   at the enclosing function's location.  This makes it more robust in general against
   implicitly synthesized code.

 - For this diagnostic in particular, emit a tailored message, since super.init is a commonly
   synthesized thing.



Swift SVN r20104
2014-07-17 17:44:16 +00:00
Chris Lattner
86df649f90 Fix <rdar://problem/16797372> Bogus error: self.init called multiple times in initializer
DI has two paths for analyzing initialization state: one optimize for solving a single
fact (e.g. the state of a single non-tuple variable in a function), and one that handles 
the full generality of multiple states in parallel (e.g. a tuple in a function or the
fields of a struct/class during its init method).

Unfortunately, the dataflow analysis between these two implementations drifted, and I
fixed a bug in the "N" case (rdar://16119509 back in feb) that didn't get fixed in the "1"
case.  This reworks all of the dataflow to make the fact propagation more similar between
the two paths and fix the bug along the way.



Swift SVN r17343
2014-05-04 00:22:33 +00:00
Chris Lattner
2aa3e50343 fix <rdar://problem/16660680> QoI: fatal() in init method complains about super.init being called multiple times
The problem here is that the implicitly generated self.init() call is unreachable, 
and DCE runs after DI, so DI doesn't know it is unreachable.  Fix this by adding a trivial
reachability check before emitting a diagnostic. 

This isn't a wholesome solution though, as certain infinite loops and other scenarios that
rely on constant folding won't be handled properly.  If anyone runs into this, we could consider
moving constant prop and DCE earlier, though that comes with its own tradeoffs.


Swift SVN r16898
2014-04-26 23:39:00 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Chris Lattner
3b29fb68a8 fit in 80 columns and format more nicely :)
Swift SVN r15803
2014-04-02 16:22:45 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6051a5e9a4 improve the QoI of DI's diagnostics when calling a method or accessing a computed
property in a base class before calling super.init.  This is a nice improvement, 
and also avoids regressing on QoI when a patch I'm working on finally lands.


Swift SVN r15379
2014-03-23 05:51:41 +00:00
Chris Lattner
001c1890e5 put all the SIL*Transform classes in anonymous namespaces, there is
no need for their symbols to be exported out of their implementation
file.


Swift SVN r14714
2014-03-06 01:49:53 +00:00
Chris Lattner
7baac64e94 fix rdar://16119509 - <unknown>:0: error: super.init called multiple times in initializer
This is a problem whereby the parallel bitvector dataflow stuff in DI was
incorrectly caching speculated results in cycles.  In principle, this algorithm
should be reworked to use standard oldschool RPO bitwise dataflow algorithms, but
this patch is a minimal fix and the performance of this code is unlikely to be an issue
anyway.


Swift SVN r14322
2014-02-24 23:23:22 +00:00
Joe Groff
b19cfb27ea Drop the context generic params from SILFunctionType.
SILFunctionType is now 100% context free!

Swift SVN r13775
2014-02-11 04:21:20 +00:00
Joe Groff
481fbb7b91 Drop the non-interface types from SILFunctionType.
There are some straggling references to the context generic param list, but nothing uses the non-interface param or result types anymore!

Swift SVN r13725
2014-02-09 22:39:01 +00:00
Andrew Trick
0825258b80 SIL transforms should only invalidate when things change.
-sil-print-all shows a nice readable evolution now.

Oh yeah, and we don't unnecessarilly rerun passes.

Swift SVN r13677
2014-02-08 08:20:45 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Nadav Rotem
27a1a63134 Remove unneeded empty virtual destructors.
Swift SVN r13599
2014-02-06 22:24:33 +00:00
Nadav Rotem
1ef0d157ca PassManager: Inject the function/module into the Transformation.
Now the pass does not need to know about the pass manager. We also don't have
runOnFunction or runOnModule anymore because the trnasformation knows
which module it is processing. The Pass itself knows how to invalidate the
analysis, based on the injected pass manager that is internal to the
transformation.

Now our DCE transformation looks like this:

class DCE : public SILModuleTransform {
  void run() {
    performSILDeadCodeElimination(getModule());
    invalidateAnalysis(SILAnalysis::InvalidationKind::All);
  }
};





Swift SVN r13598
2014-02-06 22:11:21 +00:00
Nadav Rotem
99b075c32a Rename SILFunctionTrans -> SILFunctionTransform
Swift SVN r13536
2014-02-06 01:32:10 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00
Michael Gottesman
631f9326ab [PM] Change enum => enum class everywhere in the PM code. Additionally fix some typos.
Swift SVN r13507
2014-02-05 21:25:15 +00:00
Nadav Rotem
1df8e93bbb Convert the diagnostic methods into passes.
Swift SVN r13503
2014-02-05 20:30:49 +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
Joe Groff
1f5fd1366c DefiniteInit: Assert that DI doesn't mess with copy_addrs that are already [initialization].
We should only be applying the [initialization] attribute to ambivalent copy_addrs from raw SIL.

Swift SVN r13187
2014-01-31 00:31:12 +00:00
Nadav Rotem
a07aed9d1f Change errs() -> dbgs() in a few files.
Swift SVN r12572
2014-01-20 06:36:50 +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
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +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
22545ffe1f Stop treating escape points as definitions for liveness purposes. While it
is a cute microoptimization (given that escape points *must* be live at their
point in the CFG), it leads to worse diagnostic QoI.



Swift SVN r11985
2014-01-07 06:20:36 +00:00
Chris Lattner
95d05b6b2f emit a custom diagnostics from DI when some path forgets to call self.init
in a delegating initializer.


Swift SVN r11984
2014-01-07 06:13:38 +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
3a970678a1 implement definite initialization enforcement for delegating class
initializers.


Swift SVN r11980
2014-01-07 05:31:33 +00:00
Chris Lattner
40d8536d20 fix a nasty iterator invalidation problem exposed by a patch
Joe is working on.


Swift SVN r11820
2014-01-02 18:37:02 +00:00
Chris Lattner
6fc4d292d6 don't verify each function twice in DI anymore now that DI is stabilized.
If someone passes -debug to the compiler, we still do the check.


Swift SVN r11732
2013-12-30 06:44:33 +00:00
Chris Lattner
23564a20b8 special case a diagnostic to produce a more sensible message when using
Builtin.addressof on an uninitialized variable.   Before:

t.swift:12:26: error: variable 'self.z' captured by a closure before being initialized
    p = UnsafePointer<Y>(Builtin.addressof(&z))
                         ^

After:

t.swift:12:26: error: address of variable 'self.z' taken before it is initialized
    p = UnsafePointer<Y>(Builtin.addressof(&z))
                         ^

This resolves rdar://15699057.



Swift SVN r11482
2013-12-19 21:32:15 +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
7ee082c542 rework general accesses to self to be modeled as full loads, instead of as escapes,
and simplify some code.  The notable aspect of this change is that it improves 
diagnostics for method calls before super.init.



Swift SVN r11081
2013-12-10 17:51:09 +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
3c03c0b5e4 rework emitOptionalToRef to use an optional code sequence to get a null class
reference, eliminating the last thing that creates a SIL builtin zero.


Swift SVN r11051
2013-12-09 23:37:51 +00:00
Chris Lattner
7c64fc4a60 remove some dead code: this eliminates the scan of an initializer body
that attempted to detect whether there was an explicit init in the body.
DI takes care of this now.  It also removes the logic for generating code
to default init ivars.


Swift SVN r11044
2013-12-09 23:04:29 +00:00
Chris Lattner
18ae5c62fa Improve the diagnostic for root classes that fail to initialize something. The location
of this diagnostic still doesn't make sense (pointing the the { of the function) but that
is tracked by rdar://15581664.

t.swift:4:3: error: instance variable 'self.x' not initialized at end of initializer
  init() {
  ^




Swift SVN r11042
2013-12-09 22:27:21 +00:00
Chris Lattner
99a3e68b32 don't emit a bogus "variable defined here" diagnostic for 'self'
related diagnostics.


Swift SVN r11037
2013-12-09 21:51:25 +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
0566ebd40b Fix a bug in in our tuple-element dataflow propagation, where
global "partial liveness" would overwrite local "always live"ness.
Always liveness on a local level always makes a value live-out,
even if it is partially live in.


Swift SVN r11005
2013-12-09 05:44:09 +00:00
Chris Lattner
aed29b4e92 When r10841 turned on DI for struct init methods, it started SILGen generating
new mark_unitialized instructions.  These defeated the alloc_box to stack promotion
pass, so everything ended up on the heap, leading to really terrible performance.
This updates things to understand mark_uninitialized, allowing us to promote them.

This fixes rdar://15607469.


Swift SVN r10985
2013-12-07 23:38:09 +00:00
Michael Gottesman
4379283013 Remove inclusion of SILPasses/Passes.h into Subsystems.h and update all relevant files.
Swift SVN r10880
2013-12-05 19:58:21 +00:00
Chris Lattner
15be357ee1 when DI is reporting an error about a multi-element access,
indicate the first element that is undefined, not the first
element being accessed.  In the example, passing the tuple
inout uses both elements, but the first element is initialized,
so we should complain about t2.1 being uninitialized, not t2.0


Swift SVN r10822
2013-12-05 00:01:21 +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
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