|
104 | 104 | //! implemented.
|
105 | 105 |
|
106 | 106 | use crate::errors;
|
| 107 | +use rustc_data_structures::base_n; |
| 108 | +use rustc_data_structures::base_n::BaseNString; |
| 109 | +use rustc_data_structures::base_n::ToBaseN; |
| 110 | +use rustc_data_structures::base_n::CASE_INSENSITIVE; |
| 111 | +use rustc_data_structures::flock; |
107 | 112 | use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
108 | 113 | use rustc_data_structures::svh::Svh;
|
109 | 114 | use rustc_data_structures::unord::{UnordMap, UnordSet};
|
110 |
| -use rustc_data_structures::{base_n, flock}; |
111 | 115 | use rustc_errors::ErrorGuaranteed;
|
112 | 116 | use rustc_fs_util::{link_or_copy, try_canonicalize, LinkOrCopy};
|
113 | 117 | use rustc_session::config::CrateType;
|
@@ -329,28 +333,20 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
|
329 | 333 |
|
330 | 334 | debug!("finalize_session_directory() - session directory: {}", incr_comp_session_dir.display());
|
331 | 335 |
|
332 |
| - let old_sub_dir_name = incr_comp_session_dir.file_name().unwrap().to_string_lossy(); |
333 |
| - assert_no_characters_lost(&old_sub_dir_name); |
| 336 | + let mut sub_dir_name = incr_comp_session_dir.file_name().unwrap().to_string_lossy().to_string(); |
| 337 | + assert_no_characters_lost(&sub_dir_name); |
334 | 338 |
|
335 |
| - // Keep the 's-{timestamp}-{random-number}' prefix, but replace the |
336 |
| - // '-working' part with the SVH of the crate |
337 |
| - let dash_indices: Vec<_> = old_sub_dir_name.match_indices('-').map(|(idx, _)| idx).collect(); |
338 |
| - if dash_indices.len() != 3 { |
339 |
| - bug!( |
340 |
| - "Encountered incremental compilation session directory with \ |
341 |
| - malformed name: {}", |
342 |
| - incr_comp_session_dir.display() |
343 |
| - ) |
344 |
| - } |
345 |
| - |
346 |
| - // State: "s-{timestamp}-{random-number}-" |
347 |
| - let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]); |
| 339 | + // Keep the 's-{timestamp}-{random-number}' prefix, but replace "working" with the SVH of the crate |
| 340 | + sub_dir_name.truncate(sub_dir_name.len() - "working".len()); |
| 341 | + // Double-check that we kept this: "s-{timestamp}-{random-number}-" |
| 342 | + assert!(sub_dir_name.ends_with('-'), "{:?}", sub_dir_name); |
| 343 | + assert!(sub_dir_name.as_bytes().iter().filter(|b| **b == b'-').count() == 3); |
348 | 344 |
|
349 |
| - // Append the svh |
350 |
| - base_n::push_str(svh.as_u128(), INT_ENCODE_BASE, &mut new_sub_dir_name); |
| 345 | + // Append the SVH |
| 346 | + sub_dir_name.push_str(&svh.as_u128().to_base_fixed_len(CASE_INSENSITIVE)); |
351 | 347 |
|
352 | 348 | // Create the full path
|
353 |
| - let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name); |
| 349 | + let new_path = incr_comp_session_dir.parent().unwrap().join(&*sub_dir_name); |
354 | 350 | debug!("finalize_session_directory() - new path: {}", new_path.display());
|
355 | 351 |
|
356 | 352 | match rename_path_with_retry(&*incr_comp_session_dir, &new_path, 3) {
|
@@ -446,11 +442,11 @@ fn generate_session_dir_path(crate_dir: &Path) -> PathBuf {
|
446 | 442 | let random_number = thread_rng().next_u32();
|
447 | 443 | debug!("generate_session_dir_path: random_number = {}", random_number);
|
448 | 444 |
|
449 |
| - let directory_name = format!( |
450 |
| - "s-{}-{}-working", |
451 |
| - timestamp, |
452 |
| - base_n::encode(random_number as u128, INT_ENCODE_BASE) |
453 |
| - ); |
| 445 | + // Chop the first 3 characters off the timestamp. Those 3 bytes will be zero for a while. |
| 446 | + let (zeroes, timestamp) = timestamp.split_at(3); |
| 447 | + assert_eq!(zeroes, "000"); |
| 448 | + let directory_name = |
| 449 | + format!("s-{}-{}-working", timestamp, random_number.to_base_fixed_len(CASE_INSENSITIVE)); |
454 | 450 | debug!("generate_session_dir_path: directory_name = {}", directory_name);
|
455 | 451 | let directory_path = crate_dir.join(directory_name);
|
456 | 452 | debug!("generate_session_dir_path: directory_path = {}", directory_path.display());
|
@@ -579,10 +575,10 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime
|
579 | 575 | string_to_timestamp(&directory_name[dash_indices[0] + 1..dash_indices[1]])
|
580 | 576 | }
|
581 | 577 |
|
582 |
| -fn timestamp_to_string(timestamp: SystemTime) -> String { |
| 578 | +fn timestamp_to_string(timestamp: SystemTime) -> BaseNString { |
583 | 579 | let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
|
584 | 580 | let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
|
585 |
| - base_n::encode(micros as u128, INT_ENCODE_BASE) |
| 581 | + micros.to_base_fixed_len(CASE_INSENSITIVE) |
586 | 582 | }
|
587 | 583 |
|
588 | 584 | fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
|
@@ -613,9 +609,8 @@ fn crate_path(sess: &Session) -> PathBuf {
|
613 | 609 | sess.cfg_version,
|
614 | 610 | );
|
615 | 611 |
|
616 |
| - let stable_crate_id = base_n::encode(stable_crate_id.as_u64() as u128, INT_ENCODE_BASE); |
617 |
| - |
618 |
| - let crate_name = format!("{crate_name}-{stable_crate_id}"); |
| 612 | + let crate_name = |
| 613 | + format!("{crate_name}-{}", stable_crate_id.as_u64().to_base_fixed_len(CASE_INSENSITIVE)); |
619 | 614 | incr_dir.join(crate_name)
|
620 | 615 | }
|
621 | 616 |
|
|
0 commit comments