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
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
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
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
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
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
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
<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
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
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
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
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
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
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
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
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
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
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
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
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
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