Commit Graph

416 Commits

Author SHA1 Message Date
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
Chris Lattner
27009ac5bd rework handling of -parse-stdlib to make it orthogonal from the mode we're in,
with the specific goal of making it work with -i.


Swift SVN r5807
2013-06-26 04:17:56 +00:00
Chris Lattner
1040bfec6a In the REPL, allow access to the Builtin module if explicitly imported,
there is no reason to deny it and it could be theoretically useful.


Swift SVN r5779
2013-06-24 16:07:56 +00:00
Chris Lattner
95163ff152 introduce a new TranslationUnit kind for .sil files, and use this to
guard access to the Builtin module (on one path), reducing the number
of ways non-stdlib and non-sil files have access to the builtin module.


Swift SVN r5767
2013-06-22 17:14:18 +00:00
Chris Lattner
cc3f22839a rework how autoimport happens. Instead of being driven by what the
source file imports in the first few lines, drive it based on the TU
mode.


Swift SVN r5751
2013-06-21 18:45:58 +00:00
Chris Lattner
ae2053b411 rename TU_Kind -> TUKind
Swift SVN r5741
2013-06-21 17:47:28 +00:00
Chris Lattner
e8bf1dd6f5 expand the TranslationUnit kind to handle "standard library", and
plumb it through the compiler a bit.  This simplifies some code
in the driver, but should not induce any behavior change (yet).


Swift SVN r5740
2013-06-21 17:42:37 +00:00
Chris Lattner
a5c7c65ee7 Move around the logic for handling autoimport of the swift standard
library.  We use the same (somewhat broken heuristics), they are
just implemented in another way.

The major functionality change is that previously, .sil files would
auto import "swift" if they started with a non-sil decl.  Now they
never do.



Swift SVN r5731
2013-06-20 23:39:27 +00:00
Chris Lattner
8c85a49d2a with the groundwork out of the way, we can now namebind types referenced
by the SIL parser.  Add a test that covers both local types, and types
that require looking through an import decl (Int, from the stdlib).


Swift SVN r5249
2013-05-21 05:34:24 +00:00
Chris Lattner
f2e3af3cf6 Eliminate the "global" list of unresolved identifier types maintained
by TranslationUnit.  This list existed solely to allow name lookup of
an unbound IdentifierType to know its DeclContext.  Instead of indirecting
through this list, just store the DeclContext in the IdentifierType in its
uninitialized state.

This eliminates a really terrible performance fixme about scanning the list,
eliminates the management fiddling around with this list in the parser, and
is generally much cleaner.


Swift SVN r5246
2013-05-21 05:27:37 +00:00
Doug Gregor
1641477826 Eliminate lookupExtensions() and the extension cache.
This infrastructure has been replaced by the extension list on nominal
declaration, which is simpler and more efficient.


Swift SVN r5225
2013-05-20 18:26:07 +00:00
Jordan Rose
42aa102c23 Replace accidental compound literal syntax in assertion.
The point of the assertion is to provide a type-dependent value that
evaluates to 'false', so that the static_assert will fire on any
instantiation of the template but not on the template itself.

Swift SVN r5176
2013-05-16 17:23:31 +00:00
Jordan Rose
ec1e47cbf0 Thread operator lookup through Module to ModuleLoader...
...even though Swift modules don't provide this lookup yet, and Clang
modules never will.

Swift SVN r5173
2013-05-16 00:23:10 +00:00
Jordan Rose
73b6269484 [serialization] Add a trivial Swift module loader.
Currently, the Swift module loader just looks for a .sm file, verifies the
signature "SMod", and produces an empty DeclContext.

Swift SVN r5126
2013-05-09 20:49:29 +00:00
Jordan Rose
7bea410369 Introduce a LoadedModule base class for ClangModule and SerializedModule.
This keeps AST insulated from the various module-loading interfaces, which
minimizes special-casing of the differences between ClangModule and the
(upcoming) SerializedModule.

Swift SVN r5096
2013-05-08 18:33:36 +00:00
Doug Gregor
0f6b7a9d22 Rework our handling of "external" definitions created by the Clang importer.
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
2013-05-03 00:24:34 +00:00
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +00:00
Joe Groff
8caf747853 Put alignas(N) on classes with strict alignment.
We use three tag bits on Expr*, Stmt*, Decl*, TypeBase* and SILTypeInfo*, and four on DeclContext*, so set the alignment of the pointed-to types formally with alignas(N) instead of relying on operator new passing down the right alignment to the allocator. Get rid of the informal T::Alignment members of these classes and pass alignof(T) to their allocators. Fix the 'operator new' of DeclContext subclasses so that we can actually use the four tag bits PointerLikeTypeTraits<DeclContext*> claims are available.

Swift SVN r4587
2013-04-03 17:27:05 +00:00
Joe Groff
7a7e3d5615 REPL: Hook up completions to name lookup.
Implement a 'lookupVisibleDecls' API similar to Clang's that replicates the UnqualifiedLookup logic for walking through a given scope looking for decls. Use it to populate the completion list in the repl.

Still to be done: Clang module lookup via Clang's lookupVisibleDecls, and context deduction from dotted path expressions.

Swift SVN r4056
2013-02-15 20:17:44 +00:00
Joe Groff
a81cc38baf ClangImporter: Run imported types thru TypeChecker
Types synthesized by the ClangImporter need to be visited at a minimum by TypeChecker::validateTypeSimple in order to set up generic substitutions and protocol conformances, so arrange for the ClangImporter to pile all of its emitted types into a list that can then be walked by the TypeChecker.

Swift SVN r3901
2013-01-30 02:05:50 +00:00
Doug Gregor
3f19098a7e Emit importer-generated thunks as linkonce_odr hidden into every translation unit that imports the corresponding module.
Swift SVN r3547
2012-12-19 21:50:55 +00:00
Doug Gregor
f3857df469 Implement an AST pretty-printer for declarations, under -print-ast.
Swift SVN r3431
2012-12-10 23:21:49 +00:00
Doug Gregor
ba4abb20df Improve tracking of which external definitions have been type-checked and IRgen'd.
Swift SVN r3380
2012-12-06 17:42:49 +00:00
Doug Gregor
1f45f28837 Emit the constructors synthesized by the Clang importer for ObjC init/new methods.
Note that the constructors we emit don't function yet, since they rely
on the not-yet-implemented class message sends to Objective-C
methods.


Swift SVN r3370
2012-12-05 22:01:38 +00:00
Doug Gregor
9904844727 Move 'external definitions' vector into the Clang module; it only makes sense there.
Swift SVN r3367
2012-12-05 18:35:33 +00:00
Doug Gregor
85f690d086 Type-check the constructors synthesized for Objective-C init/new methods.
Swift SVN r3366
2012-12-05 18:15:48 +00:00
Doug Gregor
26a23c8f3d Zap an unused member of swift::Module
Swift SVN r3201
2012-11-16 18:27:39 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Chris Lattner
a052faf351 remove some implementations of classof that are now unneeded with mainline LLVM changes.
Swift SVN r2989
2012-10-12 18:22:16 +00:00
Eli Friedman
960b0bfd35 Move most type lookup from name-binding into TypeChecker::validateType. Use this to make type resolution more powerful, so we can resolve members of types like S<Int>
and Int[].

Type resolution for types named in ExtensionDecls remains a part of name-binding; it has to use more restrictive rules because we can't perform general member lookup until
we've resolved all the types named in ExtensionDecls.



Swift SVN r2313
2012-07-06 01:51:09 +00:00
Eli Friedman
18dfa5cf7d More refactoring; allow ConstructorLookup to find constructors in classes.
Swift SVN r2171
2012-06-07 23:57:18 +00:00
Eli Friedman
0e7ef8cebb Start refactoring code towards a single complete implementation of unqualified lookup.
Swift SVN r2108
2012-06-01 01:37:44 +00:00
Eli Friedman
377972b1ba Start shuffling around code for name binding on values; with the proposed shadowing rules, we need to delay name binding on values until after some parts of type-checking.
Swift SVN r1946
2012-05-23 00:42:53 +00:00
Eli Friedman
87dd43a4b8 Refactor member and constructor lookup to depend on centralized routines in Module rather than scattering assumptions about how lookup works across Sema. This should make it easier to make changes in the future which affect lookup.
I'm not entirely sure these are the right APIs to expose, but this at least seems like progress.



Swift SVN r1848
2012-05-15 02:04:53 +00:00
Eli Friedman
907cc521ab Switch a couple booleans in Module over to an enum.
Swift SVN r1845
2012-05-15 00:20:01 +00:00
Eli Friedman
05fe3c907f Propagate a DeclContext through NameBinding for IdentifierTypes.
Swift SVN r1803
2012-05-10 23:34:01 +00:00
Eli Friedman
a143422c98 Teach name binding to look into default values for tuple types.
Swift SVN r1747
2012-05-04 23:09:55 +00:00
Eli Friedman
e6177f35a9 Get rid of the outdated notion of type lookup in Module. <rdar://problem/11026489>.
Swift SVN r1734
2012-05-04 00:41:54 +00:00
Eli Friedman
a2c6150c13 Error recovery for the REPL. Seems to be working reasonably well. <rdar://problem/11269380>.
Swift SVN r1523
2012-04-20 01:14:39 +00:00
Eli Friedman
be602fcd05 Get rid of the implicit BraceStmt for the TranslationUnit; instead, have the TranslationUnit directly store a list of decls.
Swift SVN r1521
2012-04-20 00:17:13 +00:00
Eli Friedman
acc17d69aa Initial implementation of the "print" part of the REPL.
Swift SVN r1484
2012-04-19 01:13:37 +00:00
Eli Friedman
37de44a35d Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
Next step: implement an actual REPL.



Swift SVN r1441
2012-04-16 23:52:01 +00:00
Eli Friedman
9bf8dcf0f1 Delete some dead code.
Swift SVN r1412
2012-04-13 01:05:12 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Doug Gregor
5fffa75e7b Remove empty throw specifications from all of the overloaded new operators; reduces code size by 8k
Swift SVN r1282
2012-03-28 22:00:02 +00:00
Chris Lattner
50c95e7f32 resolve the FIXME.
Swift SVN r1172
2012-03-09 11:13:43 +00:00
Eli Friedman
48f0f1d77e Fix assertion failure on tests.
Swift SVN r1168
2012-03-05 19:58:06 +00:00
Chris Lattner
1c42e8f6a6 rename DottedNameType to IdentifierType. It captures loc information for random uses of type names, among other things.
Swift SVN r1064
2012-01-18 01:52:28 +00:00
Chris Lattner
c8ca11a199 Drop in the new DottedNameType and wire it up in name binding.
This is horribly hack and slash (but enough to pass all tests) for a few reasons:
- I've #if 0'd out the tendrils of the old code 
- This handles *just* what was handled before instead of being more general
- We don't have an llvm::MutableArrayRef type, so there is some really gross
  const_cast'ing and other struggles to deal with its absence.



Swift SVN r1050
2012-01-17 06:32:00 +00:00
John McCall
6b935588e5 On second thought, components need to be known in the AST.
Swift SVN r918
2011-12-07 03:57:41 +00:00