-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Force-discard cache if cache format changed #20152
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,10 @@ | |
| from typing import TYPE_CHECKING, Any, Callable, ClassVar, Final, NoReturn, TextIO, TypedDict | ||
| from typing_extensions import TypeAlias as _TypeAlias | ||
|
|
||
| from librt.internal import cache_version | ||
|
|
||
| import mypy.semanal_main | ||
| from mypy.cache import Buffer, CacheMeta | ||
| from mypy.cache import CACHE_VERSION, Buffer, CacheMeta | ||
| from mypy.checker import TypeChecker | ||
| from mypy.error_formatter import OUTPUT_CHOICES, ErrorFormatter | ||
| from mypy.errors import CompileError, ErrorInfo, Errors, report_internal_error | ||
|
|
@@ -1334,12 +1336,18 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> CacheMeta | No | |
| return None | ||
| t1 = time.time() | ||
| if isinstance(meta, bytes): | ||
| data_io = Buffer(meta) | ||
| # If either low-level buffer format or high-level cache layout changed, we | ||
| # cannot use the cache files, even with --skip-version-check. | ||
| # TODO: switch to something like librt.internal.read_byte() if this is slow. | ||
| if meta[0] != cache_version() or meta[1] != CACHE_VERSION: | ||
| manager.log(f"Metadata abandoned for {id}: incompatible cache format") | ||
| return None | ||
| data_io = Buffer(meta[2:]) | ||
| m = CacheMeta.read(data_io, data_file) | ||
| else: | ||
| m = CacheMeta.deserialize(meta, data_file) | ||
| if m is None: | ||
| manager.log(f"Metadata abandoned for {id}: attributes are missing") | ||
| manager.log(f"Metadata abandoned for {id}: cannot deserialize data") | ||
| return None | ||
| t2 = time.time() | ||
| manager.add_stats( | ||
|
|
@@ -1671,7 +1679,9 @@ def write_cache_meta(meta: CacheMeta, manager: BuildManager, meta_file: str) -> | |
| if manager.options.fixed_format_cache: | ||
| data_io = Buffer() | ||
| meta.write(data_io) | ||
| meta_bytes = data_io.getvalue() | ||
| # Prefix with both low- and high-level cache format versions for future validation. | ||
| # TODO: switch to something like librt.internal.write_byte() if this is slow. | ||
| meta_bytes = bytes([cache_version(), CACHE_VERSION]) + data_io.getvalue() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, the concatenate operation does a full copy of the cache data. We could add a |
||
| else: | ||
| meta_dict = meta.serialize() | ||
| meta_bytes = json_dumps(meta_dict, manager.options.debug_cache) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The slice operation does an almost full copy of the meta buffer. It's probably not a big deal, but it would be nice if we could avoid it. What about adding
read_byteoperation in the internal API (that would be just an alias toread_tagfor now I guess) that could be used to read the initial two bytes? (No need to do this in this PR.)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.
Could also maybe slice the memoryview?
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 just measured this slice on a "micro-benchmark", it takes around 0.1 microsecond per file (interpreted). So even with 10K files in the build this will be an extra millisecond. It is probably even less when compiled. I will add a TODO here and below.