Commit Graph

2609 Commits

Author SHA1 Message Date
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +00:00
Dmitri Hrybenko
6a122e1d88 Clang module importer / code completion for DynamicLookup: when enumerating
decls accessible from DynamicLookup, don't import properties twice and don't
report properties with setters twice


Swift SVN r8858
2013-10-02 22:29:49 +00:00
Dmitri Hrybenko
1f9a7203de Clang importer: import subscript declarations from protocols (instead of
crashing in getClassInterface)


Swift SVN r8856
2013-10-02 20:56:22 +00:00
Dmitri Hrybenko
7e61978a22 Clang importer: don't import ObjC method decls twice
(This did not happen all the time, but it did happen for subscript operators
while enumerating all decls in a class.)


Swift SVN r8847
2013-10-02 18:38:24 +00:00
Argyrios Kyrtzidis
097d9a0d0e When we have selector-style syntax for functions, make the argument patterns implicit.
Argument patterns create pseudo-named patterns, so make them implicit and ignore them when scanning for explicit source information.
Also make sure that the clang importer sets the HasSelectorStyleSignature bit appropriately.

Swift SVN r8803
2013-10-01 15:37:46 +00:00
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +00:00
Argyrios Kyrtzidis
f0773bcba1 Rename '__subscript' -> 'subscript'.
Since 'subscript' is a keyword, it cannot conflict with a function name.

Swift SVN r8787
2013-09-30 19:17:29 +00:00
Doug Gregor
8b3d906ef7 Improve handling of Objective-C properties with dynamic lookup.
We want dynamic lookup to find the property, not the method, when
looking into an Objective-C module.


Swift SVN r8727
2013-09-27 17:08:27 +00:00
Doug Gregor
e1204bf388 Clean up handling of subscript imports from Objective-C modules.
I'm still not thrilled with this code, but it needs more thought. This
completes <rdar://problem/14656624>.


Swift SVN r8719
2013-09-27 03:58:03 +00:00
Dmitri Hrybenko
ba2e4732d0 Remove unused member EnumDecl::isEnum
Swift SVN r8710
2013-09-27 00:22:39 +00:00
Doug Gregor
c4a065abce Teach dynamic lookup to find subscript operators.
The name used for name lookup of subscript operators is "__subscript",
but when looking into an Objective-C module we instead need to look
for methods with the subscripting selectors, e.g.,
objectAtIndexedSubscript:/objectForKeyedSubscript:. Do so, and make
sure that deserializing the method first still creates the subscript
declaration.

Fixes the majority of <rdar://problem/14656624>. We can subscript 'id' now.



Swift SVN r8700
2013-09-26 21:42:45 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Doug Gregor
cc4c7d0fd8 [Clang importer] Stop creating property/subscript getter/setter thunks.
Instead of synthesizing Swift code for the property and subscript
getters and setters we import from Objective-C, just create the
declarations and mark them as being Objective-C (foreign) entry
points. This means that we'll use the Objective-C entry points (via
objc_msgSend).


Swift SVN r8692
2013-09-26 15:58:19 +00:00
Doug Gregor
40eba067b2 Limit the "requires Objective-C dispatch" predicate's use of hasClangNode().
Swift SVN r8667
2013-09-25 21:28:19 +00:00
Jordan Rose
15bfc8db2b Don't type-check imported decls unless referenced in the source file.
Instead, pass a LazyResolver down through name lookup, and type-check
things on demand. Most of the churn here is simply passing that extra
LazyResolver parameter through.

This doesn't actually work yet; the later commits will fix this.

Swift SVN r8643
2013-09-25 20:08:14 +00:00
Jordan Rose
f672d9f2ae Remove NSTypedArray and the iboutletcollection hack.
The hack was that __attribute__((iboutletcollection(NSView))) can be
specified on a collection property to provide its value type, and the
ClangImporter library co-opted that as a way to import NSArray properties
as NSTypedArray<NSView> (or whatever), a layout-compatible Swift struct
type that provided a typed (runtime-checked) view of an NSArray. The
implementation of NSTypedArray was never completed, however; none of
our sample code is actually using it; and it turns out to be problematic
for some instances of lazy type checking (because NSTypedArray is defined
in Swift). Remove it; we'll revisit this later.

Swift SVN r8639
2013-09-25 20:08:06 +00:00
Jordan Rose
2c794c0b93 [ClangImporter] Refuse to import a subscript if the index type doesn't match.
If the getter and setter have different index types, there's not much we can
do in Swift. It's better to not pretend to handle this (which currently leads
to a crash in SIL verification). Fortunately, this is likely very rare in
Objective-C, except for one special case:

We do plan to special-case this for NSDictionary, which has keys of type
'id' while NSMutableDictionary's setter uses 'id <NSCopying>'.

Swift SVN r8638
2013-09-25 20:07:59 +00:00
Argyrios Kyrtzidis
2456b33471 Propagate implicit'ness of OverloadSetRefExpr nodes.
Swift SVN r8604
2013-09-24 21:18:00 +00:00
Argyrios Kyrtzidis
e224667315 Refactor Implicit'ness of expressions.
Introduce a bit in Expr to indicate whether the expression is implicit and decouple the implicitness
of an expression from whether it has a source location or not.

This allows implicit expressions to be able to point at the source location where they originated from.
It also allows decoupling the implicitness of a parent from its children, so for example, an implicit CallExpr
can have an explicit parameter value.

Swift SVN r8600
2013-09-24 20:42:29 +00:00
Joe Groff
c4b4db732f Parse and check raw values on enum cases.
Iff an enum declares a raw type, its cases may declare raw values or else have them assigned to them implicitly by autoincrementing from zero, like in C. If the raw type is float-, string-, or char-literal-convertible, there is no autoincrement, and the raw values must all be explicit. The raw type is rejected if any cases have payloads.

We don't yet diagnose duplicate raw values. That'll come next. We also don't yet serialize or deserialize the raw values. We don't strictly need to do this, since the RawRepresentable protocol conformance will be exported from the module as API, but Jordan pointed out that, for fragile raw values, this would be good for documents/jump-to-definition purposes, so we have a plan for only serializing the literals without having to deal with fully general expression serialization.

Swift SVN r8545
2013-09-21 04:31:26 +00:00
Joe Groff
f9480828e0 Remove EnumCaseDecl backreference from EnumElementDecl.
Swift SVN r8516
2013-09-20 20:50:24 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Doug Gregor
bc3f655105 s/constructor/init in a few more places.
Swift SVN r8504
2013-09-20 18:37:15 +00:00
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +00:00
Doug Gregor
f2b0944e0b Map Objective-C's Class to DynamicLookup.metatype.
Swift SVN r8489
2013-09-20 14:52:31 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Doug Gregor
4492f85d59 When we import an Objective-C init method as a constructor, suppress the method.
This makes it impossible to call an "init" method from Swift code; one
must construct an object, delegate to another constructor (not yet
implemented), or chain to a superclass constructor.


Swift SVN r8421
2013-09-18 22:05:27 +00:00
Doug Gregor
18f9420bcb Stop generating definitions for the imported initializing constructors.
When we import an Objective-C init method into Swift as a constructor,
the Clang importer currently synthesizes both a +alloc call (used by
the allocating constructor) and a body that forwards to the
corresponding init method. Eliminate the body and stop emitting an
initializing constructor at all: instead, the allocating constructor
will invoke the init method through objc_msgSend.



Swift SVN r8420
2013-09-18 21:35:38 +00:00
Doug Gregor
dabdb5cf21 Swift has a more restrictive definition of 'init method' than Clang.
Only import an Objective-C 'init' method if both Clang and Swift
consider it an init method.


Swift SVN r8403
2013-09-18 17:28:57 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Joe Groff
bb163c11c8 Sema: Reference 'Self' archetypes back to their AssociatedTypeDecl.
We were neglecting to set the AssocType reference for protocol Self archetypes back to their implicit AssociatedTypeDecls.

Swift SVN r8167
2013-09-12 22:17:29 +00:00
Dmitri Hrybenko
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Dmitri Hrybenko
37ee3a210c Run AST verifier on modules produced by Clang importer and fix bugs found by it
Fixes two bugs in Clang importer and deserialization code that were found by
the verifier:

(1) FuncExprs were created with a null FuncDecl

(2) BoundGenericType that was created by Clang importer for UnsafePtr<> and
    other magic types did not have substitutions.


Swift SVN r8073
2013-09-10 18:22:12 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Doug Gregor
0dcca3aeda Eliminate CoerceExpr entirely.
Swift SVN r7876
2013-09-03 22:58:22 +00:00
Doug Gregor
508e02df19 All classes implicitly conform to the DynamicLookup protocol.
Swift SVN r7700
2013-08-28 22:57:24 +00:00
Dmitri Hrybenko
1593632d7b More 'this' -> 'self' replacements
Swift SVN r7659
2013-08-28 03:08:07 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Jordan Rose
fc3a5f5726 [ClangImporter] Believe type info coming from integer literals in macros.
That is, 1234 is a CInt, 1234U is a CUnsignedInt, and 1234LL is a CLongLong.
Oh, and 3.14F is a CFloat.

One caveat here is that it is not actually possible in C to write a literal
INT_MIN:

  -0x80000000 is two tokens and the literal part is unsigned
  (-INT_MAX - 1) is several tokens

I've simply dropped this test for now, but it might be confusing in the rare
case where an INT_MIN-like value is used as a sentinel.

<rdar://problem/13839025>

Swift SVN r7639
2013-08-27 22:41:05 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Doug Gregor
330f5fe1e7 For nested archetypes, track the corresponding associated type.
Each nested archetype X.Y corresponds to an associated type named 'Y'
within one of the protocols to which X conforms. Record the associated
type within the archetype itself. When performing type substitutions,
use that associated type to extract the corresponding type witness
rather than looking for the type itself. This is technically more
correct (since we used the type witness for type checking), and a step
toward pulling type substitutions into the AST.



Swift SVN r7624
2013-08-27 17:05:11 +00:00
Doug Gregor
2e91172d4f Don't record the declared type of nominal type decls within the module file.
Instead, compute the type just after we load the nominal type
declaration. This centralizes the type-computation code better as
well.


Swift SVN r7454
2013-08-22 17:33:24 +00:00
Doug Gregor
5034803021 Lazily compute the type of protocol declarations.
Swift SVN r7453
2013-08-22 17:09:16 +00:00
Doug Gregor
e7f5f3da01 Set the type of class/struct/union declarations during type checking.
Previously, we were creating the type corresponding to
class/struct/union declarations as part of creating the declaration
node, which happens at parse time. The main problem with this (at the
moment) occurs with nested nominal types, where we'd end up with the
wrong "parent" type when the type was nested inside an extension
(because the extension hadn't been resolved at the time we accessed
the parent's type). Amusingly, only code completion observed this,
because the canonical type system hid the problem. The churn in the
code-completion tests come from the fact that we now have the proper
declared type for class/struct/union declarations within extensions.

Take a step toward order-independent type checking by setting the type
of a class/struct/union declaration in type checking when we either
find the declaration (e.g., due to name lookup) or walk to the
declaration (in our walk of the whole translation unit to type-check
it), extending the existing TypeChecker::validateTypeDecl() entry
point and adding a few more callers.

The removeShadowedDecls() hack is awful; this needs to move out to the
callers, which should be abstracted better in the type checker anyway.

Incremental, non-obvious step toward fixing the representation of
polymorphic function types. This yak has a *lot* of hair.



Swift SVN r7444
2013-08-22 00:57:38 +00:00
John McCall
0fdd6e55cc We're going to type-check these expressions, no need to
try to give them the right type now.

Swift SVN r7411
2013-08-21 18:44:56 +00:00
Doug Gregor
323b9d91e0 Distinguish a function's result type in the interface vs. in the definition.
At present, this is a distinction without a difference. However, it's
a step toward detangling archetypes from the interface of a
polymorphic function.


Swift SVN r7405
2013-08-21 17:50:20 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00