Commit Graph

12816 Commits

Author SHA1 Message Date
Joe Groff
10438902dd Remove GetMetatypeExpr.
Now that we don't allow static methods to be invoked from instances we no longer need an AST node to represent an implicit instance-to-metatype conversion. MetatypeExpr encodes the explicit '.metatype' operation.

Swift SVN r4472
2013-03-22 00:28:21 +00:00
Joe Groff
98f58675d5 IRGen: Handle function values from SIL correctly.
As values, IRGen expects functions to be i8*, so bitcast function values to i8* and bitcast them back when they're actually called.

Swift SVN r4471
2013-03-21 23:44:03 +00:00
John McCall
1a8d624b6c Rename the SIL 'closure' instruction to 'partial_apply'.
Swift SVN r4468
2013-03-21 21:59:28 +00:00
Joe Groff
15d606b630 IRGen: Lower SIL class_method for native classes.
Turn class_method into a vtable lookup for Swift class and class metatype instances.

Swift SVN r4467
2013-03-21 20:50:37 +00:00
Joe Groff
aaa85831a3 IRGen: Lower SIL super_method for native classes.
ObjC classes will need a special code path to support super_method, but in the pure Swift case it's just a direct reference to the super implementation.

Swift SVN r4457
2013-03-20 21:22:24 +00:00
Joe Groff
c090f65a06 IRGen: Update lowering for SIL protocol_method.
Swift SVN r4456
2013-03-20 20:48:16 +00:00
Joe Groff
92c81b76c9 IRGen: Update lowering of SIL closure insts.
Swift SVN r4454
2013-03-20 16:16:39 +00:00
Joe Groff
6668cc7316 IRGen: Fix SIL constant_ref to destructor.
Destructor refs were getting bitcast to the wrong type.

Swift SVN r4453
2013-03-20 03:46:10 +00:00
Joe Groff
61077a641d IRGen: Lower SIL function args in right order.
Map the SIL entry point BB's args to LLVM function args in the inner-to-outer-uncurry order used by Swift's ABI.

Swift SVN r4452
2013-03-20 03:23:56 +00:00
Joe Groff
ac73865dd7 IRGen: Update lowering of SIL applications.
We no longer need the PartialCall hackery in IRGen to uncurry calls, because SILGen does it for us.

Swift SVN r4451
2013-03-20 00:02:49 +00:00
Joe Groff
4c09ef61e3 Add conditional expressions.
Implement the syntax 'if x then y else z', which evaluates to 'y' if 'x' is true or 'z' if 'x' is false. 'x' must be a valid logic value, and 'y' and 'z' must be implicitly convertible to a common type.

Swift SVN r4407
2013-03-16 20:28:58 +00:00
Joe Groff
062ad267c4 Value-only switch statements.
Implement switch statements with simple value comparison to get the drudge work of parsing and generating switches in place. Cases are checked using a '=~' operator to compare the subject of the switch to the value in the case. Unlike a C switch, cases each have their own scope and don't fall through. 'break' and 'continue' apply to an outer loop rather to the switch itself. Multiple case values can be specified in a comma-separated list, as in 'case 1, 2, 3, 4:'. Currently no effort is made to check for duplicate cases or to rank cases by match strength; cases are just checked in source order, and the first one wins (aside from 'default', which is branched to if all cases fail).

Swift SVN r4359
2013-03-12 04:43:01 +00:00
Joe Groff
340cc73e1e SIL: Track uncurry levels of SILConstants.
Pack the uncurry level onto SILConstant, and modify SILConstant constructors to determine the natural uncurry level of their referenced entity by default. While we're here, improve how SILConstant represents different kinds of constants by using a real enum for the kind. Type closure entry points by giving them an extra curry level for their context. The implementation of ApplyInst and ClosureInst hasn't been updated yet, so tests that lower closures to SIL are temporarily broken.

Swift SVN r4354
2013-03-11 23:17:35 +00:00
Joe Groff
4d4357fdc5 IRGenSIL: Don't use anonymous struct.
Apparently that's a GNU extension.

Swift SVN r4327
2013-03-08 00:33:27 +00:00
Joe Groff
8fb9a46f95 AST: Wrap super.ctor calls in a RebindThis node.
'super.constructor' shouldn't be referenceable without being called, and 'super.constructor(...)' shouldn't return a value. Require super.constructor expressions to be called at parse time, and wrap the call expression in a new RebindThisInConstructorExpr that represents consuming the delegated-to constructor by using it to reassign 'this'. This should theoretically allow super.constructor to an ill-behaved self-modifying ObjC class to work. It's also necessary to support delegating constructors of value types.

Swift SVN r4326
2013-03-08 00:09:39 +00:00
Joe Groff
0db00816cd SIL: Replace ZeroAddr/ZeroValue with InitializeVar
Rename 'ZeroAddr' to 'InitializeVar' and remove ZeroValue since only things with memory locations should ever be in a 'default-initialize' state. Add a ModuleInst so we don't need to use ZeroValue as a hack to represent ModuleExpr values.

Swift SVN r4319
2013-03-07 18:38:25 +00:00
Joe Groff
24a092bc3a IRGen: Use 'generic' cpu target.
LLVM recently changed to autodetect host features by default. Change our default to use the "generic" CPU so that we emit binaries to a portable baseline (until some time in the future when we have proper -mtune and -mattr flags).

Swift SVN r4310
2013-03-06 23:59:18 +00:00
Joe Groff
8da204e3a2 IRGenSIL: Improve Explosion handling.
Instead of embedding Explosions in IRGenSIL's LoweredValues and trying to use them directly, store an unmanaged vector of llvm::Value*s, and create Explosions as needed. This allows Explosion APIs to behave normally (consuming values out of the explosion) without potentially messing up SIL value-to-LLVM value mappings.

Swift SVN r4309
2013-03-06 22:11:13 +00:00
Joe Groff
c9c0d7e2cc Sema: Set an 'isSuper' flag on ApplyExprs.
SIL or IRGen need to consider the 'super'-ness of an apply when determining its dispatch semantics.

Swift SVN r4307
2013-03-06 19:36:30 +00:00
Joe Groff
0132f279a7 IRGen: ObjC super dispatch for super.constructor.
Implement super.constructor for ObjC superclasses by dispatching the superclass init message with objc_msgSendSuper2. Fixes <rdar://problem/13107128>.

Swift SVN r4288
2013-03-05 21:39:42 +00:00
Joe Groff
f489f2a6fd Clean up AST representation of 'super'.
Replace the more specific Super*RefExpr nodes with a single SuperRefExpr that resolves members of 'this' relative to its superclass. Add an OtherConstructorDeclRefExpr for referring to a constructor as called from another constructor, and use it to represent resolved 'super.constructor' expressions. (It should also be able to represent delegating constructors for free, if we decide we want to add syntax for that.)

Swift SVN r4286
2013-03-05 02:13:49 +00:00
Joe Groff
f78b090829 IRGen: Fix for llvm::Attributes API change.
CallInst::addAttribute takes an AttrKind now instead of an Attribute.

Swift SVN r4264
2013-03-02 17:17:41 +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
6af18efae8 IRGen: Use ObjC vwtable for ObjC classes.
Fixes <rdar://problem/13300684>.

Swift SVN r4226
2013-02-27 19:35:00 +00:00
Joe Groff
54bf40ee49 IRGen: Fix crashing objc_subclass test.
Swift SVN r4208
2013-02-26 23:05:14 +00:00
Joe Groff
be3f4ae1ec IRGen: Emit ObjC methods for properties.
Emit getter and setter ObjC methods and selectors for Swift properties declared in ObjC classes or extensions. If the type of the property is an ObjC class, also emit special-cased ObjC formal property metadata for the property as if it were declared @property (nonatomic, {readonly,strong}) in ObjC.

Swift SVN r4207
2013-02-26 22:57:45 +00:00
Joe Groff
fd0c5d6403 IRGen: Fix name of swift_getTupleTypeMetadata.
Fixes <rdar://problem/13284728>.

Swift SVN r4198
2013-02-25 21:41:16 +00:00
Doug Gregor
315451eb45 Implement parsing, AST, semantic analysis, and IRgen for dictionary literals.
Swift SVN r4193
2013-02-25 07:27:15 +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
4bac3168c9 IRGen: Retain value type elts in objc stub.
We were just shuttling value types from the objc entry point to the native one at +0 without bringing them up to +1 like the Swift native entry point expects, so things like Slices or closures that got passed through an ObjC interface were getting overfreed.

Swift SVN r4160
2013-02-23 01:22:23 +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
8392d212ec IRGen: Update ObjC mangling not to depend on attr.
Oops, missed a spot where it was referring to 'DeclAttributes::ObjC' directly instead of going through the accessor. This should make removing [objc] from the examples work.

Swift SVN r4100
2013-02-20 02:16:17 +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
Jordan Rose
7afd5f0348 Remove the "no Swift bit" hack entirely.
As Doug points out, we won't regress here. All Objective-C runtimes we care
about are correctly ignoring this bit.

<rdar://problem/13065246>

Swift SVN r4052
2013-02-14 23:07:26 +00:00
Joe Groff
72703f84a6 Sema: Typecheck UnresolvedSpecializeExprs.
Use UnresolvedSpecializeExprs to set up equality constraints on the opened generic type variables of their subexpressions, and when the system is solved, resolve the expression away to its specialized base expression. Fix the solution logic for DeclRefExprs so that they obtain the type the constraint checker solved for them and not the original unbound type of the decl. This means that constructions and static member accesses of generic types now parse! This also incidentally fixes <rdar://problem/13212959>, so 'A(0)' for generic 'A<T>' now works when T can be inferred from constructor arguments.

One thing that doesn't work yet is generics as type members, as in 'A.B<C>' or 'A<B>.C<D>'. The UnresolvedDotExpr for these generates an unbound type variable, and I'm not sure how to express opening a type variable as a generic type $TO<A, B, C>.metatype constraint system in which the thing being specialized is a variable. This patch also doesn't allow explicit specialization of functions; although we could do so in theory, the constraint system that currently gets generated for functions loses the type parameters, so it would require some redesign in the constraint checker.

Swift SVN r4047
2013-02-14 19:41:26 +00:00
Joe Groff
4792c60d2d IRGen: Implement super method calls.
For Objective-C super calls, build an objc_super struct value containing the receiver and class/metaclass object and pass it to objc_msgSendSuper2. For Swift super calls, emit a direct call to the super implementation.

Swift SVN r4023
2013-02-13 02:41:20 +00:00
Jordan Rose
b68b1b27f9 Emit [ibaction] methods as if they were [objc].
Conversely, /call/ [ibaction] methods as Swift methods, at least for now,
and ignore [iboutlet] altogether.

Swift SVN r4018
2013-02-12 01:31:50 +00:00
Joe Groff
45e5909911 IRGen: Export objc methods w/ NSRect return/args.
Fix up the thunk generator so it knows how to turn byval C arguments back into Swift explosions, so that methods that take NSRects as arguments or give NSRect as their return value can be exported as objc methods.

Swift SVN r4010
2013-02-10 17:24:27 +00:00
Joe Groff
aa75885266 IRGen: Fix C funcs with big struct return and arg.
Should have tested both together. Oops.

Swift SVN r3998
2013-02-09 01:39:22 +00:00
Joe Groff
7ad898b404 IRGen: Fudged big struct support for C functions.
Extend the NSRect kludge to freestanding functions by giving imported decls the C calling convention.

Swift SVN r3995
2013-02-08 23:20:55 +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
Jordan Rose
67eaa1abb4 Silence -Wunused-variable warnings.
No functionality change.

Swift SVN r3988
2013-02-08 00:19:54 +00:00
Jordan Rose
b44f38ef44 Emit ObjC method types for getters that return (class) objects.
This is needed for KVC.

Swift SVN r3987
2013-02-08 00:19:53 +00:00
Jordan Rose
14cbc7f39c Allow methods from Objective-C categories to be overridden.
While we don't have a model for overriding methods in Swift extensions yet,
overriding category methods is exactly like overriding any other Objective-C
method, and we shouldn't disallow it.

Swift SVN r3985
2013-02-08 00:19:49 +00:00
Jordan Rose
b5a642c670 Don't mangle Clang globals.
Use the same rule for Clang functions and Clang global variables: don't do
anything. Eventually we'll use Clang's mangler to get a proper C/C++
mangling as necessary.

Swift SVN r3961
2013-02-06 01:29:18 +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