Commit Graph

275 Commits

Author SHA1 Message Date
Chris Lattner
8a41d14b2d Fix <rdar://problem/21429694> QoI: diagnostic for accessing private methods could be improved
When member lookup completely fails and when CSDiags is the one performing
the lookup, reissue another lookup that ignores access control.  This allows
it to find inaccessible members and diagnose them as such, instead of pretending
we have no idea what the user wants.  We now produce an error message like this:

main.swift:1:6: error: 'foo' is inaccessible due to 'private' protection level
 C().foo()
     ^
test.swift:1:35: note: 'foo' declared here
  internal class C { private func foo() {} }
                                  ^

instead of:

main.swift:1:2: error: value of type 'C' has no member 'foo'
 C().foo()
 ^~~ ~~~
2016-01-17 17:13:07 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Jordan Rose
6e1bf0d10d Rename @exported to @_exported for now.
At some point I want to propose a revised model for exports, but for now
just mark that support for '@exported' is still experimental and subject
to change. (Thanks, Max.)
2015-11-05 11:59:00 -08:00
Jordan Rose
a42531ebf0 Tweak diagnostic message when importing the current module.
Before:
  error: cannot import module being compiled
After:
  warning: file 'foo.swift' is part of module 'Foo'; ignoring import

rdar://problem/22635888

Swift SVN r31995
2015-09-16 17:24:13 +00:00
Jordan Rose
7ec4c4fef3 Don't suggest using 'xcrun' when not on OS X.
Also, suggest "xcrun swiftc" instead of "xcrun swift" on OS X, since
"swift" already infers SDKs and we shouldn't get into this situation.
(We shouldn't get into it on non-OS-X either thanks to the previous
commit, but just in case.)

rdar://problem/22440615

Swift SVN r31535
2015-08-27 18:47:26 +00:00
Jordan Rose
955e130536 Diagnose self-imports of the module being compiled.
The case where this comes up is when people name their app and framework
targets the same thing, or when they've renamed their test target module
in an attempt to avoid issues with  NSClassFromString and differing
runtime names. We currently do various wrong things when this happens,
so just emit an error instead.

I left a hole for our overlays, which use '@exported import <the-current-module>'
to get at their Clang modules. The previous commit means this can be
replaced by -import-underlying-module, but that doesn't help our tests,
which use -enable-source-import for their overlays. Which we should stop doing.

rdar://problem/21254367

Swift SVN r29440
2015-06-17 04:48:01 +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
Jordan Rose
35f5c885cb The lookup context for lookupInModule and lookupVisibleDeclsInModule is required.
This determines whether or not testable declarations are visible.

Part of rdar://problem/17732115

Swift SVN r26845
2015-04-02 02:57:39 +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
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
8a3fcf621e Add -disable-testable-attr-requires-testable-module.
...which allows "@testable import" to work with modules not compiled for
testing. This isn't generally safe, but should be fine for clients like
SourceKit which just need to have the API available and might not be able
to properly rebuild the original target for testing.

We may revisit this in the future.

Swift SVN r26629
2015-03-27 16:36:41 +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
673b95a538 Remove the use of the 'Playground' language option for non-playground things.
LLDB has been setting 'Playground' for their REPL mode too to get some of
these behaviors, but that's not something we want to do long-term, and it's
already been subtly wrong in a few cases. Now 'Playground' really does mean
playgrounds, and 'DebuggerSupport' means REPL /or/ LLDB expression parser
mode.

rdar://problem/18338200

Swift SVN r22030
2014-09-17 18:49:44 +00:00
Jordan Rose
9d2e2cb4bc Don't treat missing imports as an error when -debugger-support is on.
For now, also check that -playground is off; once <rdar://problem/18090611>
is in we can drop this check and treat them as mostly orthogonal options.

Part of <rdar://problem/17994094>

Swift SVN r21385
2014-08-21 22:36:24 +00:00
Jordan Rose
9ddf57f7ba Don't treat missing imports as a fatal error in REPL mode.
We don't want typos in import statements to take down the whole REPL, but we
/do/ want the REPL to be honoring fatal errors that effectively take down the
ASTContext.

This doesn't (yet) apply to the real LLDB REPL, which does not use
SourceFileKind::REPL for its input. The right option to test there is
LangOpts.DebuggerSupport, but that's currently being set for Playgrounds as
well. I've filed <rdar://problem/18090611> for LLDB to adjust their input.

Part of <rdar://problem/17994094>

Swift SVN r21383
2014-08-21 22:36:22 +00:00
Jordan Rose
4eebcb9853 Change ASTContext's LoadedModules map to be keyed by Identifiers, not strings.
No intended functionality change, but there's no reason to be performing
string lookups here.

Swift SVN r20902
2014-08-01 18:03:47 +00:00
Jordan Rose
ed8f1c578e Handle scoped imports for Clang submodules.
"import func Darwin.C.math.hypot" will now work to just import "hypot".
(Since 'Darwin.C.math' is an implicit submodule of 'Darwin',
 "import func Darwin.hypot" also works. That's okay.)

<rdar://problem/17272311>

Swift SVN r20356
2014-07-23 01:12:39 +00:00
Jordan Rose
58befc46e2 [ClangImporter] Handle submodule imports.
Specifically, handle them by also importing the top-level module. This is
unfortunate, but at least lets people /access/ things in explicit submodules,
even if it doesn't let them limit their import to a specific submodule.

    (swift) import OpenGL.GL3
    (swift) glGetString
    // r0 : (GLenum) -> ConstUnsafePointer<GLubyte> = (Function)
    (swift) OpenGL.glGetString
    // r1 : (GLenum) -> ConstUnsafePointer<GLubyte> = (Function)

One unfortunate side effect of having a single Clang ASTContext is that if
one Swift module imports a Clang submodule, every Swift module can now see
it. That means /mixing/ incompatible submodules, such as OpenGL.GL and
OpenGL.GL3, still won't work. Filed <rdar://problem/17756745> for that.

<rdar://problem/13140302>

Swift SVN r20288
2014-07-22 01:31:17 +00:00
Jordan Rose
5b80dc3d44 Respect accessibility for scoped imports.
"import var Foo.bar" should error if "Foo.bar" is not public.

Swift SVN r19747
2014-07-09 22:10:20 +00:00
Mark Lacey
dccd703315 Use <system_error> rather than llvm/Support/system_error.h.
Rafael removed the latter in r210803.

Swift SVN r18842
2014-06-12 21:53:16 +00:00
Doug Gregor
c1daf3fd7f Use perfect forwarding for diagnostic arguments.
While this should be a pointless performance tweak along a path where
we don't care about performance, it actually matters because we
occasionally end up copying SmallStrings or std::strings, then taking
StringRefs to the copies and holding on to them. This was manifesting
as occasional corruption in keyword-argument diagnostics.

Swift SVN r17811
2014-05-09 22:38:01 +00:00
Argyrios Kyrtzidis
1784315096 [AST/IDE] Keep track of semantic info of imports (resolved module and decls) and report module/decl references via
the SourceEntityWalker.

Swift SVN r17689
2014-05-08 07:10:06 +00:00
Jordan Rose
017f7e0ce2 Revert "Emit an error when the user tries to import a submodule."
Even though declarations end up in the top-level module, this can still
/expose/ them if the submodule is explicit. I'll have to think more about
this.

This reverts r17656 / <rdar://problem/16818519>

Swift SVN r17668
2014-05-08 01:45:13 +00:00
Jordan Rose
ac59e5772a Emit an error when the user tries to import a submodule.
<rdar://problem/16818519>

Swift SVN r17656
2014-05-08 00:12:59 +00:00
Dmitri Hrybenko
0e00f513d1 Overload checking: implement simplistic overload checking for top-level
variables and types


Swift SVN r15579
2014-03-28 15:09:41 +00:00
Jordan Rose
608fee70f1 Replace ASTMutationListener with a new LazyResolver callback.
..."resolveExternalDeclImplicitMembers".

Now that the ClangImporter has direct access to the type-checker (through
a LazyResolver), there's no reason to bounce through an obtusely generic
interface on ASTContext. Just call through directly to handle the implicit
members and conformances of external decls.

There's no actual functionality change here, though we can probably do
further cleanup in this area.

Swift SVN r15356
2014-03-22 00:20:00 +00:00
Joe Groff
b08f06f191 Revert "Accept (and prefer) "import type" as a scoped import for any non-protocol type."
This reverts commit r14488, since we're demoting 'type' back to a plain old identifier.

We could consider reallowing 'type' as a contextual keyword here, but from talking to Jordan he was OK with just reverting this functionality.

Swift SVN r14931
2014-03-11 23:18:30 +00:00
Jordan Rose
1fe8630bcd Accept (and prefer) "import type" as a scoped import for any non-protocol type.
Previously this was spelled "import typealias", and that spelling will
continue to be allowed (since someone may specifically be importing a
typealias and want that to match), but now that 'type' is a keyword,
"import type" is the right way to spell the generic "import any type"
scoped import.

Swift SVN r14488
2014-02-27 23:46:06 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Jordan Rose
1d0d9ed070 Include the xcrun incantation to print the SDK path in the "no SDK" error.
Per DaveA's suggestion.

Swift SVN r13250
2014-01-31 23:01:08 +00:00
Jordan Rose
130ebe4fd4 Revert "Special-case the standard library to always live relative to the compiler."
This reverts r12932; it breaks the iOS simulator build.

Swift SVN r12944
2014-01-24 23:12:24 +00:00
Jordan Rose
4844f22475 Special-case the standard library to always live relative to the compiler.
Import "swift" will now only find "swift.swiftmodule", and only in the
runtime import path.

<rdar://problem/15898866>

Swift SVN r12932
2014-01-24 20:10:26 +00:00
Jordan Rose
fcc9843882 Always track external decls, not just during name binding and type checking.
LLDB creates variables that have types before name binding and type checking
actually occur, and this can bring in types from the Clang importer...which
then don't satisfy the constraints of a valid AST. Make sure we always get
a shot at checking these decls.

No test case, unfortunately, but LLDB should have one in their test suite
once this goes in.

<rdar://problem/15838120>

Swift SVN r12686
2014-01-22 01:08:22 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Jordan Rose
a5c2fedc1b When a module is not found and there is no SDK set, remind the user.
(swift) import Darwin
    <REPL Input>:1:8: error: no such module 'Darwin'
    import Darwin
           ^
    <unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT?

This note does not fire if any SDK path is set, even an invalid one.

Swift SVN r12415
2014-01-16 20:08:08 +00:00
Dmitri Hrybenko
41b5f2486c AST printer: pretty-print import declarations while printing deserialized modules
Swift SVN r11144
2013-12-11 21:48:57 +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
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +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
a333b692b4 Flip the switch: multiple input files = multiple SourceFiles.
There is still plenty of fallout to get everything fully correct, but
right now we can build the standard library and run all the tests in
multiple-file mode.

Swift SVN r9673
2013-10-25 17:30:45 +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
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
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
25deab5f31 Misc. cleanup related to use of TranslationUnit.
Swift SVN r9164
2013-10-10 19:49:32 +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
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
9f7ea273d6 Make performAutoImport work in terms of SourceFiles.
Swift SVN r9078
2013-10-09 18:38:27 +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