Commit Graph

430 Commits

Author SHA1 Message Date
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
Manman Ren
480b41c824 [SIL Vtable emission] use the least derived method in sil_vtable.
Given base class A and dervied class B, both with member functions f(),
to look for A.f in B's vtable, we should return SILFunction for B.f.

Before this commit, B's vtable will have entry for B.f, A's vtable will
have entry for A.f. When looking for A.f in B's vtable, it returns null.
And devirtualizer will look for A.f in A's vtable and resolve it to
SILFunction for A.f.

When replacing a class_method %1 : $A, #A.f!1 with a function ref to B.f,
we will have type checking issues for the apply instructions. So devirtualizer
will replace the argument of the apply instructions when necessary.

rdar://16681983


Swift SVN r16854
2014-04-25 23:42:12 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Joe Groff
c73acc67f2 SIL: Add an "UnownedInnerPointer" result convention.
This will represent the return convention of imported __attribute__((objc_returns_inner_pointer)) methods. Leave it unimplemented for now until we can autorelease things sanely.

Swift SVN r16628
2014-04-21 21:57:13 +00:00
Doug Gregor
e80f99ad57 Teach SILGen to build ParamDecls, too.
Swift SVN r16594
2014-04-20 19:05:03 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Dmitri Hrybenko
e2e8db5f38 Migrate IB attributes to new decl attribute representation and fix a few bugs
along the way


Swift SVN r16542
2014-04-18 20:00:09 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Joe Groff
e245f9ee89 SILGen: Thunk blocks into native Swift functions when bridging into Swift.
Emit Swift thunk functions to bridge blocks into native function values. On entry into @objc thunks, copy_block blocks to ensure they've been lifted off the stack.

Swift SVN r16177
2014-04-10 22:35:42 +00:00
Joe Groff
d149851607 SILGen: Copy blocks received as function arguments.
We want to generally treat blocks as heap objects until proven stack-able by escape analysis, like we do generally with other heap entities. The only place we should be exposed to stack blocks is when they're passed as arguments, so handle this by copy_block'ing any block arguments we get in the function prolog. Optimization can eliminate them when analysis shows the block doesn't escape or is already on the heap.

Swift SVN r16096
2014-04-09 04:35:17 +00:00
John McCall
372d6513bb Don't propagate let-binding Initializations down into
conditional-executed initializers.

Swift SVN r16033
2014-04-08 01:12:56 +00:00
John McCall
62844f58b6 Emit storage and (lazy) global initialization for static
variables in extensions of non-generic structs and enums.

rdar://16520242

Swift SVN r15957
2014-04-04 21:42:17 +00:00
Chris Lattner
e6aef8e980 enhance silgen and IRGen to not emit vtable entries for non-overriding @final members
Swift SVN r15929
2014-04-04 05:32:53 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
John McCall
71381ccdca Petty optimization that I noticed while doing significant
work in this file that turned out to be unnecessary.

Swift SVN r15573
2014-03-28 05:39:24 +00:00
Joe Groff
9ab2005b43 SILGen: Verify protocol witnesses after they're emitted.
Swift SVN r15351
2014-03-21 23:47:05 +00:00
Joe Groff
03a7b98806 SILGen/IRGen: Don't emit redundant witness thunks for @objc protocol witnesses that are already @objc.
If an extension introduces an @objc protocol conformance using existing methods that are already @objc, then we shouldn't emit @objc thunks for them again, and indeed, we can't for native ObjC classes. Fixes <rdar://problem/16330856>.

Swift SVN r15087
2014-03-14 22:48:59 +00:00
Joe Groff
e0c34d9fcc SILGen: 'cast' -> 'dyn_cast' in SILGenExtension::emitObjCConformanceThunks.
Allows @objc protocol property requirements to work with existing properties of a class, fixing the immediate problem in <rdar://problem/16284654> and <rdar://problem/16284574> (though there's a still a problem adopting methods of natively ObjC classes as protocol conformances, <rdar://problem/16330856>).

Swift SVN r15078
2014-03-14 22:00:04 +00:00
Joe Groff
9645e66029 SILGen: Properly handle generic substitution when calling [super dealloc] from a generic @objc grandchild class.
Swift SVN r15077
2014-03-14 21:19:26 +00:00
Joe Groff
8b82082920 SILGen: Properly carry through generic arguments when producing ObjC thunks.
We can't assume that ObjC types aren't generic anymore because container bridging requires generic subclasses of ObjC types, so remove the assertions that ObjC entry points are never generic and properly handle interface type substitution when emitting thunks.

Swift SVN r15073
2014-03-14 20:43:22 +00:00
Chris Lattner
52379cea20 Properly compute the override set for accessors in subscripts
and properties, allowing us to set up vtables properly.  Before
this patch, we'd get new entries in the derived class vtable for
overridden property accessors, which didn't help things.

This is progress along the way towards fixing:
<rdar://problem/16310561> Property vtables not set up correctly
but isn't the full story.  Dispatch is still not going through the vtable,
so we get the wrong behavior still.


This patch also exposes a totally mystifying (to me) problem with the deserializer.
A test is temporarily disabled because of this.




Swift SVN r15051
2014-03-14 16:36:37 +00:00
Chris Lattner
4543a345c1 remove some fixme's.
Swift SVN r14993
2014-03-13 06:02:22 +00:00
Joe Groff
c5feea4697 SILGen: Emit conformances for external definitions.
Teach IRGen to honor the linkage of SILWitnessTables, and teach SILGen to emit witness tables and protocol witness thunks for external definitions with shared linkage. Fixes <rdar://problem/16264703>.

Swift SVN r14908
2014-03-11 05:08:58 +00:00
Joe Groff
945fbaf167 SIL: Add a linkage specifier to SILWitnessTables.
In the short term, we need to be able to emit shared symbols for SILWitnessTables corresponding to Clang-imported modules, and soon, the generic specializer will need to be able to reference *_external witness tables deserialized from library modules.

Swift SVN r14887
2014-03-10 23:14:16 +00:00
Joe Groff
8e2521e8c2 SILGen: Emit derived '==' operators from Clang modules with shared linkage.
In Sema, give derived '==' definitions the module's DerivedFileUnit as their decl context instead of the more general Module, and give it a backreference to the nominal type for which it was derived. 
In SILGen, visit the derived global decls associated with Clang-imported enums, and give them shared linkage. Part of fixing <rdar://problem/16264703>.

Swift SVN r14875
2014-03-10 20:33:54 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Dmitri Hrybenko
ba6548b072 Track uptstream LLVM API change: llvm::tie() was removed, use std::tie() instead
Swift SVN r14573
2014-03-02 13:53:19 +00:00
Doug Gregor
aa337d4899 Start emitting vtable entries for
Swift SVN r14565
2014-03-02 05:39:15 +00:00
Joe Groff
8e6b353542 Derive conformances of Equatable and Hashable for simple enums.
If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
2014-02-27 20:28:38 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +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
Joe Pamer
183ff12250 The old visiitVarDecl method in SILGenDecl.cpp was carried forward from my working branch - remove it.
Swift SVN r14308
2014-02-24 18:16:50 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +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
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
Chris Lattner
fc42659613 Generalize witness table generation logic in silgen and irgen to handle properties.
We can now form witness tables for both properties and subscripts, but still can't
call them.  Also, only computed properties can fulfill a protocol requirement (which
is tracked by rdar://15912000).



Swift SVN r14137
2014-02-20 08:13:36 +00:00
Doug Gregor
a341300cb0 Switch ClassDecl::getSuperclass() and EnumDecl::getRawType() to interface types.
This has the nice "side effect" of making overrides of generic
functions work better, fixing the remaining type checker issues from
<rdar://problem/15836098>.

Also synthesize the types for derived RawRepresentable conformances
directly rather than going through the type checker, so we get the
interface types right. 



Swift SVN r14066
2014-02-19 00:54:04 +00:00
John McCall
c7da19725a Allow the mangler to mangle accessor kinds and make
protocol conformance thunk generation handle accessors
correctly.

Swift SVN r14050
2014-02-18 21:53:10 +00:00
Chris Lattner
ecbbb4a42c rework our representations of subscripts to not curry the indexes
separately from the get/set value.  There is no exposed way in the
source language to use this, and this causes shorter term annoyance.

I chose to flatten the value and indices so the value comes first.
In principle, this allows us to completely eliminate our ObjC importer
thunks.  I haven't removed them though, because they might be useful
for something else.


Swift SVN r14049
2014-02-18 21:34:33 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Joe Groff
df356b475b SIL: Set the context generic params of reabstraction thunks less greedily.
Don't try to set the generic params of a reabstraction thunk until we've established it hasn't already been defined, fixing an issue where the same generic reabstraction pattern occurred in different contexts and we ended up clobbering the archetypes of a thunk that was already defined in terms of other archetypes.

Swift SVN r13964
2014-02-16 16:56:43 +00:00
Chris Lattner
4a86056dff Progress towards putting subscript accessors into protocol witness tables.
This isn't testable yet, as it is blocked by at least two things:
 1. we can't put curried functions into witness tables (rdar://16079147),
    which is a problem given that subscript accessors are curried on their 
    index argument.
 2. accessors cannot silgen is curried form, we currently die in mangling.




Swift SVN r13947
2014-02-16 07:04:33 +00:00
Chris Lattner
0388d07cb1 fix <rdar://problem/16006333> observing properties don't work in @objc classes
willSet and didSet accessors need to be dispatched directly, even in the 
@objc case, and should never be added to vtables.



Swift SVN r13918
2014-02-14 19:29: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
Joe Groff
5c9470b9ca AST: Shun empty GenericSignatures, and remove the ASTContext argument from GenericSignature factories.
GenericSignatures with no params or requirements are a bug, so verify that they don't happen by making GenericSignature::get return null and GenericFunctionType assert that it has a nonnull signature. Hack Sema not to try to produce nongeneric GenericFunctionTypes when a function in a local type in a generic function context is type-checked; there's a deeper modeling issue that needs to be fixed here, but that's beyond the scope of 1.0. Now that GenericSignature always has at least one subtype, its factories no longer need an independent ASTContext argument.

Swift SVN r13837
2014-02-12 19:17:27 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Doug Gregor
016d62d930 Disallow @objc on methods, properties, subscripts, etc. in generic contexts.
Addresses <rdar://problem/16042185>.


Swift SVN r13790
2014-02-12 00:09:45 +00:00
Doug Gregor
8f0a7c5e19 Only use Objective-C dispatch to a constructor if it is actuallly @objc.
<rdar://problem/15967182> fixed the inference of @objc for
initializers, but our SILGen predicate deciding whether to perform
Objective-C dispatch was failing to heed the @objc bit on
constructors. Fixes <rdar://problem/16041090>.


Swift SVN r13787
2014-02-11 22:41:02 +00:00