Commit Graph

430 Commits

Author SHA1 Message Date
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
John McCall
dc4431ebff Split addressors into unsafe, owning, and pinning variants.
Change all the existing addressors to the unsafe variant.

Update the addressor mangling to include the variant.

The addressor and mutable-addressor may be any of the
variants, independent of the choice for the other.

SILGen and code synthesis for the new variants is still
untested.

Swift SVN r24387
2015-01-13 03:09:16 +00:00
Joe Groff
da46c43879 SILGen: Keep ParameterInfos in sync with BB args as they're emitted.
We were falling out of sync when there were multiple parameter patterns, or when there were tuple parameters that destructured into multiple BB arguments. Add an assertion that the types match, which should catch a lot bugs most of the time. This gets us to retain-balance @guaranteed parameters in more cases in -enable-guaranteed-self mode.

Swift SVN r24354
2015-01-10 04:36:32 +00:00
David Farler
3530e542ca Static class stored properties
rdar://problem/19422120

Allow static/class final stored properties to get through to the
mangled global property implementations.

Swift SVN r24303
2015-01-09 09:54:18 +00:00
Chris Lattner
bf43c5cd49 move getDeclCaptureKind to be a method on TypeConverter and simplify a bunch of
clients of CaptureKind by having getDeclCaptureKind map address-only lets onto
Box or NoEscape, instead of having all the clients do it.


Swift SVN r24136
2014-12-24 00:23:24 +00:00
Chris Lattner
d59a2d0490 Teach SILGen about NoEscape:
- Introduce a new 'noescape' CaptureKind and have getDeclCaptureKind()
   use it for by-address captures in noescape closures.
 - Lower NoEscape captures to a simple inout pointer instead of to a
   pointer + refcount.

This includes a test of the SILGen produced code itself along with an
integration test that shows that this enables inout deshadowing to remove
shadows that would otherwise have to be preserved due to closures capturing
them.

This can be more aggressive for address-only let constants, but that will
wait for a follow-up patch.



Swift SVN r24135
2014-12-24 00:03:13 +00:00
Chris Lattner
58e0efc345 Enhance getDeclCaptureKind() to take the closure that is capturing the
given decl, and plumb the information down to it.  NFC since the argument
is currently dead.



Swift SVN r24132
2014-12-23 23:08:38 +00:00
John McCall
24f41462db Change the materializeForSet callback to take the
value buffer inout, just for better typing.

Swift SVN r24041
2014-12-19 22:41:11 +00:00
Jordan Rose
3f7c72d390 Make @NSManaged imply 'dynamic'.
This lets us remove a few special cases for @NSManaged, and also fixes
some of the special cases that we didn't handle, like rdar://problem/18801796.

Swift SVN r24037
2014-12-19 19:12:28 +00:00
Chris Lattner
031f05c82c Unthread PatternKind from SILGen and remove it.
Swift SVN r23958
2014-12-16 19:04:00 +00:00
Chris Lattner
a31c71bfe1 now that the AST is better formed, we can start ripping out complexity in SILGen that worked
around the brokenness.  Revise the logic in LetValueInitialization to be based on structural
properties of the AST instead of PatternKind.


Swift SVN r23957
2014-12-16 18:59:35 +00:00
Chris Lattner
a048b078e3 Implement: <rdar://problem/16181314> don't require immediate initialization of 'let' values
... now that we have an exquisitely shaved yak.

This provides a simple and uniform model for "let" constants: they are always either
immediately initialized in their declaration, or they are initialized dynamically
exactly once before any use.  

This is a simple generalization of our current model for initializers, but enables
the use of let constants in more cases in local context, e.g. patterns like this:

   let x : SomeThing

   if condition {
     x = foo()
   } else {
     x = bar()
   }
   use(x)

Previously this would have to be declared a "var" for no good reason: the value is
only ever initialized, never actually mutated.

The implementation of this is reasonably straight-forward now that the infrastructure
is in place: Sema treats 'let' constants as "settable" if they lack an initializer
(either in the declaration or in a non-PBD binding).  This exposes them as an lvalue
at the AST level.  SILGen then lowers these things to an alloc_stack, and DI enforces
the "initialization only" requirement that it already enforces for uninitialized 'let'
properties in structs/classes.



Swift SVN r23916
2014-12-13 07:17:44 +00:00
Chris Lattner
e2da1224d6 generalize and clean up the logic in LetValueInitialization to be easier to follow,
paving the way for future progress.


Swift SVN r23875
2014-12-12 01:14:43 +00:00
Chris Lattner
8236e7f18b Simplify the implementation of SILGenFunction::VarLoc by eliminating the
"isConstant" distinction.  This was an irritating bit of redundant state
that was making the code more complicated.  Clients of VarLoc really only
care about "has address" and "has box", not whether the VarLoc came from
a let or var (and if they did, they can ask the VarDecl directly).  NFC,
just more "yak shaving" as Doug likes to say.


Swift SVN r23869
2014-12-11 22:11:23 +00:00
Chris Lattner
4618e7d2fb remove some now-dead code. This computation is now done based on
SIL function types, not on AST types.


Swift SVN r23865
2014-12-11 20:43:37 +00:00
Chris Lattner
d513803d84 Sigificantly replumb how SILGen generates mark_uninitialized instructions, generating
them in a more consistent and principled way.  Two changes here: MUI is generated
when a vardecl is emitted, not as a separate "MarkPatternUninitialized" pass.  Second,
when generating a MUI for self parameters with a temporary alloc_stack (due to the
possibility of superclass remapping of self) emit the MUI on the allocation itself,
not on the incoming argument.  This is a lot more consistent (dissolving a bunch of 
hacks in DI).

In terms of behavior changes, this only changes the raw sil generated by SILGen and
consumed by DI, so there is no user-visible change.  This simply unblocks future work.



Swift SVN r23823
2014-12-10 00:29:40 +00:00
Joe Groff
90651fcdd6 Clang importer: Preserve unknown NS_ENUM values through raw value conversions.
We can't reliably reject raw values in an NS_ENUM's init(rawValue:), because the enum may have SPI or future values we don't statically know about. Fixes https://twitter.com/autorelease/status/524698585406124033

Swift SVN r23817
2014-12-09 23:33:42 +00:00
Chris Lattner
674a50df2f refactor how "getPathStringToElement" in DI works, to clean it up and simplify
clients.  NFC except for slightly better diagnostic in .sil testcases.  


Swift SVN r23809
2014-12-09 17:51:06 +00:00