Commit Graph

136 Commits

Author SHA1 Message Date
gregomni
63f810d2fd Variables in 'case' labels with multiple patterns.
Parser now accepts multiple patterns in switch cases that contain variables.
Every pattern must contain the same variable names, but can be in arbitrary
positions. New error for variable that doesn't exist in all patterns.

Sema now checks cases with multiple patterns that each occurence of a variable
name is bound to the same type. New error for unexpected types.

SILGen now shares basic blocks for switch cases that contain multiple
patterns. That BB takes incoming arguments from each applicable pattern match
emission with the specific var decls for the pattern that matched.

Added tests for all three of these, and some simple IDE completion
sanity tests.
2016-02-24 15:46:36 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Michael Ilseman
88060d580a [_BridgedNSError] Emit dynamic cast witness tables
_BridgedNSError conformances can affect the runtime behavior of
dynamic casts (e.g. 'is'). Unfortunately, the conformance is not
always emitted, in an effort to save space when not used. This change
forces the conformance witness tables to be emitted when we can detect
a dynamic cast to an _BridgedNSError conforming enum.

Test cases included, as well as a note about a potentially erroneous
path that is not currently handled: when the dynamic cast occurs in a
generic function to a generic type (and thus we are unsure which
conformances we need to pull in).
2016-02-08 15:18:48 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Slava Pestov
ec06e814b7 SIL: Start plumbing ResilienceExpansion through SIL type lowering
Also do some general cleanup, pushing the ResilienceExpansion
query up from IRGen to the AST.
2016-01-23 23:39:30 -08:00
practicalswift
33312eac6b [gardening] Remove unreachable/unused/redundant code
* Make parameter naming in forward declaration match definition
* Remove unused argument to function persistAsync(…)
* Remove unused enum ShouldHalt
* Remove unused enum class IsProtocol
* Remove unused function dumpTypeSubstitutionMap()
* Remove unused function template getFirstPairElt(…)
* Remove unused method addConstantWordInWords(…)
* Remove unused method asExistentialTI()
* Remove unused method currentTrackedState()
* Remove unused method getNumBodyParameters()
* Remove unused method getSuccIndex()
* Remove unused method getTypeOfDeclReference(…)
* Remove unused method hasStructWithAtMostOneNonTrivialField(…)
* Remove unused method initForDirectValues()
* Remove unused method nextIfNot(…)
* Remove unused method overwriteLoweredValue(…)
* Remove unused method removeColumn(…)
* Remove unused methods HasSingleDecl() and GetFirstDecl()
* Remove unused methods overwriteLoweredExplosion(…) and setLoweredSingleValue(…)
* Remove unused methods requireRetainablePointerValue(…), getMethodSelfInstanceType(…) and isSelfArchetype(…)
* Remove unused methods setAsEmptyDirect(), setAsSingleDirectUnmanagedFragileValue(…), setAsIndirectAddress(…) and getDirectValues()
* Remove unused struct CachedMemberInfo
* Remove unused struct CallEdit
* Remove unused struct ErrorImportInfo
* Remove unused synonym ConformancePair
* Remove unused variable SemaInfo
* Remove unused variable localDeclNameNode
* Remove unused variables kindToken and kindLoc
2016-01-22 09:43:24 +01:00
Erik Eckstein
2db6f3d213 SIL: remove multiple result values from SILValue
As there are no instructions left which produce multiple result values, this is a NFC regarding the generated SIL and generated code.
Although this commit is large, most changes are straightforward adoptions to the changes in the ValueBase and SILValue classes.
2016-01-21 10:30:31 -08:00
Slava Pestov
df38bd1764 SILGen: More interface type abstraction pattern goodness, NFC 2016-01-18 23:17:17 -08:00
Chris Lattner
2af78aede1 forward declare ASTWalker in ASTNode.h instead of including its header, NFC. 2015-12-31 21:05:13 -08:00
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