Commit Graph

747 Commits

Author SHA1 Message Date
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
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Doug Gregor
06a92048a1 SILGenConformance works with normal protocol conformances, only.
NFC

Swift SVN r26438
2015-03-23 17:51:40 +00:00
Doug Gregor
f50ef5005c Start detangling the uses of TypeDecl::getProtocols(). NFC
Getting the protocols of an arbitrary type doesn't make sense, so start phasing this out by introducing specialized entry points that do make sense:
  - get the inherited protocols of a ProtocolDecl
  - get the conforming protocols for an associated type or generic
  type parameter
  - (already present) ask for the protocols to which a nominal type conforms

Swift SVN r26411
2015-03-22 12:35:17 +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
Mark Lacey
63f11bf990 Set IsThunk on reabstraction thunks.
Swift SVN r26396
2015-03-21 23:05:23 +00:00
Mark Lacey
6889fc84cf Mark protocol witness thunks as transparent.
This is needed for the forthcoming change in which we'll devirtualize
during mandatory inlining.

Swift SVN r26395
2015-03-21 23:05:21 +00:00
Doug Gregor
fa6c8f162f Teach SILGen to use getLocalConformances() when emitting conformances.
While here, fix a bug in our use of getAllConformances(). We don’t want to be emitting inherited conformances here.

Swift SVN r26332
2015-03-19 23:38:08 +00:00
Doug Gregor
a5a46752c2 Teach SILGen to use getAllConformances() when emitting witness tables we might need.
Sort the conformances here so we keep the order deterministic.

Swift SVN r26330
2015-03-19 22:10:11 +00:00
Doug Gregor
940ba832e5 Use the conformance lookup table to find protocol conformances.
Replace the loop over all known protocols with a query into the
actual conformance lookup table, which more properly deals with
out-of-order conformance queries, inheritance of protocol
conformances, and conformance queries in multi-file situtations.

The SILGen test change is because we're no longer emitting redundant
conformances, while the slight diagnostic regression in
circular-inheritance cases is because we handle circular inheritance
very poorly throughout the compiler.

While not the end, this is a major step toward finishing
rdar://problem/18448811.

Swift SVN r26299
2015-03-19 06:35:28 +00:00
Doug Gregor
9f47f2c205 Stop jumping through hoops to emit Objective-C conformance thunks. NFC
Witnesses for @objc protocols need to be @objc, so this code is dead.

Swift SVN r26231
2015-03-17 20:36:16 +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
Michael Gottesman
3c2216b115 [+0 self] Add the deallocating parameter convention.
The deallocating parameter convention is a new convention put on a
non-trivial parameter if the caller function guarantees to the callee
that the parameter has the deallocating bit set in its object header.

This means that retains and releases do not need to be emitted on these
parameters even though they are non-trivial. This helps to solve a bug
in +0 self and makes it trivial for the optimizer to perform
optimizations based on this property.

It is not emitted yet by SILGen and will only be put on the self
argument of Deallocator functions.

Swift SVN r26179
2015-03-16 07:51:11 +00:00
Chris Lattner
01f3e81aa5 Work on VarDecl:
- Rename getParentPattern() -> getParentPatternBinding(), since
   it returns the pattern binding, not the pattern.
 - Introduce new getParentPattern()/getParentInitializer() methods,
   covering the most common uses of getParentPatternBinding().

NFC.



Swift SVN r26175
2015-03-16 01:54:20 +00:00
Ted Kremenek
9e7471d68b Revert "Revert "Rework processing of @noescape closures a bit to fix rdar://19981118:""
Turns out llvm::DataLayoutPass is used in other places, so the bots are still unhappy.
Re-applying the original change so we can fix the problem holistically.

Swift SVN r25761
2015-03-04 20:15:45 +00:00
Ted Kremenek
6781ac7bec Revert "Rework processing of @noescape closures a bit to fix rdar://19981118:"
This is breaking the testing bot because DataLayoutPass was just removed from LLVM trunk.
Chris is the best one to fix this change, but we need to get the bots green.

Swift SVN r25760
2015-03-04 20:03:33 +00:00
Chris Lattner
ab43e444d6 Rework processing of @noescape closures a bit to fix rdar://19981118:
- Have Sema, not SILGen decide if a vardecl can be captured by address
  instead of by-box.  This is a non-local property that is best computed
  during capture set formation.  Sema captures this as a bit on the new
  CapturedValue entry.
- Rework some diagnostic emission to centralize a class of noescape 
  diagnostics in capture set calculation.  Previously, funcdecl closures
  produced their diagnostics there, but ClosureExprs produced them in
  MiscDiagnostics (NFC for this part).

This fixes <rdar://problem/19981118> Swift 1.2 beta 2: Closures nested in @noescape closures copy, rather than reference, captured vars.



Swift SVN r25759
2015-03-04 19:30:36 +00:00
Chris Lattner
feb350f201 rename CaptureKind::NoEscape -> CaptureKind::StorageAddress,
since the CaptureKind enum names describe "what happens", not
"why they are formed".  NFC.



Swift SVN r25750
2015-03-04 06:27:02 +00:00
Chris Lattner
3489840b8d rework our representation of capture lists to compute the "isDirect" bit up front
when computing the list.  This simplifies getLocalCaptures to *just* filter out
global captures, and paves the way for other enhancements.  NFC.


Swift SVN r25739
2015-03-04 01:56:48 +00:00
Joe Groff
5fa20867e9 SILGen: Implement thunking for C function pointer conversions.
If we have a C function pointer conversion, generate a thunk using the same logic we use for ObjC method thunks, and emit a pointer to that thunk as the C function pointer value. (This works for nongeneric, nonmember functions; generics will additionally need to apply generic parameters within the thunks. Static functions would need to gather the metatype as well.)

Swift SVN r25653
2015-03-01 06:18:58 +00:00
Justin Bogner
92be153564 InstrProf: Handle extensions
Swift SVN r25474
2015-02-21 21:31:07 +00:00
Justin Bogner
99d6486f4b InstrProf: Add profiling and coverage for members of nominal types
Move the profiler setup logic into an RAII object and use it to set up
profiling for contructors, destructors, and methods.

Swift SVN r25473
2015-02-21 20:15:23 +00:00
Adrian Prantl
45544727ac Mark reabstraction thunk helpers as auto-generated.
Fixes <rdar://problem/18670152> Stack trace is a lie.

Swift SVN r25362
2015-02-18 00:46:25 +00:00
Michael Gottesman
617ea48e8b Refactor getForwardingSubstitutions onto SILFunction. NFC.
This is also useful in general SIL passes when generating thunks. I am going to
use this in function signature optimization and closure specialization.

Swift SVN r25356
2015-02-17 21:03:24 +00:00
Chris Lattner
1496cde7d8 fix rdar://19854166 - Swift 1.2 uninitialized constant causes crash
This rearranges code so that the destroy_addr cleanup generated to 
deallocate a 'let' stack temporary is generated against the mark_uninitialized
instruction.  This allows DI to see it, and nuke it on paths where the let constant
is never assigned.



Swift SVN r25349
2015-02-17 04:50:23 +00:00
Joe Groff
6e59195933 SILGen: Don't emit vtable entries for willSet/didSet.
Observers shouldn't ever be ABI. Fixes rdar://problem/19777115.

Swift SVN r25119
2015-02-10 05:12:51 +00:00
Joe Groff
96303f4c7f SIL: Factor the vtable override logic from SILGen into a method on SILDeclRef.
rdar://problem/19514920 is caused by a disagreement between IRGen and SILGen about which SILDeclRefs override vtable slots. Factor out the somewhat-hairy code in SILGen to a place IRGen will be able to share it. NFC yet.

Swift SVN r25063
2015-02-07 02:01:37 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Joe Groff
a449948275 SILGen: Emit vtable thunks to handle optional variance.
If a subclass overrides methods with variance in the optionality of non-class-type members, emit a thunk to handle wrapping more optional parameters or results and force-unwrapping any IUO parameters made non-optional in the derived. For this to be useful, we need IRGen to finally pay attention to SILVTables, but this is a step on the way to fixing rdar://problem/19321484.

Swift SVN r24705
2015-01-24 05:21:26 +00:00
Chris Willmore
94bf316fc2 <rdar://problem/16937737> global NSString constants showing as NSString, not String
Import global variables of type NSString * as String instead of
NSString. Emit bridging code in SIL when such a variable is loaded.

Swift SVN r24495
2015-01-17 04:00:55 +00:00
Joe Groff
fa823ad2f4 SILGen: Balance guaranteed self arguments in @objc thunks.
Swift SVN r24439
2015-01-15 04:18:59 +00:00
Joe Groff
9962cfbb63 SILGen: Remove dead code for binding ParamDecls in LetValueInitialization.
Now that argument binding has its own code path, we don't need this special case anymore. NFC.

Swift SVN r24415
2015-01-14 18:31:29 +00:00
Joe Groff
07a47a02d0 SILGen: Remove InOutInitialization and its related "AddressBinding" initialization kind.
We don't need these now that we don't set up argument bindings via initializations.

Swift SVN r24413
2015-01-14 05:51:01 +00:00
Joe Groff
78a53ec74e SILGen: Unwind some levels of abstraction in argument binding.
Have the ArgumentInitVisitor directly bind argument variables to BB arguments, instead of trying to reuse the InitializationForPattern logic used for general variable bindings. That was a nice idea, but it leads to some ugly edge cases because of the many little ways arguments are different from local variable bindings. By getting rid of the abstraction layers, it's easy for argument binding to bind +0 guaranteed or +1 arguments in place when appropriate, avoiding an r/r pair for "let" bindings. It will also let us eliminate some ugly code from variable binding initialization. Should be NFC aside from some harmless reordering of prolog/epilog variable setup.

Swift SVN r24412
2015-01-14 05:50:58 +00:00