Skip to content

[20210107][index] Add macro definitions to the index store #2803

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

Conversation

benlangmuir
Copy link

@benlangmuir benlangmuir commented Apr 6, 2021

Cherry-pick 93c87fc, 2934d72, and cb756c2 to apple/stable/20210107 branch.

Originally reviewed #2740 and https://reviews.llvm.org/D99758


Add support for indexing macro definitions, undefs, and references in
the index store. In the normal case of compiling source files the macros
are indexed using preprocessor callbacks that include every reference.
When we are instead indexing a module that has already been compiled
(.pcm), we get the module macros from the preprocessor, and only
one definition is found.

Macro indexing is enabled by default, but can be disabled using a new
-index-ignore-macros driver flag.

rdar://47815401

The major change here is to index macro occurrences in more places than
before, specifically

* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
  all definition locations and undefinitions instead of just the latest
  one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
  macros, and we no longer report unrelated preprocessor macros during
  indexing the module, which could have caused duplication.

Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.

Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.

Differential Revision: https://reviews.llvm.org/D99758
This is a minimal change to fix the build/tests; a change to actually
use the new macro support is forthcoming.
Add support for indexing macro definitions, undefs, and references in
the index store. In the normal case of compiling source files the macros
are indexed using preprocessor callbacks that include every reference.
When we are instead indexing a module that has already been compiled
(.pcm), we get the module macros from the preprocessor, and only
one definition is found.

Macro indexing is enabled by default, but can be disabled using a new
-index-ignore-macros driver flag.

rdar://47815401
@benlangmuir
Copy link
Author

@swift-ci please test

@benlangmuir
Copy link
Author

@swift-ci please test macOS

@benlangmuir benlangmuir merged commit e2dc83c into swiftlang:apple/stable/20210107 Apr 7, 2021
@benlangmuir benlangmuir deleted the index-macros-20210107 branch September 1, 2022 22:55
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.

1 participant