Commit Graph

463 Commits

Author SHA1 Message Date
Dmitri Hrybenko
e50b52fa02 Serializer/Driver: serialize comments to separate .swiftdoc files
The driver infers the filename from the module file by replacing the extension,
and passes the explicit path to the swiftdoc file to the frontend.  But there
is no option in the driver to control emission of swiftdoc (it is always
emitted, and name is always inferred from the swiftmodule name).

The swiftdoc file consists of a single table that maps USRs to {brief comment,
raw comment}.  In order to look up a comment for decl we generate the USR
first.  We hope that the performance hit will not be that bad, because most
declarations come from Clang.  The advantage of this design is that the
swiftdoc file is not locked to the swiftmodule file, and can be updated,
replaced, and even localized.


Swift SVN r14914
2014-03-11 10:42:26 +00:00
Joe Groff
96c09d7179 Renovate name lookup to prepare for compound name lookup.
Make the name lookup interfaces all take DeclNames instead of identifiers, and update the lookup caches of the various file units to index their members by both compound name and simple name. Serialized modules are keyed by identifiers, so as a transitional hack, do simple name lookup then filter the results by compound name.

Swift SVN r14768
2014-03-07 03:21:29 +00:00
Dmitri Hrybenko
cd48638f9a Fix a use-after-free caused by creating DerivedFileUnit on the fly
Sema was creating DerivedFileUnit on the fly, while something else is iterating
over FileUnits in the module.  The fix is to create DerivedFileUnit in advance.
This change immediately uncovered a lot of code that assumed that the module
consists of a single FileUnit at certain conditions.  This patch also fixes
that code (SourceKit patch is separate, not sending it).

The test change is because now operator == on NSObjects is correctly recognised
as coming from a system module.

rdar://16153700, rdar://16227621, possibly rdar://16049613


Swift SVN r14692
2014-03-05 22:24:25 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Doug Gregor
2b31656a28 Constructor lookup is no longer special from the client perspective.
Swift SVN r14552
2014-03-01 00:51:22 +00:00
Doug Gregor
d92f1a3158 Inherit complete object initializers when a class supports it.
Teach name lookup to find complete object initializers in its
superclass when the current class overrides all of the subobject
initializers of its direct superclass.

Clean up the implicit declaration of constructors, so we don't rely on
callers in the type checker doing the right thing.

When we refer to a constructor within the type checker, always use the
type through which the constructor was found as the result of
construction, so that we can type-check uses of inherited complete
object initializers. Fixed a problem with the creation of
OpenExistentialExprs when the base object is a metatype.

The changes to the code completion tests are an improvement: we're
generating ExprSpecific completion results when referring to the
superclass initializer with the same signature as the initializer
we're in after "super.".

Swift SVN r14551
2014-03-01 00:51:21 +00:00
Joe Groff
8e6b353542 Derive conformances of Equatable and Hashable for simple enums.
If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
2014-02-27 20:28:38 +00:00
Jordan Rose
7995dde448 Module::getImportedModules can now get public, private, or all imports.
...whereas before the only options were "public" and "all".

No functionality change.

Swift SVN r13849
2014-02-12 23:57:43 +00:00
Jordan Rose
cbcf17f9bd Stop leaking memory from Module and FileUnit.
Also, disallow creating Modules and FileUnits on the stack. They must always
live as long as the ASTContext.

<rdar://problem/15596964>

Swift SVN r13671
2014-02-08 02:12:57 +00:00
Jordan Rose
0f7a1e2cc6 Re-apply "[serialization] Preserve dependencies when merging modules."
This re-applies r13401, reverted in r13404. This wasn't actually causing
problems, but got pulled along with r13400 (reverted in r13405).

Swift SVN r13452
2014-02-04 22:46:50 +00:00
Michael Gottesman
a602f130e7 Revert "[serialization] Preserve dependencies when merging modules."
This reverts commit r13401. This broke the build.

Swift SVN r13404
2014-02-04 05:48:50 +00:00
Jordan Rose
fcdf8a4542 [serialization] Preserve dependencies when merging modules.
Swift SVN r13401
2014-02-04 01:32:47 +00:00
Argyrios Kyrtzidis
742cffb715 [AST] Add an out-of-line destructor for SourceFile.
Note that we are currently leaking memory via SourceFile, see rdar://15964312

Swift SVN r13312
2014-02-02 03:14:30 +00:00
Jordan Rose
fd48fb3144 Add a mode to Module::forAllVisibleModules that includes private imports.
Also, remove the mode that left the current module out of the callback.
That's easy enough to check for.

No functionality change yet, but groundwork for the next commit (as well
as some possible uses in LLDB).

Swift SVN r12616
2014-01-20 23:25:04 +00:00
Argyrios Kyrtzidis
90fa27f1b6 [AST] Introduce Module::isSystemModule() which is rather self-explanatory.
Swift SVN r12474
2014-01-17 07:33:49 +00:00
Jordan Rose
37a578ad0b [swift2objc] Sort output for determinism reasons.
If Module::getTopLevelDecls ever becomes guaranteed to be deterministic,
we can drop this sort.

Swift SVN r12083
2014-01-09 01:20:01 +00:00
Argyrios Kyrtzidis
93c15bed50 [AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing.

Swift SVN r11338
2013-12-16 01:26:36 +00:00
Dmitri Hrybenko
374aa1d57c AST printing: when printing module interface, explode PatternBindingDecls
The exact pattern that was used to declare a variable is not important from the
module interface point of view.


Swift SVN r11231
2013-12-13 02:19:04 +00:00
Sean Callanan
a1881434c2 Added support to allow LLDB to provide the
location of variables at SIL generation time.
This patch introduces a SILDebuggerClient that
knows how to resolve the locations of variables
that are generated by the debugger.  These
variables have a flag on them that only LLDB
sets.


Swift SVN r11230
2013-12-13 01:43:02 +00:00
Joe Groff
4a25b56846 SILGen: REPL globals are not lazily initialized.
Check for a REPL SourceFileKind along with Main before going the lazy initialization path. Also put response variables in the REPL SourceFile decl context so they are recognized as REPL variables and not lazily initialized. Handle PatternBindingDecls that appear under a script-mode SourceFile decl context but not a TopLevelCodeDecl context.

Swift SVN r11133
2013-12-11 17:54:17 +00:00
Dmitri Hrybenko
11ccb38e06 AST printer: use getDisplayDecls() to find a list of decls to print.
We are still not completely correct in determining which extensions to print,
will fix in future patches.


Swift SVN r10960
2013-12-07 00:54:05 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
5dda63aa82 Remove LoadedModule, and strip ModuleLoader down to just loading things.
Now that everything is done in terms of FileUnits, we don't need LoadedModule
anymore, and now that FileUnits just use virtual dispatch, we don't need to
indirect through ModuleLoader to distinguish them.

This doesn't quite simplify as much as it could, because the next change is
going to combine TranslationUnit and Module.

Swift SVN r10836
2013-12-05 01:51:12 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
68272b15c4 Remove FailedImportModule. A failed import is now represented as an empty TU.
No other functionality change.

Swift SVN r10833
2013-12-05 01:51:10 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
d0d661164d Move lookupQualified from Module to DeclContext.
Qualified lookup depends not only on the current module but actually the
current file, since imports are file-scoped by default. Currently this only
affects lookup into other modules (e.g. "Foundation.NSString"), but this
could also be used for extension filtering.

This breaks one name resolution test, but the refactoring in the next
commit changes everything anyway and will restore the test.

Swift SVN r10831
2013-12-05 01:51:07 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Jordan Rose
b43dd09107 All SourceFiles should always remember their buffer IDs, not just imports.
Swift SVN r9946
2013-11-04 23:50:48 +00:00
Jordan Rose
fc88c5dae6 Operators imported in one source file shouldn't affect another one.
Previously we would cache the results of operator lookup whether or not the
operator we found came from an imported module. Since different source files
can have different imports, it's not correct to automatically share operators
from imported modules with all files in the translation unit.

This still isn't fully correct; the current logic prefers operators from
local imports over operators implicitly available from other source files.

Swift SVN r9683
2013-10-25 22:21:14 +00:00
Jordan Rose
28e01f3c3a Eliminate "MainSourceFile" from TranslationUnit in favor of an array.
Anywhere that assumes a single input file per TU now has to do so explicitly.
Parsing still puts all files in a single SourceFile instance; that's next on
the list.

There are a lot of issues still to go, but the design is now in place.

Swift SVN r9669
2013-10-25 17:30:37 +00:00
Jordan Rose
cf31df96c5 Push operator lookup into SourceFile, and simplify the interface.
The operator lookup cache already lived in SourceFile, but we need to be
able to look up operators on a per-SourceFile basis. Different files can
have different imports. The interface previously distinguished between
"no operator found" and "error", but none of the call sites were making
use of this distinction, and indeed some were misusing the return value
(Optional<SomeOperatorDecl *>). Now the lookup functions just return
operator decl pointers, which may be null.

Swift SVN r9668
2013-10-25 17:30:33 +00:00
Jordan Rose
0702acab3d Make SourceFile a DeclContext, but don't actually do anything with it yet.
Swift SVN r9646
2013-10-24 18:59:21 +00:00
Jordan Rose
ec23db6962 Push the TU's lookup cache down to SourceFile.
Also move print() and dump() from TranslationUnit to SourceFile.

Swift SVN r9645
2013-10-24 18:59:18 +00:00
Jordan Rose
1ecf1fb593 Distribute Module's lookup cache to its subclasses.
Each one has a different kind of lookup cache anyway, and there's no real
reason to have them share storage at the cost of type-safety.

Swift SVN r9242
2013-10-12 00:08:09 +00:00
Jordan Rose
ad75aa5021 Remove -l flag from Swift interim driver.
Being able to pass -l to the driver isn't so interesting, and it's an
extra field that lives on TranslationUnit for no reason. Just remove it.

This doesn't interfere with autolinking, i.e. inferring -l flags based on
imported modules.

Swift SVN r9241
2013-10-12 00:08:06 +00:00
Jordan Rose
ce612d3231 Remove TranslationUnit's HasBuiltinModuleAccess field.
This information is important when a SourceFile is created, and never
again after that.

Swift SVN r9240
2013-10-12 00:08:04 +00:00
Jordan Rose
8b6b9b7965 Use 'unsigned' to represent a present input buffer ID.
LLVM's SourceMgr uses 'int' for buffer IDs, but -1 is a special placeholder
value that means "no such buffer". Swift's SourceManager then makes a
distinction between 'unsigned' and 'int' -- an unsigned buffer ID always
refers to an actual buffer, while an int ID may be -1. Respect this in
SourceFile, which uses Optional to represent a "potential" buffer.

Swift SVN r9239
2013-10-12 00:08:01 +00:00
Jordan Rose
7b936e2b85 Remove unfinished notion of "Component" (originally for resilience).
docs/Resilience.rst describes the notion of a resilience component:
if the current source file is in the same component as a module being
used, it can use fragile access for everything in the other module,
with the assumption that everything in a component will always be
recompiled together.

However, nothing is actually using this today, and the interface we
have is probably not what we'll want in 2.0, when we actually implement
resilience.

Swift SVN r9174
2013-10-10 21:41:57 +00:00
Jordan Rose
0d2ccf7cb3 Adopt SourceFile in name-binding.
Swift SVN r9105
2013-10-09 22:44:32 +00:00
Jordan Rose
589341ac79 Replace operator StringMaps with Identifier-keyed DenseMaps.
Micro-optimization, but avoids extra indirection and allocation associated
with StringMaps.

Swift SVN r9083
2013-10-09 19:11:21 +00:00
Jordan Rose
e83d0d608a Use Optional for SourceFile::getImportBufferID, instead of a sentinel.
No functionality change.

Swift SVN r9082
2013-10-09 18:45:10 +00:00
Jordan Rose
ccce45b981 Improve comments for SourceFile.
Swift SVN r9081
2013-10-09 18:38:30 +00:00
Jordan Rose
266c445b3c Push ASTStage down into SourceFile.
This was only meaningful for TranslationUnit anyway, and it may help
avoid repeating work in the future.

Swift SVN r9079
2013-10-09 18:38:28 +00:00
Jordan Rose
55d4d05b23 Don't automatically create one SourceFile for every TranslationUnit.
Many places are still relying on having one, though.

Swift SVN r9077
2013-10-09 18:38:26 +00:00
Jordan Rose
09787207fc Push TUKind into SourceFile (as InputKind).
Different SourceFiles in the same module will eventually have different
input kinds (at the very least Main vs. Library).

Swift SVN r9076
2013-10-09 18:38:25 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Dmitri Hrybenko
3bb5ae1ef4 ExternalNameLookup: fix the build and address review comments
Swift SVN r9016
2013-10-08 01:20:49 +00:00
Sean Callanan
03e51df72e Added ExternalNameLookup, a mechanism that allows
UnqualifiedLookup to ask an external source for
names.  There are two phases to this external lookup:

- Before consulting globals in other modules,
  UnqualifiedLookup calls lookupOverrides() to see
  if there are any results that should override the
  results from modules.  (N.b.: these should not be
  able to override names that are locally defined.)

- After consulting globals in other modules,
  UnqualifiedLookup as a last resort calls
  lookupFallbacks() to see if there's anything out
  there at all that could serve that name.  This may
  be more computationally expensive.

These hooks are used by LLDB's expression parser to
resolve names for persistent variables (akin to the
existing $0, $1, ... variables) and variables local
to the current frame.


Swift SVN r9014
2013-10-08 00:58:14 +00:00