Skip to content

Commit

Permalink
Auto merge of rust-lang#130695 - GuillaumeGomez:rollup-7w2zou6, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#129545 (rustdoc: redesign toolbar and disclosure widgets)
 - rust-lang#130658 (Fix docs of compare_bytes)
 - rust-lang#130670 (delay uncapping the max_read_size in File::read_to_end)
 - rust-lang#130680 (Call module_name_to_str instead of just unwrapping)
 - rust-lang#130690 (interpret: remove outdated FIXME)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 22, 2024
2 parents 4ae36d9 + 1f96e55 commit 5242b6f
Show file tree
Hide file tree
Showing 52 changed files with 555 additions and 343 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ impl ThinLTOKeysMap {
llvm::LLVMRustComputeLTOCacheKey(rust_str, module.identifier, data.0);
})
.expect("Invalid ThinLTO module key");
(name.clone().into_string().unwrap(), key)
(module_name_to_str(name).to_string(), key)
})
.collect();
Self { keys }
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}

// Fall back to exact equality.
// FIXME: We are missing the rules for "repr(C) wrapping compatible types".
Ok(caller == callee)
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@ extern "rust-intrinsic" {

/// Lexicographically compare `[left, left + bytes)` and `[right, right + bytes)`
/// as unsigned bytes, returning negative if `left` is less, zero if all the
/// bytes match, or positive if `right` is greater.
/// bytes match, or positive if `left` is greater.
///
/// This underlies things like `<[u8]>::cmp`, and will usually lower to `memcmp`.
///
Expand Down
16 changes: 13 additions & 3 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ where
// - avoid passing large buffers to readers that always initialize the free capacity if they perform short reads (#23815, #23820)
// - pass large buffers to readers that do not initialize the spare capacity. this can amortize per-call overheads
// - and finally pass not-too-small and not-too-large buffers to Windows read APIs because they manage to suffer from both problems
// at the same time, i.e. small reads suffer from syscall overhead, all reads incur initialization cost
// proportional to buffer size (#110650)
// at the same time, i.e. small reads suffer from syscall overhead, all reads incur costs proportional to buffer size (#110650)
//
pub(crate) fn default_read_to_end<R: Read + ?Sized>(
r: &mut R,
Expand Down Expand Up @@ -444,6 +443,8 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
}
}

let mut consecutive_short_reads = 0;

loop {
if buf.len() == buf.capacity() && buf.capacity() == start_cap {
// The buffer might be an exact fit. Let's read into a probe buffer
Expand Down Expand Up @@ -489,6 +490,12 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
return Ok(buf.len() - start_len);
}

if bytes_read < buf_len {
consecutive_short_reads += 1;
} else {
consecutive_short_reads = 0;
}

// store how much was initialized but not filled
initialized = unfilled_but_initialized;

Expand All @@ -503,7 +510,10 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
// The reader is returning short reads but it doesn't call ensure_init().
// In that case we no longer need to restrict read sizes to avoid
// initialization costs.
if !was_fully_initialized {
// When reading from disk we usually don't get any short reads except at EOF.
// So we wait for at least 2 short reads before uncapping the read buffer;
// this helps with the Windows issue.
if !was_fully_initialized && consecutive_short_reads > 1 {
max_read_size = usize::MAX;
}

Expand Down
18 changes: 11 additions & 7 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
//!
//! Once you are familiar with the contents of the standard library you may
//! begin to find the verbosity of the prose distracting. At this stage in your
//! development you may want to press the `[-]` button near the top of the
//! page to collapse it into a more skimmable view.
//!
//! While you are looking at that `[-]` button also notice the `source`
//! link. Rust's API documentation comes with the source code and you are
//! encouraged to read it. The standard library source is generally high
//! quality and a peek behind the curtains is often enlightening.
//! development you may want to press the <code>
//! <svg width="0.75rem" height="0.75rem" viewBox="0 0 12 12"
//! stroke="currentColor" fill="none">
//! <path d="M2,2l4,4l4,-4M2,6l4,4l4,-4"/></svg> Summary</code> button near the
//! top of the page to collapse it into a more skimmable view.
//!
//! While you are looking at the top of the page, also notice the
//! <code>source</code> link. Rust's API documentation comes with the source
//! code and you are encouraged to read it. The standard library source is
//! generally high quality and a peek behind the curtains is
//! often enlightening.
//!
//! # What is in the standard library documentation?
//!
Expand Down
35 changes: 27 additions & 8 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), E

let dst = cx.dst.join("src").join(krate.name(cx.tcx()).as_str());
cx.shared.ensure_dir(&dst)?;
let crate_name = krate.name(cx.tcx());
let crate_name = crate_name.as_str();

let mut collector = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
let mut collector =
SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default(), crate_name };
collector.visit_crate(krate);
Ok(())
}
Expand Down Expand Up @@ -115,6 +118,8 @@ struct SourceCollector<'a, 'tcx> {
/// Root destination to place all HTML output into
dst: PathBuf,
emitted_local_sources: FxHashSet<PathBuf>,

crate_name: &'a str,
}

impl DocVisitor for SourceCollector<'_, '_> {
Expand Down Expand Up @@ -210,19 +215,22 @@ impl SourceCollector<'_, '_> {
},
);

let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();

let root_path = PathBuf::from("../../").join(root_path.into_inner());
let mut root_path = root_path.to_string_lossy();
if let Some(c) = root_path.as_bytes().last()
&& *c != b'/'
{
root_path += "/";
}
let mut file_path = Path::new(&self.crate_name).join(&*cur.borrow());
file_path.push(&fname);
fname.push(".html");
let mut cur = self.dst.join(cur.into_inner());
shared.ensure_dir(&cur)?;

let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();
fname.push(".html");
cur.push(&fname);

let title = format!("{} - source", src_fname.to_string_lossy());
Expand Down Expand Up @@ -250,7 +258,7 @@ impl SourceCollector<'_, '_> {
cx,
&root_path,
highlight::DecorationInfo::default(),
SourceContext::Standalone,
SourceContext::Standalone { file_path },
)
},
&shared.style_files,
Expand Down Expand Up @@ -312,10 +320,11 @@ struct ScrapedSource<'a, Code: std::fmt::Display> {
struct Source<Code: std::fmt::Display> {
lines: RangeInclusive<usize>,
code_html: Code,
file_path: Option<(String, String)>,
}

pub(crate) enum SourceContext<'a> {
Standalone,
Standalone { file_path: PathBuf },
Embedded(ScrapedInfo<'a>),
}

Expand Down Expand Up @@ -344,9 +353,19 @@ pub(crate) fn print_src(
});
let lines = s.lines().count();
match source_context {
SourceContext::Standalone => {
Source { lines: (1..=lines), code_html: code }.render_into(&mut writer).unwrap()
SourceContext::Standalone { file_path } => Source {
lines: (1..=lines),
code_html: code,
file_path: if let Some(file_name) = file_path.file_name()
&& let Some(file_path) = file_path.parent()
{
Some((file_path.display().to_string(), file_name.display().to_string()))
} else {
None
},
}
.render_into(&mut writer)
.unwrap(),
SourceContext::Embedded(info) => {
let lines = (1 + info.offset)..=(lines + info.offset);
ScrapedSource { info, lines, code_html: code }.render_into(&mut writer).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ nav.sub {
--copy-path-img-hover-filter: invert(35%);
--code-example-button-color: #7f7f7f;
--code-example-button-hover-color: #595959;
--settings-menu-filter: invert(50%);
--settings-menu-hover-filter: invert(35%);
--codeblock-error-hover-color: rgb(255, 0, 0);
--codeblock-error-color: rgba(255, 0, 0, .5);
--codeblock-ignore-hover-color: rgb(255, 142, 0);
Expand All @@ -87,7 +89,6 @@ nav.sub {
--search-tab-button-not-selected-background: #e6e6e6;
--search-tab-button-selected-border-top-color: #0089ff;
--search-tab-button-selected-background: #fff;
--settings-menu-filter: none;
--stab-background-color: #fff5d6;
--stab-code-color: #000;
--code-highlight-kw-color: #8959a8;
Expand Down Expand Up @@ -192,6 +193,8 @@ nav.sub {
--search-tab-button-not-selected-background: #252525;
--search-tab-button-selected-border-top-color: #0089ff;
--search-tab-button-selected-background: #353535;
--settings-menu-filter: invert(50%);
--settings-menu-hover-filter: invert(65%);
--stab-background-color: #314559;
--stab-code-color: #e6e1cf;
--code-highlight-kw-color: #ab8ac1;
Expand Down
Loading

0 comments on commit 5242b6f

Please sign in to comment.