Commit Graph

1572 Commits

Author SHA1 Message Date
Joe Groff
700615e864 SIL: Don't leak byref(heap) into closure types.
It causes IRGen to do the wrong thing, and we want to kill byref(heap).

Swift SVN r4729
2013-04-13 20:45:15 +00:00
Dave Abrahams
f2c548871d Whitespace fixups
Swift SVN r4644
2013-04-09 22:33:13 +00:00
Dave Abrahams
1c06a920fb Poke the (argc, argv) parameters to Swift's generated main() into the stdlib's (C_ARGC, C_ARGV) variables
Swift SVN r4637
2013-04-08 20:26:45 +00:00
Dave Abrahams
40ca34b072 Prepare LLVM-level access to argc, argv
Swift SVN r4620
2013-04-06 03:40:34 +00:00
Dave Abrahams
f890168fd1 Add argc, argv to the signature of swift's generated main()
Swift SVN r4619
2013-04-06 03:40:33 +00:00
Chris Lattner
b4fd6dd04a Change TopLevelCodeDecl to allow it to hold a sequence of different exprs and statements in one unit, wrapping them into a BraceStmt. This makes it more similar to other decls (e.g. funcdecl, ctor decls, etc) and will be useful for future sil work.
Unfortunately, this regresses the repl when expressions like (1,2) are entered. This is because the repl is violating some invariants (forming dags out of ASTs, making ASDAG's which upset the type checker).  I'm going to fix this next, but can't bring myself to do it in the same commit.



Swift SVN r4617
2013-04-05 22:33:14 +00:00
Joe Groff
aeeda4ee12 Parser: Parse operator decls.
At the top level, if 'operator' is followed by 'infix', 'prefix', or 'postfix', consider it a contextual keyword, and parse an operator decl following it that looks like:

  operator {infix|postfix|prefix} <+> {
    attributes…
  }

Prefix and postfix operator decls currently admit no attributes. Infix operators have 'associativity {left|right|none}' and 'precedence <int>' attributes.

This patch implements parsing for operator declarations but does not yet attach the declared attributes to func decls for the operators.

Swift SVN r4596
2013-04-03 23:30:50 +00:00
Chris Lattner
65cd2b2d25 rename swift::Function to swift::SILFunction to be more explicit.
Swift SVN r4590
2013-04-03 18:36:15 +00:00
Joe Groff
ef6d33039e Mark fallthroughs with [[clang::fallthrough]].
Use [[clang::fallthrough]] instead of informal /*fallthrough*/ comments.

Swift SVN r4574
2013-04-02 20:51:38 +00:00
Joe Groff
08d06e850d IRGen: Emit top-level globals from SIL.
Set up IRGen to emit SIL code that uses top-level-code global variables. Add -sil-i to a bunch of Interpreter tests that use global variables.

Swift SVN r4480
2013-03-22 23:34:38 +00:00
Joe Groff
fab787a585 IRGen: Linkage for anonymous SIL functions.
CapturingExprs get mapped to referenceable SILConstants by SILGen instead of getting emitted in-place as in IRGen, so they need LinkEntities and mangling. For now I just mangle them all to "closure", which matches what old IRGen does.

Swift SVN r4477
2013-03-22 19:09:28 +00:00
Joe Groff
990c136699 IRGen: Fix stupid typo in ObjC JIT extensions.
I'm dumb. Only the first method or property was getting visited!

Swift SVN r4242
2013-02-28 22:30:13 +00:00
Joe Groff
470ad60d60 IRGen: Emit properties for ivars of ObjC classes.
If a class has ObjC interop, synthesize property accessors for its ivars so that things like IBOutlets and bindings work correctly.

Swift SVN r4240
2013-02-28 20:24:43 +00:00
Joe Groff
23aaa56143 IRGen: Emit type metadata for Clang structs.
We need type metadata symbols for Clang structs so that they have witness tables and can conform to protocols (or be part of structs that conform to protocols). Consider Clang struct metadata to be 'isClangThunk' like other Clang-emitted definitions so that it all gets linkonce_odr'ed to avoid linker issues when multiple TUs import the same modules. Fixes <rdar://problem/13187143>.

Swift SVN r4170
2013-02-23 21:13:50 +00:00
Joe Groff
38a8b1f7e3 REPL: Don't call global_ctors before each entry.
The REPL was accreting global_ctors and rerunning all global initializers ever registered before every entry. Change it so that it only runs global initializers once and so that the ObjC initialization stuff that needs to happen on a per-entry basis just gets dropped directly into the main() for each entry.

Swift SVN r4154
2013-02-22 22:24:29 +00:00
Joe Groff
827cbfe0b0 IRGen: Dynamic init for repl ObjC extensions.
When running in immediate mode, generate a global initializer when an extension is defined for an ObjC class that uses the class_replaceMethod runtime function to dynamically add the extension methods to the ObjC class.

Swift SVN r4153
2013-02-22 21:08:39 +00:00
Joe Groff
a9f747ec1f IRGen: Emit categories for ObjC class extensions.
Emit ObjC stubs and categories for methods defined in extensions of ObjC-compatible classes. This makes extensions of ObjC classes available to ObjC in statically compiled code. For immediate-mode code we'll still need to dynamically register extension methods using the ObjC runtime.

Swift SVN r4149
2013-02-22 05:40:09 +00:00
Joe Groff
74589d788e Make ObjC-ness implicit to ObjC-inherited classes.
Add 'isObjC' as a property of ValueDecl, and set it during type checking if a class is either explicitly annotated with an [objc] attribute or inherits from an isObjC class, or if a func is a method of an isObjC class. Tweak the ClangImporter and other places that summon magic ValueDecl nodes to set up the decls they synthesize as isObjC. Replace logic in typechecking and IRGen that branched on the 'isObjC' attribute to now branch on the 'isObjC' property of ValueDecls.

Swift SVN r4078
2013-02-19 02:11:09 +00:00
Joe Groff
9c022d5d65 IRGen: Fudge passing large ObjC structs as byvals.
Push LLVM attribute generation from expandAbstractCC into getFunctionSignature and CallEmission so that they can generate sret and/or byval attributes per-argument according to the calling convention. Copy our bogus rule for emitting sret returns (more than three elements in the explosion) and reuse it to pass large struct values as byvals rather than as explosions. This should be good enough to get both 'NSRect' and
'NSRange', 'NSSize' etc. to pass correctly to ObjC methods. Next step is to set the AbstractCC correctly for imported func decls so that standalone C functions follow the same bogus rule.

Swift SVN r3993
2013-02-08 21:50:08 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Jordan Rose
3917fa66f0 Take three: both __objc_classlist and __objc_nlclslist are necessary.
Swift SVN r3959
2013-02-06 00:32:55 +00:00
Jordan Rose
5e71ffc421 Use __objc_nlclslist to force Swift classes to be registered with ObjC.
Per Greg's feedback, this variable obviates the need for a static
constructor when the output is compiled. In interpreted mode, we still
initialize the classes by calling +load ourselves.

This is a fix-up for r3949, but we probably still need a better long-term
solution. See <rdar://problem/13154445>.

Swift SVN r3956
2013-02-05 23:46:37 +00:00
Jordan Rose
f028cd2b6a Call +load on all classes to register them with the Objective-C runtime.
When an Objective-C class is first used, the runtime will "realize" it,
i.e. create the rw-data and set a couple flags. With pure Swift classes,
though, it's possible to create an instance and then send a message to it
without ever sending a message to the class, in which case the runtime will
try to realize the /instance/ and mess everything up.

This patch "fixes" that by sending the +load message to all Swift classes,
to make sure they get realized before being used. This is a very
unfortunate cost in startup time but will be necessary for id-compatibility.

I will admit that I'm not sure why this is necessary for compiled classes.
I would have expected the object file to contain the necessary information
for the runtime to realize the classes in it by default. But perhaps
classes aren't realized until their first class message even in statically-
compiled code.

<rdar://problem/13154445>

Swift SVN r3951
2013-02-05 19:53:01 +00:00
Doug Gregor
03b1689b60 Import C enumerations into usable struct types in Swift.
Import C enumeration types as either structs wrapping the underlying
integral type (when the C enumeration type has a name) or as the
underlying integral type (when the C enumeration type has no
name). The structs have a constructor from the underlying integral
type, so one can write, e.g., NSStringCompareOptions(0) to get a
zero-valued enumeration.

Enumerators are imported as a global read-only properties.

Once oneofs start to work, we'll have a way to map some enumeration
types to oneofs, either via a Clang attribute or by sniffing out
NS_ENUM (most likely both).

Once we have static data members of structs working, we'll replace the
global constants with prefix-stripped static variables within the
struct, so we can use ".foo" notation with them.

Once we have constant declarations, we'll map to those instead of
properties.

We can add |, &, and ~ operations are part of
<rdar://problem/13028799> and have not yet been implemented.

Fixes <rdar://problem/13028891>.


Swift SVN r3945
2013-02-05 00:01:27 +00:00
Jordan Rose
f1d7337880 Update for LLVM changes to make llvm::AttributeSet an opaque type.
Swift SVN r3909
2013-01-30 22:30:00 +00:00
Joe Groff
6cca08826a IRGen: Hack in calls to block converter funcs.
Add a mangling for 'block converter' functions and for [objc_block] function types. [objc_block] types also need their own HeapTypeInfo representation that uses ObjC retain/release. When we see a BridgeToBlockExpr, feed the function pointer and context from the Swift closure to the external conversion function and hope we get a block back.

Swift SVN r3899
2013-01-30 01:01:34 +00:00
Joe Groff
0bf66dae4b IRGen: Separate allocating and initializing ctors.
Emit separate entry points for the allocating and initializing constructors. 'super.constructor' now works for the small subset of cases for which I've implemented sema support.

Swift SVN r3864
2013-01-25 17:50:55 +00:00
Joe Groff
5be34d6337 IRGen: Fix type of initing ctor, destroying dtor
IRGen was generating the exact same signature for the initializing/allocating constructors and destroying/deallocating destructors. Make it do the right thing by typing the initializing constructor as Swift T -> (...) -> T and the destroying destructor as LLVM void(%swift.refcounted*). (This will later change to '%swift.refcounted*(%swift.refcounted*)' pending some irgen/runtime cleanup.)

Swift SVN r3837
2013-01-22 23:36:35 +00:00
Joe Groff
5852448152 IRGen: Generate SIL ctor and property decls.
Remove the filter that only irgenned SIL functions for FuncDecls so that we emit functions for all SIL decls, and disable the old paths for properties, constructors, and destructors when a SIL module is present. Unfortunately this breaks class constructors because SIL and IRGen don't agree on how initializing constructors should work. I need to sync with John to figure out how to fix that.

Swift SVN r3827
2013-01-22 02:45:27 +00:00
Joe Groff
19d65fede5 IRGen: Visit all SIL Functions in a SILModule.
Make the SIL visitor path a bit less hacky by more cleanly separating the AST walk to find types to codegen from the SIL module walk to find functions to codegen. This way, local functions and other such entry points from SIL actually get generated, and the closures test works.

Swift SVN r3820
2013-01-21 20:17:05 +00:00
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
John McCall
3713b6a549 Add a framework for distinguishing between deallocating
and non-deallocating destructors and allocating/non-allocating
constructors.

Non-deallocating destructors might not play well with ObjC
classes;  we might have to limit them to pure-swift hierarchies.

No functionality change except that I decided to not force
destructors to have internal linkage unconditionally.

Swift SVN r3814
2013-01-20 19:40:12 +00:00
John McCall
f166686df0 Permit invoking the mangler with either a buffer or a stream.
Swift SVN r3797
2013-01-18 09:06:11 +00:00
John McCall
9a4984b836 Use mangled type names for classes unless exporting them as [objc].
Swift SVN r3796
2013-01-18 09:06:09 +00:00
Joe Groff
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +00:00
John McCall
02c3c8703d Collect references to non-generic classes in __DATA,__objc_classlist.
Swift SVN r3788
2013-01-17 23:54:09 +00:00
Joe Groff
0970a18e7d IRGen: Compile the toplevel through SIL.
If IRGenModule has a SILModule, use its toplevel Function to emit the top-level code instead of re-walking TopLevelCodeDecls itself.

Swift SVN r3761
2013-01-14 18:33:08 +00:00
John McCall
61dd2646f1 Add a flag (always true) for whether to support ObjC interop.
Swift SVN r3744
2013-01-11 08:09:01 +00:00
John McCall
2e0070e229 Emit metaclass stub objects for swift classes.
Swift SVN r3740
2013-01-11 08:08:50 +00:00
John McCall
f6c2e0a92b Support for emitting references to ObjC metaclasses.
Swift SVN r3739
2013-01-11 08:08:48 +00:00
Doug Gregor
f40f990d9d Improve our logic to emit all of the thunks generated by the Clang importer.
Swift SVN r3651
2013-01-03 00:18:34 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Doug Gregor
f45c1c93d2 Fix dynamic casts to Objective-C-compiled classes.
Previously, we would emit bogus references to Swift metadata when
attempting to downcast to an Objective-C-compiled class, which doesn't
exist. Now, we just emit a direct reference to the Objective-C class
data.


Swift SVN r3559
2012-12-20 17:09:01 +00:00
Doug Gregor
3f19098a7e Emit importer-generated thunks as linkonce_odr hidden into every translation unit that imports the corresponding module.
Swift SVN r3547
2012-12-19 21:50:55 +00:00
John McCall
d01b272531 Untested infrastructure for emitting non-constant field accesses.
Swift SVN r3542
2012-12-19 08:45:47 +00:00
John McCall
b90adfa000 Add linking support for field-offset variables.
Not actually using them anywhere yet.

Swift SVN r3479
2012-12-13 10:28:35 +00:00
Doug Gregor
b4ca0f1fef Rename llvm::AttrListPtr -> llvm::AttributeSet to sync with LLVM mainline.
Swift SVN r3430
2012-12-10 23:21:19 +00:00
John McCall
59d4677b35 Implement metatype references to ObjC classes.
The interesting thing here is that we need runtime support in
order to generate references to metatypes for classes, mostly
because normal ObjC classes don't have all the information we want
in a metatype (which for now just means the VWT pointer).
We'll need to be able to reverse this mapping when finding a
class pointer to hand off to, say, an Objective-C class method,
of course.

Swift SVN r3424
2012-12-10 08:17:57 +00:00
Doug Gregor
4c71d7386a Implement getter/setter thunks for imported Objective-C properties.
With this, we are able to access Objective-C properties from within Swift.


Swift SVN r3393
2012-12-07 01:11:52 +00:00
Doug Gregor
aabff2b65b Create a getter thunk for Objective-C subscripts.
Swift SVN r3385
2012-12-06 23:52:16 +00:00