Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #134096

Merged
merged 21 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f884f18
Move tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`
Zalathar Dec 7, 2024
0a48b96
Move more tests into `tests/ui/link-native-libs`
Zalathar Dec 7, 2024
477b722
docs: better examples for `std::ops::ControlFlow`
snprajwal Dec 8, 2024
999aed4
Add URL to test cases
notriddle Dec 9, 2024
b531854
rustdoc: rename `issue-\d+.rs` tests to have meaningful names
notriddle Dec 9, 2024
15d7331
bootstrap: `print{,ln}!` -> `eprint{,ln}!`
clubby789 Dec 3, 2024
a6c4628
compiletest: `print{,ln}!` -> `eprint{,ln}!`
clubby789 Dec 3, 2024
d0986f4
dataflow_const_prop: do not eval a ptr address in SwitchInt
DianQK Dec 9, 2024
73dc95d
interpret: clean up deduplicating allocation functions
RalfJung Dec 9, 2024
a97404e
Add test to check unicode identifier version
ehuss Dec 8, 2024
5404cbb
Fix typo in RFC mention 3598 -> 3593
estebank Dec 9, 2024
2d71dd5
Grammar fixes
aarikpokras Dec 7, 2024
df5ec03
Rollup merge of #133996 - Zalathar:ui-link-native-libs, r=jieyouxu
fmease Dec 9, 2024
780b5bb
Rollup merge of #134012 - aarikpokras:patch-1, r=saethlin
fmease Dec 9, 2024
e0f3db0
Rollup merge of #134032 - snprajwal:fix-docs, r=joboet
fmease Dec 9, 2024
b282774
Rollup merge of #134040 - clubby789:bootstrap-eprintln, r=jieyouxu
fmease Dec 9, 2024
0cb12f9
Rollup merge of #134043 - ehuss:unicode-version, r=jieyouxu
fmease Dec 9, 2024
76fbe8d
Rollup merge of #134053 - notriddle:notriddle/issue-d, r=GuillaumeGomez
fmease Dec 9, 2024
e0bec9d
Rollup merge of #134055 - RalfJung:interpret-alloc-dedup, r=oli-obk
fmease Dec 9, 2024
cb5f03c
Rollup merge of #134073 - DianQK:fix-131227, r=oli-obk
fmease Dec 9, 2024
5a33ab0
Rollup merge of #134084 - estebank:typo, r=compiler-errors
fmease Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ standard library, and documentation.

## Why Rust?

- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrate with other languages.
- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrated with other languages.

- **Reliability:** Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.

Expand Down
44 changes: 17 additions & 27 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use std::assert_matches::assert_matches;

use either::{Either, Left, Right};
use rustc_abi::{Align, BackendRepr, HasDataLayout, Size};
use rustc_ast::Mutability;
use rustc_abi::{BackendRepr, HasDataLayout, Size};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::{bug, mir, span_bug};
Expand Down Expand Up @@ -1018,40 +1017,31 @@ where
self.allocate_dyn(layout, kind, MemPlaceMeta::None)
}

/// Allocates a sequence of bytes in the interpreter's memory.
/// For immutable allocations, uses deduplication to reuse existing memory.
/// For mutable allocations, creates a new unique allocation.
pub fn allocate_bytes(
/// Allocates a sequence of bytes in the interpreter's memory with alignment 1.
/// This is allocated in immutable global memory and deduplicated.
pub fn allocate_bytes_dedup(
&mut self,
bytes: &[u8],
align: Align,
kind: MemoryKind<M::MemoryKind>,
mutbl: Mutability,
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
// Use cache for immutable strings.
if mutbl.is_not() {
// Use dedup'd allocation function.
let salt = M::get_global_alloc_salt(self, None);
let id = self.tcx.allocate_bytes_dedup(bytes, salt);

// Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation.
M::adjust_alloc_root_pointer(&self, Pointer::from(id), Some(kind))
} else {
// Allocate new memory for mutable data.
self.allocate_bytes_ptr(bytes, align, kind, mutbl)
}
let salt = M::get_global_alloc_salt(self, None);
let id = self.tcx.allocate_bytes_dedup(bytes, salt);

// Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation.
M::adjust_alloc_root_pointer(
&self,
Pointer::from(id),
M::GLOBAL_KIND.map(MemoryKind::Machine),
)
}

/// Allocates a string in the interpreter's memory with metadata for length.
/// Uses `allocate_bytes` internally but adds string-specific metadata handling.
pub fn allocate_str(
/// Allocates a string in the interpreter's memory, returning it as a (wide) place.
/// This is allocated in immutable global memory and deduplicated.
pub fn allocate_str_dedup(
&mut self,
str: &str,
kind: MemoryKind<M::MemoryKind>,
mutbl: Mutability,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
let bytes = str.as_bytes();
let ptr = self.allocate_bytes(bytes, Align::ONE, kind, mutbl)?;
let ptr = self.allocate_bytes_dedup(bytes)?;

// Create length metadata for the string.
let meta = Scalar::from_target_usize(u64::try_from(bytes.len()).unwrap(), self);
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_const_eval/src/util/caller_location.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_hir::LangItem;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Mutability};
use rustc_middle::ty::{self};
use rustc_middle::{bug, mir};
use rustc_span::symbol::Symbol;
use tracing::trace;
Expand All @@ -20,12 +20,9 @@ fn alloc_caller_location<'tcx>(
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
// pointless, since that would require allocating more memory than these short strings.
let file = if loc_details.file {
ecx.allocate_str(filename.as_str(), MemoryKind::CallerLocation, Mutability::Not).unwrap()
ecx.allocate_str_dedup(filename.as_str()).unwrap()
} else {
// FIXME: This creates a new allocation each time. It might be preferable to
// perform this allocation only once, and re-use the `MPlaceTy`.
// See https://github.com/rust-lang/rust/pull/89920#discussion_r730012398
ecx.allocate_str("<redacted>", MemoryKind::CallerLocation, Mutability::Not).unwrap()
ecx.allocate_str_dedup("<redacted>").unwrap()
};
let file = file.map_provenance(CtfeProvenance::as_immutable);
let line = if loc_details.line { Scalar::from_u32(line) } else { Scalar::from_u32(0) };
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod unescape;
mod tests;

use unicode_properties::UnicodeEmoji;
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;

use self::LiteralKind::*;
use self::TokenKind::*;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_adt_def_from_data(ty::AdtDefData::new(self, did, kind, variants, repr))
}

/// Allocates a read-only byte or string literal for `mir::interpret`.
/// Allocates a read-only byte or string literal for `mir::interpret` with alignment 1.
/// Returns the same `AllocId` if called again with the same bytes.
pub fn allocate_bytes_dedup(self, bytes: &[u8], salt: usize) -> interpret::AllocId {
// Create an allocation that just contains these bytes.
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,13 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
// This allows the set of visited edges to grow monotonically with the lattice.
FlatSet::Bottom => TerminatorEdges::None,
FlatSet::Elem(scalar) => {
let choice = scalar.assert_scalar_int().to_bits_unchecked();
TerminatorEdges::Single(targets.target_for_value(choice))
if let Ok(scalar_int) = scalar.try_to_scalar_int() {
TerminatorEdges::Single(
targets.target_for_value(scalar_int.to_bits_unchecked()),
)
} else {
TerminatorEdges::SwitchInt { discr, targets }
}
}
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {

/// Detect guarded string literal syntax
///
/// RFC 3598 reserved this syntax for future use. As of Rust 2024,
/// RFC 3593 reserved this syntax for future use. As of Rust 2024,
/// using this syntax produces an error. In earlier editions, however, it
/// only results in an (allowed by default) lint, and is treated as
/// separate tokens.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::{Diag, FatalError, PResult};
use rustc_session::parse::ParseSess;
use rustc_span::{FileName, SourceFile, Span};
pub use unicode_normalization::UNICODE_VERSION as UNICODE_NORMALIZATION_VERSION;

pub const MACRO_ARGUMENTS: Option<&str> = Some("macro arguments");

Expand Down
16 changes: 8 additions & 8 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl<B, C> ControlFlow<B, C> {
/// ```
/// use std::ops::ControlFlow;
///
/// assert!(ControlFlow::<i32, String>::Break(3).is_break());
/// assert!(!ControlFlow::<String, i32>::Continue(3).is_break());
/// assert!(ControlFlow::<&str, i32>::Break("Stop right there!").is_break());
/// assert!(!ControlFlow::<&str, i32>::Continue(3).is_break());
/// ```
#[inline]
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
Expand All @@ -157,8 +157,8 @@ impl<B, C> ControlFlow<B, C> {
/// ```
/// use std::ops::ControlFlow;
///
/// assert!(!ControlFlow::<i32, String>::Break(3).is_continue());
/// assert!(ControlFlow::<String, i32>::Continue(3).is_continue());
/// assert!(!ControlFlow::<&str, i32>::Break("Stop right there!").is_continue());
/// assert!(ControlFlow::<&str, i32>::Continue(3).is_continue());
/// ```
#[inline]
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
Expand All @@ -174,8 +174,8 @@ impl<B, C> ControlFlow<B, C> {
/// ```
/// use std::ops::ControlFlow;
///
/// assert_eq!(ControlFlow::<i32, String>::Break(3).break_value(), Some(3));
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).break_value(), None);
/// assert_eq!(ControlFlow::<&str, i32>::Break("Stop right there!").break_value(), Some("Stop right there!"));
/// assert_eq!(ControlFlow::<&str, i32>::Continue(3).break_value(), None);
/// ```
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
Expand Down Expand Up @@ -205,8 +205,8 @@ impl<B, C> ControlFlow<B, C> {
/// ```
/// use std::ops::ControlFlow;
///
/// assert_eq!(ControlFlow::<i32, String>::Break(3).continue_value(), None);
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).continue_value(), Some(3));
/// assert_eq!(ControlFlow::<&str, i32>::Break("Stop right there!").continue_value(), None);
/// assert_eq!(ControlFlow::<&str, i32>::Continue(3).continue_value(), Some(3));
/// ```
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
Expand Down
20 changes: 10 additions & 10 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn main() {
err => {
drop(err);
if let Ok(pid) = pid {
println!("WARNING: build directory locked by process {pid}, waiting for lock");
eprintln!("WARNING: build directory locked by process {pid}, waiting for lock");
} else {
println!("WARNING: build directory locked, waiting for lock");
eprintln!("WARNING: build directory locked, waiting for lock");
}
let mut lock = t!(build_lock.write());
t!(lock.write(process::id().to_string().as_ref()));
Expand All @@ -70,13 +70,13 @@ fn main() {
// changelog warning, not the `x.py setup` message.
let suggest_setup = config.config.is_none() && !matches!(config.cmd, Subcommand::Setup { .. });
if suggest_setup {
println!("WARNING: you have not made a `config.toml`");
println!(
eprintln!("WARNING: you have not made a `config.toml`");
eprintln!(
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{suggestion}");
eprintln!("{suggestion}");
}

let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
Expand All @@ -86,13 +86,13 @@ fn main() {
Build::new(config).build();

if suggest_setup {
println!("WARNING: you have not made a `config.toml`");
println!(
eprintln!("WARNING: you have not made a `config.toml`");
eprintln!(
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{suggestion}");
eprintln!("{suggestion}");
}

// Give a warning if the pre-commit script is in pre-commit and not pre-push.
Expand All @@ -102,14 +102,14 @@ fn main() {
if fs::read_to_string(pre_commit).is_ok_and(|contents| {
contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
}) {
println!(
eprintln!(
"WARNING: You have the pre-push script installed to .git/hooks/pre-commit. \
Consider moving it to .git/hooks/pre-push instead, which runs less often."
);
}

if suggest_setup || changelog_suggestion.is_some() {
println!("NOTE: this message was printed twice to make it more likely to be seen");
eprintln!("NOTE: this message was printed twice to make it more likely to be seen");
}

if dump_bootstrap_shims {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn main() {
// should run on success, after this block.
}
if verbose > 0 {
println!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
eprintln!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
}

if let Some(mut on_fail) = on_fail {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Step for CodegenBackend {
fn run(self, builder: &Builder<'_>) {
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
if builder.build.config.vendor && self.backend == "gcc" {
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
eprintln!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ impl Step for Sysroot {
let sysroot = sysroot_dir(compiler.stage);

builder
.verbose(|| println!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
.verbose(|| eprintln!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
let _ = fs::remove_dir_all(&sysroot);
t!(fs::create_dir_all(&sysroot));

Expand Down Expand Up @@ -1681,7 +1681,7 @@ impl Step for Sysroot {
return true;
}
if !filtered_files.iter().all(|f| f != path.file_name().unwrap()) {
builder.verbose_than(1, || println!("ignoring {}", path.display()));
builder.verbose_than(1, || eprintln!("ignoring {}", path.display()));
false
} else {
true
Expand Down Expand Up @@ -2240,7 +2240,7 @@ pub fn stream_cargo(
cargo.arg(arg);
}

builder.verbose(|| println!("running: {cargo:?}"));
builder.verbose(|| eprintln!("running: {cargo:?}"));

if builder.config.dry_run() {
return true;
Expand All @@ -2261,12 +2261,12 @@ pub fn stream_cargo(
Ok(msg) => {
if builder.config.json_output {
// Forward JSON to stdout.
println!("{line}");
eprintln!("{line}");
}
cb(msg)
}
// If this was informational, just print it out and continue
Err(_) => println!("{line}"),
Err(_) => eprintln!("{line}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ fn maybe_install_llvm(
{
let mut cmd = command(llvm_config);
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
builder.verbose(|| eprintln!("running {cmd:?}"));
let files = cmd.run_capture_stdout(builder).stdout();
let build_llvm_out = &builder.llvm_out(builder.config.build);
let target_llvm_out = &builder.llvm_out(target);
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
if let Some(adjective) = adjective { format!("{adjective} ") } else { String::new() };
if len <= 10 {
for path in paths {
println!("fmt: {verb} {adjective}file {path}");
eprintln!("fmt: {verb} {adjective}file {path}");
}
} else {
println!("fmt: {verb} {len} {adjective}files");
eprintln!("fmt: {verb} {len} {adjective}files");
}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
match get_modified_rs_files(build) {
Ok(Some(files)) => {
if files.is_empty() {
println!("fmt info: No modified files detected for formatting.");
eprintln!("fmt info: No modified files detected for formatting.");
return;
}

Expand Down
Loading
Loading