Commit Graph

753 Commits

Author SHA1 Message Date
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
Michael Gottesman
dedebe5f0d [silgen] Emit guaranteed arguments as managed retains.
This means that even though the guaranteed parameter comes in at +0, we
immediately retain it and add a cleanup handler at the end of the function. Once
+0 self has been turned on, I will add a guaranteed optimization that removes
such retains, releases.

Tests will follow with the commit that enables the actual +0 self parameter.

Swift SVN r23627
2014-12-03 01:43:28 +00:00
Michael Gottesman
5bfdc670ad [silgen] Move EmitBBArguments into SILGenDecl.cpp since that is the only place it is used and remove the resulting dead methods.
This was done at John's request.

Swift SVN r23623
2014-12-02 23:58:42 +00:00
Michael Gottesman
61f4f28fca Remove trailing whitespace. NFC.
Swift SVN r23622
2014-12-02 23:46:41 +00:00
Adrian Prantl
4016c57819 Debug info: Make a store that is part of the initial setup of a frame
variable part of the function prologue by omitting its location.

Fixes <rdar://problem/18989457> Xcode 6.2 6C86C (lldb-320.4.157) : po self returns error: Execution was interrupted, reason: EXC_BAD_ACCESS

Swift SVN r23569
2014-11-24 01:06:18 +00:00
Joe Groff
f8dfcaa84e SIL: Consider the original Clang type of a decl before bridging Bool back to ObjCBool.
It's not always correct to map a Swift Bool back to ObjCBool in C land, since Bool could have originally been a proper _Bool. Pass the clang::Decl down to type lowering so we can recognize this. We still don't have a great solution for block types, because there's no decl to refer to, and Swift's user-level type system erases the distinction between void(^)(_Bool) and void(^)(BOOL). However, this is enough to let us start using C APIs that traffic in _Bool.

Swift SVN r23546
2014-11-22 05:21:55 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Joe Groff
4b2097c9f4 SILGen: Include overrides of required allocating initializers in the vtable.
Part of fixing rdar://problem/18877135.

Swift SVN r23271
2014-11-12 17:36:55 +00:00
Erik Eckstein
3eea8e3052 Set SILLinkage of witness tables according to the protocol visibility.
This is the same change as already done for functions and globals
(for details see <rdar://problem/18201785>).




Swift SVN r22907
2014-10-24 09:02:05 +00:00
Joe Groff
3f23b82e6d SIL: Rename SILGlobalAddr to GlobalAddr.
All globals are SIL globals now.

Swift SVN r22827
2014-10-18 17:08:28 +00:00
Dave Abrahams
90a34d86fa Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.

Swift SVN r22812
2014-10-17 06:02:22 +00:00
Dave Abrahams
e4588e4896 Revert "Mangle names of globalinit_{token,func} like other private entities."
This reverts r22795, because it broke my RelWithDebInfo,
SWIFT_OPTIMIZED=NO build.

Swift SVN r22802
2014-10-16 21:12:11 +00:00
Erik Eckstein
b5cfd00f74 Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.



Swift SVN r22795
2014-10-16 08:24:18 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Joe Groff
18e2ab4e0f SILGen/IRGen: Leave stub initializers out of the vtable.
Stub initializers don't get serialized, so this fixes a vtable layout inconsistency when a method of a subclass of a subclass of NSObject is accessed. Fixes rdar://problem/18498385.

Swift SVN r22480
2014-10-02 21:31:35 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Erik Eckstein
5e894aa80f Reference deallocating constructors in the SILVtable to prevent dead function elimination.
Those destructors are not referenced anywhere else in the SIL, but are used in the metadata
of a class. If they are private then dead function elimination would remove them.

This fixes <rdar://problem/18431856> unreachable executed at GenDecl.cpp:808



Swift SVN r22261
2014-09-24 11:29:38 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Joe Groff
232cec4b61 SIL: Rename TypeConverter::getInterfaceType{In,OutOf}Context
It extracts an interface type out of a contextual type, but the name made it sound like it put it into a context. NFC.

Swift SVN r22188
2014-09-22 21:56:47 +00:00
John McCall
9c1d89289f Fix some bugs involving the implicit generation of
materializeForSet accessors for stored properties.

Also, reliably place materializeForSet after the
setter, no matter when we generate it.

Swift SVN r22014
2014-09-17 08:08:08 +00:00
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +00:00
Manman Ren
a952c556c9 [Global Opt] replace GlobalAddrInst with SILGlobalAddrInst.
Update SILGen to create SILGlobalVariable and SILGlobalAddrInst instead of
GlobalAddrInst. When we see a definition for a global variable, we create
the corrsponding SILGlobalVariable definition.

When creating SILGlobalVariable from a global VarDecl, we mangle the global
VarDecl in the same way as we mangle it at IRGen. The SILLinkage is also
set in the same way as we set it at IRGen.

At IRGen, we use the associated VarDecl for SILGlobalVariable if it exists,
to have better debugging information.

We set the initializer for SILGlobalVariable definition only.

We also handle SILGlobalAddrInst in various SILPasses, in the similar way
as we handle GlobalAddrInst.

rdar://15493694


Swift SVN r21887
2014-09-11 20:00:39 +00:00
Joe Groff
419ba5cbea Change RawRepresentable to use failable initializers and property requirements.
Redefine the RawRepresentable protocol to use an 'init?' method instead of 'fromRaw(Raw)', and a 'raw' get-only property instead of 'toRaw()'. Update the compiler to support deriving conformances for enums and option sets with the new protocol. rdar://problem/18216832

Swift SVN r21762
2014-09-06 18:40:14 +00:00
Joe Groff
2395820d2d SILGen: Only emit base conformances that belong to the current module.
Fixes rdar://problem/17619178. I can't make a SILGen test case because of rdar://problem/18182969 -- under normal circumstances we appear to produce new conformances for base protocols even when there are conformances in the stdlib we should reuse instead.

Swift SVN r21594
2014-08-29 23:14:11 +00:00
Chris Lattner
50979a2ff4 implement SILGen and IRGen support for witness table generation of non-objc optional
protocol requirements.  Not testable because sema doesn't allow these to exist.


Swift SVN r21513
2014-08-28 04:20:02 +00:00
Joe Groff
d63be086e0 SILGen: Forward failure from a delegated value constructor.
Swift SVN r21427
2014-08-23 00:14:56 +00:00
Doug Gregor
7cae0cfc8e Remove -enable-dynamic and its language option; it's always on anyway.
Swift SVN r21354
2014-08-21 15:15:12 +00:00
Chris Lattner
07d8963ba9 fix <rdar://problem/16554056> __FUNCTION__ in deinit for NSObject subclasses crashes the compiler
Swift SVN r21300
2014-08-20 00:28:01 +00:00