Skip to content

[5.9] Cherry-pick missing cas-related commits from stable/20221013 #6618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Apr 7, 2023

Conversation

akyrtzi
Copy link

@akyrtzi akyrtzi commented Apr 7, 2023

No description provided.

The IncludeTreeBuilder is responsible for building the include-tree for
a specific TU. Factor it out of IncludeTreeActionConsumer to prepare for
building modules, which require their own builder.

(cherry picked from commit 062b023)
(cherry picked from commit 30c89b9)
These were only used by include-tree, and we now have a mechanism to
inject PPCallbacks without going through DependencyActionController.
Remove them and simplify the IncludeTreeActionController.

(cherry picked from commit c603c65)
(cherry picked from commit ca4eed9)
This adds the scaffolding needed for include-tree to push
IncludeTreeBuilder stacks, to compute an include-tree for a module and
to get fmodule-file-cache-key options for dependencies. Note: this does
not yet support building or importing modules, but it lets us compute
dependencies in the right way.

(cherry picked from commit 3b87a20)
(cherry picked from commit 3221056)
Moves IncludeFile after IncludeTree in the header file in preparation
for changing it to IncludeTree::File. Also moves FileInfo to IncludeTree
to simplify declaration.

(cherry picked from commit f36469e)
(cherry picked from commit fa13d21)
(cherry picked from commit 7caa9d9)
(cherry picked from commit 2c3a949)
This handles building and importing simple modules and PCH with modules
using include-tree, when modules are found via header path.

* Extend IncludeTree to represent module imports and modulemap mainfile
* Make IncludeTreeBuilder add the new nodes for #include
* Make PPDirectives import modules from PPCachedActions in #include
* Teach FrontendAction/CompilerInvocation how to setup the main input
  file modulemap and module includes buffer from IncludeTreeRoot.

There are still lots of things missing, including @import syntax and
submodule semantics.

(cherry picked from commit 55b697d)
(cherry picked from commit a9db055)
Track the submodule of each modular header and enter the submodule via
PPCachedActions. This fixes declaration and macro header visibility.

(cherry picked from commit bd61c2c)
(cherry picked from commit d926cee)
…dule

When building a non-header file with -fmodule-name set, add the
requisite modulemap file even though it is not imported as a module, and
test that we are getting the right semantics for the header include.

(cherry picked from commit 43df61c)
(cherry picked from commit 1459055)
With explicit imports, we do not record the module import in the include
tree, because the only thing that happens is to lookup the module by
name, which works already via the command-line options that provide the
module via the action cache.

(cherry picked from commit a13b79f)
(cherry picked from commit 232e662)
…ontext NFC

Unlike the cache key string, these are not needed for multiple modules
at once, and this allows us to store the include-tree ID for a PCH,
which will be useful in the next commit.

(cherry picked from commit d64e27a)
(cherry picked from commit 843daa7)
Instead of looking through the PCH or modules for input files and
loading them into the current FileManager while scanning, merge them
directly from the include-tree that was used to build that PCH and/or
module. This makes it easier to understand where files come from in the
include-tree, and eliminates certain issues where the scanner module may
include more files than are necessary, or include them with different
paths in the case of VFS/symlinks.  It also avoids needing to re-stat
these files if they are not used during scanning the importing TU. As
part of this, we teach IncludeTreeFilesystem to handle ./ stripping in
paths to match what ASTWriter does.

(cherry picked from commit 4c3f73e)
(cherry picked from commit fcf503d)
Instead of putting the modulemap file in the include-tree filesystem and
parsing it at build time, create a data structure that represents just
the parts of the modulemap we need when building the module:

* Flags (explicit, system, framework, etc.)
* Exports (export *, export Foo)
* LinkLibraries (implicit framework autolink, link Foo)

Additionally, we add modular headers lazily by inserting known headers
when we encounter an include-tree header that is part of a submodule
(this is needed for missing #include diagnostics).

This removes the possibility of mismatches between header paths seen
during modulemap parsing from the paths we embed due to #includes, for
exmaple due to VFS virtual vs external paths.

(cherry picked from commit a237e68)

 Conflicts:
	clang/include/clang/Basic/Module.h
	clang/lib/Serialization/ASTWriter.cpp

(cherry picked from commit c6b9298)
* Private modules with fmodule-name
* Inferred framework modules
* Framework autolink
* VFS

(cherry picked from commit 9565950)
(cherry picked from commit 871b0e7)
…isibility

Modules imported for visibility only can happen when -fmodule-name
matches a modular header that is imported more than once so that we
trigger the correct re-exports but without trying to import a module.

(cherry picked from commit d844c16)
(cherry picked from commit 02b64b7)
We were dropping the modular import of a private module if its public
module was imported via PCH, because we skipped parsing the private
modulemap during scanning.

(cherry picked from commit 6034ccd)
(cherry picked from commit ab658ce)
This was review feedback on a previous PR that somehow went missing.
Bring it back.

(cherry picked from commit f1ccf9d)
(cherry picked from commit 0b727cd)
Missing the module named by fmodule-name is not an error for a TU or
PCH.

(cherry picked from commit fcd06ba)
(cherry picked from commit 3e11b20)
Instead of flattening file lists when importing PCH/modules, just create
a chained reference to the list and flatten it only in
FileList::forEachFile. This reduces the storage cost and performance
overhead of merging file lists.

(cherry picked from commit ee7ddda)
(cherry picked from commit 2fbfa49)
(cherry picked from commit f796c8f)
(cherry picked from commit c2817ea)
If we see the same File or FileList more than once, skip visiting it
again. This improves performance if the same module is reached through
multiple dependency chains, or the same file is in multiple
modules/PCH/TU file lists explicitly.

(cherry picked from commit 591fa52)
(cherry picked from commit 653e01b)
* Framework autolink is not automatic unless the binary exists
* Inputs are sorted by name in dep scan
…ules

When an inferred submodule is missing, because the umbrella header does
not actually include it, we need to fall back to textual include. This
was not working when included via PCH, because we were not serializing
the inference flag(s) in the include-tree.

rdar://107281193
(cherry picked from commit ecf7946)
In 6034ccd we fixed an issue where if a public module is imported
via PCH we cannot import the private module in a TU because the
modulemap is not parsed. This is also an issue when building a module
that imports the private module and the TU used a PCH, because even
though we don't import the PCH itself, we still use the
prebuilt/explicit module found via the PCH instead of building an
implicit scanner module.

This commit generalizes the original fix to handle all prebuilt/explicit
modules.

rdar://107446573
(cherry picked from commit 159fe25)
…m modules

When not performing codegen, we can strip the coverage-data-file and
coverage-notes-file options to improve canonicalization.

rdar://107443796

Differential Revision: https://reviews.llvm.org/D147282

(cherry picked from commit 758bca6)
Companion to https://reviews.llvm.org/D147282; when caching a PCH,
remove the -coverage-data-file and -coverage-notes-file options. These
paths cannot currently be prefix-mapped, because they are emitted into
the binary for the coverage runtime to use. However, they have no effect
on PCH, so remove them.

rdar://107443796
(cherry picked from commit 0d086a5)
(cherry picked from commit eb9236e)
Centralize the handling of prefix mapping options so that the driver is
responsible for lowering `-fdepscan-prefix-map-sdk` and
`-fdepscan-prefix-map-toolchain` to use `-fdepscan-prefix-map`, and all
the tools take their prefix mappings from
`FrontendOptions::PathPrefixMappings` instead of each having their own
handling.

This makes it easier for new code paths to use prefix mapping, since
they get configuration "for free".

cc1depscan[d] no longer needs special handling of these options at all,
and in tests we just move to the driver or cc1 options. For
clang-scan-deps it's move convenient to keep the command-line options,
but implement them in the argument adjuster by adding the right driver
options.

rdar://106307646
(cherry picked from commit 5f5cf44)
…> _Private

While we eventually want to remove the mapping from .Private to _Private
modules, until we do, ensure that it behaves the same for explicit
modules.

rdar://107449872

Differential Revision: https://reviews.llvm.org/D147477

(cherry picked from commit 8ec36e6)
akyrtzi and others added 7 commits April 6, 2023 20:32
This is useful so we can evolve the reported scanning information without breaking ABI.

(cherry picked from commit 5577930)
… `clang_experimental_DepGraph_getDiagnostics`

The `StoredDiagnostic`s captured from the `getFileDependencies()` call reference a `SourceManager` object that
gets destroyed and is invalid to use for getting diagnostic location info.

To address this, capture diagnostics as a serialized diagnostics buffer and "materialize" it for the
`clang_experimental_DepGraph_getDiagnostics` call, by re-using existing libclang machinery for loading
serialized diagnostics.

Also delete `clang_experimental_DependencyScannerWorker_getFileDependencies_v5` since it's unsafe to use to get diagnostics
and its functionality is superseeded by `clang_experimental_DependencyScannerWorker_getDepGraph`.

rdar://105978877
(cherry picked from commit 397a30d)
…anning output

Also add translation unit and module cache keys in the json output of `clang-scan-deps` for testing purposes.

(cherry picked from commit c1784bd)
…ee output is requested

It has overhead that is not needed for the include-tree mechanism.

(cherry picked from commit 32bd17b)
As of 3a924f2 we have significantly fewer known isuses with
include-tree caching than with cas-fs, so it's time to switch the
default.

rdar://107575958
(cherry picked from commit cfdc12e)
rdar://107634986
(cherry picked from commit 3c2b29f)
@akyrtzi
Copy link
Author

akyrtzi commented Apr 7, 2023

@swift-ci Please test

Fix doxygen warning: '\c' command does not have a valid word argument
[-Wdocumentation]
@akyrtzi
Copy link
Author

akyrtzi commented Apr 7, 2023

swiftlang/swift#65002
@swift-ci Please test

1 similar comment
@akyrtzi
Copy link
Author

akyrtzi commented Apr 7, 2023

swiftlang/swift#65002
@swift-ci Please test

@akyrtzi akyrtzi merged commit f8abdec into swiftlang:swift/release/5.9 Apr 7, 2023
@akyrtzi akyrtzi deleted the pr/5.9/cas-cherry-pick branch April 7, 2023 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants