Conversation
|
Are the changes in |
We need to update map from hashes to def indices while encoding |
|
@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.
Remap def indices for deterministic metadata encoding
This comment has been minimized.
This comment has been minimized.
cc58a69 to
9736cd8
Compare
|
Finished benchmarking commit (ceb9839): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf 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 3.0%, secondary 4.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 10.2%, secondary 14.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.4%, secondary -0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 496.137s -> 496.27s (0.03%) |
|
@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.
Remap def indices for deterministic metadata encoding
|
|
||
| #[inline] | ||
| fn map_index(&self, index: DefIndex) -> DefIndex { | ||
| self.def_indexes_remapping.get(&index).copied().unwrap_or(index) |
There was a problem hiding this comment.
This could be donewith a vec for better performance. Since we know that these indices are dense in a range. Either a full IndexVec mapping every LocalDefId, or a shorter Vec, that only contains the remapped ones, indexed by remapped_index - min_remapped_index
There was a problem hiding this comment.
It is very strong assumption that def ids that are needed to be remapped will be in the end, now it should be true, because resolution and AST -> HIR lowering is executed without any parallelism, however AST -> HIR lowering became more incremental recently by introducing lower_to_hir query which is very easy to parallelize in the beginning of the run_required_analysis function (now it is executed sequentially as we prefetch hir_crate_items which is a sequential HIR visit). If it is parallelized then from each lower_to_hir execution we may invoke arbitrary code that can allocate def ids that do not need to be remapped.
But I like the idea, I was thinking about something similar in a bit different direction: create separate IndexVecs in Definitions struct for different stages of compilation, thus we can maybe pre-allocate and remap ids only for selected parts.
I think that it is reasonable to track the last def id that is allocated during resolution stage, because it is not likely to get parallelized in the nearest time (I hope so) and then to remap all def ids that are allocated after it, I will try it tomorrow.
| let mut to_remap = vec![]; | ||
| let mut def_ids = vec![]; | ||
| for idx in 0..defs.num_definitions() { | ||
| let def_id = LocalDefId { local_def_index: idx.into() }; |
There was a problem hiding this comment.
I think this could iterate backwards, stopping when it hits an index not needing remapping. Remapped indices should be at the end
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (8bcd37a): comparison URL. Overall result: ❌ regressions - BENCHMARK(S) FAILEDBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf ❗ ❗ ❗ ❗ ❗
❗ ❗ ❗ ❗ ❗ Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 496.137s -> 495.635s (-0.10%) |
4f2feb6 to
e01cdf1
Compare
|
Finished benchmarking commit (501ad34): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never rustc-perf 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.3%, secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 4.4%, secondary 4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 500.132s -> 498.753s (-0.28%) |
This comment has been minimized.
This comment has been minimized.
0e96bcc to
1a64dd7
Compare
This comment has been minimized.
This comment has been minimized.
…coding, r=petrochenkov Deterministic encoding of `DefPathHashMap` This PR splits DefPathHashMap into two parts: deterministic (`det_part`) and non-deterministic (`non_det_part`). `det_part` is used while we sure that allocation and insertion order of def ids is deterministic, at the moment of writing it happens before we start parallel checks after prefetch of `hir_crate_items` in `run_required_analysis`. Up until this point of compilation the allocation of def ids and their insertion order into `det_part` should be the same between different compilations. Next, when non-determinism starts due to parallel compilation we put all mapping between local hash and def ids into a `SortedMap` which gives us ready-to-use sorted by local hash slice of pairs to encode while encoding metadata. Note, that this PR does not solve the problem of allocation of different def indices to same code entities (meaning same local hash), this problem is solved in rust-lang#162809 by remapping needed local def indices. Also note that we serialize `det_part` as a raw bytes sequence, so during remapping if we do not place all def indices that are needed to be remapped into separate container we will end up with copying `det_part`, changing some entries in it and then serialize it as a bytes sequence. With the approach in this PR we do not copy and modify `det_part`, instead we do all modifications in `non_det_part`. r? @petrochenkov
Rollup merge of #162910 - aerooneqq:det-def-path-hash-map-encoding, r=petrochenkov Deterministic encoding of `DefPathHashMap` This PR splits DefPathHashMap into two parts: deterministic (`det_part`) and non-deterministic (`non_det_part`). `det_part` is used while we sure that allocation and insertion order of def ids is deterministic, at the moment of writing it happens before we start parallel checks after prefetch of `hir_crate_items` in `run_required_analysis`. Up until this point of compilation the allocation of def ids and their insertion order into `det_part` should be the same between different compilations. Next, when non-determinism starts due to parallel compilation we put all mapping between local hash and def ids into a `SortedMap` which gives us ready-to-use sorted by local hash slice of pairs to encode while encoding metadata. Note, that this PR does not solve the problem of allocation of different def indices to same code entities (meaning same local hash), this problem is solved in #162809 by remapping needed local def indices. Also note that we serialize `det_part` as a raw bytes sequence, so during remapping if we do not place all def indices that are needed to be remapped into separate container we will end up with copying `det_part`, changing some entries in it and then serialize it as a bytes sequence. With the approach in this PR we do not copy and modify `det_part`, instead we do all modifications in `non_det_part`. r? @petrochenkov
…=petrochenkov Deterministic encoding of `DefPathHashMap` This PR splits DefPathHashMap into two parts: deterministic (`det_part`) and non-deterministic (`non_det_part`). `det_part` is used while we sure that allocation and insertion order of def ids is deterministic, at the moment of writing it happens before we start parallel checks after prefetch of `hir_crate_items` in `run_required_analysis`. Up until this point of compilation the allocation of def ids and their insertion order into `det_part` should be the same between different compilations. Next, when non-determinism starts due to parallel compilation we put all mapping between local hash and def ids into a `SortedMap` which gives us ready-to-use sorted by local hash slice of pairs to encode while encoding metadata. Note, that this PR does not solve the problem of allocation of different def indices to same code entities (meaning same local hash), this problem is solved in rust-lang/rust#162809 by remapping needed local def indices. Also note that we serialize `det_part` as a raw bytes sequence, so during remapping if we do not place all def indices that are needed to be remapped into separate container we will end up with copying `det_part`, changing some entries in it and then serialize it as a bytes sequence. With the approach in this PR we do not copy and modify `det_part`, instead we do all modifications in `non_det_part`. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
d1c40cc to
d51440b
Compare
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
|
|
||
| self.last_deterministic_index | ||
| .set( | ||
| if self.def_id_to_key.is_empty() { 0 } else { self.def_id_to_key.len() - 1 }.into(), |
There was a problem hiding this comment.
will this ever be empty? shouldn't the first entry always be the crate root?
| #[derive(MetadataEncodable, LazyDecodable)] | ||
| pub(crate) struct TraitImpls { | ||
| trait_id: (u32, DefIndex), | ||
| trait_id: (u32 /* crate */, u32 /* def index */), |
There was a problem hiding this comment.
why was this changed?
| proc_macro_decls_static: DefIndex, | ||
| stability: Option<Stability>, | ||
| macros: LazyArray<(DefIndex, LazyValue<ProcMacroKind>)>, | ||
| proc_macro_quoted_spans: LazyTableSingleIdx<usize, Option<LazyValue<Span>>>, |
There was a problem hiding this comment.
this can be its own commit, it's not really necessary, just moving it to the right place, right?
| let def_id = local_id.to_def_id(); | ||
| let def_kind = tcx.def_kind(local_id); | ||
| self.tables.def_kind.set_some(def_id.index, def_kind); | ||
| record_non_lazy!(self.tables.def_kind[def_id] <- def_kind); |
There was a problem hiding this comment.
lots of unrelated changes, move them to a separate commit
There was a problem hiding this comment.
| && matches!( | ||
| data.data, | ||
| DefPathData::SyntheticCoroutineBody | ||
| | DefPathData::OpaqueLifetime(..) | ||
| | DefPathData::NestedStatic | ||
| | DefPathData::AnonAssocTy(..) | ||
| ) |
There was a problem hiding this comment.
This seems fragile. How do we ensure that we won't end up with new nondeterminism in the future?
There was a problem hiding this comment.
which DefPathDatas aren't on this list but are after the last deterministic index?
|
Reminder, once the PR becomes ready for a review, use |
|
Blocked by #163321. |
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
…cros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from rust-lang#162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in rust-lang#162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
Rollup merge of #162900 - aerooneqq:record-tables-through-macros, r=petrochenkov Some refactorings around metadata encoding Two refactorings that were extracted from #162809: - Use macros to record values in all tables, this unifies writing to tables and makes it much easier to modify or refactor writing process as it was needed in #162809, - Moves `proc_macro_quoted_spans` table into `ProcMacroData` as it is filled only when `ProcMacroData` is `Some` (meaning crate type is `proc-macro`), so it is reasonable to place it here, moreover all tables left in `LazyTables` have `DefIndex` as key, this simplifies refactorings and modifications that are connected with `DefIndex`es. r? @petrochenkov
|
☔ The latest upstream changes (presumably #163609) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
View all comments
Now at the very early stage (however fixes corresponding issues), draft primarily for CI.
cc #t-compiler/const-eval > DefId reproducibility with the parallel frontend
r? @petrochenkov