|
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_middle::bug; |
@@ -333,31 +337,24 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) { |
333 | 337 |
|
334 | 338 | debug!("finalize_session_directory() - session directory: {}", incr_comp_session_dir.display()); |
335 | 339 |
|
336 | | - let old_sub_dir_name = incr_comp_session_dir |
| 340 | + let mut sub_dir_name = incr_comp_session_dir |
337 | 341 | .file_name() |
338 | 342 | .unwrap() |
339 | 343 | .to_str() |
340 | | - .expect("malformed session dir name: contains non-Unicode characters"); |
| 344 | + .expect("malformed session dir name: contains non-Unicode characters") |
| 345 | + .to_string(); |
341 | 346 |
|
342 | | - // Keep the 's-{timestamp}-{random-number}' prefix, but replace the |
343 | | - // '-working' part with the SVH of the crate |
344 | | - let dash_indices: Vec<_> = old_sub_dir_name.match_indices('-').map(|(idx, _)| idx).collect(); |
345 | | - if dash_indices.len() != 3 { |
346 | | - bug!( |
347 | | - "Encountered incremental compilation session directory with \ |
348 | | - malformed name: {}", |
349 | | - incr_comp_session_dir.display() |
350 | | - ) |
351 | | - } |
352 | | - |
353 | | - // State: "s-{timestamp}-{random-number}-" |
354 | | - let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]); |
| 347 | + // Keep the 's-{timestamp}-{random-number}' prefix, but replace "working" with the SVH of the crate |
| 348 | + sub_dir_name.truncate(sub_dir_name.len() - "working".len()); |
| 349 | + // Double-check that we kept this: "s-{timestamp}-{random-number}-" |
| 350 | + assert!(sub_dir_name.ends_with('-'), "{:?}", sub_dir_name); |
| 351 | + assert!(sub_dir_name.as_bytes().iter().filter(|b| **b == b'-').count() == 3); |
355 | 352 |
|
356 | | - // Append the svh |
357 | | - base_n::push_str(svh.as_u128(), INT_ENCODE_BASE, &mut new_sub_dir_name); |
| 353 | + // Append the SVH |
| 354 | + sub_dir_name.push_str(&svh.as_u128().to_base_fixed_len(CASE_INSENSITIVE)); |
358 | 355 |
|
359 | 356 | // Create the full path |
360 | | - let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name); |
| 357 | + let new_path = incr_comp_session_dir.parent().unwrap().join(&*sub_dir_name); |
361 | 358 | debug!("finalize_session_directory() - new path: {}", new_path.display()); |
362 | 359 |
|
363 | 360 | match rename_path_with_retry(&*incr_comp_session_dir, &new_path, 3) { |
@@ -453,11 +450,11 @@ fn generate_session_dir_path(crate_dir: &Path) -> PathBuf { |
453 | 450 | let random_number = thread_rng().next_u32(); |
454 | 451 | debug!("generate_session_dir_path: random_number = {}", random_number); |
455 | 452 |
|
456 | | - let directory_name = format!( |
457 | | - "s-{}-{}-working", |
458 | | - timestamp, |
459 | | - base_n::encode(random_number as u128, INT_ENCODE_BASE) |
460 | | - ); |
| 453 | + // Chop the first 3 characters off the timestamp. Those 3 bytes will be zero for a while. |
| 454 | + let (zeroes, timestamp) = timestamp.split_at(3); |
| 455 | + assert_eq!(zeroes, "000"); |
| 456 | + let directory_name = |
| 457 | + format!("s-{}-{}-working", timestamp, random_number.to_base_fixed_len(CASE_INSENSITIVE)); |
461 | 458 | debug!("generate_session_dir_path: directory_name = {}", directory_name); |
462 | 459 | let directory_path = crate_dir.join(directory_name); |
463 | 460 | debug!("generate_session_dir_path: directory_path = {}", directory_path.display()); |
@@ -588,10 +585,10 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime |
588 | 585 | string_to_timestamp(&directory_name[dash_indices[0] + 1..dash_indices[1]]) |
589 | 586 | } |
590 | 587 |
|
591 | | -fn timestamp_to_string(timestamp: SystemTime) -> String { |
| 588 | +fn timestamp_to_string(timestamp: SystemTime) -> BaseNString { |
592 | 589 | let duration = timestamp.duration_since(UNIX_EPOCH).unwrap(); |
593 | 590 | let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000; |
594 | | - base_n::encode(micros as u128, INT_ENCODE_BASE) |
| 591 | + micros.to_base_fixed_len(CASE_INSENSITIVE) |
595 | 592 | } |
596 | 593 |
|
597 | 594 | fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> { |
@@ -622,9 +619,8 @@ fn crate_path(sess: &Session) -> PathBuf { |
622 | 619 | sess.cfg_version, |
623 | 620 | ); |
624 | 621 |
|
625 | | - let stable_crate_id = base_n::encode(stable_crate_id.as_u64() as u128, INT_ENCODE_BASE); |
626 | | - |
627 | | - let crate_name = format!("{crate_name}-{stable_crate_id}"); |
| 622 | + let crate_name = |
| 623 | + format!("{crate_name}-{}", stable_crate_id.as_u64().to_base_fixed_len(CASE_INSENSITIVE)); |
628 | 624 | incr_dir.join(crate_name) |
629 | 625 | } |
630 | 626 |
|
|
0 commit comments