Commit Graph

21693 Commits

Author SHA1 Message Date
Doug Gregor
a2df2ca302 Introduce TypeBase::getTypeOfMember() to produce the type of a member access.
This routine provides an AST-level operation that takes a base type
and a member, then computes the type the member will have when
accessed through that base, substituting (e.g.) generic arguments for
the archetypes in the type of the member. It is a cleaned up, slightly
generalized, and slightly more correct formulation of
TypeChecker::substMemberTypeWithBase(), which is now just a shim that
invokes TypeBase::getTypeOfMember().

Addresses <rdar://problem/14778376>.


Swift SVN r8198
2013-09-13 16:07:27 +00:00
Doug Gregor
baf070b654 Zap BoundGenericType::hasSubstitutions() and its only, unnecessary use.
Swift SVN r8195
2013-09-13 14:45:24 +00:00
Doug Gregor
e5c39d3e16 Always compute the substitutions of a BoundGenericType on-the-fly.
We often won't need the complete substitutions, so only compute them
when needed. This also means that we don't need to serialize them into
module files.


Swift SVN r8194
2013-09-13 14:38:23 +00:00
Doug Gregor
978eaab5c6 Introduce lazy computation of a BoundGenericType's substitutions.
Teach a BoundGenericType to compute its own substitutions, which
allows AST clients to create new bound generic types without the aid
of the type checker. 

This eliminates the TypeChecker::validateTypeSimple() abomination as
well as the need for the BoundGenericType AST validation step. There
is still more cleanup to do in this area.

Note that BoundGenericType::getSubstitutions() now accepts a module
parameter, which is the place from which we will look for
conformances. This is a baby step toward properly modeling the
conformances as part of the bound generic type, and is nowhere near
complete.


Swift SVN r8193
2013-09-13 14:25:36 +00:00
Dmitri Hrybenko
ea75b2ac5f Fix implementation of ValueDecl::isDefinition()
No testcase because this is not testable now -- this function is only used in
diagnostics of value redefinitions, which are broken now for redefinitions of
member functions.


Swift SVN r8187
2013-09-13 03:49:07 +00:00
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +00:00
Dmitri Hrybenko
16ce358562 Sink FuncDecl::getExtensionType() to AbstractFunctionDecl
Swift SVN r8184
2013-09-13 02:57:09 +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
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +00:00
Doug Gregor
2ca2ce9e73 Teach BoundGenericType to compute its own substitutions.
This eliminates the need for the hackish
LazyResolver::resolveUnvalidatedType() entry point, making type
substitution on ASTs far more useful. As part of this, teach it to
handle conformances for existentials and archetypes.


Swift SVN r8169
2013-09-12 22:51:21 +00:00
Doug Gregor
12c365e643 Allow type substitution with a null resolver.
This allows AST clients to perform type substitutions without
requiring a type checker. Test this by performing substitutions within
the AST verifier.


Swift SVN r8166
2013-09-12 21:53:22 +00:00
Doug Gregor
526dbd8231 Propagate explicit-conformance declaration to inherited protocol checks.
Eliminates the redundant diagnostics I introduced in r8127.


Swift SVN r8163
2013-09-12 21:06:03 +00:00
Dmitri Hrybenko
8db6568394 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
(Recommit a complete refactoring.)


Swift SVN r8161
2013-09-12 21:01:52 +00:00
Dmitri Hrybenko
9e889d1b56 Revert my commit r8157. It is breaking tests in +Asserts.
Swift SVN r8160
2013-09-12 20:53:00 +00:00
Dmitri Hrybenko
f49f9b0774 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
Swift SVN r8159
2013-09-12 20:44:28 +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
Doug Gregor
26eec21081 Factor out the search for explicit conformances.
Swift SVN r8151
2013-09-12 17:52:27 +00:00
Dmitri Hrybenko
796eac4b3f Make SILLocation::dump() more informative
Swift SVN r8130
2013-09-12 00:25:32 +00:00
Doug Gregor
e6076d1caf Move protocol-conformance computation into Module::lookupConformance().
Introduce an AST operation that, given a type and a protocol, determines
whether the type conforms to the protocol and produces the protocol
conformance structure. Previously, this operation was only available
on the type checker, requiring many callbacks from the AST to the type
checker during AST substitution operations (for example).

Now, we only call back into the type checker when we hit a case where
we see an explicit conformance in the AST, but the actual
ProtocolConformance object has not yet been built due to lazy type
checking.

Note that we still require a resolver (i.e., a TypeChecker) in a few
places, although we shouldn't need it outside of lazy type
checking. I'll loosen up the restrictions next.

There's a minor diagnostics regression here that will be cleaned up in
a future commit.


Swift SVN r8129
2013-09-12 00:23:19 +00:00
Dmitri Hrybenko
3fb2d14a8e Simplify FuncDecl::getExtensionType() implementation
Replace it with a call to DeclContext::getDeclaredTypeInContext().


Swift SVN r8105
2013-09-11 20:52:52 +00:00
Doug Gregor
ce592de287 Introduce TypeBase::getSuperclass() to retrieve the superclass of a given type.
This routine performs the substitutions necessary to get the actual
superclass for (e.g.) any class or substitutable type, including bound
generic classes and inner classes thereof. This routine still requires
a lazy resolver (i.e. a type checker).


Swift SVN r8101
2013-09-11 19:48:19 +00:00
Dmitri Hrybenko
7a4ff53826 getSourceRange(): handle delayed constructor and destructor bodies
Right now we don't delay bodies, but we eventually will.


Swift SVN r8100
2013-09-11 19:13:56 +00:00
Doug Gregor
da7bb5ba36 Factor type substitution logic into Type::subst().
The type substitution still depends fairly heavily on the type
checker, which is accessed via the LazyResolver abstract
interface. That interface should get simpler, and become unnecessary
except to deal with lazy type checking, over time. At that point, it
will become optional, and Type::subst() will be usable without a type
checker around.


Swift SVN r8099
2013-09-11 18:50:50 +00:00
Dmitri Hrybenko
abfa512c4f Sink getArgParamPatterns() and getBodyParamPatterns() into AbstractFunctionDecl
Swift SVN r8097
2013-09-11 18:42:28 +00:00
Dmitri Hrybenko
2c8e7e45a5 Sink GenericParamList to AbstractFunctionDecl from derived classes
Swift SVN r8092
2013-09-11 17:27:59 +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
e6bfc39e04 FuncExpr: use the function name as the primary source location
(used to be the 'func' keyword)


Swift SVN r8088
2013-09-11 03:09:21 +00:00
Dmitri Hrybenko
88c310ae5e Verifier: add verifyCheckedAlways() family of functions, that is run on
typechecked ASTs even if there were errors.


Swift SVN r8080
2013-09-10 21:19:18 +00:00
Dmitri Hrybenko
cb008946f4 Refactor the way builtin functions are created
Specifically, don't call the FuncDecl constructor everywhere directly.  We only
ever pass a few non-trivial parameters.


Swift SVN r8079
2013-09-10 20:56:48 +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
Doug Gregor
cdf160ecbd Introduce and optimize for uniquely-referenced opaque values.
If an OpaqueValueExpr is only used in one place, mark it as such. SIL
generation will then elide the retain/release pair associated with
each reference to the opaque value, instead consuming the value at the
point of use.


Swift SVN r8072
2013-09-10 18:03:55 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Doug Gregor
8c60d88f5a Provide DynamicMemberRefExpr with .Some(fn)/.None helper expressions.
These helper expressions will eventually be used by SILGen to help
package up the optional values. I expect that we'll eventually have
library builtins for this, so consider this a stop-gap until those
appear.

As part of this, make OpaqueValueExpr a bit more usable: it can now
persist in the AST as a placeholder, but its uses must be within AST
subtrees of some specific introduction point (similarly to how Clang's
OpaqueValueExpr works).


Swift SVN r8051
2013-09-09 19:58:51 +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
Chris Lattner
e48b3a4702 Rework how capture lists work in CaptureExpr: now we record
global variables used by functions in the capture list as well.

SILGen and other things that don't care about these (i.e., all 
current current clients) filter the list to get what they want.

This is needed for future definite init improvements, and unblocked
by Doug's patch in r8039 (thanks! :)

No functionality change.



Swift SVN r8045
2013-09-09 18:15:07 +00:00
Chris Lattner
964075185e update file header comment, ooops.
Swift SVN r8040
2013-09-09 17:08:16 +00:00
Chris Lattner
13c33e0cdd split declcontext stuff out to its own file.
Swift SVN r8039
2013-09-09 17:06:45 +00:00
Chris Lattner
77d0fb5ac8 add some support for dumping DeclContexts, which is useful for diagnosing
problems, particularly given LLDB's bug handing our DeclContext class
(filed as rdar://14944683)



Swift SVN r8038
2013-09-09 17:03:57 +00:00
Doug Gregor
5b310906fb Propagate [objc] to properties, methods of [objc] protocols.
Swift SVN r8035
2013-09-09 15:45:05 +00:00
Doug Gregor
1b48b78c07 Dynamic lookup can find members of class extensions.
Swift SVN r8034
2013-09-09 15:13:26 +00:00
Doug Gregor
edbeaa92b1 AST verifier for dynamic member reference expressions.
We weren't ensuring that the base was an rvalue.


Swift SVN r8030
2013-09-09 14:19:03 +00:00
Chris Lattner
c75a339a26 for completeness, have -ast-dump print the captures list on FuncDecls as well as FuncExprs.
Swift SVN r7998
2013-09-06 20:46:32 +00:00
Argyrios Kyrtzidis
f295c484b8 [AST/Verifier] Push the check for HadError down into the verifyChecked implementations.
Swift SVN r7987
2013-09-06 17:16:00 +00:00
Dmitri Hrybenko
9bbfe27615 Add an option for diagnostics -- PointsToFirstBadToken
Diagnostics that point to the first bad token are marked with this option in
Diagnostics.def.  Parser::diagnose treats the source location of such
diagnostics in a special way: if source location points to a token at the
beginning of the line, then it moves the diagnostic to the end of the previous
token.

This behaviour improves experience for "expected token X" diagnostics.


Swift SVN r7965
2013-09-05 23:38:32 +00:00
Eli Friedman
933e7c4088 Add verifier check for invalid decls.
We want to enforce the invariant that invalid ValueDecls have type ErrorType.
This patch adds that check, and fixes up the last few places which violated
it.

Last part of <rdar://problem/10157547>.

Swift SVN r7960
2013-09-05 21:00:46 +00:00
Dmitri Hrybenko
409d7c38bb ArrayTypeRepr printing: print size as an expression, instead of a pointer value
Swift SVN r7955
2013-09-05 20:36:28 +00:00
Argyrios Kyrtzidis
36a469df0b [modules] Introduce Module::getTopLevelDecls() to get the local-in-module top-level decls.
getDisplayDecls() was introduced for ":print_module" and works slightly differently, e.g.
it will return the decls from a shadowed clang module, since we want to display them.

Swift SVN r7909
2013-09-04 20:55:27 +00:00
Argyrios Kyrtzidis
2a6dc12607 [modules] Introduce APIs to get the path for the file that a module came from.
Swift SVN r7890
2013-09-04 01:57:53 +00:00
Dmitri Hrybenko
d3b0f3ff66 lookupVisibleDecls(): visit patterns in switch 'case' stmts
Fixes a few code completion FIXMEs


Swift SVN r7887
2013-09-04 00:53:44 +00:00
Jordan Rose
3107bcd8bb AST printer: include inheritance info even if we don't have source info for it
Essentially, fall back to the list of protocols (and possibly the superclass)
if the "inherited types" array is empty.

<rdar://problem/14788337>

Swift SVN r7884
2013-09-04 00:31:32 +00:00