Commit Graph

439 Commits

Author SHA1 Message Date
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Dmitri Hrybenko
8fdd6aca87 Fix warnings about falling off the end of a function without a return
Swift SVN r22317
2014-09-27 23:34:22 +00:00
Devin Coughlin
0d4e945b3a Construct type refinement context hierarchy in Sema.
This patch adds the beginning of building the type refinement context tree for
availability checking in Sema, guarded by by the
-enable-experimental-availability-checking option. This tree parallels the AST
but is much more sparse: we introduce a new TypeRefinementContext only when
needed. Each context refines the range of potential OS versions that could be
encountered at run time. For the moment, we only refine contexts for function
bodies. I will add refinement contexts for #os(...) in a later commit.

The AST is not directly connected to the TRC tree except at the SourceFile
level; when type checking, we use source locations to look up the TRC
corresponding to an AST element. For the moment, we emit a diagnostic when the
programmer references a potentially unavailable declaration. We will later
change this to treat the declaration as if it had optional type.


Swift SVN r22145
2014-09-19 22:11:29 +00:00
Adrian Prantl
90d0d69dcb Store the main SourceFile's private discriminator in the DWARF debug flags.
<rdar://problem/18297696> Store a SourceFile's discriminator somewhere in the debug info

Swift SVN r21912
2014-09-12 18:16:20 +00:00
Jordan Rose
94ed6a1fb3 Teach private-discriminator lookup to handle lookup into nominals.
This works using the nominal's normal lookupDirect to gather decls from the
original declaration and all its extensions, then filters them by module and
private-discriminator. This does not yet do the right thing for extensions
because we don't include the extension's module in a member's mangling except
in very specific circumstances. In order to make this work in general we'll
have to start doing this more generally.

Part of rdar://problem/17632175

Swift SVN r21785
2014-09-08 20:37:41 +00:00
Jordan Rose
f4daadc2e6 s/DC/container/ in Module::lookupMember, for clarification.
This is the container of the member, not the context from which lookup is
being performed.

No functionality change.

Swift SVN r21784
2014-09-08 20:37:40 +00:00
Jordan Rose
cacec395db Drop the separate "LookupName" type for discriminated lookup.
Now that there's just one entry point for discriminated lookup, there's not
really a need for this extra abstraction.

One thing still up in the air is unqualified lookup support for discriminator
preferences (for, say, breakpoint conditions), but we'll cross that bridge
when we come to it.

Part of rdar://problem/17632175

Swift SVN r21755
2014-09-06 00:18:05 +00:00
Jordan Rose
9aa8c5c133 Push lookup with private-discriminators into the AST as Module::lookupMember.
Since the primary purpose here is to go from a mangled name to a decl, and
discriminators are only valid in the context of a particular module, it
makes sense to make this an API on Module. Eventually this will also support
lookup into a type or its extensions, limited by module and discriminator.

Swift SVN r21754
2014-09-06 00:18:04 +00:00
Joe Groff
d7c98dcff4 Add an @NSApplicationMain attribute.
This behaves like @UIApplicationMain, except for AppKit. Attach it to your NSApplicationDelegate, and an artificial "main" will be generated that invokes NSApplicationMain() for you. Implements rdar://problem/16904667.

Swift SVN r21697
2014-09-04 05:52:26 +00:00
Jordan Rose
fcfd44c756 Use actual Identifiers for private discriminators, rather than strings.
This is useful both for caching purposes and for comparison of discriminators
(something the debugger will need to do when looking up a particular decl).

No observable functionality change.

Swift SVN r21610
2014-08-30 17:26:59 +00:00
Jordan Rose
77daee9036 Hash the basename of a source file to use as a discriminator for 'private'.
Now we can test the mangling rules set up in the previous commit: include
the discriminator for the top-most 'private' decl, but not anything nested
within it.

Part of rdar://problem/17632175

Swift SVN r21599
2014-08-30 00:17:21 +00:00
Jordan Rose
47658c87eb Start mangling names of private declarations specially.
We currently mangle private declarations exactly like public declarations,
which means that private entities with the same name and same type will
have the same symbol even if defined in separate files.

This commit introduces a new mangling production, private-decl-name, which
includes a discriminator string to identify the file a decl came from.
Actually producing a unique string has not yet been implemented, nor
serialization, nor lookup using such a discriminator.

Part of rdar://problem/17632175.

Swift SVN r21598
2014-08-30 00:17:18 +00:00
Joe Groff
8f52302f8e SILGen: Implement artificial main for NSApplicationMain.
We're not sure how to trigger this from source code yet, so trigger it with a hidden -emit-NSApplicationMain frontend flag for now.

Swift SVN r21563
2014-08-29 04:45:47 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Jordan Rose
11742821c1 Respect access control for member lookups as well.
(when -enable-access-control is used)

Note that this is currently circumvented when looking up requirements in a
protocol. We're not currently set up to pass along the DeclContext where a
protocol's requirements are requested /from/, so we're just relying on the
fact that the requirements have the same visibility as the protocol in 1.0.

Swift SVN r19355
2014-06-30 18:50:53 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Joe Groff
6e13190f47 Diagnose when @UIApplicationMain tries to coexist with a main.swift file.
Swift SVN r18072
2014-05-14 16:10:29 +00:00
Joe Groff
09d8d68099 Allow at most one main class per module.
Register valid @UIApplicationMain classes with the enclosing module, and diagnose when we see more than one.

Swift SVN r18061
2014-05-14 04:40:30 +00:00
Argyrios Kyrtzidis
918f373d97 [AST] For USR generation, ignore symbols coming from the builtin module.
Swift SVN r17858
2014-05-11 00:00:57 +00:00
Argyrios Kyrtzidis
9afa0333db [Frontend] Make sure we don't do any module imports during parse-only pass.
Fixes performance regression of rdar://16816861

Swift SVN r17600
2014-05-07 02:37:49 +00:00
Jordan Rose
8699a3b83f Add -import-underlying-module option.
This option implicitly imports the Clang module with the same name as the
module being built into every source file in the module being built.
This will be used for mixed-source framework targets to give Swift code the
same implicit visibility for Objective-C decls in the same module that it
already has for other Swift decls.

<rdar://problem/16701230>

Swift SVN r17053
2014-04-29 23:13:45 +00:00
Ted Kremenek
2d4342b87a Give an error if “@obj” is used without importing ObjectiveC.
The standard library is exemptmpt (-parse-stdlib) from this checking.

Implements <rdar://problem/16559137>.

Swift SVN r16155
2014-04-10 09:08:09 +00:00
Michael Gottesman
e3081a2027 [deserialization] Add debug logging to SerializedSILLoader so one can
easily tell the order that deserializers are being visited.

Swift SVN r15067
2014-03-14 20:27:20 +00:00
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