Commit Graph

430 Commits

Author SHA1 Message Date
Arnold Schwaighofer
7f98df29c6 Serialize whether a function is a reabstraction thunk
A follow up patch will add a peephole to remove superflous reabstraction thunk
combinations.

Swift SVN r30225
2015-07-15 20:17:19 +00:00
Doug Gregor
3855bb824b Sort protocol conformances for serialization and SILGen emission.
Determinism++, otherwise NFC

Swift SVN r30169
2015-07-13 22:16:57 +00:00
Slava Pestov
a6f81779d1 SILGen: Fix crash when protocol defines instance and static property with same name
Mangler::mangleEntity() correctly handles accessors these days, so
by calling mangleAccessorEntity() from SILGenConformance, we were just
skipping the 'Z' modifier if the accessor was static...

As a result, generating a conformance to such a protocol tried to emit
duplicate SIL functions.

Fixes <rdar://problem/21426579>.

Swift SVN r29601
2015-06-24 05:41:57 +00:00
Joe Groff
d84993108b SILGen: Emit Clang-imported witness tables by need too.
The other part of rdar://problem/21444126. This is a little trickier since SIL doesn't track uses of witness tables in a principled way. Track uses in SILGen by putting a "SILGenBuilder" wrapper in front of SILBuilder, which marks conformances from apply, existential erasure, and metatype lookup instructions as used, so we can avoid emitting shared Clang importer witnesses when they aren't needed.

Swift SVN r29544
2015-06-22 03:08:41 +00:00
Joe Groff
abf953e5e8 SILGen: No longer recursively emit inherited conformances.
Now that we properly track inherited conformances and don't re-emit the inherited conformance in every translation unit that asks for it, this is no longer necessary or correct. The necessary conformances for a file should be emitted while visiting the types in that file, and trying to recursively emit their dependencies introduces duplicate symbols. Fixes rdar://problem/21107266.

Swift SVN r29093
2015-05-28 01:05:37 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Chris Lattner
8a7b3f414e Revise the parser and AST representation of #available to be part of StmtCondition
instead of being an expression.

To the user, this has a couple of behavior changes, stemming from its non-expression-likeness.
 - #available cannot be parenthesized anymore
 - #available is in its own clause, not used in a 'where' clause of if/let.

Also, the implementation in the compiler is simpler and fits the model better.  This
fixes:
<rdar://problem/20904820> Following a "let" condition with #available is incorrectly rejected



Swift SVN r28521
2015-05-13 19:00:40 +00:00
Joe Groff
ab4e578aeb AST: More robustly grab a Module for ArchetypeBuilder to canonicalize generic signatures.
Use the Module from the associated decl instead of using getStdlibModule, which sometimes produces null for -parse-stdlib tests, and is probably wrong.

Swift SVN r28380
2015-05-09 22:20:47 +00:00
Chris Lattner
3814b7003f Implement support for arbitrary pattern matching in for-each statements,
which composes straight-forwardly on top of the existing stuff for if/let
and guard.



Swift SVN r28371
2015-05-09 21:34:35 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +00:00
Joe Groff
e2962ed213 SILGen: Implement recursive local function references.
Instead of immediately creating closures for local function declarations and treating them directly as capturable values, break function captures down and transitively capture the storage necessary to invoke the captured functions. Change the way SILGen emits calls to closures and local functions so that it treats the capture list as the first curry level of an invocation, so that full applications of closure literals or nested functions don't require a partial apply at all. This allows references among local functions with captures to work within the existing confines of partial_apply, and also has the nice benefit that circular references would work without creating reference cycles (though Sema unfortunately rejects them; something we arguably ought to fix.)

This fixes rdar://problem/11266246 and improves codegen of local functions. Full applications of functions, or immediate applications of closure literals like { }(), now never need to allocate a closure.

Swift SVN r28112
2015-05-04 05:33:55 +00:00
Chris Lattner
7927a230ae remove compiler support for let/else. This simplifies PBD back to being
an unconditional binding, yay.


Swift SVN r28101
2015-05-03 22:13:02 +00:00
Chris Lattner
d5073d9e4f rework StmtCondition to be based on patterns initializers and boolean
conditions instead of being wrapped around PatternBindingDecl.  When
let/else goes away, PatternBindingDecl will become a lot simpler.


Swift SVN r28055
2015-05-01 23:33:59 +00:00
Slava Pestov
9d2d52b7ff SILWitnessVisitor: canonicalize protocols for associated types
Fixes <rdar://problem/20714534>.

Swift SVN r27990
2015-04-30 18:41:11 +00:00
Slava Pestov
18f0915432 Factor out SILWitnessVisitor from SILGenConformance and IRGen's WitnessVisitor
Bad things could happen if these ever got out of sync, and there's
no reason to repeat the logic twice. NFC

Swift SVN r27989
2015-04-30 18:41:10 +00:00
Slava Pestov
41c0626a16 SILGenConformance can use ASTVisitor instead of Lowering::ASTVisitor
I don't believe we actually encounter IdentityExprs here. NFC (?)

Swift SVN r27988
2015-04-30 18:41:09 +00:00
Slava Pestov
fafd0b83ee Attempt to properly handle static global variables
This is based on Jordan Rose's patch from rdar://problem/17597453.

Swift SVN r27821
2015-04-27 22:16:37 +00:00
Michael Gottesman
9006fca42b Rename SILBuilder::emitDestroyAddr => SILBuilder::emitDestroyAddrAndFold.
Now it matches SILBuilder::emit{StrongRelease,ReleaseValue}AndFold which perform
the same operation but on object types.

Swift SVN r27806
2015-04-27 17:29:50 +00:00
Michael Gottesman
a3aa89d4c4 Remove Callback from SILBuilder and instead rename
emit{StrongRelease,ReleaseValue} => emit{StrongRelease,ReleaseValue}AndFold.
Then introduce a new method emit{StrongRelease,ReleaseValue} that returns a
PointerUnion containing the increment to be deleted if it exists. This obviates
the need for the callback.

Swift SVN r27804
2015-04-27 07:29:13 +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
ac82fd572f fix a SILGen crash on tuple-destructuring in let/else.
Swift SVN r27564
2015-04-22 05:28:22 +00:00
Chris Lattner
e1e31916cb inline a method into its only caller.
Swift SVN r27544
2015-04-22 00:29:14 +00:00
Chris Lattner
c419698093 Now that emitLocalVariable is gone, we can merge all the complexity of
local variable emission into LocalVariableInitialization, making it
similar in structure to LetValueInitialization.

NFC.



Swift SVN r27543
2015-04-22 00:25:43 +00:00
Chris Lattner
2d35d51ead Now that initializers have been reworked, there is finally only one client of
SGF::emitLocalVariable: inline it into its only remaining client (which is
indirectly part of 'var' pattern binding emission) and simplify the code a bit.
NFC.



Swift SVN r27531
2015-04-21 16:58:53 +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
d1351e221f completely remove the 'Kind' field/enum of Initialization. NFC.
Swift SVN r27464
2015-04-19 04:50:20 +00:00
Chris Lattner
fa6f078d0a Continue tidying up Initialization, NFC:
- Privatize "kind" in the base Initialization class.
 - Simplify canForwardInBranch() to just isSingleBuffer().
   There is only one client of it (which avoids emitting the
   formation of an optional temporary) and the only cases we're
   dropping is for "_" patterns and single element tuple patterns,
   which are not worth optimizing for.
 - Change getSubInitializationsForTuple() into a virtual method
   since it has wildly different behavior based on the subclass and
   requires otherwise private implementation details of those subclasses
   to implement it.
 - Simplify subclasses based on these changes.



Swift SVN r27463
2015-04-19 04:47:02 +00:00
Chris Lattner
020fe7835d Various cleanups for the initialization logic:
- Use virtual dispatch to localize some predicates instead
   of having special cases for LetValue inits in global places.
 - Improve 'const'ness of methods.
 - Introduce a common "KnownAddressInitialization" class to centralize
   the notion of an initialization corresponding to a specific physical
   address that is known up front.  Consolidate dupes of this concept into
   uses of it.

NFC.



Swift SVN r27462
2015-04-19 04:12:02 +00:00
Chris Lattner
5cbd92781c Fix let/else enum projection to reabstract back out to the right argument type,
instead of being the generic type, fixing a crash on the testcase.



Swift SVN r27461
2015-04-19 01:16:46 +00:00
Chris Lattner
d89fded653 Implement a micro-optimization to the let-else SILGen for enum matches:
don't run the cleanup for the enum if the failure path can only contain
trivial enum element matches.  For example, on:

class Base {}

func test_is(a : Base?) {
  let x? = a else { abort() }
}

we previously emitted:

  switch_enum %0 : $Optional<Base>, case #Optional.Some!enumelt.1: bb2, default bb1 // id: %3

bb1:                                              // Preds: bb0
  release_value %0 : $Optional<Base>              // id: %4
  br bb3                                          // id: %5


which is silly because the release_value is always dynamically a no-op (the 
.None element of an enum is always trivial).



Swift SVN r27460
2015-04-19 00:24:44 +00:00
Chris Lattner
e68e10d856 Implement support for is/as patterns in let/else, making them functionality complete.
Swift SVN r27459
2015-04-19 00:04:33 +00:00
Chris Lattner
24f7d7b9be fix <rdar://problem/20563234> let-else problem: cleanups for bound patterns shouldn't be run in the else block
We were previously emitting the 'else' block on a let-else after emitting the patterns bound, which
would cause cleanups for the bound patterns to be run on entry to the else.  This doesn't make sense
because those have already been torn down by the failure path in the conditional pattern binding.

Fix this by emitting the 'else' code up front, before any of the patterns are bound.



Swift SVN r27451
2015-04-18 05:14:53 +00:00
Chris Lattner
780a3c9eae following llvm coding style by wrapping each struct/class in an anon-namespace,
instead of using an expansive block containing lots of stuff.  NFC.



Swift SVN r27366
2015-04-16 18:43:37 +00:00
John McCall
237635ad42 Move @objc thunk emission to SILGenBridging.cpp. NFC.
Swift SVN r27351
2015-04-16 05:45:34 +00:00
John McCall
a67452c72c SILGen for throwing foreign errors out of @objc thunks.
Also, create a new file specifically for the foreign-error
code.

Swift SVN r27347
2015-04-16 05:16:54 +00:00
Mark Lacey
aeea1b7756 Mark witnesses as always_inline if they thunk to an always_inline function.
As a result, when we're able to devirtualize calls to these functions
we'll also be able to inline all the way down to the user function.

Swift SVN r27136
2015-04-08 21:25:15 +00:00
Chris Lattner
2e4d4b46e8 Implement SILGen support for enum patterns, which are the most common and important
kind of pattern for let/else.  While I haven't done extensive testing, I believe
that let/else is wired up and working now.

Please feel free to kick the tires on let/else and file radars if you run into problems.

The only piece that I know is missing is support for is/as patterns (which will fail on
an llvm_unreachable).


Swift SVN r27135
2015-04-08 21:15:38 +00:00
Chris Lattner
2f507f675e improve the errors printed by some unimplemented code to actually make sense.
Swift SVN r27134
2015-04-08 20:29:37 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Chris Lattner
3118f09856 Add SILGen support for Conditional PBD's and add the first example
refutable pattern (expr patterns) to show that this works, this enables
weird things like:

	let 1...40 = foo() else { ... }

:-)



Swift SVN r27050
2015-04-07 00:56:36 +00:00
Chris Lattner
453529b8bf When emitting a 'let' initialization for a value of trivial type, don't
register a DestroyLocalVariable cleanup: it will be a noop.  Getting it out
of the apparently active set of cleanups allows us to avoid emitting empty
blocks in some cases.



Swift SVN r27049
2015-04-07 00:41:48 +00:00
Chris Lattner
73c32d6074 remove some no-op overrides and fix some wonky indentation I introduced, NFC.
Swift SVN r27038
2015-04-06 20:38:15 +00:00
Chris Lattner
0c35b2e8d4 refactor a bunch of stuff around Initialization to simplify the code and
make it easier to extend, NFC.

 3 files changed, 196 insertions(+), 238 deletions(-)



Swift SVN r27029
2015-04-06 06:00:30 +00:00
Chris Lattner
95b7b4d5e4 rename CleanupLocation::getCleanupLocation -> CleanupLocation::get, NFC.
Swift SVN r26994
2015-04-04 22:56:01 +00:00
John McCall
723a6077cf Reorganize some code in SILGen into new files; NFC.
Swift SVN r26971
2015-04-04 03:32:18 +00:00
John McCall
dc4b8ff2c2 Incorporate an optional Clang type into AbstractionPattern.
This is necessary for correctly dealing with non-standard
ownership conventions in secondary positions, and it should
also help with non-injective type imports (like BOOL/_Bool).
But right now we aren't doing much with it.

Swift SVN r26954
2015-04-03 21:39:31 +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
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00