Commit Graph

396 Commits

Author SHA1 Message Date
Joe Groff
fc4ecc92c7 SILGen: Don't box 'let' bindings inside 'switch' patterns.
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
2014-01-24 05:33:14 +00:00
Chris Lattner
84f9919016 introduce a SGF::emitRValueAsSingleValue helper function to wrap a common
and repetitive pattern.


Swift SVN r12808
2014-01-22 22:51:55 +00:00
Chris Lattner
63784ca41c remove the ManagedValue::Unmanaged marker, lets just use ManagedValue::forUnmanaged()
instead, which is shorter.  It is better to have one way to do things than two.


Swift SVN r12710
2014-01-22 06:26:34 +00:00
Joe Groff
81759cde52 SILGen: Strip non-semantic pattern nodes before dispatching.
Don't crash when sugary pattern nodes like Paren and Var get mixed and we try to cast subpatterns to the expected semantic pattern type.

Swift SVN r12674
2014-01-21 23:56:11 +00:00
Chris Lattner
d4594b77a5 Switch the nominal type pattern matching destructuring logic to
use the new RValue emission infrastructure instead of duplicating
some of it.  This enables the use of computed properties, fixing
<rdar://problem/15859432> SILGen abort when pattern matching on computed property

and eliminates some code that future changes would otherwise have to 
worry about.  

There are other problems with this code (e.g. see rdar://15863069), so I think 
we should disable the feature until it has time to really bake, but this is still
useful progress in the right direction and is a net reduction of code.



Swift SVN r12618
2014-01-20 23:29:42 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
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
2014-01-20 18:16:30 +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
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
261b21a10f various random cleanups to pattern processing stuff, NFC.
Swift SVN r12335
2014-01-15 19:12:45 +00:00
Joe Groff
ee85fb341a SILGen: Strip non-semantic pattern nodes before dispatching.
Fixes a crash when redundant parens wrapped a subpattern.

Swift SVN r12164
2014-01-10 23:15:32 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
Joe Groff
d3c0532205 SILGen: Reabstract enum payloads matched out by a 'switch' pattern.
Swift SVN r11696
2013-12-28 16:42:06 +00:00
Joe Groff
af9d91f2a9 SIL: Use 'SILType::fieldType' consistently instead of 'Type::getTypeOfMember'.
Centralizes the somewhat tricky dance to get a property type at the right abstraction level for the containing type. NFC.

Swift SVN r11491
2013-12-19 23:43:33 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
c1f34728e2 SILGen: Release re-abstracted value on 'default' branch of 'is T' pattern match.
Now that the stack allocation for an abstraction change is in a predictable place, we can cleanly deallocate it at the end of dispatch. Fixes <rdar://14835992>.

Swift SVN r10024
2013-11-07 16:27:49 +00:00
Joe Groff
18dd9335f3 SILGen: Factor abstraction change from branch in checked cast emission.
<rdar://problem/14835992> happens because, when we emitted a chain of checked casts for 'is' patterns in a 'switch', we would emit abstraction changes for each individual cast that required them. This is both redundant and makes cleaning up messier, because the number of branches with different stack heights increases. Instead, let's emit one abstraction change up front for all of the casts. No functionality change yet, but this is a step on the way to fixing <rdar://problem/14835992>.

Swift SVN r9921
2013-11-04 17:44:03 +00:00
Joe Groff
5744b57e8f SILGen: Handle an 'is T' pattern in a switch that introduces concrete-to-archetype casts.
When destructuring the 'is Int' pattern in:

func f<T, U>(t: T, u: U) {
  switch t {
    case is Int: println("Int")
    case is U: println("U")
    case _: println("other")
  }
}

there is the possibility that 'U' is 'Int', so it needs to be included in the specialization on 'is Int' using a concrete-to-archetype cast from Int to U. This wasn't handled correctly and we tried to do a super-to-archetype class cast instead, which blew up because 'Int' is neither a class nor statically related to U. Fixes <rdar://problem/14826416>.

Swift SVN r9869
2013-11-01 15:23:46 +00:00
Joe Groff
d3fd8292ff SILGenPattern: Let 'is T' and 'U(x:, y:)' patterns coexist.
When destructuring a NominalTypePattern, keep the aggregate around as an extra column of the destructured matrix so we can still match non-NominalTypePatterns against it. This handles 'is T' patterns on the same type, and should also handle other fancy high-level patterns we might add in the future.

Swift SVN r9538
2013-10-21 15:25:01 +00:00
Joe Groff
4bc267f716 SILGenPattern: Don't drop preceding wildcard rows when specializing a column.
Other columns may have significant patterns.

Swift SVN r9537
2013-10-21 15:24:57 +00:00
Joe Groff
4872a6fc7b SILGen: Use "constructor prefix" heuristic to optimize switch decision trees.
According to Maranget this heuristic gave the best results over a large corpus of Ocaml code. Luckily, it's really easy to implement too—just count through each column until we hit a wildcard, and specialize on the column with the most non-wildcard pattern nodes before a wildcard.

Swift SVN r9533
2013-10-21 03:57:32 +00:00
Joe Groff
98a78306fc SILGen: Run cleanups emitted as a part of pattern dispatch.
Fixes the issue with address-only struct patterns.

Swift SVN r9527
2013-10-20 17:16:27 +00:00
Joe Groff
6760c8dce7 SILGen: Implement NominalTypePatterns for stored properties.
If we see nominal type patterns in a switch column, grab all of the needed properties for all of the patterns when destructuring so we only need to do it once. For now, only handle stored properties. John's in the middle of reinventing the world for SIL functions and I don't want to create merge problems.

There's an issue handling the temporary allocation for address-only properties that I don't have time to address right now but will fix soon.

Swift SVN r9520
2013-10-20 05:20:08 +00:00
Joe Groff
4d8d79712c SILGenPattern: Add debug output.
Give ClauseMatrix a dump method that gives nice columnar output of the current decision matrix, and add DEBUG output to emitSwitchStmt so there's more visibility into decision tree generation.

Swift SVN r9519
2013-10-20 05:20:03 +00:00
Joe Groff
a288f160ba SILGenPattern: Refactor clause matrix specialization to filter pattern set by each pattern.
No intended functionality change yet. For now this gives a slightly better constant factor to the O(n^2) linear scan for subsumed pattern nodes. Later on, for nominal type patterns, this will also give us an opportunity to collect the properties from all the equivalent patterns into one NominalTypePattern specialization.

Swift SVN r9297
2013-10-13 22:57:09 +00:00
Joe Groff
235f4e5017 SILGenPattern: Kill redundant helper function.
Swift SVN r8951
2013-10-07 02:18:17 +00:00
Joe Groff
9909ba275c SILGenPattern: Handle subsumption and orthogonality of superclasses in 'is' patterns.
Now that we can ask about superclasses outside of the type-checker, we can consider superclass relationships when pattern-matching 'is' patterns, producing better decision trees when a subclass checked is subsumed by a superclass check, a subclass check renders a superclass check redundant, or two classes or orthogonal and a check of one rules out the other.

Swift SVN r8769
2013-09-29 18:23:52 +00:00
Joe Groff
a2672e9313 SIL: Turn conditional checked casts into a branch instruction.
Replace the existing suite of checked cast instructions with:

- unconditional_checked_cast, which performs an unconditional cast that aborts on failure (like the former downcast unconditional); and
- checked_cast_br, which performs a conditional pass and branches on whether the cast succeeds, passing the result to the true branch as an argument.

Both instructions take a CheckedCastKind that discriminates the different casting modes formerly discriminated by instruction type. This eliminates a source of null references in SIL and eliminates null SIL addresses completely.

Swift SVN r8696
2013-09-26 18:24:44 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
John McCall
6f32a8464f Add a convenient method to create a new basic block.
Swift SVN r8326
2013-09-17 07:22:23 +00:00
Joe Groff
74aa05b724 SILGen: Handle () and arg-less union cases consistently in the face of substitutions.
Swift SVN r8259
2013-09-15 01:15:21 +00:00
Joe Groff
fcd8204042 SILGen: Substitute union element types when emitting union pattern matches.
Swift SVN r8257
2013-09-15 01:15:09 +00:00
Anna Zaks
a1f21b20d7 [SIL] Add a location to destructive_switch_union_addr + a couple more.
Swift SVN r7926
2013-09-05 00:01:56 +00:00
Anna Zaks
115a15830b [SIL] Replace empty locations with valid locations in tuple exploding/encoding and pattern gen code.
Tuple exploding happens during RValue construction, so changed the constructor and addElement() method to take the location parameter. The imploding happens on RValue::forwardAsSingleValue and RValue::getAsSingleValue(). Make sure the right SIL locations are passed to all of these

Also, added some missing locations in pattern matching code.

Swift SVN r7916
2013-09-04 21:57:52 +00:00
Joe Groff
1b07a4ed2b SILGenPattern: Spot fix. No functionality change.
Swift SVN r7829
2013-08-31 04:31:00 +00:00
Joe Groff
cfa8cb7518 SILGenPattern: Support address-only unions.
Switch on address-only unions using the destructive_switch_union_addr instruction. This is safe to do now thanks to r7812: The destructured value will now naturally be cleaned up instead of the invalidated union.

Swift SVN r7821
2013-08-30 23:50:34 +00:00
Joe Groff
3358955042 SILGenPattern: Destroy destructured subject rvalue before entering cases.
Before, we left the switch subject rvalue to be cleaned up at the close of the switch's scope. This is a bit wasteful because it keeps the rvalue live long after it's actually needed, and destroying the subject potentially requires replicating a bunch of destructuring we already do in the course of the pattern match. This patch changes things so that, just prior to entering a case, we clean up the destructured occurrence vector we have at the point of entering the case, which should be equivalent to but potentially more efficient than destroying the original subject rvalue.

Swift SVN r7814
2013-08-30 23:28:38 +00:00
Joe Groff
1e51c4992b SILGenPattern: Tidy up some weedy logic in ClauseRow::emitDispatch.
Swift SVN r7803
2013-08-30 21:42:26 +00:00
Joe Groff
e45792c084 SILGenPattern: Simplify tracking of ExprPattern guards.
We no longer need the separate pattern-to-value mapping in ClauseMatrix rows; that's handled by pattern variable binding now.

Swift SVN r7795
2013-08-30 19:12:48 +00:00
Anna Zaks
8f3c9002d0 [SIL] Add cleanup locations to SIL instructions.
I've decided to keep only the location of the scope AST node that corresponds to the cleanup. (Currently, there is no user that needs the originator expression, which caused the cleanup. So keeping things simple.)

Added the cleanup location to the Scope and JumpDest classes, which gets assigned on construction of those. The Scope's and JumpDest locations are used when we emit the cleanup instructions.

We now give better location info for 2 existing tests for definitive initialization.

(+ Rather sparse testing of all this.)

Swift SVN r7764
2013-08-29 23:14:22 +00:00
Joe Groff
202f65bb41 SILGen: Warm over some stale comments in SILGenPattern.
Swift SVN r7762
2013-08-29 23:08:12 +00:00
John McCall
02ce2fe199 Make is_nonnull produce a primitive Builtin.Int1 instead
of Bool, and use swift._getBool to turn that into a Bool
as necessary.

Swift SVN r7720
2013-08-29 06:47:15 +00:00
Dmitri Hrybenko
f7ab5bc7eb Change oneof -> union in a comment
Swift SVN r7662
2013-08-28 03:49:38 +00:00
Anna Zaks
b67f3c3552 [SIL] Use the ReturnLocation/ImplicitReturnLocation instead of generic SILLocations.
We mark the branch instructions leading into single epilog code with ReturnLocation/ImplicitReturnLocation. If SIL Gen simplifies the code and merges the code representing the return into the epilog block, the terminator of the epilog block (the ReturnInst) will have the return location info on it. Otherwise, the ReturnInst has the RegularLocation, which represents the enclosing FunctionExpr or Constructor/Destructor Decls.
(I've discussed dropping the optimization from SILGen, and keeping the epilog code canonical, with Adrian; but he said that there might not be any wins in doing so, so keeping it for now.)

Added AutoGeneratedLocation to represent segments of code generated by SILGen. This will be used for thunks and other auto-generated segments.

Swift SVN r7634
2013-08-27 22:16:24 +00:00
Adrian Prantl
a1c6b653ad Move DebugScopeStack from SILBuilder to SILGenFunction, using the swift new
InsertedInstrs facility.
No functionality change intended.

Swift SVN r7520
2013-08-23 20:11:44 +00:00
Stephen Lin
8d90466523 Reorganize SIL source tree: move lib/SIL/SILGen -> lib/SILGen, move lib/SIL/Passes -> lib/SILPasses, add lib/SILPasses/Utils
Swift SVN r7246
2013-08-14 23:47:29 +00:00