Commit Graph

9332 Commits

Author SHA1 Message Date
Chris Lattner
ab4048bac2 make the -enable-definite-init staging option enable the new "assign" insertion
logic in SILGen.  This exposes a bug in the definite analysis pass handling 
aggregates, which is why the testcase is changing.  Given that noone is using
this yet, I'm just changing the test, I'll fix it next.


Swift SVN r7187
2013-08-12 23:59:12 +00:00
Joe Groff
a093f2ad4c SILGen: Choose pattern specialization branches by subsumption rather than orthogonality.
In the case of 'is' patterns involving classes or archetype, we need to include other type casts in the specialization based on whether the archetype or class could still dynamically match the specialized type. We were filtering casts based on orthogonality, which is wrong; we really need to filter based on whether the patterns have nonexhaustive overlap.

Swift SVN r7181
2013-08-12 22:28:58 +00:00
Joe Groff
c5c8eccee0 SILGen: Actually set the new cast kind on specialized IsaPatterns.
When we have potentially overlapping 'is' patterns, such as multiple class or archetype patterns, and we specialize the decision tree on an 'is' pattern, we derive new 'is' patterns relative to the specialized type, but we weren't actually setting the correct kind for those new patterns. Oops. Caught by Ted.

Swift SVN r7180
2013-08-12 22:28:55 +00:00
Chris Lattner
67affb462a Introduce a new concept into TypeLowering: the idea of "not knowing" whether an
assignment is an initialization or not.  This will be used by SILGen shortly to
emit the right operation when it doesn't know what sort of an assignment it is
dealing with (which is a flow sensitive property).  The definite initialization
pass will then "do the right thing".


Swift SVN r7172
2013-08-12 20:11:12 +00:00
Chris Lattner
4ba60359cf implement definite initialization checking for unowned pointers, which are modeled
with the assign instruction.


Swift SVN r7171
2013-08-12 19:55:16 +00:00
Stephen Lin
5fc7966675 Add [force_inline] to SIL apply instruction; kill FunctionInst abstract value type
Swift SVN r7163
2013-08-12 17:33:37 +00:00
Chris Lattner
48e4fbae0a Implement definite initialization support for load_weak and store_weak,
includes testcase for store_weak sil parsing.


Swift SVN r7162
2013-08-12 17:33:12 +00:00
Chris Lattner
b25af92552 change the StoreWeak "initialization" bit and accessors to follow the naming
convention of the CopyAddrInst methods.


Swift SVN r7161
2013-08-12 17:30:02 +00:00
Chris Lattner
2ab06da576 Teach memory promotion to handle "assign"ment analysis of address-only types,
turning "assign" copy_addrs into initialization when necessary.


Swift SVN r7158
2013-08-12 16:37:33 +00:00
Chris Lattner
f3a96575f6 teach the memory promotion pass to properly handle assign instructions,
turning them into initializations or stores depending on what they are,
and diagnosing cases where an assignment has different behavior depending
on the path to the instruction.


Swift SVN r7156
2013-08-12 16:11:13 +00:00
Chris Lattner
c8f01a0bf3 Introduce a new SIL "assign" instruction to represent assignments in SIL when
SILGen doesn't know whether they are initializations or stores.


Swift SVN r7146
2013-08-12 14:24:52 +00:00
Chris Lattner
242f6303dd significantly improve the QoI of the definitive initialization check by printing
the variable being used and the access path to the uninitialized field (if relevant).

For example, for:

func test3() {
  var s2 : ((Int, Int), (), SomeStruct, Int)
  s2.0 = (1,2)
  s2.2.x = 1
  s2.2.z = 1
  s2.3 = 17337
  noop(s2)
}

we now produce:

t.swift:12:8: error: variable 's2.2.y' used before being initialized
  noop(s2)
       ^
t.swift:7:7: note: variable defined here
  var s2 : ((Int, Int), (), SomeStruct, Int)
      ^




Swift SVN r7140
2013-08-10 22:03:17 +00:00
Chris Lattner
0fd72ac805 teach mem promotion about InitializeVarInst, allowing it to handle struct ctors.
Add tests for various struct field sensitivity cases, which depend on this.


Swift SVN r7138
2013-08-10 21:11:38 +00:00
Chris Lattner
f825c0d6a6 hack up sema and silgen to respect the -enable-definite-init flag. This
lets us write our first pure swift test for definite initialization.

Despite this being a SIL pass that implements this, writing tests as .swift
files makes sense, given that this is intended to be a stable diagnostic pass.
It is basically like writing a sema test.



Swift SVN r7136
2013-08-10 20:50:38 +00:00
Chris Lattner
86997d3b2f fix a crash when promoting a singular subelement of a struct or tuple
where a larger wrapper is also used.   This was the last crash of mempromotion
on the stdlib (not that it is particularly useful yet).


Swift SVN r7134
2013-08-10 20:26:09 +00:00
Chris Lattner
981976e0d8 fix a crash that occurred when we would mix aggregate and scalar element load promotions,
leading to a dangling pointer dereference.


Swift SVN r7132
2013-08-10 19:09:03 +00:00
Chris Lattner
37726d1f95 teach memory promotion about properties, which are not a structural field in a struct.
Swift SVN r7131
2013-08-10 18:54:13 +00:00
Chris Lattner
8f6f8f318c cache computation of NumElements, turning an exponential algorithm into a linear one.
Swift SVN r7130
2013-08-10 18:27:38 +00:00
Dmitri Hrybenko
efd688dcd9 Now findBufferContainingLoc() can not fail, so store Buffer IDs in unsigned
variables.


Swift SVN r7121
2013-08-10 02:12:59 +00:00
Dmitri Hrybenko
13070a31bd SourceManager: make findBufferContainingLoc() always succeed.
Every valid source location corresponds to a source buffer.  There should be no
cases where we create a source location for a random string.  Thus,
findBufferContainingLoc() always succeeds.


Swift SVN r7120
2013-08-10 01:48:04 +00:00
Dmitri Hrybenko
8f7a437d44 Wrap a few functions from LLVM SourceMgr in preparation of making
SourceLoc::Value private


Swift SVN r7114
2013-08-09 23:15:59 +00:00
Manman Ren
538a4c118c SIL Parser: parse specialize.
Modify SILPrinter to print the generic function type for specialize.

TODO: the testing case needs uniquing of PolymorphicFunctionType. Right now,
we will get a type mismatch between two copies of the same
PolymorphicFunctionType.


Swift SVN r7097
2013-08-09 20:27:24 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Manman Ren
591410ea23 SIL Parser: parse init_existential, init_existential_ref, deinit_existential.
TODO: Conformances are currently not included in SIL.rst for init_existential
or init_existential_ref, but they exist in InitExistentialInst and
InitExistentialRefInst.


Swift SVN r7076
2013-08-09 01:10:10 +00:00
Anna Zaks
4799118038 [SIL Verifier] Check that there is a unique epilog block
If this is not an invariant on SIL, but only on the output of SILGen,
I'll add an option to the verifier to only check this after SILGen.

Swift SVN r7068
2013-08-08 23:59:09 +00:00
Anna Zaks
b52166a2f3 [SILGen] Propagate location info through InitializeTupleValues
The test displays "<invalid loc>" even though the SIL location is
non-null because the corresponding AST node (Expr) does not have a location.

Swift SVN r7066
2013-08-08 23:59:08 +00:00
Ted Kremenek
a32d8e357a Add basic color output to SILPrinter for terminals that support color.
Current the following is colorized:
- basic block labels
- types
- SSA values

Swift SVN r7044
2013-08-08 15:05:51 +00:00
John McCall
810f5dde95 Kill apparent debugging code.
Swift SVN r7042
2013-08-08 04:04:53 +00:00
John McCall
14cb7001b3 Implement basic support for [weak].
Swift SVN r7041
2013-08-08 04:04:51 +00:00
Chris Lattner
c122e15c5e Fix handling of partial_apply: byref is *always* a capture for partial_apply,
since it's stated purpose in life is to build a closure around its argument
values.

Teach definite assignment that escape points for closures require their value
to be initialized.  Use this to produce a diagnostic about closures over values
that are not yet initialized.


Swift SVN r7035
2013-08-08 01:05:34 +00:00
Anna Zaks
a5b45fdd1f [SILGen] Add location info to function_ref instruction.
Swift SVN r7034
2013-08-08 01:03:01 +00:00
Chris Lattner
5dde862742 Teach memory promotion about copy_addr, enableing definite initialization
checks for address only types.


Swift SVN r7029
2013-08-08 00:12:40 +00:00
Chris Lattner
c3708c283f Enhance the definite initialization checker to be field sensitive for
structs and the properly support generic structs as well.


Swift SVN r7011
2013-08-07 22:43:54 +00:00
Chris Lattner
d9791c3f91 teach memory promotion to model tuple elements precisely,
this allows us to diagnose things like:

 var x : (Int, Int)
 foo(&x.1)




Swift SVN r7008
2013-08-07 22:18:59 +00:00
Chris Lattner
a8059b387b fix indirect return to be modeled as a store, not a byref use.
Swift SVN r7006
2013-08-07 21:55:08 +00:00
Chris Lattner
20c5ee3867 Calls passing a variable byref demand that the variable is initialized.
Diagnose errors where they aren't.


Swift SVN r7004
2013-08-07 21:40:32 +00:00
Chris Lattner
214983b745 add a "Variable declared here" note to the use-of-uninitialized variable check.
Convert the byref mem promotion check to be an alloc_box, so that mempromotion
actually considers it.


Swift SVN r7003
2013-08-07 21:34:42 +00:00
Anna Zaks
1659de21a1 [SILGen] Add location info to branches generated from control flow ASTNodes.
This is what the current behavior is, it can change if we find this info
insufficient.

Branches formed from control flow due to IfStmt, ForLoop and other statements and
expressions will have the statement as the location. With one exception - if the
block ends with a return statement, we have the return statement as the location.
Currently, this preserves the location of the original return; before merging into
a single return block.

The instructions building the conditions of the control flow ASTNodes, have the
condition as the location. (I've added test for this, but this was already working
as expected.)

Swift SVN r6992
2013-08-07 18:39:49 +00:00
Anna Zaks
aaa4b2c332 [SIL Printer] Add optional source location printing.
Added a -v(verbose) option to swift that will trigger verbose printing in SIL
Printer. SIL Printer will print the location info only in the verbose mode.

Here is the example of the format - only the line and colon are displayed for
brevity:

%24 = apply %13(%22) : $[cc(method), thin] ((), [byref] Bool) -> Builtin.Int1 // user: %26 line:46:10

(This will be used to test the validity of SILLocation info.)

Swift SVN r6991
2013-08-07 18:39:48 +00:00
Chris Lattner
b478def6b1 Extend the SIL parser to add source locations to all parsed instructions.
Based on this, .sil files can now use -verify mode.  Switch memory_promotion.sil
to use it.


Swift SVN r6990
2013-08-07 18:37:25 +00:00
Chris Lattner
e2611273fc extend SILLocation to be able to store locations in SIL files.
This doubles SILLocation to being two words, since SourceLocations
can't be dumped into a PointerUnion, but it is due for a redesign someday
anyway, so I'm not going to worry about it.


Swift SVN r6989
2013-08-07 18:36:45 +00:00
Chris Lattner
615079a610 Diagnose (trivial) use before definition errors. There is a bunch of work to make
diagnostics tests on .sil files make sense.


Swift SVN r6981
2013-08-07 16:53:15 +00:00
Chris Lattner
26fda44bc4 make SILLocation tolerate null locations, which is what it gets when parsing .sil files.
Swift SVN r6980
2013-08-07 16:50:45 +00:00
Chris Lattner
b8b806ad71 use 'static' for functions instead of using anonymous namespaces,
following the llvm conventions.  No functionality change.


Swift SVN r6978
2013-08-07 16:35:02 +00:00
Chris Lattner
fcfab40e63 Build out a lot more of memory promotion for loads. We now actually
do promote local stores, catching up to the stack-to-ssa pass in that
regard.


Swift SVN r6977
2013-08-07 16:24:15 +00:00
John McCall
b66567ea92 Be sure to check for uses of any result of an instruction
before declaring that it has only one use.

Swift SVN r6974
2013-08-07 03:21:12 +00:00
Chris Lattner
68a86e1b48 restructure this around a new ElementPromotion class to centralize the per-element
promotion logic.


Swift SVN r6970
2013-08-07 00:38:12 +00:00
Chris Lattner
89d688d896 continued progress on the uber memory promotion / definitive initialization pass.
This is still not doing anything useful, but before I make a turn in how it is
structured, a checkpoint is useful.


Swift SVN r6969
2013-08-07 00:25:09 +00:00
John McCall
e9b913fb5b Remove LocalStorageType, make it a kind of SILType.
Swift SVN r6968
2013-08-07 00:22:26 +00:00