Commit Graph

127 Commits

Author SHA1 Message Date
Chris Lattner
cc3f173040 remove variadics, default args etc, from tuple patterns, and simplify
the Pattern::clone interface now that the complexity isn't needed.
This also removes support for serializing this state.
2015-12-31 20:12:12 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
practicalswift
8b6c9b6768 Fix typo: artifical → artificial 2015-12-14 00:11:13 +01:00
Slava Pestov
2874a6d8df SILGen: Switches over resilient enums must include a default case
In the future, we might want two defaults, one for cases that were
available at the time the client code was compiled, and another
for new cases.
2015-11-17 10:02:10 -08:00
Dmitri Hrybenko
130e79f2fa KnownIdentifiers: avoid generating 'Id__value', which is a reserved identifier
Swift SVN r32113
2015-09-21 17:28:54 +00:00
Dmitri Hrybenko
4375a463a7 stdlib: rename Int**.value and Float**.value to _value per naming convention
rdar://21357661

Swift SVN r32096
2015-09-20 00:01:13 +00:00
Slava Pestov
48fe3e1c9b SILGen: Fix static computed properties in protocol extensions
We need to keep the AST formal type of the base around when building up
lvalues.

When the getter or setter involves an accessor call, we would use the
lowered type of the self argument to form the call. However, it might be
at the wrong level of abstraction, causing a @thin -vs- @thick metatype
mismatch. Using the formal type instead allows SILGenApply logic to emit
a thin to thick metatype conversion if necessary.

Fixes <rdar://problem/21358641>.

Swift SVN r30913
2015-08-01 07:21:25 +00:00
Chris Lattner
c114dc9abc generalize ASTWalker to allow clients to visit TypeLocs, not just TypeReprs.
NFC, since nothing is using this functionality yet.


Swift SVN r29983
2015-07-08 18:46:36 +00:00
Joe Groff
729e599ffc SILGen: Project boxed payloads when switching indirect enums.
And fix some bugs in the switch implementation I ran into on the way:

- Make getManagedSubobject(CopyOnSuccess) really produce a CopyOnSuccess ConsumableManagedValue;
- Avoid invalidating address-only enums when they can't be unconditionally taken by copying the enum before projecting it. Ideally there'd be a copy_enum_data_addr instruction to do this more efficiently.

Swift SVN r29817
2015-06-30 23:10:38 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Joe Groff
515983bcfa SILGen: Route the cleanup state management through the failure chain of IsPatterns.
Failure paths need to maintain a consistent view of the cleanup state, so we can't just branch to a common exit point and fixup the cleanup state later. Fixes rdar://problem/21087371.

Swift SVN r29287
2015-06-04 01:03:36 +00:00
Joe Groff
b4224acafb SILGen: Only specialize 'is' patterns one type at a time.
This simplifies the cleanup juggling we have to do, making it easier to get to the fix for rdar://problem/21087371. NFC yet (since emitting casts one at a time is equivalent to pretending we emit them simultaneously like we were).

Swift SVN r29277
2015-06-03 23:07:48 +00:00
Joe Groff
9c0695875e SIL: Casts that may be to NSError must use indirect cast instructions.
checked_cast_br promises to maintain RC identity, but a cast from an ErrorType-conforming class to NSError may change the RC identity by bridging. Make sure that potential class-to-NSError casts go through the indirect cast entry points for now. The runtime implementation still needs to be fixed to handle the class-to-NSError case, but this is part of rdar://problem/21116814.

Swift SVN r29089
2015-05-27 22:50:37 +00:00
Chris Lattner
4b4f909d1a Several tangled up changes:
- Enable 'catch is NSError' and 'catch let e as NSError {' patterns to
   a) work, and b) be considered to be exhaustive catches.  This enables
   people to catch an error and *use* it as an NSError directly, instead
   of having to do boiler-platey cases.  This is particularly important
   for the migrator.

 - Do not warn about non-noop coersion casts (like "_ as NSError" when
   matching an ErrorType), since they provide useful type adjustment to
   the subpattern.  Still warn on noop ones.

 - Simplify CatchStmt::isSyntacticallyExhaustive to use 
   Pattern::isRefutablePattern.  Add a FIXME, because the parser is guiding
   closure "throws" inference before the pattern is type checked, which means
   that it is incorrect (but only in subtle cases).

 - When diagnosing pointless 'as' patterns like:

  switch 4 {
  case _ as Int: break 

say "'as' test is always true" instead of "'is' test is always true".




Swift SVN r28774
2015-05-19 17:32:32 +00:00
Slava Pestov
cbbde4739e SILGen: remove dead diagnostics for error handling
Looks like Sema is checking all of this stuff now. NFC

Swift SVN r28571
2015-05-14 17:22:44 +00:00
Chris Lattner
935e95080c minor cleanups.
Swift SVN r27566
2015-04-22 06:04:35 +00:00
Chris Lattner
06ad473cab Switch if/let SILGen to use the same codepath as let/else, instead of using the
ClauseMatrix stuff.



Swift SVN r27565
2015-04-22 05:49:57 +00:00
Chris Lattner
e8dfbd8ed8 remove dead parameter from SILGenFunction::emitInitializationForVarDecl, NFC.
Swift SVN r27465
2015-04-19 05:28:42 +00:00
Chris Lattner
7185252a2b remove dead argument to canUseScalarCheckedCastInstructions.
Swift SVN r27455
2015-04-18 22:12:50 +00:00
Chris Lattner
6dc6ecddf3 factor some code for cleanup emission (which avoids creating an empty block
in a common case) out into CleanupManager, where it can be used by lots of 
clients.  NFC.


Swift SVN r27044
2015-04-06 21:40:43 +00:00
Chris Lattner
fb87132f72 significantly simplify the BoolPattern AST representation and logic surrounding it.
The SILGen code could be further simplified, but this is progress at least.  NFC.


Swift SVN r27011
2015-04-05 04:52:38 +00:00
Chris Lattner
95b7b4d5e4 rename CleanupLocation::getCleanupLocation -> CleanupLocation::get, NFC.
Swift SVN r26994
2015-04-04 22:56:01 +00:00
Chris Lattner
dbdc0a1801 remove dead code.
Swift SVN r26990
2015-04-04 21:39:45 +00:00
Chris Lattner
8a07a85a91 Progress towards let/else:
- Implement SILGen for conditional multi-pattern PBD's.
 - Have the type checker check where clauses on PBDs.
 - Change the AST to represent complex if/let PBD's with
   composed PBDs instead of breaking them down. For example, 
   represent:
     if let x? = foo(), y? = bar() where x == y {
   as a single PBD in a StmtCondition instead of representing
   it as three entries in the condition.

The later change is good for AST/source fidelity as well as providing
a cheap way to exercise all the logic I'm building.



Swift SVN r26959
2015-04-03 22:46:34 +00:00
Chris Lattner
60560640b6 introduce a new common base class between if and while statements:
they are both labeled and have conditions.  NFC.


Swift SVN r26933
2015-04-03 05:44:08 +00:00
Chris Lattner
8d78b9d29e fix <rdar://problem/20410102> SILGen overrelease in pattern match
... a miscompile producing an overrelease that I noticed while fixing rdar://20364869.


Swift SVN r26931
2015-04-03 04:13:27 +00:00
Chris Lattner
4c3857bcad rename emitIsaDispatch -> emitIsDispatch since they are 'is' patterns, not 'isa' patterns anymore, NFC.
Swift SVN r26921
2015-04-03 01:11:58 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Chris Lattner
40242d323d rework PatternMatchEmission::emitSharedCaseBlocks to avoid emitting empty blocks
(containing just an uncond branch) when a shared block isn't actually shared.

This is a revised version of r26676 that makes sure to emit the cleanups for a
case pattern as soon as possible.  Extending the lifetime of the case value
across the body of the switch caused extra copies of COW types.


Swift SVN r26685
2015-03-28 22:12:49 +00:00
Arnold Schwaighofer
74df04c957 Revert "now that SILGen has a notion of whether a case can be fallthrough'd into, use this to avoid emitting empty basic blocks in case statements all over the place."
The incremental bot started failing the validation test suite.

This reverts commit r26676.

rdar://20337695

Swift SVN r26682
2015-03-28 14:36:20 +00:00
Chris Lattner
7c189eb5bb improve diagnostic and add test for unreachable default.
Swift SVN r26678
2015-03-28 05:45:36 +00:00
Chris Lattner
964078efae improve static typing of ClauseRow::ClientData, NFC.
Swift SVN r26677
2015-03-28 05:26:23 +00:00
Chris Lattner
9da355878e now that SILGen has a notion of whether a case can be fallthrough'd into, use this to
avoid emitting empty basic blocks in case statements all over the place.


Swift SVN r26676
2015-03-28 05:02:46 +00:00
Chris Lattner
0b2312edfe diagnose unreachable cases in switches, fixing:
<rdar://problem/20253447> `case let Case` without bindings incorrectly matches other cases




Swift SVN r26675
2015-03-28 04:31:38 +00:00
Roman Levenstein
941e5b6a58 [patternmatch-silgen] Improve silken and diagnostics for switches on bools and tuples of bools.
This patch introduces a new kind of pattern for matching bool literals, i.e. true and false. Essentially, it is very similar to a pattern for matching enum elements, but simpler. Most of the code is just a boiler plate code copy/pasted from the code for enum element patterns. The only different thing is the emitBoolDispatch function, which emits a SIL code for matching bools.

With this patch, we don't get any false non-exhaustive switch diagnostics for switches on bools anymore. And we have a lot of radars complaining about it. For example rdar://16514545 and rdar://20130240.

Note, that this patch fixes the non-exhaustive switch diagnostics without changing the internal representation of bools. Implementing bool as an enum would have the same effect when it comes to these diagnostics and we would get this diagnostics fix for free, i.e. without any code committed here. But implementing bools-as-enums is an ongoing work and I'm investigating its performance implications. If we become confident that bool-as-enum does not have a negative impact on performance and decide to merge it, then we can revert this patch as it would not be necessary anymore. But if we decide to skip the enum-as-bool approach to its performance issues, then we would have at least fixed the false non-exhaustive diagnostics for bools by means of this patch.

Swift SVN r26650
2015-03-27 22:43:47 +00:00
John McCall
5d2f32bf83 Disallow trailing closures in catch patterns and
fix an assertion with rethrows out of non-exhaustive
catch statements.

Swift SVN r26470
2015-03-24 01:34:50 +00:00
John McCall
ee4aa14703 Stop reordering blocks in SILBuilder::emitBlock.
This change permits SILGen to make smarter decisions about
block placement by keeping related blocks together instead
of always inserting to the end to the function.  The
flipside is that SILGen needs to be somewhat careful to
create blocks in the right order.  Counter-intuitively,
that order is the reverse of the order in which the blocks
should be laid out, since blocks created later will be
inserted before blocks created earlier.  Note, however,
that this produces the right results for recursive
emission.

To that end, adjust a couple of places in SILGen to
create blocks in properly nested order.

All of the block-order differences in the tests seem
to be desirable; several of them even had confused
comments wondering how on earth a block got injected
where it did.

Also, fix the implementation of SILBuilder::moveBlockTo,
and fix a latent bug in epilogue emission where epilogBB
was erased from its parent (deleting it) and then
queried multiple times (!).

Swift SVN r26428
2015-03-23 06:38:20 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Chris Lattner
8962cd2665 eliminate an unneccesary intermediate std::vector, NFC.
Swift SVN r26144
2015-03-15 03:01:21 +00:00
Chris Lattner
d8cb56bb13 refactor ClauseRow's ctor to not take a CaseLabelItem, reducing impedence
mismatch with the if/let handling stuff.  NFC.


Swift SVN r26143
2015-03-15 02:57:30 +00:00
Chris Lattner
e2fe7704ad Reimplement emission of StmtCondition (e.g. if/let & while/let) to be
in terms of the pattern binding/emission facilities that are currently
used for switches.  They are more general (handling all patterns,
not hacked up just for optionals).

This leads to us producing better code for if/let bindings, because we 
don't alloc_stack a temporary and deal with memory for non-address-only
types (e.g. the common case of an optional pointer).  Instead, the code 
emits a select_enum{_addr} on the value.

While this changes the generated code in the compiler, there is no exposed
behavioral change to the developer.




Swift SVN r26142
2015-03-14 20:31:23 +00:00
Chris Lattner
5745300718 rename PatternMatchStack back to SwitchStack. I was too quick to rename it: it
is only for processing of fallthrough statements, which really do only apply to
switch.


Swift SVN r26127
2015-03-14 03:32:28 +00:00
Chris Lattner
a6d95e4630 Generalize some terminology in SILGenPattern to say "PatternMatch" instead
of "Switch" since this logic will be used by if/let and while/let pattern
matching in the near future.


Swift SVN r26126
2015-03-14 02:57:42 +00:00
Chris Lattner
5549775677 enhance silgen to treat OptionalSomePattern and EnumElementPattern as
"similar", avoiding false positive "not exhaustive" diagnostics on switches
like:

switch ... {
case let x?: break
case .None: break
}

Also, start using x? patterns in the stdlib more (review appreciated!), which 
is what shook this issue out.



Swift SVN r26004
2015-03-12 00:39:43 +00:00
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00