Commit Graph

376 Commits

Author SHA1 Message Date
Xi Ge
33b4de7ff6 [Serialization] Add grouping information of Stdlib to its module documentation file and deserialize it into ModuleFile.
We currently do not support more sophisticated naming mechanisms; group names are stemmed source file names.
2016-02-05 16:56:41 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -08:00
practicalswift
8efa5f587e [gardening] Remove "-*- C++ -*-" tag from .cpp files
Emacs assumes .h files are C files by default which is why the
tag "-*- C++ -*-" is needed.

.cpp files do not have this problem.
2016-01-23 12:09:32 +01:00
Slava Pestov
81267ce1db AST: Serialize -enable-resilience flag on the ModuleDecl
Since resilience is a property of the module being compiled,
not decls being accessed, we need to record which types are
resilient as part of the module.

Previously we would only ever look at the @_fixed_layout
attribute on a type. If the flag was not specified, Sema
would slap this attribute on every type that gets validated.

This is wasteful for non-resilient builds, because there
all types get the attribute. It was also apparently wrong,
and I don't fully understand when Sema decides to validate
which decls.

It is much cleaner conceptually to just serialize this flag
with the module, and check for its presence if the
attribute was not found on a type.
2016-01-16 02:23:27 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
practicalswift
ef849258c6 Fix typo: ambigous → ambiguous 2015-12-13 23:56:40 +01:00
Jordan Rose
3028dc8f44 Failure to load a bridging header -> failure to load a module.
This is important for both test targets and for debugging.

rdar://problem/20616099

Swift SVN r30784
2015-07-30 00:39:35 +00:00
Jordan Rose
98ed31fb99 Make -import-underlying-module automatically export that module.
That's how everything behaved anyway. Might as well make it explicit and
stop special-casing it.

I've left in compatibility for modules built with older compilers so that
people using the OS toolchains aren't immediately unable to debug their apps.
As soon as we change the module format in a more significant way, I can take
this out.

Groundwork for rdar://problem/21254367; see next commit.

Swift SVN r29437
2015-06-17 04:47:39 +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
f0d529719c Deduplicate search paths.
Now that we can pick up search paths from frameworks (necessary to debug
them properly), we can end up with exponential explosions leading to the
same search path coming up thousands of times, which destroys compilation
time /and/ debugger responsiveness. This is already hitting people with
frameworks compiled for app extensions (due to a mistaken approximation
of whether or not something is a framework), but we're turning this on for
all frameworks in the immediate future.

rdar://problem/20291720

Swift SVN r27087
2015-04-07 18:24:12 +00:00
Jordan Rose
960a4f164a Add LangOptions::EnableTargetOSChecking, so that LLDB can ignore OS mismatches.
In particular, this is problematic when libraries are loaded dynamically, and
may have newer deployment targets than the main executable.

Swift SVN r26786
2015-04-01 01:12:29 +00:00
Doug Gregor
8b97f911c6 Reimplement (de-)serialization of protocol conformances.
Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
2015-03-24 06:48:23 +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
Luqman Aden
34b74cfa1c [driver] Add -emit-sib primary action.
Swift SVN r25783
2015-03-05 19:15:07 +00:00
Dmitri Hrybenko
f6faf8ad81 sil-opt: implement partial AST verification
... and use it to parallelize the parse_stdlib.sil test, which was
taking too long.

Swift SVN r25295
2015-02-14 11:48:11 +00:00
Jordan Rose
dbd3b60f6b [Serialization] Move (Module)Status and validateSerializedAST into a namespace.
Also into a separate file.

Before (swift/Serialization/SerializedModuleLoader.h):
  ModuleStatus
  SerializedModuleLoader::ValidationInfo
  SerializedModuleLoader::ExtendedValidationInfo
  SerializedModuleLoader::isSerializedAST
  SerializedModuleLoader::validateSerializedAST

After (swift/Serialization/Validation.h):
  serialization::Status
  serialization::ValidationInfo
  serialization::ExtendedValidationInfo
  serialization::isSerializedAST
  serialization::validateSerializedAST

No functionality change, just a lot of renaming and a bit of reorganizing.

Swift SVN r25226
2015-02-12 05:32:25 +00:00
Jordan Rose
de8a05b293 [Serialization] Serialize the SDK path and -Xcc arguments for an app.
...so that the debugger has the best possible chance of being able to load
the app properly.

We don't do this for frameworks today because we don't want to leak this
information into the public module; once we have a distinction between
"the module that ships with the framework" and "the module that goes into
the debug info" we can do this for frameworks as well.

Part of rdar://problem/17670778

Swift SVN r25204
2015-02-11 23:07:48 +00:00
Jordan Rose
478fdcf3ab [serialization] Stop recording the full paths to input source files.
There were no clients and it leaks information about the developer's system.
After this commit, there should be no full paths present in framework modules.
(App modules may contain search paths for debugging reasons, as well as a
full or relative path to the bridging header.)

Swift SVN r24851
2015-01-30 19:22:34 +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
8ee17a4d0d Serialize search paths when building an app, for a better debugging experience.
There's also a testing option, -serialize-debugging-options, to force this
extra info to be serialized even for library targets. In the long run we'll
probably write out this information for all targets, but strip it out of
the "public module" when a framework is built. (That way it ends up in the
debug info's copy of the module.)

Incidentally, this commit includes the ability to add search paths to the
Clang importer on the fly, which is most of rdar://problem/16347147.
Unfortunately there's no centralized way to add search paths to both Clang
/and/ Swift at the moment.

Part of rdar://problem/17670778

Swift SVN r24545
2015-01-20 03:02:54 +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
6b4dc17038 [Serialization] Serialize and check the target a module was compiled with.
Refuse to load a module if it was compiled for a different architecture or
OS, or if its minimum deployment target is newer than the current target.
Additionally, provide the target triple as part of pre-loading validation
for clients who care (like LLDB).

Part of rdar://problem/17670778

Swift SVN r24469
2015-01-16 02:48:59 +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
John McCall
2e60c2947d Revert "Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history."
This reverts commit dc98e17d84b991b6be8b8feb5e0d05aad24f52a4.

I believe this commit was causing test failures on:
  IRGen/c_layout.sil
  IRGen/existentials.sil
It also recreates the file lib/Serialization/ModuleFormat.h,
which really can't have been intended.

Swift SVN r23732
2014-12-05 06:53:27 +00:00
Joe Groff
df53d4bd80 Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history.
Adding explicit constructors to Clang-imported structs in the previous commits exposes a latent phase ordering issue between the Clang importer and SIL deserialization. Deserializing the standard library SIL ends up pulling in additional Clang decls which never get type-checked before we attempt to emit their code. Work around this by bringing back the "EagerDeserializedDecls" block in the serialization format, and adding any cross-referenced decls that get referenced in SILSerializeAll mode to it, so that we ensure they're available before SILGen. We also have to type-check external decls after doing so, since when only importing a module, we wouldn't do any type-checking at all otherwise.

Swift SVN r23728
2014-12-05 05:31:25 +00:00
Argyrios Kyrtzidis
4130a8efa3 [IDE] Make sure the import decls for swift modules from the generated interface have the module assigned to them.
Swift SVN r23723
2014-12-05 04:43:38 +00:00
Dmitri Hrybenko
e03ff647ec Actually set the variable that is used to trigger the assertion
Swift SVN r23639
2014-12-03 04:47:17 +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
Doug Gregor
b27e88b70b Record Objective-C method lookup tables in Swift modules.
Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
2014-11-11 00:19:03 +00:00
Jordan Rose
9d9f9ef150 Re-apply "[serialization] Reject loading a module with the wrong case."
This included a test that failed on case-sensitive filesystems. Test fixed.

(Aside: Why not just have this fail with "no such module"? Why use a different
error? Because even if "import FOO" picks up a module named 'Foo', there may
actually be a module named 'FOO' on the system (in another folder), and we
should be able to find that. Fixing that is tracked by rdar://problem/18691936.)

rdar://problem/15632996 (again)

Swift SVN r22856
2014-10-21 00:30:09 +00:00
Dave Abrahams
7eb173e487 Revert "[serialization] Reject loading a module with the wrong case."
This reverts commit r22818, which caused
to fail.

Swift SVN r22822
2014-10-18 01:02:20 +00:00
Jordan Rose
5aa27cea08 [serialization] Reject loading a module with the wrong case.
Due to case-insensitive filesystems, "import foundation" can result in the
overlay module for Foundation being loaded. Everything is confused later on
because the (wrong) module name is used in manglings, leading to all sorts
of issues.

This is not the right fix for the problem, because a user really is allowed
to have modules named "foundation" and "FOUNDATION" and "Foundation" coexisting
on their system. To do that we'll want to check the actual case of a
.framework bundle or .swiftmodule file on disk and make sure it matches before
even trying to load the file. But this is a good sanity check anyway.

rdar://problem/15632996

Swift SVN r22818
2014-10-17 21:48:03 +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
Jordan Rose
9aed764daa Re-apply "Verify deserialized Swift decls as well as imported Clang decls."
Swift SVN r22248
2014-09-24 00:53:36 +00:00
Dmitri Hrybenko
fec622de0a Revert "Verify deserialized Swift decls as well as imported Clang decls."
This reverts commit 22200.  It broke building PerfTestSuite:
<rdar://problem/18423171> crash in type checking

Swift SVN r22209
2014-09-23 10:13:03 +00:00
Jordan Rose
a49874afb5 Verify deserialized Swift decls as well as imported Clang decls.
Like the Clang decls, this happens at the end of the type-checking, just as
a simple walk through the loaded decls of the loaded modules. This caught
all of the issues in this commit series and will hopefully keep us honest in
the future.

(By the way, we don't verify right when we return a deserialized decl for the
same reason we don't verify right when we return an imported decl: parts of
the decl may be delayed, and (a) we don't want to force things to be imported
or deserialized sooner than necessary, yet (b) we want to verify as much as
possible.)

rdar://problem/16968891

Swift SVN r22200
2014-09-23 02:06:27 +00:00
Doug Gregor
3119e6d345 Remove the tables that track the types that conform to "known" protocols.
The type checker no longer needs them.


Swift SVN r22137
2014-09-19 16:41:26 +00:00
Jordan Rose
1b51b60e72 [Serialization] Preserve private discriminators through serialization.
Part of rdar://problem/17632175

Swift SVN r21611
2014-08-30 17:27:02 +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
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
Jordan Rose
422565100e [Serialization] Keep track of whether a module has an underlying Clang module.
Previously, we depended on whether or not a serialized module was located
within a framework bundle to consider whether or not it may have a "Clang
half". However, LLDB loads serialized modules from dSYM bundles. Rather
than try to figure out if such a module is "really" a framework, just track
whether the original module was built with -import-underlying-module. If so,
consider the underlying Clang module to be re-exported.

rdar://problem/18099523

Swift SVN r21544
2014-08-28 21:36:02 +00:00
Jordan Rose
6d7d141b09 [Serialization] Sanity-check alignment of AST data.
Somewhere--and I forget where--either the LLVM bitcode system or the
OnDiskHashTable implementation depends on 32-bit alignment being preserved.
We had thought that only alignment /from the start of the stream/ mattered,
but it looks like the whole data section has to be 32-bit-aligned.

<rdar://problem/17814086>

Swift SVN r20599
2014-07-27 00:47:39 +00:00
Jordan Rose
aae4a3d731 [ClangImporter] Pass through diagnostic locations for imports.
If importing a Clang module fails, we should report that at the location of
the import statement. This doesn't do that fully because it isn't transitive
(if Swift module Foo imports Swift module Bar, which fails to import Clang
module Baz, we don't get an error in user source), but it's a step forward
for the simple cases.

Swift SVN r20575
2014-07-25 23:01:51 +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
6ee53ff75f [Serialization] Preserve submodule import paths through serialization.
This is a bit of a hack, but Clang submodules are the only case we have to
support.

Part of <rdar://problem/13140302>

Swift SVN r20287
2014-07-22 01:31:15 +00:00
Chris Lattner
48687380b7 now that DeclAttributes is a single word, there is no reason to deal with
it indirectly through another pointer from Decl, just embed DeclAttributes
directly into Decl and get rid of the "getMutableAttrs" nonsense.



Swift SVN r20216
2014-07-20 04:09:42 +00:00
Jordan Rose
fce31decdc Serialize bridging headers into the merged module file.
We do this so that the swiftmodule file contains all info necessary to
reconstruct the AST for debugging purposes. If the swiftmodule file is copied
into a dSYM bundle, it can (in theory) be used to debug a built app months
later. The header is processed with -frewrite-includes so that it includes
any non-modular content; the user will not have to recreate their project
structure and header maps to reload the AST.

There is some extra complexity here: a target with a bridging header
(such as a unit test target) may depend on another target with a bridging
header (such as an app target). This is a rare case, but one we'd like to
still keep working. However, if both bridging headers import some common.h,
we have a problem, because -frewrite-includes will lose the once-ness
of #import. Therefore, we /also/ store the path, size, and mtime of a
bridging header in the swiftmodule, and prefer to use a regular parse from
the original file if it can be located and hasn't been changed.

<rdar://problem/17688408>

Swift SVN r20128
2014-07-18 00:22:53 +00:00
Argyrios Kyrtzidis
9a060c0de8 In ModuleFile::lookupVisibleDecls(), if the caller requested scoped decls, don't return the all the top-level ones as well.
Swift SVN r18327
2014-05-18 16:08:40 +00:00