Commit Graph

317 Commits

Author SHA1 Message Date
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +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
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Jordan Rose
a35f7cbd4b Thread [exported] through TranslationUnit and the Serialization library.
This still doesn't do anything yet.

Swift SVN r7051
2013-08-08 19:09:21 +00:00
Jordan Rose
35f84dfbee Remove "import foo, bar" syntax.
We never really discussed this and it doesn't really buy us much. If we
want to have a compact way to import many things, it may not even end
up looking like this.

Swift SVN r7015
2013-08-07 22:56:58 +00:00
Jordan Rose
d3b31b8b72 Don't include re-exports in a TU's imported module list.
We can get to these transitively; we should only record what the TU
actually claims to reference.

It turns out that we were still relying on this to force the load of
adapter modules for Clang modules. For now, we just force that up front,
even though currently that also forces the creation of ClangModule
wrappers for all transitive includes.

No intended visible functionality change.

Swift SVN r7012
2013-08-07 22:56:32 +00:00
Jordan Rose
33aced7312 Show decls in import kind warnings.
main.swift: error: ambiguous name 'A' in module 'letters'
      import struct letters.A
  abcde.A: note: found this candidate
      struct A {}
  aeiou.A: note: found this candidate
      struct A {}

  main.swift: 'B' was imported as 'var', but is a struct
      import var letters.B
  abcde.B: note: 'B' declared here
      struct B {}

<rdar://problem/14650883>

Swift SVN r6918
2013-08-05 21:03:07 +00:00
Jordan Rose
1d54332bc5 Validate import kind, e.g. "import var swift.max" now errors, with fix-it.
Again, the import kind rules are:
 - 'import KIND' can import any decl whose introducer is KIND.
 - 'import typealias' can also import a struct, class, or union.
 - Conversely, 'import KIND' can import a typealias for a decl whose
   introducer is KIND.
 - Only functions can be overloaded; anything else counts as an ambiguous
   import and is an error.
 - If an import statement only imports a single decl, but the user got the
   kind wrong, we can issue a fix-it for the kind.

We don't have source locations or synthetic source for declarations yet,
so there are no notes about what's /causing/ the ambiguities. Tracked by
<rdar://problem/14650883>

Swift SVN r6917
2013-08-05 21:03:01 +00:00
Jordan Rose
9d5c803aff Enable specific-decl imports.
Note that the import kind is not checked yet; this is effectively our old
behavior for "import swift.print".

Infrastructure: move Module::forAllVisibleModules out-of-line, and add
makeStackLambda to STLExtras for using a non-escaping lambda with
std::function.

Swift SVN r6852
2013-08-02 21:00:41 +00:00
Jordan Rose
4c05f35914 If a submodule is missing, don't claim that the top-level module is missing.
Our diagnostic message says "no such module 'NAME'". However, if we tried
to import a submodule, the top-level module's name would be used for NAME
and the submodule part dropped. For now, just don't include the name if
importing a submodule.

Swift SVN r6851
2013-08-02 21:00:35 +00:00
Jordan Rose
c92fa28833 Have ImportDecl vend a separate "module path" and "decl path".
This makes it very clean to reason about which part should be used
to find a module to load, and which part should be used to filter
lookup within that module.

This breaks the old "import swift.print" syntax in favor of the new
"import func swift.print", but the new syntax is currently ignored.

Swift SVN r6849
2013-08-02 21:00:22 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +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
3e7eef56e7 Kill [stdlib] attribute.
Now that we have true serialized modules, the standard library can import
the Builtin module without any special direction (beyond -parse-stdlib),
and anyone can include those modules without special direction.

Swift SVN r6752
2013-07-30 21:27:42 +00:00
Jordan Rose
acce3767db Introduce Module::forAllVisibleModules, and use it where useful.
This iterates over a module's exports, transitively, in an unspecified
but deterministic order. This is useful for any sort of lookup and for
managing transitive inclusion. It also allows us to remove the hack in
Sema for loading a Clang module's adapter module, and just rely on the
previous commit.

Swift SVN r6699
2013-07-29 18:57:04 +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
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Doug Gregor
bcf41bbc3f Move the resolution of extension types, operator declarations, and superclasses into the type checker.
This eliminates the duplicate IdentifierType resolution code (fixing
<rdar://problem/13946567>), and moves us a step closure to elimining
name binding as a separate pass.


Swift SVN r5940
2013-07-01 18:38:05 +00:00
Chris Lattner
c03d4454a0 implement support for a new [stdlib] attribute that can be slapped on an import decl.
This causes the SourceLoader to recursively parse the imported module in standard 
library mode, giving it access to the Builtin module.

This is all a terrible hack and should be ripped out with great victory someday, but 
until we have binary modules that persist the build setting used to produce the 
module, this is the best we can do.



Swift SVN r5847
2013-06-27 21:31:15 +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
6bd87540e0 Don't allow the global search of imported modules to include the Builtin module,
wrapping up rdar://11187080

Now the only way you get access to the Builtin module is if you're the standard
library (currently modeled with the -parse-stdlib command line flag, will eventually
be part of build configuration goop or something).

This breaks a few of Jordan's serialization tests, which I've XFAILed after discussion.



Swift SVN r5777
2013-06-24 15:31:58 +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
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
Joe Groff
6dcf8ae206 Parse assignments as part of expr-sequence.
Parse '=' as a binary operator with fixed precedence, parsing it into a temporary UnsequencedAssignExpr that gets matched to operands and turned into an AssignExpr during sequence expr folding. This makes '=' behave like library-defined assignment-like binary operators.

This temporarily puts '=' at the wrong precedence relative to 'as' and 'is', until 'as' and 'is' can be integrated into sequence parsing as well.

Swift SVN r5508
2013-06-07 16:15:40 +00:00
Chris Lattner
e0527c8a84 simplify resolveIdentifierType() in two ways:
1) a DeclContext doesn't need to be passed in, now that IdentifierType tracks it.
2) factor the code that sets Components to ErrorType out of the clients.




Swift SVN r5250
2013-05-21 05:46:16 +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
Chris Lattner
caf9d718c0 another early return to reduce indentation, no functionality change.
Swift SVN r5236
2013-05-20 22:44:18 +00:00
Chris Lattner
3b149efd94 factor out some code into helper functions to reduce the size of a huge loop.
Swift SVN r5233
2013-05-20 19:51:47 +00:00
Jordan Rose
ccae995f61 Use a list of module loaders instead of a single Clang importer.
This paves the way for having a Swift module importer. The eventual goal
here is to eliminate all explicit uses of the Clang module loader, but
I'm not going to push too hard on that for now.

Swift SVN r5092
2013-05-08 18:09:33 +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
Jordan Rose
790248d8b4 Diagnostics: use builder pattern instead of streaming for ranges/fix-its.
Per Chris's feedback and suggestions on the verbose fix-it API, convert
diagnostics over to using the builder pattern instead of Clang's streaming
pattern (<<) for fix-its and ranges. Ranges are included because
otherwise it's syntactically difficult to add a fix-it after a range.

New syntax:

  diagnose(Loc, diag::warn_problem)
    .highlight(E->getRange())
    .fixItRemove(E->getLHS()->getRange())
    .fixItInsert(E->getRHS()->getLoc(), "&")
    .fixItReplace(E->getOp()->getRange(), "++");

These builder functions only exist on InFlightDiagnostic; while you can
still modify a plain Diagnostic, you have to do it with plain accessors
and a raw DiagnosticInfo::FixIt.

Swift SVN r4894
2013-04-24 23:15:53 +00:00
Jordan Rose
f2d4a6af37 Fix typo in diagnostic name.
Swift SVN r4815
2013-04-18 23:34:25 +00:00
Joe Groff
d39ee86c71 Sema: Check func operator arity syntactically.
This gives us a couple things:

- It lets name binding match up operator funcs to operator decls reliably without depending on unary operators being properly attributed;
- It allows unary operators on tuples to be distinguished from binary operators; the former should always be declared 'func +(_:(x:A,y:B))', and the latter as 'func +(x:A,y:B)'.

Swift SVN r4636
2013-04-08 18:01:19 +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
Doug Gregor
a253bd09fb Import the Swift modules that corresponding to any re-exported Clang module.
Now, 

  import Cocoa

will bring in the Cocoa Clang module, which re-exports (among
other things), the AppKit, Foundation, and ObjectiveC Clang
modules. We will look for Swift modules of the same name and load them
implicitly.



Swift SVN r4229
2013-02-27 21:41:42 +00:00
Joe Groff
36224410d0 Remove debug output.
Swift SVN r4214
2013-02-27 00:19:20 +00:00
Joe Groff
9337e66fc2 Sema: Allow type extensions through typealiases.
Allow an extension to extend a type using a typealias. This allows Clang-imported typedef-ed structs such as NSRect/CGRect to be extended, and in general allows extensions to be used without having to expose users to potentially ugly internal-use-only names like 'Int64'. Fixes <rdar://problem/13280448>.

Swift SVN r4213
2013-02-27 00:09:39 +00:00
Doug Gregor
72a2f87ede Propagate -constraint-checker to imported modules *except* swift.swift (for performance reasons).
Swift SVN r4081
2013-02-19 19:08:45 +00:00
Joe Groff
6d30e0bbe1 ClangImporter: Kludge submodule imports.
Make things like 'import OpenGL.GL3' and 'import IOKit.hid' kind-of work.

Swift SVN r4065
2013-02-17 21:11:15 +00:00
Jordan Rose
339c18c79f Don't replace a Swift module with a Clang one in the list of loaded modules.
We want to make sure that a global lookup always finds the Swift module
first. Moreover, we should never be loading two modules with the same name
into the same TU /unless/ they are (a) identical or (b) a Swift / C pair.

Swift SVN r3723
2013-01-10 00:53:57 +00:00
Doug Gregor
bfcd8274fe Every Swift file is a module; let name lookup find the name of the current module.
Swift SVN r3531
2012-12-18 21:41:58 +00:00
Doug Gregor
319a100189 Allow diagnostics to accept declarations in lieu of source locations.
Swift's diagnostic system is built on the quaint notion that every
declaration known to the front end has a valid source location to
which diagnostics mentioning that declaration (say, in a "here is a
candidate" note) can point. However, with a real module system, the
source corresponding to a declaration in a module does not need to be
present, so we can't rely on source locations.

Instead of source locations, allow diagnostics to be anchored at a
declaration. If that declaration has source-location information, it
is used. Otherwise, we just drop source-location information for
now. In the future, we'll find a better way to render this information
so it feels natural for the programmer.


Swift SVN r3413
2012-12-07 22:51:11 +00:00
Doug Gregor
608b2d8a5b Allow a Swift and a Clang module to have the same name, and load both.
This change allows client code to just use, e.g.,

  import Foundation

to get both the Clang Foundation module and the Swift Foundation
module that provides various adaptation (typically via
extensions). At some point later, we can consider whether the modules
will end up in different namespaces somehow, or whether this is best
tackled by some kind of module re-export directive, but for now it's
convenient while we await the design of a real module system for
Swift.



Swift SVN r3405
2012-12-07 18:23:35 +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
Doug Gregor
10664981aa Add command line options to turn on the two LangOptions options for
the constraint-based type checker:

  -constraint-checker turns on constraint-based type checking for the
   current swift module (but not imported modules; we're not ready for that)
  
  -debug-constraints turns on detailed debugging information for the
   constraint-based type checker

Use these flags to de-REPL-ify the tests for the constraint-based type
checker. The REPL is still quite useful for experimenting with the
type checker, but shouldn't be our normal means of testing it.



Swift SVN r2840
2012-09-12 21:19:49 +00:00
Eli Friedman
8f85913c2b Start of support for semantic analysis of generic base classes.
Swift SVN r2729
2012-08-23 23:04:43 +00:00
Eli Friedman
da954c0cbd Minor cleanup for type validation: a type only needs to be validated once,
and type validation should never fail in a call to validateTypeSimple.

The one thing I really don't like about this whole approach is that we end
up with validateTypeSimple calls scattered all over the place...
the ultimate solution here is probably something along the lines of
introducing getUnvalidated() getters for types for use from the parser,
and make the standard getters for types assert that the type is valid
and perform any necessary computations themselves.



Swift SVN r2728
2012-08-23 22:42:36 +00:00