Commit Graph

416 Commits

Author SHA1 Message Date
Jordan Rose
c129637bf6 Name lookup: avoid even calling lookup code on Clang submodules.
This is a hack.

We currently don't put anything in Clang submodules; they're just wrappers
to track what is and isn't visible. All lookups happen through the top-
level module.

This commit adds a new API getImportedModulesForLookup, which is ONLY used
by top-level name lookup and forAllVisibleModules. It is identical to
getImportedModules for everything but ClangModuleUnits, which instead
compute and cache a list of their transitively imported top-level modules.

This speeds up building Foundation.swiftmodule with a release compiler by
a bit more than 5%, and makes a previously lookup-bound test case compile
a third faster than before.

This is a hack.

rdar://problem/20813240

Swift SVN r28598
2015-05-15 01:26:05 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Doug Gregor
297c9e2911 Introduce NameLookupOptions for TypeChecker::lookupMember(). NFC
Swift SVN r28281
2015-05-07 21:10:38 +00:00
Jordan Rose
c5e46b524d Add Module::failedToLoad(), mainly for REPL and debugging purposes.
LLDB asked for this to differentiate between modules loaded successfully and
modules that are correctly found but can't be loaded for some reason.

rdar://problem/19750055

Swift SVN r27041
2015-04-06 21:23:57 +00:00
Jordan Rose
85a3751f6d Remove SourceFile::getImports in favor of FileUnit::getImportedModules.
getImportedModules is the canonical way to get imports, whether private,
public, or both. This is especially true now that we have more flags
for SourceFile imports that really shouldn't be consumed by anyone
outside of SourceFile.

In this same vein, provide addImports instead of setImports, since imports
are always additive.

No visible functionality change.

Swift SVN r26634
2015-03-27 16:36:47 +00:00
Jordan Rose
eb4ade4462 Honor @testable import for internal decls in ValueDecl::isAccessibleFrom.
We can now use internal declarations safely and correctly in source files!
The remaining work is to make sure testable imports work reliably through
modules, which is important for debugging unit tests.

It's also possible this work will affect compile time, but for the most
part we don't have large quantities of internal declarations that are
being ignored, and some day we will strip them out of non-testable modules
altogether.

Part of rdar://problem/17732115

Swift SVN r26633
2015-03-27 16:36:46 +00:00
Jordan Rose
e334eed7a4 Record @testable in a SourceFile's import list.
No functionality change, since nothing's using it yet.

Swift SVN r26632
2015-03-27 16:36:44 +00:00
Jordan Rose
e6c2131bda Check that "@testable import Foo" is only used to import testable modules.
(i.e. modules compiled with -enable-testing)

Part of testability (rdar://problem/17732115)

Swift SVN r26293
2015-03-19 02:20:41 +00:00
Jordan Rose
c6739b6b6c Add the -enable-testing flag, and serialize it.
This flag indicates that internal APIs within the module should be made
available to client code for testing purposes. Currently does nothing.

Not ready for developer consumption yet, ergo a hidden frontend-only flag.

Part of testability (rdar://problem/17732115)

Swift SVN r26292
2015-03-19 02:20:38 +00:00
Jordan Rose
efd7268948 Remove flags in Module, unused since r24531.
No functionality change.

Swift SVN r26291
2015-03-19 02:20:33 +00:00
Jordan Rose
367bfbc374 Require "import Foundation" to use @objc in library files, too.
Make this diagnostic a little nicer in other ways, too:
- Highlight the whole attribute (including the at-sign).
- Don't hardcode the string "objc".

Swift SVN r25999
2015-03-11 23:07:48 +00:00
Jordan Rose
0cb941bf40 Remove Optional from SourceLoc field.
SourceLoc already has an absent state (invalid).

No functionality change.

Swift SVN r25998
2015-03-11 23:07:47 +00:00
Devin Coughlin
6b5a3d775e [Sema]Construct type refinement hierarchy for other source files
Resolving signatures of declarations from files other than the primary source
file causes first-pass type checking, including diagnostics for potential
unavailability, to be performed on those declarations. Prior to this commit, the
type refinement context hierarchy was only constructed for the primary file, so
spurious errors were emitted when checking declarations in other files. With
this commit, the availability checker builds the hierarchy for a source file the
first time its hierarchy is queried. We will eventually want to build the
hierarchy more lazily, but that will come later.

Swift SVN r25746
2015-03-04 05:36:48 +00:00
David Farler
51f8070abe Serialize local types
Local type declarations are saved in the source file during parsing,
now serialized as decls. Some of these may be defined in DeclContexts
which aren't Decls and previously weren't serialized. Create four new
record kinds:

* PatternBindingInitializer
* DefaultArgumentInitializer
* AbstractClosureExpr
* TopLevelCodeDecl

These new records are used to only preserve enough information for
remangling in the debugger, and parental context relationships.

Finally, provide a lookup API in the module to search by mangled name.
With the new remangling API, the debugging lifecycle for local types
should be complete.

The extra LOCAL_CONTEXT record will compressed back down in a
subsequent patch.

Swift SVN r24739
2015-01-27 01:49:54 +00:00
Jordan Rose
4acb19541a PrintAsObjC: Detect apps by the presence of a file with a main entry point.
PrintAsObjC behaves slightly differently in apps vs. frameworks: for apps,
you get internal decls exposed in the header as well as public ones. This
is because the generated header is not being shipped anywhere and thus we
don't have a secrecy leak.

However, we were detecting whether we were in an app based on whether or
not we had a bridging header. That's no good for mixed-source apps where
there's no bridging header, so now we also check for a main entry point,
whether generated from @UIApplicationMain or @NSApplicationMain, or from
a script source file (main.swift).

rdar://problem/17877235

Swift SVN r24532
2015-01-19 23:08:58 +00:00
Jordan Rose
6de91151e2 Record whether a file contains a main entry point in the serialized module.
This isn't being used for much yet, but it will allow us to tell whether
something is an app target even at the module-merging stage, which is a
better way to tell if something is an app than whether it has a bridging
header.

We'll also need this if we ever take advantage of reusing "partial modules"
(serialized ASTs for other parts of the module that aren't affected by the
current source file) for compiling source files in incremental builds;
unfortunately that's unlikely given our dependency model.

Swift SVN r24531
2015-01-19 23:08:57 +00:00
Jordan Rose
66d0eccad2 Refactor the handling of *ApplicationMain classes.
Rather than keeping just a "main class" in every module, track the "main file"
that's responsible for producing the module's entry point. This covers both
main source files and files containing classes marked @UIApplicationMain or
@NSApplicationMain.

This should have no functionality change, but is preparation for the next
commit, where we will preserve some of this information in serialization.

Swift SVN r24529
2015-01-19 23:08:54 +00:00
David Farler
cad9f99929 Revert "Serialize local types and provide a lookup API"
Changing the design of this to maintain more local context
information and changing the lookup API.

This reverts commit 4f2ff1819064dc61c20e31c7c308ae6b3e6615d0.

Swift SVN r24432
2015-01-15 00:33:10 +00:00
David Farler
fab3d491d9 Serialize local types and provide a lookup API
rdar://problem/18295292

Locally scoped type declarations were previously not serialized into the
module, which meant that the debugger couldn't reason about the
structure of instances of those types.

Introduce a new mangling for local types:
[file basename MD5][counter][identifier]
This allows the demangle node's data to be used directly for lookup
without having to backtrack in the debugger.

Local decls are now serialized into a LOCAL_TYPE_DECLS table in the
module, which acts as the backing hash table for looking up
[file basename MD5][counter][identifier] -> DeclID mappings.

New tests:
* swift-ide-test mode for testing the demangle/lookup/mangle lifecycle
of a module that contains local decls
* mangling
* module merging with local decls

Swift SVN r24426
2015-01-14 22:08:47 +00:00
Jordan Rose
99075516ce Use "cascading/non-" terms for dependencies instead of "private/non-".
"private" is a very overloaded term already. "Cascading" instead of
"non-private" is a bit more clear about what will happen with this sort
of lookup.

No functionality change. There are some double negatives I plan to clean
up in the next commit, but this one was supposed to be very mechanical.

Swift SVN r23969
2014-12-17 02:42:45 +00:00
Jordan Rose
9abf77d59a Operator lookups may be private (non-cascading) dependencies.
This helps reduce the impact when touching a file that, say,
defines a custom ==.

Swift SVN r23718
2014-12-05 02:24:35 +00:00
Argyrios Kyrtzidis
d039fb6369 [AST] Move ide::findUnderlyingClangModule() to Module::findUnderlyingClangModule() so that the ASTPrinter can use it.
Swift SVN r23691
2014-12-04 20:17:03 +00:00
Argyrios Kyrtzidis
1552772a15 [AST] Move ModuleEntity from libIDE to libAST so that the ASTPrinter can use it.
Swift SVN r23680
2014-12-04 05:52:16 +00:00
Jordan Rose
985cbb8b2a Dependencies: Add new options to qualified lookup for known dependencies.
Specifically, a qualified lookup can now be treated as:
- a known private dependency, which does not affect downstream files
- a known non-private dependency, which may affect downstream files
- a known non-dependency
- unknown, which means the compiler will try to infer whether it's a
  private dependency from the context

This commit also includes some obvious uses of the new flags, but nothing
actually too interesting yet; there shouldn't be any observable behavior
change here in normal user code.

Swift SVN r23483
2014-11-20 20:58:17 +00:00
Jordan Rose
5ad871ecd6 Adopt llvm::function_ref for callbacks that aren't persisted.
...removing a few other constructs that were doing the same thing
(mostly from me).

No functionality change.

Swift SVN r23294
2014-11-13 00:19:03 +00:00
Jordan Rose
fc09bd4585 Add basic reference tracking based on name lookups.
This tracks top-level qualified and unqualified lookups in the primary
source file, meaning we see all top-level names used in the file. This
is part of the intra-module dependency tracking work that can enable
incremental rebuilds.

This doesn't quite cover all of a file's dependencies. In particular, it
misses cases involving extensions  defined in terms of typealiases, and
it doesn't yet track operator lookups. The whole scheme is also very
dependent on being used to track file-level dependencies; if C is a subclass
of B and B is a subclass of A, C doesn't appear to depend on A. It only
works because changing A will mark B as dirty.

Part of rdar://problem/15353101

Swift SVN r22925
2014-10-24 22:23:03 +00:00
Jordan Rose
05bf3a3cf3 Stop leaking lookup caches; attach them to the ASTContext instead.
This might not matter for the compiler, but both LLDB and SourceKit have to
deal with multiple ASTContexts and multiple SourceFiles all the time.

Swift SVN r22869
2014-10-21 23:06:58 +00:00
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