Skip to content

Commit 0156670

Browse files
committed
Auto merge of rust-lang#124142 - workingjubilee:rollup-srpepgj, r=workingjubilee
Rollup of 9 pull requests Successful merges: - rust-lang#117919 (Introduce perma-unstable `wasm-c-abi` flag) - rust-lang#123406 (Force exhaustion in iter::ArrayChunks::into_remainder) - rust-lang#123752 (Properly handle emojis as literal prefix in macros) - rust-lang#123935 (Don't inline integer literals when they overflow - new attempt) - rust-lang#123980 ( Add an opt-in to store incoming edges in `VecGraph` + misc) - rust-lang#124019 (Use raw-dylib for Windows synchronization functions) - rust-lang#124110 (Fix negating `f16` and `f128` constants) - rust-lang#124112 (Fix ICE when there is a non-Unicode entry in the incremental crate directory) - rust-lang#124116 (when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e3181b0 + ea1b92d commit 0156670

File tree

65 files changed

+751
-218
lines changed

Some content is hidden

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

65 files changed

+751
-218
lines changed

compiler/rustc_ast_lowering/src/format.rs

+117-77
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,126 @@ impl<'hir> LoweringContext<'_, 'hir> {
2020
let mut fmt = Cow::Borrowed(fmt);
2121
if self.tcx.sess.opts.unstable_opts.flatten_format_args {
2222
fmt = flatten_format_args(fmt);
23-
fmt = inline_literals(fmt);
23+
fmt = self.inline_literals(fmt);
2424
}
2525
expand_format_args(self, sp, &fmt, allow_const)
2626
}
27+
28+
/// Try to convert a literal into an interned string
29+
fn try_inline_lit(&self, lit: token::Lit) -> Option<Symbol> {
30+
match LitKind::from_token_lit(lit) {
31+
Ok(LitKind::Str(s, _)) => Some(s),
32+
Ok(LitKind::Int(n, ty)) => {
33+
match ty {
34+
// unsuffixed integer literals are assumed to be i32's
35+
LitIntType::Unsuffixed => {
36+
(n <= i32::MAX as u128).then_some(Symbol::intern(&n.to_string()))
37+
}
38+
LitIntType::Signed(int_ty) => {
39+
let max_literal = self.int_ty_max(int_ty);
40+
(n <= max_literal).then_some(Symbol::intern(&n.to_string()))
41+
}
42+
LitIntType::Unsigned(uint_ty) => {
43+
let max_literal = self.uint_ty_max(uint_ty);
44+
(n <= max_literal).then_some(Symbol::intern(&n.to_string()))
45+
}
46+
}
47+
}
48+
_ => None,
49+
}
50+
}
51+
52+
/// Get the maximum value of int_ty. It is platform-dependent due to the byte size of isize
53+
fn int_ty_max(&self, int_ty: IntTy) -> u128 {
54+
match int_ty {
55+
IntTy::Isize => self.tcx.data_layout.pointer_size.signed_int_max() as u128,
56+
IntTy::I8 => i8::MAX as u128,
57+
IntTy::I16 => i16::MAX as u128,
58+
IntTy::I32 => i32::MAX as u128,
59+
IntTy::I64 => i64::MAX as u128,
60+
IntTy::I128 => i128::MAX as u128,
61+
}
62+
}
63+
64+
/// Get the maximum value of uint_ty. It is platform-dependent due to the byte size of usize
65+
fn uint_ty_max(&self, uint_ty: UintTy) -> u128 {
66+
match uint_ty {
67+
UintTy::Usize => self.tcx.data_layout.pointer_size.unsigned_int_max(),
68+
UintTy::U8 => u8::MAX as u128,
69+
UintTy::U16 => u16::MAX as u128,
70+
UintTy::U32 => u32::MAX as u128,
71+
UintTy::U64 => u64::MAX as u128,
72+
UintTy::U128 => u128::MAX as u128,
73+
}
74+
}
75+
76+
/// Inline literals into the format string.
77+
///
78+
/// Turns
79+
///
80+
/// `format_args!("Hello, {}! {} {}", "World", 123, x)`
81+
///
82+
/// into
83+
///
84+
/// `format_args!("Hello, World! 123 {}", x)`.
85+
fn inline_literals<'fmt>(&self, mut fmt: Cow<'fmt, FormatArgs>) -> Cow<'fmt, FormatArgs> {
86+
let mut was_inlined = vec![false; fmt.arguments.all_args().len()];
87+
let mut inlined_anything = false;
88+
89+
for i in 0..fmt.template.len() {
90+
let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue };
91+
let Ok(arg_index) = placeholder.argument.index else { continue };
92+
93+
let mut literal = None;
94+
95+
if let FormatTrait::Display = placeholder.format_trait
96+
&& placeholder.format_options == Default::default()
97+
&& let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs()
98+
&& let ExprKind::Lit(lit) = arg.kind
99+
{
100+
literal = self.try_inline_lit(lit);
101+
}
102+
103+
if let Some(literal) = literal {
104+
// Now we need to mutate the outer FormatArgs.
105+
// If this is the first time, this clones the outer FormatArgs.
106+
let fmt = fmt.to_mut();
107+
// Replace the placeholder with the literal.
108+
fmt.template[i] = FormatArgsPiece::Literal(literal);
109+
was_inlined[arg_index] = true;
110+
inlined_anything = true;
111+
}
112+
}
113+
114+
// Remove the arguments that were inlined.
115+
if inlined_anything {
116+
let fmt = fmt.to_mut();
117+
118+
let mut remove = was_inlined;
119+
120+
// Don't remove anything that's still used.
121+
for_all_argument_indexes(&mut fmt.template, |index| remove[*index] = false);
122+
123+
// Drop all the arguments that are marked for removal.
124+
let mut remove_it = remove.iter();
125+
fmt.arguments.all_args_mut().retain(|_| remove_it.next() != Some(&true));
126+
127+
// Calculate the mapping of old to new indexes for the remaining arguments.
128+
let index_map: Vec<usize> = remove
129+
.into_iter()
130+
.scan(0, |i, remove| {
131+
let mapped = *i;
132+
*i += !remove as usize;
133+
Some(mapped)
134+
})
135+
.collect();
136+
137+
// Correct the indexes that refer to arguments that have shifted position.
138+
for_all_argument_indexes(&mut fmt.template, |index| *index = index_map[*index]);
139+
}
140+
141+
fmt
142+
}
27143
}
28144

29145
/// Flattens nested `format_args!()` into one.
@@ -103,82 +219,6 @@ fn flatten_format_args(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
103219
fmt
104220
}
105221

106-
/// Inline literals into the format string.
107-
///
108-
/// Turns
109-
///
110-
/// `format_args!("Hello, {}! {} {}", "World", 123, x)`
111-
///
112-
/// into
113-
///
114-
/// `format_args!("Hello, World! 123 {}", x)`.
115-
fn inline_literals(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
116-
let mut was_inlined = vec![false; fmt.arguments.all_args().len()];
117-
let mut inlined_anything = false;
118-
119-
for i in 0..fmt.template.len() {
120-
let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue };
121-
let Ok(arg_index) = placeholder.argument.index else { continue };
122-
123-
let mut literal = None;
124-
125-
if let FormatTrait::Display = placeholder.format_trait
126-
&& placeholder.format_options == Default::default()
127-
&& let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs()
128-
&& let ExprKind::Lit(lit) = arg.kind
129-
{
130-
if let token::LitKind::Str | token::LitKind::StrRaw(_) = lit.kind
131-
&& let Ok(LitKind::Str(s, _)) = LitKind::from_token_lit(lit)
132-
{
133-
literal = Some(s);
134-
} else if let token::LitKind::Integer = lit.kind
135-
&& let Ok(LitKind::Int(n, _)) = LitKind::from_token_lit(lit)
136-
{
137-
literal = Some(Symbol::intern(&n.to_string()));
138-
}
139-
}
140-
141-
if let Some(literal) = literal {
142-
// Now we need to mutate the outer FormatArgs.
143-
// If this is the first time, this clones the outer FormatArgs.
144-
let fmt = fmt.to_mut();
145-
// Replace the placeholder with the literal.
146-
fmt.template[i] = FormatArgsPiece::Literal(literal);
147-
was_inlined[arg_index] = true;
148-
inlined_anything = true;
149-
}
150-
}
151-
152-
// Remove the arguments that were inlined.
153-
if inlined_anything {
154-
let fmt = fmt.to_mut();
155-
156-
let mut remove = was_inlined;
157-
158-
// Don't remove anything that's still used.
159-
for_all_argument_indexes(&mut fmt.template, |index| remove[*index] = false);
160-
161-
// Drop all the arguments that are marked for removal.
162-
let mut remove_it = remove.iter();
163-
fmt.arguments.all_args_mut().retain(|_| remove_it.next() != Some(&true));
164-
165-
// Calculate the mapping of old to new indexes for the remaining arguments.
166-
let index_map: Vec<usize> = remove
167-
.into_iter()
168-
.scan(0, |i, remove| {
169-
let mapped = *i;
170-
*i += !remove as usize;
171-
Some(mapped)
172-
})
173-
.collect();
174-
175-
// Correct the indexes that refer to arguments that have shifted position.
176-
for_all_argument_indexes(&mut fmt.template, |index| *index = index_map[*index]);
177-
}
178-
179-
fmt
180-
}
181-
182222
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
183223
enum ArgumentType {
184224
Format(FormatTrait),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 0d741cf82c3c908616abd39dc84ebf7d8702e0c3 Mon Sep 17 00:00:00 2001
2+
From: Chris Denton <[email protected]>
3+
Date: Tue, 16 Apr 2024 15:51:34 +0000
4+
Subject: [PATCH] Revert use raw-dylib for Windows futex APIs
5+
6+
---
7+
library/std/src/sys/pal/windows/c.rs | 14 +-------------
8+
1 file changed, 1 insertion(+), 13 deletions(-)
9+
10+
diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs
11+
index 9d58ce05f01..1c828bac4b6 100644
12+
--- a/library/std/src/sys/pal/windows/c.rs
13+
+++ b/library/std/src/sys/pal/windows/c.rs
14+
@@ -357,19 +357,7 @@ pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 {
15+
}
16+
17+
#[cfg(not(target_vendor = "win7"))]
18+
-// Use raw-dylib to import synchronization functions to workaround issues with the older mingw import library.
19+
-#[cfg_attr(
20+
- target_arch = "x86",
21+
- link(
22+
- name = "api-ms-win-core-synch-l1-2-0",
23+
- kind = "raw-dylib",
24+
- import_name_type = "undecorated"
25+
- )
26+
-)]
27+
-#[cfg_attr(
28+
- not(target_arch = "x86"),
29+
- link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib")
30+
-)]
31+
+#[link(name = "synchronization")]
32+
extern "system" {
33+
pub fn WaitOnAddress(
34+
address: *const c_void,
35+
--
36+
2.42.0.windows.2
37+

compiler/rustc_codegen_gcc/src/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_span::Span;
3131
use rustc_target::abi::{
3232
self, call::FnAbi, Align, HasDataLayout, Size, TargetDataLayout, WrappingRange,
3333
};
34-
use rustc_target::spec::{HasTargetSpec, Target};
34+
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, Target, WasmCAbi};
3535

3636
use crate::common::{type_is_pointer, SignType, TypeReflection};
3737
use crate::context::CodegenCx;
@@ -2352,6 +2352,12 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23522352
}
23532353
}
23542354

2355+
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2356+
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2357+
self.cx.wasm_c_abi_opt()
2358+
}
2359+
}
2360+
23552361
pub trait ToGccComp {
23562362
fn to_gcc_comparison(&self) -> ComparisonOp;
23572363
}

compiler/rustc_codegen_gcc/src/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_span::{source_map::respan, Span};
2020
use rustc_target::abi::{
2121
call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx,
2222
};
23-
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
23+
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, Target, TlsModel, WasmCAbi};
2424

2525
use crate::callee::get_fn;
2626
use crate::common::SignType;
@@ -557,6 +557,12 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
557557
}
558558
}
559559

560+
impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
561+
fn wasm_c_abi_opt(&self) -> WasmCAbi {
562+
self.tcx.sess.opts.unstable_opts.wasm_c_abi
563+
}
564+
}
565+
560566
impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
561567
type LayoutOfResult = TyAndLayout<'tcx>;
562568

compiler/rustc_data_structures/src/graph/iterate/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ pub fn reverse_post_order<G: DirectedGraph + Successors>(
7070
}
7171

7272
/// A "depth-first search" iterator for a directed graph.
73-
pub struct DepthFirstSearch<'graph, G>
73+
pub struct DepthFirstSearch<G>
7474
where
75-
G: ?Sized + DirectedGraph + Successors,
75+
G: DirectedGraph + Successors,
7676
{
77-
graph: &'graph G,
77+
graph: G,
7878
stack: Vec<G::Node>,
7979
visited: BitSet<G::Node>,
8080
}
8181

82-
impl<'graph, G> DepthFirstSearch<'graph, G>
82+
impl<G> DepthFirstSearch<G>
8383
where
84-
G: ?Sized + DirectedGraph + Successors,
84+
G: DirectedGraph + Successors,
8585
{
86-
pub fn new(graph: &'graph G) -> Self {
87-
Self { graph, stack: vec![], visited: BitSet::new_empty(graph.num_nodes()) }
86+
pub fn new(graph: G) -> Self {
87+
Self { stack: vec![], visited: BitSet::new_empty(graph.num_nodes()), graph }
8888
}
8989

9090
/// Version of `push_start_node` that is convenient for chained
@@ -125,9 +125,9 @@ where
125125
}
126126
}
127127

128-
impl<G> std::fmt::Debug for DepthFirstSearch<'_, G>
128+
impl<G> std::fmt::Debug for DepthFirstSearch<G>
129129
where
130-
G: ?Sized + DirectedGraph + Successors,
130+
G: DirectedGraph + Successors,
131131
{
132132
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
133133
let mut f = fmt.debug_set();
@@ -138,9 +138,9 @@ where
138138
}
139139
}
140140

141-
impl<G> Iterator for DepthFirstSearch<'_, G>
141+
impl<G> Iterator for DepthFirstSearch<G>
142142
where
143-
G: ?Sized + DirectedGraph + Successors,
143+
G: DirectedGraph + Successors,
144144
{
145145
type Item = G::Node;
146146

compiler/rustc_data_structures/src/graph/mod.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,35 @@ where
4646
.is_some()
4747
}
4848

49-
pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G>
49+
pub fn depth_first_search<G>(graph: G, from: G::Node) -> iterate::DepthFirstSearch<G>
5050
where
51-
G: ?Sized + Successors,
51+
G: Successors,
5252
{
5353
iterate::DepthFirstSearch::new(graph).with_start_node(from)
5454
}
55+
56+
pub fn depth_first_search_as_undirected<G>(
57+
graph: G,
58+
from: G::Node,
59+
) -> iterate::DepthFirstSearch<impl Successors<Node = G::Node>>
60+
where
61+
G: Successors + Predecessors,
62+
{
63+
struct AsUndirected<G>(G);
64+
65+
impl<G: DirectedGraph> DirectedGraph for AsUndirected<G> {
66+
type Node = G::Node;
67+
68+
fn num_nodes(&self) -> usize {
69+
self.0.num_nodes()
70+
}
71+
}
72+
73+
impl<G: Successors + Predecessors> Successors for AsUndirected<G> {
74+
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
75+
self.0.successors(node).chain(self.0.predecessors(node))
76+
}
77+
}
78+
79+
iterate::DepthFirstSearch::new(AsUndirected(graph)).with_start_node(from)
80+
}

0 commit comments

Comments
 (0)