Commit Graph

396 Commits

Author SHA1 Message Date
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -07:00
gregomni
9508fdc8a7 Simpler implementation for multiple matching patterns in case with variable bindings
Backed off of the implementation with a shared body block, which got
messy really fast with multiple patterns containing address-only values
to pass in, as it led to separated stack alloc/cleanup requirements and
passing stack alloc’d values as block args, aliasing of addresses for
stack cleanup verifying, etc. A mess.

This now does the conservative thing of repeating the body in each
matching pattern block.
2016-10-02 15:25:55 -07:00
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Chris Lattner
62e4811dac Remove support for nominal type patterns, which have never been supported in an
official swift release and have bitrotted.
2016-07-31 18:44:08 -07:00
gregomni
fc4fe97332 Memory management bug fix here for indirect nested enums. 2016-07-13 21:41:46 -07:00
Gary Liu
ac53a1ef45 New test case to show the problem fixed by commit 61ce47014b
Fix new test case from commit fcaba99c81edcb8320856cb55367e1d8a9176675

Adding the review changes to #3193
2016-06-30 15:11:25 -04:00
Bryan Chan
61ce47014b Case statements are not the only kind that require wildcard dispatches and have guard branches. 2016-06-22 08:40:46 -04:00
Joe Groff
dfc3e7fb0c 80 columns, NFC 2016-05-16 10:58:49 -07:00
Doug Gregor
945831023a [SILGen] Eliminate SILGen-specific handling of imported, synthesized conformances
Now that Sema communicates its "used" conformances to SILGen, there is
no reason for SILGen to separately look for "used" conformances. NFC
2016-05-09 20:59:30 -07:00
Roman Levenstein
2e77b3990b Add [nonatomic] attribute to all SIL reference counting instructions. 2016-04-06 01:52:43 -07:00
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