Skip to content

Commit de7ab3d

Browse files
committed
Auto merge of rust-lang#138803 - matthiaskrgr:rollup-qtvr8ov, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#136769 (Provide optional `Read`/`Write` methods for stdio) - rust-lang#138410 (Couple mir building cleanups) - rust-lang#138490 (Forward `stream_position` in `Arc<File>` as well) - rust-lang#138535 (Cleanup `LangString::parse`) - rust-lang#138536 (stable_mir: Add `MutMirVisitor`) - rust-lang#138673 (Fix build failure on Trusty) - rust-lang#138750 (Make `crate_hash` not iterate over `hir_crate` owners anymore) - rust-lang#138763 (jsondocck: Replace `jsonpath_lib` with `jsonpath-rust`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 48b36c9 + 66d2e2a commit de7ab3d

File tree

172 files changed

+1984
-1772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1984
-1772
lines changed

Cargo.lock

+59-7
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ version = "0.1.0"
19251925
dependencies = [
19261926
"fs-err",
19271927
"getopts",
1928-
"jsonpath_lib",
1928+
"jsonpath-rust",
19291929
"regex",
19301930
"serde_json",
19311931
"shlex",
@@ -1945,14 +1945,16 @@ dependencies = [
19451945
]
19461946

19471947
[[package]]
1948-
name = "jsonpath_lib"
1949-
version = "0.3.0"
1948+
name = "jsonpath-rust"
1949+
version = "1.0.0"
19501950
source = "registry+https://github.com/rust-lang/crates.io-index"
1951-
checksum = "eaa63191d68230cccb81c5aa23abd53ed64d83337cacbb25a7b8c7979523774f"
1951+
checksum = "9b0231bb404a6cd6c8f0ab41b907049063a089fc02aa7636cc5cd9a4d87364c9"
19521952
dependencies = [
1953-
"log",
1954-
"serde",
1953+
"pest",
1954+
"pest_derive",
1955+
"regex",
19551956
"serde_json",
1957+
"thiserror 2.0.11",
19561958
]
19571959

19581960
[[package]]
@@ -2645,6 +2647,51 @@ dependencies = [
26452647
"libc",
26462648
]
26472649

2650+
[[package]]
2651+
name = "pest"
2652+
version = "2.7.15"
2653+
source = "registry+https://github.com/rust-lang/crates.io-index"
2654+
checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc"
2655+
dependencies = [
2656+
"memchr",
2657+
"thiserror 2.0.11",
2658+
"ucd-trie",
2659+
]
2660+
2661+
[[package]]
2662+
name = "pest_derive"
2663+
version = "2.7.15"
2664+
source = "registry+https://github.com/rust-lang/crates.io-index"
2665+
checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e"
2666+
dependencies = [
2667+
"pest",
2668+
"pest_generator",
2669+
]
2670+
2671+
[[package]]
2672+
name = "pest_generator"
2673+
version = "2.7.15"
2674+
source = "registry+https://github.com/rust-lang/crates.io-index"
2675+
checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b"
2676+
dependencies = [
2677+
"pest",
2678+
"pest_meta",
2679+
"proc-macro2",
2680+
"quote",
2681+
"syn 2.0.96",
2682+
]
2683+
2684+
[[package]]
2685+
name = "pest_meta"
2686+
version = "2.7.15"
2687+
source = "registry+https://github.com/rust-lang/crates.io-index"
2688+
checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea"
2689+
dependencies = [
2690+
"once_cell",
2691+
"pest",
2692+
"sha2",
2693+
]
2694+
26482695
[[package]]
26492696
name = "phf"
26502697
version = "0.11.3"
@@ -4780,7 +4827,6 @@ version = "1.0.135"
47804827
source = "registry+https://github.com/rust-lang/crates.io-index"
47814828
checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9"
47824829
dependencies = [
4783-
"indexmap",
47844830
"itoa",
47854831
"memchr",
47864832
"ryu",
@@ -5486,6 +5532,12 @@ dependencies = [
54865532
"regex-lite",
54875533
]
54885534

5535+
[[package]]
5536+
name = "ucd-trie"
5537+
version = "0.1.7"
5538+
source = "registry+https://github.com/rust-lang/crates.io-index"
5539+
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
5540+
54895541
[[package]]
54905542
name = "ui_test"
54915543
version = "0.28.0"

compiler/rustc_middle/src/hir/map.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1176,15 +1176,14 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
11761176
debugger_visualizers.hash_stable(&mut hcx, &mut stable_hasher);
11771177
if tcx.sess.opts.incremental.is_some() {
11781178
let definitions = tcx.untracked().definitions.freeze();
1179-
let mut owner_spans: Vec<_> = krate
1180-
.owners
1181-
.iter_enumerated()
1182-
.filter_map(|(def_id, info)| {
1183-
let _ = info.as_owner()?;
1179+
let mut owner_spans: Vec<_> = tcx
1180+
.hir_crate_items(())
1181+
.definitions()
1182+
.map(|def_id| {
11841183
let def_path_hash = definitions.def_path_hash(def_id);
11851184
let span = tcx.source_span(def_id);
11861185
debug_assert_eq!(span.parent(), None);
1187-
Some((def_path_hash, span))
1186+
(def_path_hash, span)
11881187
})
11891188
.collect();
11901189
owner_spans.sort_unstable_by_key(|bn| bn.0);

compiler/rustc_mir_build/src/builder/expr/as_constant.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,19 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
105105
return Const::Ty(Ty::new_error(tcx, guar), ty::Const::new_error(tcx, guar));
106106
}
107107

108-
let trunc = |n, width: ty::UintTy| {
109-
let width = width
110-
.normalize(tcx.data_layout.pointer_size.bits().try_into().unwrap())
111-
.bit_width()
112-
.unwrap();
113-
let width = Size::from_bits(width);
108+
let lit_ty = match *ty.kind() {
109+
ty::Pat(base, _) => base,
110+
_ => ty,
111+
};
112+
113+
let trunc = |n| {
114+
let width = lit_ty.primitive_size(tcx);
114115
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
115116
let result = width.truncate(n);
116117
trace!("trunc result: {}", result);
117118
ConstValue::Scalar(Scalar::from_uint(result, width))
118119
};
119120

120-
let lit_ty = match *ty.kind() {
121-
ty::Pat(base, _) => base,
122-
_ => ty,
123-
};
124-
125121
let value = match (lit, lit_ty.kind()) {
126122
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
127123
let s = s.as_str();
@@ -149,11 +145,10 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
149145
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {
150146
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
151147
}
152-
(ast::LitKind::Int(n, _), ty::Uint(ui)) if !neg => trunc(n.get(), *ui),
153-
(ast::LitKind::Int(n, _), ty::Int(i)) => trunc(
154-
if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() },
155-
i.to_unsigned(),
156-
),
148+
(ast::LitKind::Int(n, _), ty::Uint(_)) if !neg => trunc(n.get()),
149+
(ast::LitKind::Int(n, _), ty::Int(_)) => {
150+
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() })
151+
}
157152
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
158153
parse_float_into_constval(*n, *fty, neg).unwrap()
159154
}

compiler/rustc_mir_build/src/builder/scope.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -305,27 +305,25 @@ impl DropTree {
305305
}
306306

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

319-
self.assign_blocks::<T>(cfg, blocks);
320-
self.link_blocks(cfg, blocks)
315+
let mut blocks = self.assign_blocks::<T>(cfg, root_node);
316+
self.link_blocks(cfg, &mut blocks);
317+
318+
blocks
321319
}
322320

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

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

386387
debug!("assign_blocks: blocks = {:#?}", blocks);
387388
assert!(entry_points.is_empty());
389+
390+
blocks
388391
}
389392

390393
fn link_blocks<'tcx>(
@@ -1574,10 +1577,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
15741577
span: Span,
15751578
continue_block: Option<BasicBlock>,
15761579
) -> Option<BlockAnd<()>> {
1577-
let mut blocks = IndexVec::from_elem(None, &drops.drops);
1578-
blocks[ROOT_NODE] = continue_block;
1579-
1580-
drops.build_mir::<ExitScopes>(&mut self.cfg, &mut blocks);
1580+
let blocks = drops.build_mir::<ExitScopes>(&mut self.cfg, continue_block);
15811581
let is_coroutine = self.coroutine.is_some();
15821582

15831583
// Link the exit drop tree to unwind drop tree.
@@ -1633,8 +1633,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
16331633
let drops = &mut self.scopes.coroutine_drops;
16341634
let cfg = &mut self.cfg;
16351635
let fn_span = self.fn_span;
1636-
let mut blocks = IndexVec::from_elem(None, &drops.drops);
1637-
drops.build_mir::<CoroutineDrop>(cfg, &mut blocks);
1636+
let blocks = drops.build_mir::<CoroutineDrop>(cfg, None);
16381637
if let Some(root_block) = blocks[ROOT_NODE] {
16391638
cfg.terminate(
16401639
root_block,
@@ -1670,9 +1669,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
16701669
fn_span: Span,
16711670
resume_block: &mut Option<BasicBlock>,
16721671
) {
1673-
let mut blocks = IndexVec::from_elem(None, &drops.drops);
1674-
blocks[ROOT_NODE] = *resume_block;
1675-
drops.build_mir::<Unwind>(cfg, &mut blocks);
1672+
let blocks = drops.build_mir::<Unwind>(cfg, *resume_block);
16761673
if let (None, Some(resume)) = (*resume_block, blocks[ROOT_NODE]) {
16771674
cfg.terminate(resume, SourceInfo::outermost(fn_span), TerminatorKind::UnwindResume);
16781675

compiler/stable_mir/src/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ pub mod pretty;
55
pub mod visit;
66

77
pub use body::*;
8-
pub use visit::MirVisitor;
8+
pub use visit::{MirVisitor, MutMirVisitor};

compiler/stable_mir/src/mir/body.rs

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ impl Body {
7777
&self.locals[self.arg_count + 1..]
7878
}
7979

80+
/// Returns a mutable reference to the local that holds this function's return value.
81+
pub(crate) fn ret_local_mut(&mut self) -> &mut LocalDecl {
82+
&mut self.locals[RETURN_LOCAL]
83+
}
84+
85+
/// Returns a mutable slice of locals corresponding to this function's arguments.
86+
pub(crate) fn arg_locals_mut(&mut self) -> &mut [LocalDecl] {
87+
&mut self.locals[1..][..self.arg_count]
88+
}
89+
90+
/// Returns a mutable slice of inner locals for this function.
91+
/// Inner locals are those that are neither the return local nor the argument locals.
92+
pub(crate) fn inner_locals_mut(&mut self) -> &mut [LocalDecl] {
93+
&mut self.locals[self.arg_count + 1..]
94+
}
95+
8096
/// Convenience function to get all the locals in this function.
8197
///
8298
/// Locals are typically accessed via the more specific methods `ret_local`,

0 commit comments

Comments
 (0)