Trailing closure syntax allows one to write a closure following any
other postfix expression, which passes the closure to that postfix
expression as an arguments. For example:
sort(fruits) { |lhs, rhs|
print("Comparing \(lhs) to \(rhs)\n")
return lhs > rhs
}
As a temporary limitation to work around the ambiguity with
if foo { ... } { ... }
we require trailing closures to have an explicit parameter list, e.g.,
if foo { || ... } { ... }
Swift SVN r5210
The importer has always imported types differently in different
places, e.g., function parameter types have special rules for C++
references. Formalize this notion a bit, and make it work properly
when dealing with typedefs where the underlying type itself might be
imported differently in different contexts.
As part of this, limit the import of C's 'void' type to the result of
a function type.
Swift SVN r5055
Keep track of external definitions as they are created by broadcasting
them through a mutation listener interface. At name binding time, we
just cache them. When a type checker is alive, it immediately performs
any additional operations necessary on those types (e.g., declaring
implicit constructors).
This also eliminates some O(N^2) behavior in the type checker as well,
because we don't have to walk through all of the module imports to
find the external definitions. We just keep a single list in the
ASTContext along with our place in the list.
Fixes <rdar://problem/13769497>.
Swift SVN r5032
Previously, the Clang importer would synthesize the memberwise
constructor itself, but not a default constructor. Eliminate the
redundant code path and provide correct semantics for the second by
letting the type checker introduce the implicitly-defined constructors
itself.
Swift SVN r4973
When importing an enum constant, we import its enum type, which then recursively imports the same enum constant, returns, and finishes importing the enum constant--again. Oops. Hack around this by re-checking for a cached imported definition for an enum constant after importing its type.
Swift SVN r4963
NSAppleEventDescriptor has multiple "default" init methods, -init, -initRecordDescriptor, and -initListDescriptor, and they were all getting imported as default constructors in Swift. I don't know what the right thing to do long-term about init methods like these, but short-term I think we can get away with suppressing them.
Swift SVN r4962
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
Following up on the NS(U)Integer -> Int mapping change, also map
64-bit anonymous enums and their enumerators to Int rather than
directly mapping the underlying integer type. This improves
interoperability with NSInteger types, allowing (e.g.) comparisons of
NSIntegers to NSNotFound.
Swift SVN r4089
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
r4035 introduced overridden-method searches into the Clang importer by
looking into the Swift declarations. However, because Objective-C
allows forward declarations, there's no order in which we could
populate the Swift declarations to ensure that all of the appropriate
overrides were found. Instead, we do the right (and lazy) thing of
performing the lookup within Clang, then importing the results. This
change also introduces caching for mirrored protocol imports, so they
can be imported lazily.
Fixes <rdar://problem/13219096>.
Swift SVN r4072
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
This makes sure that, when we load the real Foundation module, all
references to id/Class/SEL get mapped to NSObject/NSObject/ObjCSel.
Note that you'll need Clang r174234 for this to actually work
properly. Clang modules weren't coping with these redefinitions
appropriately.
Swift SVN r3934
explicitly conforms to protocols, mirror any protocol methods that
aren't also declared in the class/category/extension within the
extension. Among other things, this makes sure that "-hash" and
"-isKindOfClass:" are available on NSObject (they come from the
NSObject protocol).
Fixes <rdar://problem/13074691>.
Swift SVN r3920
Update everywhere in Swift that refers to this module accordingly.
This change is backwards-incompatible and will require rebuilding any
Objective-C-based object files. I recommend a clean of swiftFoundation
and NSStringDemo at the very least. The swiftObjC target is also being
renamed to swiftObjectiveC for consistency.
Swift SVN r3784
We can't IRGen the getter and setter thunks, and we don't want to import
the getter and setter methods individually because that's not
source-compatible with properties in Swift. Support for importing
protocol properties properly is tracked in <rdar://problem/12993073>.
Swift SVN r3735
This maps methods with selectors that have repeated names, such
as performSelector:withObject:withObject:, to function types for which
one can meaningfully call with named arguments. Once an identifier has
been seen as a parameter name, subsequent parameters will have a
number appended to them, so we'll end up with calls like
foo.performSelector(sel, withObject=x, withObject2=y)
Swift SVN r3645
When we import an Objective-C protocol, we add the "Proto" suffix to
the name to avoid collisions when a class and protocol have the same
name. Of course, one's "Proto"-suffixed declarations will still
conflict, so this rule isn't great.
Swift SVN r3642
By splitting out the expression used to allocate 'this' (which exists
in the AST but cannot be written in the Swift language proper), we
make it possible to emit non-allocating constructors for imported
Objective-C classes, which are the only classes that have an
allocate-this expression.
Swift SVN r3558
...although we're not planning to use them for anything. (It's possible they
need to be inherited for ibtool to work correctly, but that's a long ways
off.)
Swift SVN r3433
The ObjCBool type interoperates with Swift's native Bool type, so one
can use true/false as well as conditionals with Objective-C
functions/methods that involve BOOL.
Swift SVN r3410