Use interior mutability for StableHashingContext::caching_source_map.#154735
Use interior mutability for StableHashingContext::caching_source_map.#154735nnethercote wants to merge 3 commits intorust-lang:mainfrom
StableHashingContext::caching_source_map.#154735Conversation
`StableHashingContext::caching_source_map` is currently externally mutated by `span_hash_stable`, which is reachable from many `hash_stable` methods. But the mutation that happens is just some internal caching, via `CachingSourceMap`. Conceptually it feels like a read-only lookup of source map data. This commit changes the field to interior mutability. This will let `hash_stable` use `&Hcx` instead of `&mut Hcx`. The switch involves replacing the existing `StableHashingContext::source_map` method with a new `StableHashingContxt::span_data_to_lines_and_cols` method, because returning a `&mut` was problematic with the use of `RefCell`. The existing `CachingSourceMapView::span_data_to_lines_and_cols` now returns an `Arc`, but that seems fine because the nearby `CachingSourceMapView::byte_pos_to_line_and_col` already does that.
This was enabled by the previous commit. A few related functions also get a similar change.
It's no longer needed now that `hash_stable` takes a `&hcx` instead of `&mut hcx`.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Use interior mutability for `StableHashingContext::caching_source_map`.
|
☔ The latest upstream changes (presumably #154727) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f43d2c0): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -2.2%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 487.024s -> 488.913s (0.39%) |
This lets a lot of
&mut hcxparameters change to&hcx, for symmetry withto_hash_stable_key, and avoids some unnecessary cloning ofStableHashingContext. Details in individual commits.