-
Notifications
You must be signed in to change notification settings - Fork 344
Support hermetic index store data via path remappings #4207
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
Conversation
@swift-ci Please test |
@swift-ci please test |
swiftlang/llvm-project#4207 adds path remappings to the index store to allow using hermetic index data but remapping for local use without the need of any external tools like index-import. This adds a new parameter to IndexStoreDB.init to allow giving the prefix mapping to remap from hermetic --> local paths.
- When indexing, `-fdebug-prefix-map` will be used to remap paths so the computed index data will be hermetic. This includes the unit files' names as well as all paths embedded in the unit files. - When reading, a reverse mapping can be used e.g. via `indexstore_store_create_with_prefix_mapping` to automatically remap the hermetic index data to the correct local paths.
0a4dd82
to
836e3f0
Compare
Updated the tests to confirm that the unit file names are deterministic by including the hash in the expected output |
std::map<std::string, std::string, std::greater<std::string>> | ||
PrefixMap, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be nice to extract this out into a separate data structure. IIUC there's no need for this to be a map other than that it's convenient (though not really) to pass around. So if we had a separate class for this it could internally just store a SmallVector of <struct with original and remap path>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, and as an input to the API I think conceptually it should be an array of string pairs. Whether then the underlying implementation uses a std::map
or a llvm::StringMap
for the lookups, it would be an implementation detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I don't think a "lookup" is ever actually performed, we only ever iterate over them all and check whether there's a prefix match (hence my suggestion of a SmallVector internally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mirroring how Clang stores its prefix maps: https://cs.github.com/llvm/llvm-project/blob/0f304ef0170231b860a249f34e07f50686392253/clang/lib/CodeGen/CGDebugInfo.h#L87 and https://cs.github.com/llvm/llvm-project/blob/0f304ef0170231b860a249f34e07f50686392253/clang/include/clang/Basic/LangOptions.h#L421. I can change this to be more like how Swift does it (they're different, like you mentioned)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally those wouldn't be maps either 😅. So these are checked in alphabetical order rather than the order they were given on the CLI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's my understanding. I think it would make sense to clean up, but not sure it's in scope for here. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's worth making whatever you add usable in those cases, but we'd want to fix that upstream anyway (so no, not in scope).
Also increment INDEXSTORE_VERSION_MINOR
Also avoid storing relative paths in the index data - make them absolute first, which means they can be stored using UNIT_PATH_PREFIX_WORKDIR.
Also went ahead and made sure paths are absolutized in IndexUnitWriter --> meaning they will be stored relative to UNIT_PATH_PREFIX_WORKDIR. |
@swift-ci please test |
4581e58
to
a0248b7
Compare
- The PathRemapper preserves insertion order of the remappings instead of sorting
Swiftc port of swiftlang/llvm-project#4207.
Swiftc port of swiftlang/llvm-project#4207. This introduces a new flag, `-file-prefix-map` which can be used instead of the existing `-debug-prefix-map` and `-coverage-prefix-map` flags, and also remaps paths in index information currently.
Support hermetic index store data via path remappings #4207
Closing, will re-open with cherry-picks from stable. |
Swiftc port of swiftlang/llvm-project#4207. This introduces a new flag, `-file-prefix-map` which can be used instead of the existing `-debug-prefix-map` and `-coverage-prefix-map` flags, and also remaps paths in index information currently.
swiftlang/llvm-project#4207 adds path remappings to the index store to allow using hermetic index data but remapping for local use without the need of any external tools like index-import. This adds a new prefixMappings parameter to IndexStoreDB.init to allow giving the prefix mapping to remap from hermetic/canonical --> local paths. If prefix mappings are given while the new IndexStore API is unavailable, indexstoredb creation will fail noting that the new API is only available in newer versions of libIndexStore. In addition, I've added a new `indexstoredb_creation_options_*` API to allow configuring options when creating indexstoredb from Swift. To support testing the remappings, TibsBuilder now supports replacing arguments containing `$SRC_DIR` and `$BUILD_DIR` with the respective directories.
swiftlang/llvm-project#4207 adds path remappings to the index store to allow using hermetic index data but remapping for local use without the need of any external tools like index-import. This adds a new prefixMappings parameter to IndexStoreDB.init to allow giving the prefix mapping to remap from hermetic/canonical --> local paths. If prefix mappings are given while the new IndexStore API is unavailable, indexstoredb creation will fail noting that the new API is only available in newer versions of libIndexStore. In addition, I've added a new `indexstoredb_creation_options_*` API to allow configuring options when creating indexstoredb from Swift. To support testing the remappings, TibsBuilder now supports replacing arguments containing `$SRC_DIR` and `$BUILD_DIR` with the respective directories. (cherry picked from commit aff5369)
When indexing,
-fdebug-prefix-map
will be used to remappaths so the computed index data will be hermetic. This
includes the unit files' names as well as all paths embedded
in the unit files.
When reading, a reverse mapping can be used e.g. via
indexstore_store_create_with_prefix_mapping
to automaticallyremap the hermetic index data to the correct local paths.