Commit Graph

2428 Commits

Author SHA1 Message Date
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
Doug Gregor
6c80f64c6e Diagnostic circular class inheritance.
Break cycles agressively when we find circular class inheritance. The
stronger AST invariants prevent us from having to check for loops
everywhere in the front end.


Swift SVN r7325
2013-08-19 15:31:13 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Dmitri Hrybenko
bb3d38b727 Clang importer: put the top-level declarations into the correct ClangModule
Before this change, DeclContext of all imported decls was set to the first
imported module.

No tests now, will be tested by future code completion commits.


Swift SVN r6949
2013-08-06 21:06:44 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Doug Gregor
a0dc08c650 [Clang importer] Never set the 'inherited' fields of type declarations.
Instead, just set the list of protocols directly. The 'inherited'
fields are only for the parsed representation of the ASTs.


Swift SVN r6685
2013-07-29 14:37:18 +00:00
Jordan Rose
beda29740a [ClangImporter] Don't assume forward declarations are never filled in.
Previously the result of a failed import was always cached, even if it
failed because a forward declaration was missing.

There is an actual problem here: NSString methods in the ObjectiveC
module (specifically, -description and +description, and later
-debugDescription) are not being imported if ObjectiveC is imported
before Foundation. However, previously this resulted in a crash.

Swift SVN r6524
2013-07-23 23:10:20 +00:00
Dmitri Hrybenko
2534aff169 Clang importer: don't assert when a mapped type can not be resolved in the
standard library modules because the user did not import the module.

For example, using 'SEL' without importing ObjectiveC (and while importing
other Clang module) used to assert.


Swift SVN r6337
2013-07-17 21:52:38 +00:00
Argyrios Kyrtzidis
f616eeee8b Utilize TypeReprs for type checking.
-Refactor Parser to stop creating types
-Refactor TypeChecker to create types by resolving TypeReprs.
-Remove "validation" bit from the type system.
  We don't need to "validate" every type that gets created but there's still a validation bit in TypeLoc,
  necessary because of generic substitutions.

Swift SVN r6326
2013-07-17 14:57:35 +00:00
Doug Gregor
66d3027847 Stop building UnstructuredUnresolvedTypes.
Instead, actually fill in errors types when type checking fails.


Swift SVN r6240
2013-07-13 04:17:32 +00:00
Joe Groff
d956fdbd9e Update 'oneof' syntax.
Give oneof bodies syntax consistent with other NominalTypes. Give oneof elements first-class declaration syntax using the 'case' introducer, as suggested by Jordan. Oneofs can contain 'case' decls, functions, properties, and constructors, but not physical ivars. Non-oneof scopes cannot contain 'case' decls. Add some QoI to the oneof 'case' parser to also parse and complain about things that resemble switch 'case' labels inside decl contexts.

Swift SVN r6211
2013-07-12 20:42:19 +00:00
Argyrios Kyrtzidis
a70eff6609 Introduce TypeRepr and related subclasses, that is a representation of a type as written in source.
This the first part for improving source location fidelity for types,
changes to follow:

-The Parser will not create any types, it will just create TypeReprs.
-The type checker will create the types by going through TypeReprs.
-IdentifierType will be removed.

Swift SVN r6112
2013-07-10 14:58:52 +00:00
Doug Gregor
fc1c256ef5 Allow references to deduced associated types.
When checking a type's conformance against a protocol, we can deduce
the values of associated types. Make these associated types visible to
qualified name lookup so that (for example) VectorEnumeratorType does
not need to define the Element type. It is deduced from the signautre
of next(), and made available as, e.g.,
VectorEnumeratorType<Int>.Element through the Enumerator protocol
conformance. Fixes <rdar://problem/11510701>, but with some lingering
dependencies on lazy type resolution (<rdar://problem/12202655>).

Note that the infrastructure here is meant to be generalized to
support default implementations in protocols, but there are several
pieces still not in place.



Swift SVN r6073
2013-07-08 22:32:27 +00:00
Dmitri Hrybenko
f428683842 Remove unused 'Body' parameter in FuncExpr::create()
'nullptr' is only ever passed as the argument value.


Swift SVN r5966
2013-07-02 23:12:15 +00:00
Doug Gregor
ed2823184a Have the type checker explicitly set the list of protocols
Previously, this set of protocols was computed lazily, which fails
catastrophically if getProtocols() was invoked before validation of
the types in a type/extension's "inherited" list.


Swift SVN r5924
2013-07-01 16:23:01 +00:00
Doug Gregor
1239757489 [Name lookup] Move ASTContext::lookup to Module::lookupQualified, where it belongs.
No functionality change.


Swift SVN r5921
2013-07-01 14:05:55 +00:00
Doug Gregor
a99df7a7b9 [Name lookup] Eliminate MemberLookup in favor of ASTContext::lookup().
Swift SVN r5888
2013-06-28 22:56:15 +00:00
Joe Groff
647421a013 ClangImporter: Rename 'BridgedTypes' to 'MappedTypes'.
This avoids some potential confusion with what SIL calls "bridged types", which involve more than a simple mapping to bridge.

Swift SVN r5815
2013-06-26 17:20:08 +00:00
Dmitri Hrybenko
05203f70f3 ClangImporter: Use ConstDeclVisitor and constify Clang's decls throughout the importer
Swift SVN r5788
2013-06-24 20:27:57 +00:00
Joe Groff
f072c48e45 Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.

In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.

At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.

The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.

Swift SVN r5737
2013-06-21 05:54:03 +00:00
Dmitri Hrybenko
8c3995996f Add infrastructure to easily map C types to swift stdlib types when they are
binary compatible.

This enables us to import MacTypes.h types as stdlib swift types to avoid name
conflicts.  We also import stdint.h types as stdlib swift types.

We can not map 'long double'-based ctypes.Float80 to swift.Float80 because size
of long double is 128 according to SysV ABI, and I compare that against what
the type name says (I did not find a way to find the size of the type).

Darwin.Float80 is a struct, so I don’t think we can import it as swift.Float80.
So with import Darwin, Float80 is still ambiguous.

I had to rename test/ClangModules/ctypes.swift ->
test/ClangModules/ctypes_test.swift because other tests do 'import ctypes',
which picks up 'ctypes.swift'.


Swift SVN r5727
2013-06-20 22:08:35 +00:00
Joe Groff
a55f246946 Remove the controversial "bounded" from "class-bounded".
Just refer to "class archetypes" and "class protocols". Change 'isClassBounded' methods to 'requiresClass', which is a character shorter.

Swift SVN r5674
2013-06-19 03:58:11 +00:00
Joe Groff
a491a3fc93 ClangImporter: Emit metadata for imported protocol types.
Swift SVN r5605
2013-06-16 02:55:47 +00:00
Joe Groff
e9cd5b255c ClangImporter: Conditionally reenable import of ObjC protocol types.
Import ObjC protocol decls into Swift with the [class_protocol] and [objc] attributes. Add an -import-objc-protocol-types flag to reenable import of ObjC qualified object types as Swift protocol types.

Swift SVN r5604
2013-06-16 02:08:24 +00:00
Joe Groff
cb1f81db84 Make assignment an expression.
Change AssignStmt into AssignExpr; this will make assignment behave more consistently with assignment-like operators, and is a first step toward integrating '=' parsing with SequenceExpr resolution so that '=' can obey precedence rules. This also nicely simplifies the AST representation of c-style ForStmts; the initializer and increment need only be Expr* instead of awkward Expr*/AssignStmt* unions.

This doesn't actually change any user-visible behavior yet; AssignExpr is still only parsed at statement scope, and typeCheckAssignment is still segregrated from the constraint checker at large. (In particular, a PipeClosureExpr containing a single assign expr in its body still doesn't use the assign expr to resolve its own type.) The parsing issue will be addressed by handling '=' during SequenceExpr resolution. typeCheckAssignment can hopefully be reworked to work within the constraint checker too.

Swift SVN r5500
2013-06-06 22:18:54 +00:00
Doug Gregor
78f722558c Fix weird spacing
Swift SVN r5495
2013-06-06 18:54:18 +00:00
Doug Gregor
452f9562e1 [Clang importer] Only import prototyped functions.
Unprototyped C functions can't sensibly be reflected in the Swift type
system, and are awful besides, so don't import them. Then, always go
through importFunctionType to import function types, fixing the
missing pattern in <rdar://problem/13992215>.


Swift SVN r5494
2013-06-06 18:34:46 +00:00
Doug Gregor
87965ac319 When the index types of an Objective-C class's subscript getter and setter mismatch, don't build thunks for either.
Previously, we would build an invalid AST for the getter.


Swift SVN r5434
2013-06-03 18:23:48 +00:00
Doug Gregor
5e2619802d Tighten up the semantics of unchecked downcasts (x as! T).
Explicit detect (and reject) conversions that aren't class
downcasts. We'll want to lift some of these restrictions later (see
<rdar://problem/14013456>), but for now we just reject them with a
decent diagnostic (rather than crashing).

When an explicit downcast is actually just a coercion, complain,
provide a Fix-It, and update the AST appropriately.

This also splits the checking of unchecked downcasts into two different
constraint systems: one for the context of expression, and one for the
subexpression, then compares the results. This eliminates the need to
model "can be downcast to" in the constraint solver, and makes it
easier to provide good diagnostics.



Swift SVN r5377
2013-05-29 17:48:43 +00:00
Joe Groff
11c7a3a92d ClangImporter: Bridge NSString objc properties to String properties.
We had an inconsistency where the synthesized Swift getter/setters were bridged but the VarDecl wasn't, causing assertion failures in SILGen.

Swift SVN r5366
2013-05-28 22:53:14 +00:00