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 7 pull requests #138830

Merged
merged 19 commits into from
Mar 22, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c58c06a
Return blocks from DropTree::build_mir
bjorn3 Mar 11, 2025
8dc0c0e
Simplify lit_to_mir_constant a bit
bjorn3 Mar 12, 2025
bdaf23b
Forward `stream_position` in `Arc<File>` as well
tbu- Mar 14, 2025
eca391f
Cleanup `LangString::parse`
yotamofek Mar 15, 2025
69a3ad0
Add `MutMirVisitor`
makai410 Mar 18, 2025
ad315f6
Add test for `MutMirVisitor`
makai410 Mar 18, 2025
68267d0
Fix build failure on Trusty
taiki-e Mar 18, 2025
485c14f
Make `crate_hash` not iterate over `hir_crate` owners anymore
oli-obk Mar 19, 2025
a0918b7
jsondocck: Replace `jsonpath_lib` with `jsonpath-rust`
aDotInTheVoid Mar 20, 2025
7ab71c4
tests/rustdoc-json: replace `$.index[*][?` with `$.index[?`
aDotInTheVoid Mar 20, 2025
42631d8
tests/rustdoc-json: replace `$.paths[*][?` with `$.paths[?`
aDotInTheVoid Mar 20, 2025
13335e3
tests/rustdoc-json: change assertions to use RFC 9535 jsonpath
aDotInTheVoid Mar 21, 2025
92acd14
Rollup merge of #138410 - bjorn3:misc_cleanups, r=compiler-errors
matthiaskrgr Mar 22, 2025
07c503c
Rollup merge of #138490 - tbu-:pr_arc_file_pos, r=Noratrieb
matthiaskrgr Mar 22, 2025
e832680
Rollup merge of #138535 - yotamofek:pr/rustdoc/lang-string-parse-clea…
matthiaskrgr Mar 22, 2025
1cb17dd
Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinval
matthiaskrgr Mar 22, 2025
14f6216
Rollup merge of #138673 - taiki-e:trusty-fix, r=Noratrieb
matthiaskrgr Mar 22, 2025
fb09bd5
Rollup merge of #138750 - oli-obk:decouple-hir-queries, r=fee1-dead
matthiaskrgr Mar 22, 2025
a4c0173
Rollup merge of #138763 - aDotInTheVoid:two-years-later, r=GuillaumeG…
matthiaskrgr Mar 22, 2025
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
66 changes: 59 additions & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -1925,7 +1925,7 @@ version = "0.1.0"
dependencies = [
"fs-err",
"getopts",
"jsonpath_lib",
"jsonpath-rust",
"regex",
"serde_json",
"shlex",
@@ -1945,14 +1945,16 @@ dependencies = [
]

[[package]]
name = "jsonpath_lib"
version = "0.3.0"
name = "jsonpath-rust"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaa63191d68230cccb81c5aa23abd53ed64d83337cacbb25a7b8c7979523774f"
checksum = "9b0231bb404a6cd6c8f0ab41b907049063a089fc02aa7636cc5cd9a4d87364c9"
dependencies = [
"log",
"serde",
"pest",
"pest_derive",
"regex",
"serde_json",
"thiserror 2.0.11",
]

[[package]]
@@ -2645,6 +2647,51 @@ dependencies = [
"libc",
]

[[package]]
name = "pest"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc"
dependencies = [
"memchr",
"thiserror 2.0.11",
"ucd-trie",
]

[[package]]
name = "pest_derive"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e"
dependencies = [
"pest",
"pest_generator",
]

[[package]]
name = "pest_generator"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.96",
]

[[package]]
name = "pest_meta"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea"
dependencies = [
"once_cell",
"pest",
"sha2",
]

[[package]]
name = "phf"
version = "0.11.3"
@@ -4780,7 +4827,6 @@ version = "1.0.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9"
dependencies = [
"indexmap",
"itoa",
"memchr",
"ryu",
@@ -5486,6 +5532,12 @@ dependencies = [
"regex-lite",
]

[[package]]
name = "ucd-trie"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"

[[package]]
name = "ui_test"
version = "0.28.0"
11 changes: 5 additions & 6 deletions compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
@@ -1176,15 +1176,14 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
debugger_visualizers.hash_stable(&mut hcx, &mut stable_hasher);
if tcx.sess.opts.incremental.is_some() {
let definitions = tcx.untracked().definitions.freeze();
let mut owner_spans: Vec<_> = krate
.owners
.iter_enumerated()
.filter_map(|(def_id, info)| {
let _ = info.as_owner()?;
let mut owner_spans: Vec<_> = tcx
.hir_crate_items(())
.definitions()
.map(|def_id| {
let def_path_hash = definitions.def_path_hash(def_id);
let span = tcx.source_span(def_id);
debug_assert_eq!(span.parent(), None);
Some((def_path_hash, span))
(def_path_hash, span)
})
.collect();
owner_spans.sort_unstable_by_key(|bn| bn.0);
27 changes: 11 additions & 16 deletions compiler/rustc_mir_build/src/builder/expr/as_constant.rs
Original file line number Diff line number Diff line change
@@ -105,23 +105,19 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
return Const::Ty(Ty::new_error(tcx, guar), ty::Const::new_error(tcx, guar));
}

let trunc = |n, width: ty::UintTy| {
let width = width
.normalize(tcx.data_layout.pointer_size.bits().try_into().unwrap())
.bit_width()
.unwrap();
let width = Size::from_bits(width);
let lit_ty = match *ty.kind() {
ty::Pat(base, _) => base,
_ => ty,
};

let trunc = |n| {
let width = lit_ty.primitive_size(tcx);
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
let result = width.truncate(n);
trace!("trunc result: {}", result);
ConstValue::Scalar(Scalar::from_uint(result, width))
};

let lit_ty = match *ty.kind() {
ty::Pat(base, _) => base,
_ => ty,
};

let value = match (lit, lit_ty.kind()) {
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
let s = s.as_str();
@@ -149,11 +145,10 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
}
(ast::LitKind::Int(n, _), ty::Uint(ui)) if !neg => trunc(n.get(), *ui),
(ast::LitKind::Int(n, _), ty::Int(i)) => trunc(
if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() },
i.to_unsigned(),
),
(ast::LitKind::Int(n, _), ty::Uint(_)) if !neg => trunc(n.get()),
(ast::LitKind::Int(n, _), ty::Int(_)) => {
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() })
}
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
parse_float_into_constval(*n, *fty, neg).unwrap()
}
37 changes: 17 additions & 20 deletions compiler/rustc_mir_build/src/builder/scope.rs
Original file line number Diff line number Diff line change
@@ -305,27 +305,25 @@ impl DropTree {
}

/// Builds the MIR for a given drop tree.
///
/// `blocks` should have the same length as `self.drops`, and may have its
/// first value set to some already existing block.
fn build_mir<'tcx, T: DropTreeBuilder<'tcx>>(
&mut self,
cfg: &mut CFG<'tcx>,
blocks: &mut IndexVec<DropIdx, Option<BasicBlock>>,
) {
root_node: Option<BasicBlock>,
) -> IndexVec<DropIdx, Option<BasicBlock>> {
debug!("DropTree::build_mir(drops = {:#?})", self);
assert_eq!(blocks.len(), self.drops.len());

self.assign_blocks::<T>(cfg, blocks);
self.link_blocks(cfg, blocks)
let mut blocks = self.assign_blocks::<T>(cfg, root_node);
self.link_blocks(cfg, &mut blocks);

blocks
}

/// Assign blocks for all of the drops in the drop tree that need them.
fn assign_blocks<'tcx, T: DropTreeBuilder<'tcx>>(
&mut self,
cfg: &mut CFG<'tcx>,
blocks: &mut IndexVec<DropIdx, Option<BasicBlock>>,
) {
root_node: Option<BasicBlock>,
) -> IndexVec<DropIdx, Option<BasicBlock>> {
// StorageDead statements can share blocks with each other and also with
// a Drop terminator. We iterate through the drops to find which drops
// need their own block.
@@ -342,8 +340,11 @@ impl DropTree {
Own,
}

let mut blocks = IndexVec::from_elem(None, &self.drops);
blocks[ROOT_NODE] = root_node;

let mut needs_block = IndexVec::from_elem(Block::None, &self.drops);
if blocks[ROOT_NODE].is_some() {
if root_node.is_some() {
// In some cases (such as drops for `continue`) the root node
// already has a block. In this case, make sure that we don't
// override it.
@@ -385,6 +386,8 @@ impl DropTree {

debug!("assign_blocks: blocks = {:#?}", blocks);
assert!(entry_points.is_empty());

blocks
}

fn link_blocks<'tcx>(
@@ -1574,10 +1577,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
span: Span,
continue_block: Option<BasicBlock>,
) -> Option<BlockAnd<()>> {
let mut blocks = IndexVec::from_elem(None, &drops.drops);
blocks[ROOT_NODE] = continue_block;

drops.build_mir::<ExitScopes>(&mut self.cfg, &mut blocks);
let blocks = drops.build_mir::<ExitScopes>(&mut self.cfg, continue_block);
let is_coroutine = self.coroutine.is_some();

// Link the exit drop tree to unwind drop tree.
@@ -1633,8 +1633,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
let drops = &mut self.scopes.coroutine_drops;
let cfg = &mut self.cfg;
let fn_span = self.fn_span;
let mut blocks = IndexVec::from_elem(None, &drops.drops);
drops.build_mir::<CoroutineDrop>(cfg, &mut blocks);
let blocks = drops.build_mir::<CoroutineDrop>(cfg, None);
if let Some(root_block) = blocks[ROOT_NODE] {
cfg.terminate(
root_block,
@@ -1670,9 +1669,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
fn_span: Span,
resume_block: &mut Option<BasicBlock>,
) {
let mut blocks = IndexVec::from_elem(None, &drops.drops);
blocks[ROOT_NODE] = *resume_block;
drops.build_mir::<Unwind>(cfg, &mut blocks);
let blocks = drops.build_mir::<Unwind>(cfg, *resume_block);
if let (None, Some(resume)) = (*resume_block, blocks[ROOT_NODE]) {
cfg.terminate(resume, SourceInfo::outermost(fn_span), TerminatorKind::UnwindResume);

2 changes: 1 addition & 1 deletion compiler/stable_mir/src/mir.rs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@ pub mod pretty;
pub mod visit;

pub use body::*;
pub use visit::MirVisitor;
pub use visit::{MirVisitor, MutMirVisitor};
16 changes: 16 additions & 0 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
@@ -77,6 +77,22 @@ impl Body {
&self.locals[self.arg_count + 1..]
}

/// Returns a mutable reference to the local that holds this function's return value.
pub(crate) fn ret_local_mut(&mut self) -> &mut LocalDecl {
&mut self.locals[RETURN_LOCAL]
}

/// Returns a mutable slice of locals corresponding to this function's arguments.
pub(crate) fn arg_locals_mut(&mut self) -> &mut [LocalDecl] {
&mut self.locals[1..][..self.arg_count]
}

/// Returns a mutable slice of inner locals for this function.
/// Inner locals are those that are neither the return local nor the argument locals.
pub(crate) fn inner_locals_mut(&mut self) -> &mut [LocalDecl] {
&mut self.locals[self.arg_count + 1..]
}

/// Convenience function to get all the locals in this function.
///
/// Locals are typically accessed via the more specific methods `ret_local`,
Loading
Loading