Commit Graph

270 Commits

Author SHA1 Message Date
Jordan Rose
4adeb66b9f Drop uses of Optional's variadic forwarding constructor.
In preparation for the switch to llvm::Optional, which doesn't have this.
I suggested it, but got some pushback from David Blaikie, which is
understandable because implicit conversions are dangerous.
std::experimental::optional also doesn't have this, and we don't use it
too much. The only cost is being slightly more explicit when relying on
conversions to give us a T to then wrap in an Optional.

Swift SVN r22472
2014-10-02 18:51:37 +00:00
Jordan Rose
2a76f18e4b Drop uses of Optional::cache.
In preparation for the switch to llvm::Optional, which doesn't have a 'cache'
method. Given how long we spent bikeshedding over the name and how few places
we ended up using it, I didn't feel like trying to push it through on the
LLVM side.

Swift SVN r22471
2014-10-02 18:51:36 +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
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
8f52302f8e SILGen: Implement artificial main for NSApplicationMain.
We're not sure how to trigger this from source code yet, so trigger it with a hidden -emit-NSApplicationMain frontend flag for now.

Swift SVN r21563
2014-08-29 04:45:47 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Joe Groff
d63be086e0 SILGen: Forward failure from a delegated value constructor.
Swift SVN r21427
2014-08-23 00:14:56 +00:00
Arnold Schwaighofer
cd799f8e46 Revert "Add an inline(late) attribute"
This reverts commit r21286.

Discussions ongoing.

Swift SVN r21289
2014-08-19 18:15:25 +00:00
Arnold Schwaighofer
7aa62ce835 Add an inline(late) attribute
This disables inlining at the SIL level. LLVM inlining is still enabled. We can
use this to expose one function at the SIL level - which can participate in
dominance based optimizations but which is implemented in terms of a cheap check
and an expensive check (function call) that benefits from LLVM's inlining.

Example:

The inline(late) in the example below prevents inlining of the two checks. We
can now perform dominance based optimizations on isClassOrObjExistential.
Without blocking inlining the optimizations would apply to the sizeof check
only and we would have multiple expensive function calls.

@inline(late)
func isClassOrObjExistential(t: Type) -> Bool{
  return sizeof(t) == sizeof(AnyObject) &&
    swift_isClassOrObjExistential(t)
}

We do want inlining of this function to happen at the LLVM level because the
first check is constant folded away - IRGen replaces sizeof by constants.

rdar://17961249

Swift SVN r21286
2014-08-19 18:05:44 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Joe Groff
f722d3f6a6 Remove tons of now-dead code for dealing with the C*Pointer bridging types.
Swift SVN r19280
2014-06-27 00:11:36 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
Joe Groff
dba8a23d64 AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.
These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
2014-06-20 03:02:29 +00:00
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +00:00
Mark Lacey
cd00cfbf8f Fix some build warnings.
DEBUG_TYPE should be defined before the inclusion of LLVM's Support/Debug.h.

Swift SVN r18640
2014-05-26 20:17:54 +00:00
Chris Lattner
c897ee2d76 Fix <rdar://problem/16952186> Crash with @lazy in @objc class
Swift SVN r18278
2014-05-17 22:05:47 +00:00
Joe Groff
e8f71c12a2 Rename ObjCMutablePointer to AutoreleasingUnsafePointer.
This relates its interface and behavior to that of UnsafePointer, and draws an analogy to '__autoreleasing *' in ARC.

Swift SVN r18236
2014-05-17 04:44:44 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Doug Gregor
1e9f16038c Remove my accidental commit in r18010.
Swift SVN r18018
2014-05-13 20:03:24 +00:00
Nadav Rotem
185edf0492 Fix what looks like a typo to fix the buildbots.
Swift SVN r18012
2014-05-13 17:16:14 +00:00
Doug Gregor
d5a9c2ab94 Only supersede initializers with other imported initializers when the types match.
This fixes a case where the Swift-variadic and C-varargs versions of
various initializers were superseding each other
<rdar://problem/16801456>.

It also uncovered some more cases where we weren't getting quite the
right semantics for factory-methods-as-initializers, which are also
fixed here.

Swift SVN r18010
2014-05-13 16:49:39 +00:00
Doug Gregor
5159201aed Bridge T[] to NSArray when T is bridged to Objective-C.
Generalize the bridging of AnyObject[] to NSArray into bridging T[] to
NSArray, following what we already have for dictionaries. Use some new
Foundation-level entry points for the bridging, which could use an
audit from someone who understands Array better than I do.

Part of <rdar://problem/16535097>.


Swift SVN r17869
2014-05-11 06:12:34 +00:00
Doug Gregor
104cf17d5d SILGen: Bridge Dictionary<K, V> <-> NSDictionary in Objective-C thunks.
Implements the majority of Dictionary bridging in SILGen
<rdar://problem/16870626>.

Swift SVN r17838
2014-05-10 19:51:00 +00:00
Doug Gregor
335c605d58 Allow one to disable verification of a bridging function's parameter/result types.
This should be used sparingly , for cases where forming the parameter/result types is tricky due to generics. If we could form those types without too much pain, it'd be better to remove this hack. However, it enables bridging in cases where we need generic bridging.

Swift SVN r17837
2014-05-10 19:50:59 +00:00
Joe Groff
4bc0a8b964 SILGen: Change the signature of _convertStringToNSString and _convertNSStringToString not to use inouts.
This was an artifact of their long-dead C++-based implementations that was way past due to clean up. It's also a convenient workaround for <rdar://problem/16835447>, since we no longer have to look up constructor members for String at SILGen time and potentially lazily instantiate Clang-imported types during SILGen. This totally isn't a real solution to that problem, but it puts out the fire for now.

Swift SVN r17643
2014-05-07 21:50:03 +00:00
Doug Gregor
f2e331f6ed Don't emit @objc thunks for @NSManaged properties.
Another part of <rdar://problem/16736676>.

Swift SVN r17194
2014-05-01 22:24:32 +00:00
Ted Kremenek
49f393920a Rename bridging "convert" functions to start with '_'.
This is part of our poor-man's internal compiler SPI hiding
in the standard library.  We don't want these functions showing
up in code completion, etc.

Swift SVN r16916
2014-04-27 05:13:19 +00:00
Andrew Trick
f58ebbc251 Add a global_init attribute to SILFunction.
The implied semantics are:
- side-effects can occur any time before the first invocation.
- all calls to the same global_init function have the same side-effects.
- any operation that may observe the initializer's side-effects must be
  preceded by a call to the initializer.

This is currently true if the function is an addressor that was lazily
generated from a global variable access. Note that the initialization
function itself does not need this attribute. It is private and only
called within the addressor.

Swift SVN r16683
2014-04-23 01:09:47 +00:00
Chris Lattner
a3916614ef respond to mainline API changes in the Debug.h header, by defining the
DEBUG_TYPE macro in all .cpp files that use the DEBUG macro.  Hopefully
this will unbreak the build.


Swift SVN r16638
2014-04-22 02:54:55 +00:00
Doug Gregor
82a7f1f87b Improve de-duplication logic for imported Objective-C class initializers.
Before we create a new initializer, check whether it would collide
with existing initializers. If it's better than the existing
initializer, mark the existing one as unavailable; if it's not better,
don't build it.

In support of this, we tweak a few things w.r.t. unavailble
declarations:
  - An unavailable declaration is shadowed by an available one,
  - Don't emit SIL unavailable, imported initializers

This fixes the last problem with <rdar://problem/16509024>.



Swift SVN r16611
2014-04-21 06:26:52 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Joe Groff
2189947cb0 Use report_fatal_error instead of exit(1) after unrecoverable problems in SILGen or IRGen.
Swift SVN r16059
2014-04-08 17:33:21 +00:00
Doug Gregor
a87d65d617 Bridge NSArray <-> AnyObject[].
Allows AnyObject[] to occur in @objc methods/properties/etc., then
bridges between the two in SILGen based on the new array
implementation. <rdar://problem/16535097>.

Note that this commit does not change the Clang module importer to
import NSArray* as AnyObject[] (yet).


Swift SVN r16004
2014-04-07 05:49:48 +00:00
Joe Groff
fea886d048 SILGen: Bridge the C*VoidPointer types to COpaquePointer.
Swift SVN r15868
2014-04-03 15:03:48 +00:00
Joe Groff
8102dee6f0 SILGen: Bridge ObjCMutablePointer.
Make ObjCMutablePointer @objc-able for (potentially optional) class types, and bridge it down to UnsafePointer when calling @objc entry points.

Swift SVN r15838
2014-04-02 22:49:32 +00:00
Jordan Rose
fc6b20369f Only generate derived conformance bodies for decls in the primary source file.
...and for decls imported from Clang, because those don't have home locations.

Fixes <rdar://problem/15936403>

Swift SVN r15831
2014-04-02 21:00:49 +00:00
Joe Groff
86faf30617 SILGen: Emit bridging from C*Pointer to UnsafePointer.
When we see CConstPointer or CMutablePointer in a foreign function signature, transparently bridge it to UnsafePointer at the foreign entry point, lifetime-extending the C*Pointer value during foreign calls so that its owner reference is held for the duration of the call.

Swift SVN r15602
2014-03-29 02:50:35 +00:00
Joe Groff
9e5bc637ae Add __FUNCTION__ as a magic literal identifier.
Add __FUNCTION__ to the repertoire of magic source-location-identifying tokens. Inside a function, it gives the function name; inside a property accessor, it gives the property name; inside special members like 'init', 'subscript', and 'deinit', it gives the keyword name, and at top level, it gives the module name. As a bit of future-proofing, stringify the full DeclName, even though we only ever give declarations simple names currently.

Swift SVN r14710
2014-03-06 01:06:06 +00:00
Doug Gregor
b1dfcd7085 Dynamically dispatch when delegating from a complete object initializer.
Inherited initializers are now functional: one can use an inherited
initializer to construct an object of a subclass type, and we properly
handle delegation to overridden complete object or subobject
initializers as appropriate. See the executable test.

This commit also contains various fixes for the IRGen side of vtable
emission and use. Proper IRGen tests still to come.

For now, we're still performing peer delegation from a subobject
initializer to another subobject initializer, hence the SILGen hack
for identifying when we're in a complete object vs. a subobject
initializer. We'll be banning delegation from subobject initializers,
so this hack---along with the peer_method instruction---will be going
away in the near future.



Swift SVN r14571
2014-03-02 08:19:11 +00:00
Doug Gregor
ea16062f75 Basic SILGen support for initializer requirements.
Emit witnesses for initializer requirements. Allow the use of
initializer requirements on archetypes; existentials don't work due to
<rdar://problem/16165890>.


Swift SVN r14356
2014-02-25 23:06:33 +00:00
John McCall
9f6820fadc SILGenModule::getConstantLinkage -> SILDeclRef::getLinkage
Swift SVN r14247
2014-02-22 01:45:40 +00:00
John McCall
3d5d8fdc03 Resilience expansion is really an aspect of a SILDeclRef.
We should also remove it from IRGen's Explosion API; IRGen
should always use maximal explosion, and SILGen will tell us
whether or not we need to put that in memory somewhere.
But that can be a later commit.

Swift SVN r14242
2014-02-21 23:28:43 +00:00
Chris Lattner
db2309101a fix a couple of simple things off argument patterns.
Swift SVN r13914
2014-02-14 18:18:32 +00:00
Chris Lattner
d88852e457 remove SILDeclRef::Getter/Setter and supporting code. NFC, but I think
the previous patches have defined away a few obscure bugs handling subscript 
accessors (from inspection).


Swift SVN r13885
2014-02-14 01:12:56 +00:00
Chris Lattner
51609c1ac8 unbreak ClangModules/ctypes_ir.swift & ClangModules/macros_ir.swift,
imported accessors from clang modules need to be hacked to have shared
linkage, even in the new form.


Swift SVN r13883
2014-02-14 00:48:20 +00:00
Chris Lattner
12196c17ba Now that we always have funcdecls for getters and setters, we don't need
SILDeclRef::Getter/Setter and the complexity therein.  Switch the world
to make SILDeclRef::Func's instead of them.  NFC.


Swift SVN r13875
2014-02-13 23:11:29 +00:00