Commit Graph

217 Commits

Author SHA1 Message Date
Jordan Rose
3243f21280 Make sure all failures to load module interfaces are diagnosed (#25636)
...specifically, diagnosed in the parent DiagnosticEngine. This not
only provides a better user experience, but makes sure that the
compiler exits with a nonzero exit code even if the module goes
unused.

rdar://problem/50789839
2019-06-20 14:14:38 -07:00
Saleem Abdulrasool
731c31f9a5 MSVC: litter the code with llvm_unreachable (NFC)
Add `llvm_unreachable` to mark covered switches which MSVC does not
analyze correctly and believes that there exists a path through the
function without a return value.
2019-06-01 19:02:46 -07:00
Jordan Rose
6cca050fd9 [Serialization] Retire "shadowed module" in favor of "underlying" (#24711)
Similar to 517f5d6b6a, the "shadowed" terminology didn't end up
describing the most common use of the feature; there is pretty much no
intended case where a Swift module shadows a Clang module without also
re-exporting it. Switch to "underlying", which was already in use in a
few places, and which better parallels "overlay".

No intended functionality change.
2019-05-13 10:20:03 -07:00
Rintaro Ishizaki
d3d30ee246 [Serialization] Support Swift only system module
Previously 'isSystemModule()' returns true only if the module is:
- Standard library
- Clang module and that is `IsSystem`
- Swift overlay for clang `IsSystem` module

Now:
- Clang module and that is `IsSystem`; or
- Swift overlay for clang `IsSystem` module
- Swift module found in either of these directories:
  - Runtime library directoris (including stdlib)
  - Frameworks in `-Fsystem` directories
  - Frameworks in `$SDKROOT/System/Library/Frameworks/` (Darwin)
  - Frameworks in `$SDKROOT/Library/Frameworks/` (Darwin)

rdar://problem/50516314
2019-05-08 17:03:06 -07:00
Rintaro Ishizaki
0d43e5ad67 [Serialization] Avoid to call getTargetSpecificModuleTriple() twice
Maintain an invariant that forEachTargetModuleBasename() iterates names
from most to least desiable.
2019-05-08 12:41:10 -07:00
Rintaro Ishizaki
acd4cb1a9d [ASTContext] Remove unused function and includes 2019-05-08 10:12:29 -07:00
Rintaro Ishizaki
8773fe303c [Serialize] Consolidate duplicated logics
- forEachTargetModuleBasename(): Iterate through target names to search
- forEachModuleSearchPath(): Iterate through search paths
2019-05-08 10:11:52 -07:00
Rintaro Ishizaki
6956089b0b [CodeCompletion] Complete Swift only module name after 'import'
rdar://problem/39392446
2019-05-08 10:11:52 -07:00
Jordan Rose
f76d2c3976 [ModuleInterface] Short-circuit module loading for frameworks too (#24459)
Follow-up to 7969705 that handles frameworks as well. Oops.

rdar://problem/50070463
2019-05-03 11:11:07 -07:00
adrian-prantl
ecebf70745 Merge pull request #24173 from adrian-prantl/memorybufferloader
Factor out the pre-registered MemoryBuffer functionality
2019-04-22 11:32:06 -07:00
Adrian Prantl
b244b0928e Factor out the pre-registered MemoryBuffer functionality
form SerializedModuleLoader into its own ModuleLoader class. (NFC-ish)

This gives better control over the order in which the various module
load mechanisms are applied.
2019-04-22 09:17:08 -07:00
adrian-prantl
f75dea49df Merge pull request #23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2019-04-19 14:23:57 -07:00
Joe Groff
399332b75b Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to
the mangled name of the defining decl for the opaque type. To turn this back into a reference
to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction
doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and
ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type
reconstruction.

(Since we're invoking type reconstruction during type checking, when the module hasn't yet been
fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe
there's a better way to do this... Longer term, at least, this surface design gives space for
doing things more the right way--a more request-ified decl validator ought to be able to naturally
lazily service this request without the LazyResolver reference, and if type reconstruction in
the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
2019-04-17 14:46:22 -07:00
Adrian Prantl
8d03cb7a61 Record parseable interface imports in the debug info.
When a Swift module built with debug info imports a library without
debug info from a textual interface, the textual interface is
necessary to reconstruct types defined in the library's interface.  By
recording the Swift interface files in DWARF dsymutil can collect them
and LLDB can find them.

rdar://problem/49751363
2019-04-11 14:50:07 -07:00
Harlan Haskins
149367e5d5 [ParseableInterfaces] Short-circuit module loading
Previously, the ParseableInterfaceModuleLoader relied on the assumption
that, if it returned `errc::not_supported`, it would fall through the
search paths and then move on to the SerializedModuleLoader. This did
not anticipate the possibility of a valid .swiftinterface coming later
in the search paths, which can cause issues for the standard library
which is in the resource-dir and should always be loaded from there.

Instead, make the module loading explicitly short-circuit when seeing
`errc::not_supported`, and document it.

Also add some more logging throughout `discoverLoadableModule` so we can
more easily catch issues like this in the future.

Fixes rdar://49479386
2019-04-08 10:07:11 -07:00
Nathan Hawes
58d622d796 [ParseableInterface] Don't serialize resource directory deps and stop adding cached modules to the dependency tracker
This patch modifies ParseableInterfaceBuilder::CollectDepsForSerialization to
avoid serializing dependencies from the runtime resource path into the
swiftmodules generated from .swiftinterface files. This means the module cache
should now be relocatable across machines.

It also modifies ParseableInterfaceModuleLoader to never add any dependencies
from the module cache and prebuilt cache to the dependency tracker (in addition
to the existing behaviour of not serializing them in the generated
swiftmodules). As a result, CollectDepsForSerialization no longer checks if the
dependencies it is given come from the cache as they are provided by the
dependency tracker. It now asserts that's the case instead.
2019-04-03 06:35:11 -07:00
Jordan Rose
526ea54f43 [Serialization] Preserve @_implementationOnly through module merging
When we build incrementally, we produce "partial swiftmodules" for
each input source file, then merge them together into the final
compiled module that, among other things, gets used for debugging.
Without this, we'd drop @_implementationOnly imports and any types
from the modules that were imported during the module-merging step
and then be unable to debug those types
2019-03-28 16:04:35 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Harlan Haskins
f4da34f363 [ParseableInterface] Only open module buffers once while loading
In addition to being wasteful, this is a correctness issue -- the
compiler should only ever have one view of this file, and it should not
read a potentially different file after validating dependencies.

rdar://48654608
2019-03-21 18:17:07 -07:00
Brent Royal-Gordon
46ddb2a607 [NFC] Support many runtime library import paths
Replaces SearchPathOptions::RuntimeLibraryImportPath with an equivalent std::vector of paths. Also reimplements SearchPathOptions::SkipRuntimeLibraryImportPaths to cause the list of runtime library import paths to be empty, rather than exiting early from SerializedModuleLoader::findModule().
2019-03-11 19:06:51 -07:00
Brent Royal-Gordon
3f58a79174 Import error now mentions the target, not the arch 2019-02-27 11:43:12 -08:00
Brent Royal-Gordon
c1cc51d1f3 Use target triple for “universal” modules
When loading a module supporting multiple targets, the module loader now looks for a file named with a normalized version of the target triple first, and only falls back to the architecture name if the normalized triple is not found.
2019-02-27 11:43:12 -08:00
Brent Royal-Gordon
0df6ff4797 [NFC] Generalize target-specific module loading…
…from 1-2 target-specific names to 0-N target-specific names.
2019-02-22 11:19:29 -08:00
Brent Royal-Gordon
70ba0aab05 [NFC] Extract helper for loading arch-specific modules 2019-02-22 10:53:36 -08:00
Brent Royal-Gordon
652cdfc1b7 [NFC] Clean up module name pairs
Create a helper type to represent the .swiftmodule/.swiftdoc filename pair and use it in SerializedModuleLoaderBase::findModule().
2019-02-21 18:26:09 -08:00
Mishal Shah
345e9881d1 Merge pull request #22699 from apple/stable-update-5.1
Update Swift:master to work with new stable re-branch from swift-5.1-branch
2019-02-20 12:22:00 -08:00
Jordan Rose
43feb9cbe1 On Apple platforms, use swiftmodule directories for the stdlib (#21797)
This changes the Swift resource directory from looking like

    lib/
      swift/
        macosx/
          libswiftCore.dylib
          libswiftDarwin.dylib
          x86_64/
            Swift.swiftmodule
            Swift.swiftdoc
            Darwin.swiftmodule
            Darwin.swiftdoc

to

    lib/
      swift/
        macosx/
          libswiftCore.dylib
          libswiftDarwin.dylib
          Swift.swiftmodule/
            x86_64.swiftmodule
            x86_64.swiftdoc
          Darwin.swiftmodule/
            x86_64.swiftmodule
            x86_64.swiftdoc

matching the layout we use for multi-architecture swiftmodules
everywhere else (particularly frameworks).

There's no change in this commit to how Linux swiftmodules are
packaged. There's been past interest in going the /opposite/ direction
for Linux, since there's not standard support for fat
(multi-architecture) .so libraries. Moving the .so search path /down/
to an architecture-specific directory on Linux would allow the same
resource directory to be used for both host-compiling and
cross-compiling.

rdar://problem/43545560
2019-02-19 14:47:21 -08:00
Bob Wilson
40e2a7cec4 master-next: Fix up recent Swift changes to work with newer VFS code.
The main different here is that VFS moved from clang to llvm.
2019-02-08 14:22:57 -08:00
Saleem Abdulrasool
adcdc39791 swift: update for LLVM SVN r344140
Update swift's usage of clang::vfs which has been hoisted into LLVM.
2019-02-07 17:53:42 -08:00
Jordan Rose
5417ca0aa2 [ParseableInterfaces] Handle swiftdoc files correctly
The previous 'openModuleFiles' interface in SerializedModuleLoaderBase
still assumed that swiftmodule files and swiftdoc files would be found
next to each other, but that's not true anymore with
swiftinterfaces-built-to-modules. Give up on this assumption (and on
the minor optimization of passing down a scratch buffer) and split out
the interface into the customization point
'findModuleFilesInDirectory' and the implementation 'openModuleFiles'.
The latter now takes two full paths: one for the swiftmodule, one for
the swiftdoc.
2018-12-21 15:37:32 -08:00
Jordan Rose
a51f1dd3d2 [ParseableInterface] Pass down the module name and import source loc
- Use the name for the cached module, so that we don't end up with a
  zillion "x86_64-XXXXXXXX.swiftmodule" files in the cache when we're
  working with architecture-specific swiftmodules.

- Diagnose if the expected name is different from the name specified
  in the swiftinterface.

- Emit all diagnostics at the location of the import, instead of
  without any location at all.
2018-12-06 13:33:07 -08:00
Jordan Rose
06f3c11377 [Serialization] Use full target architectures for swiftmodule files (#21053)
Previously these used the same "major architecture" names that the
`#if os(...)` query accepts, but that can be a problem when building
for, say, both armv7 and armv7s, even if the content is "the same".

For a transition period where external build tools are involved, the
compiler will look for "arm.swiftmodule" if it fails to find
"armv7.swiftmodule" or any other 32-bit ARM architecture. No other
Apple platform architectures are affected, and AFAIK no one's using
the architecture-based layout on Linux or any other platforms.

rdar://problem/45174692
2018-12-06 13:31:02 -08:00
Jordan Rose
7d30f9cb1f [ParseableInterface] Fixes and tests for Graydon's fallback work 2018-11-29 11:02:24 -08:00
Graydon Hoare
f7200e87bd [ModuleInterface] <rdar://46081260> Fallback behaviour and testing env vars. 2018-11-28 18:34:41 -08:00
Jordan Rose
1e465f5fc0 [Serialization] Consistently use the VFS for checking if files exist 2018-11-28 18:34:41 -08:00
Graydon Hoare
f212d185c5 Merge pull request #20458 from graydon/text-interface-format-version
Text interface format version
2018-11-14 09:19:27 -08:00
Jordan Rose
6c68ac22f9 [Serialization] Only diagnose a bad architecture when there are others (#20550)
This diagnostic needs to be adapted for swiftinterfaces too, but
meanwhile let's not have it get in the way when dealing with a
multi-architecture module that has parseable interfaces.

    MyKit.framework/
      Modules/
        MyKit.swiftmodule/
          x86_64.swiftinterface
          x86_64.swiftdoc
          # no x86_64.swiftmodule
2018-11-13 18:11:01 -08:00
Graydon Hoare
74dc5a1558 [ModuleInterface] Remove protected helper, redundant with visible dependencyTracker member. 2018-11-13 13:53:46 -08:00
Arnold Schwaighofer
963c64e3e7 Add @_private(from: "SourceFile.swift") imports
A module compiled with `-enable-private-imports` allows other modules to
import private declarations if the importing source file uses an
``@_private(from: "SourceFile.swift") import statement.

rdar://29318654
2018-11-08 08:00:47 -08:00
Graydon Hoare
7a27f6fd59 [ModuleInterface] Extract Base class out of SerializedModuleLoader. 2018-10-11 16:43:51 -07:00
fischertony
e505d417fa [Parse][CodeCompletion] Completions for precedencegroup decls
Added the 'Module::getPrecedenceGroups' API to separate precedence group lookup
from 'Module::lookupVisibleDecls', which together with 'FileUnit::lookupVisibleDecls',
to which the former is forwarded, are expected to look up only 'ValueDecl'. In particular, this
prevents completions like Module.PrecedenceGroup.
2018-10-03 22:12:20 +03:00
Vedant Kumar
5137c013d0 [serialization] Factor out logic to diagnose failure to load an AST (#19352)
This can be used by LLDB to make its error messages more user-friendly.
2018-09-19 14:40:23 -07:00
Jordan Rose
245b06b832 Use llvm::StringSet instead of StringMap where appropriate
That is, where we aren't using the value for anything.

No functionality change.
2018-09-13 15:15:24 -07:00
Jordan Rose
53d0ef8131 [Serialization] Tweak deployment-target-too-new diagnostic (#18475)
Before:

  module file's minimum deployment target is iOS 12.0:
  /path/to/FooKit.swiftmodule

After:

  compiling for iOS 11.0, but module 'FooKit' has a minimum deployment
  target of iOS 12.0: /path/to/FooKit.swiftmodule

Also tweak the "incompatible target" error to include the module name.

rdar://problem/35546499
2018-08-02 19:31:10 -07:00
Robert Widmann
0e58b7fd14 Plumbing for a Virtual File System
Adds the -vfsoverlay frontend option that enables the user to pass
VFS overlay YAML files to Swift. These files define a (potentially
many-layered) virtual mapping on which we predicate a VFS.

Switch all input-based memory buffer reads in the Frontend to the new
FileSystem-based approach.
2018-07-31 13:16:14 -07:00
Jordan Rose
97b152d71e Consistently get extensions from swift/Basic/FileTypes.h (part 2)
Remove the last few literal extension strings from Strings.h in favor
of the file_types APIs, and use those APIs in a few more places.
2018-07-25 22:23:01 -07:00
Jordan Rose
2c40c6bc21 [Serialization] Fix message for using an older compiler's module file (#17340)
Previously: "module compiled with Swift 4.1 cannot be imported in Swift
4.1.50" (i.e. following the -swift-version flag)

Now: "module compiled with Swift 4.1 cannot be imported by the Swift
4.2 compiler"

I'm pretty sure this is what I intended to do all along, and I just
messed it up when I originally implemented it. This is especially
important when working with downloadable toolchains, which would say
"module compiled with Swift 4.2 cannot be imported in Swift 4.1.50",
which is not really the problem at all. Now it'll fall back to the
more generic "module file was created by an older version of the
compiler" error.
2018-06-25 09:20:31 -07:00
Doug Gregor
b6c5830277 [Request-evaluator] Add GraphViz output option -output-request-graphviz.
Introduce a command-line option to visualize the complete set of output
request dependencies evaluated by a particular compile action. This is
exposing existing visualization facilities to the (-frontend) command line.
2018-06-21 00:23:50 -07:00
Tapan Thaker
359385babf Print proper error message when the swiftmodule for architecture not found (#17092)
https://bugs.swift.org/browse/SR-7160
2018-06-18 17:41:24 -07:00