Skip to content

Commit 33df85e

Browse files
committed
Auto merge of #147745 - matthiaskrgr:rollup-b4kftk9, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang/rust#143191 (Stabilize `rwlock_downgrade` library feature) - rust-lang/rust#147444 (Allow printing a fully-qualified path in `def_path_str`) - rust-lang/rust#147527 (Update t-compiler beta nomination Zulip msg) - rust-lang/rust#147670 (some `ErrorGuaranteed` cleanups) - rust-lang/rust#147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes) - rust-lang/rust#147708 (const `mem::drop`) - rust-lang/rust#147710 (Fix ICE when using contracts on async functions) - rust-lang/rust#147716 (Fix some comments) - rust-lang/rust#147718 (miri: use allocator_shim_contents codegen helper) - rust-lang/rust#147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius) - rust-lang/rust#147742 (Revert unintentional whitespace changes to rustfmt-excluded file) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 44c9af8 + 4b92f68 commit 33df85e

File tree

6 files changed

+257
-263
lines changed

6 files changed

+257
-263
lines changed

src/bin/log/tracing_chrome.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,16 @@ where
523523
}
524524
},
525525
TraceStyle::Async => Some(
526-
span.scope()
527-
.from_root()
528-
.take(1)
529-
.next()
530-
.unwrap_or(span)
531-
.id()
532-
.into_u64()
526+
span.scope()
527+
.from_root()
528+
.take(1)
529+
.next()
530+
.unwrap_or(span)
531+
.id()
532+
.into_u64()
533533
.cast_signed() // the comment above explains the cast
534534
),
535-
}
535+
}
536536
}
537537

538538
fn enter_span(&self, span: SpanRef<S>, ts: f64, tid: usize, out: &Sender<Message>) {
@@ -567,11 +567,11 @@ where
567567
Some(thread_data) => (thread_data, false),
568568
None => {
569569
let tid = self.max_tid.fetch_add(1, Ordering::SeqCst);
570-
let out = self.out.lock().unwrap().clone();
570+
let out = self.out.lock().unwrap().clone();
571571
let start = TracingChromeInstant::setup_for_thread_and_start(tid);
572572
*thread_data = Some(ThreadData { tid, out, start });
573573
(thread_data.as_mut().unwrap(), true)
574-
}
574+
}
575575
};
576576

577577
start.with_elapsed_micros_subtracting_tracing(|ts| {
@@ -583,7 +583,7 @@ where
583583
let _ignored = out.send(Message::NewThread(*tid, name));
584584
}
585585
f(ts, *tid, out);
586-
});
586+
});
587587
});
588588
}
589589
}
@@ -605,15 +605,15 @@ where
605605
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
606606
if self.include_args {
607607
self.with_elapsed_micros_subtracting_tracing(|_, _, _| {
608-
let span = ctx.span(id).unwrap();
609-
let mut exts = span.extensions_mut();
608+
let span = ctx.span(id).unwrap();
609+
let mut exts = span.extensions_mut();
610610

611-
let args = exts.get_mut::<ArgsWrapper>();
611+
let args = exts.get_mut::<ArgsWrapper>();
612612

613-
if let Some(args) = args {
614-
let args = Arc::make_mut(&mut args.args);
615-
values.record(&mut JsonVisitor { object: args });
616-
}
613+
if let Some(args) = args {
614+
let args = Arc::make_mut(&mut args.args);
615+
values.record(&mut JsonVisitor { object: args });
616+
}
617617
});
618618
}
619619
}
@@ -636,16 +636,16 @@ where
636636

637637
fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
638638
self.with_elapsed_micros_subtracting_tracing(|ts, tid, out| {
639-
if self.include_args {
640-
let mut args = Object::new();
641-
attrs.record(&mut JsonVisitor { object: &mut args });
642-
ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper {
643-
args: Arc::new(args),
644-
});
645-
}
646-
if let TraceStyle::Threaded = self.trace_style {
647-
return;
648-
}
639+
if self.include_args {
640+
let mut args = Object::new();
641+
attrs.record(&mut JsonVisitor { object: &mut args });
642+
ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper {
643+
args: Arc::new(args),
644+
});
645+
}
646+
if let TraceStyle::Threaded = self.trace_style {
647+
return;
648+
}
649649

650650
self.enter_span(ctx.span(id).expect("Span not found."), ts, tid, out);
651651
});

src/intrinsics/simd.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,47 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3838
for i in 0..dest_len {
3939
let op = this.read_immediate(&this.project_index(&op, i)?)?;
4040
let dest = this.project_index(&dest, i)?;
41-
let ty::Float(float_ty) = op.layout.ty.kind() else {
42-
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
43-
};
44-
// Using host floats except for sqrt (but it's fine, these operations do not
45-
// have guaranteed precision).
41+
let ty::Float(float_ty) = op.layout.ty.kind() else {
42+
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
43+
};
44+
// Using host floats except for sqrt (but it's fine, these operations do not
45+
// have guaranteed precision).
4646
let val = match float_ty {
47-
FloatTy::F16 => unimplemented!("f16_f128"),
48-
FloatTy::F32 => {
49-
let f = op.to_scalar().to_f32()?;
47+
FloatTy::F16 => unimplemented!("f16_f128"),
48+
FloatTy::F32 => {
49+
let f = op.to_scalar().to_f32()?;
5050
let res = match intrinsic_name {
51-
"fsqrt" => math::sqrt(f),
52-
"fsin" => f.to_host().sin().to_soft(),
53-
"fcos" => f.to_host().cos().to_soft(),
54-
"fexp" => f.to_host().exp().to_soft(),
55-
"fexp2" => f.to_host().exp2().to_soft(),
56-
"flog" => f.to_host().ln().to_soft(),
57-
"flog2" => f.to_host().log2().to_soft(),
58-
"flog10" => f.to_host().log10().to_soft(),
59-
_ => bug!(),
60-
};
61-
let res = this.adjust_nan(res, &[f]);
62-
Scalar::from(res)
63-
}
64-
FloatTy::F64 => {
65-
let f = op.to_scalar().to_f64()?;
51+
"fsqrt" => math::sqrt(f),
52+
"fsin" => f.to_host().sin().to_soft(),
53+
"fcos" => f.to_host().cos().to_soft(),
54+
"fexp" => f.to_host().exp().to_soft(),
55+
"fexp2" => f.to_host().exp2().to_soft(),
56+
"flog" => f.to_host().ln().to_soft(),
57+
"flog2" => f.to_host().log2().to_soft(),
58+
"flog10" => f.to_host().log10().to_soft(),
59+
_ => bug!(),
60+
};
61+
let res = this.adjust_nan(res, &[f]);
62+
Scalar::from(res)
63+
}
64+
FloatTy::F64 => {
65+
let f = op.to_scalar().to_f64()?;
6666
let res = match intrinsic_name {
67-
"fsqrt" => math::sqrt(f),
68-
"fsin" => f.to_host().sin().to_soft(),
69-
"fcos" => f.to_host().cos().to_soft(),
70-
"fexp" => f.to_host().exp().to_soft(),
71-
"fexp2" => f.to_host().exp2().to_soft(),
72-
"flog" => f.to_host().ln().to_soft(),
73-
"flog2" => f.to_host().log2().to_soft(),
74-
"flog10" => f.to_host().log10().to_soft(),
75-
_ => bug!(),
76-
};
77-
let res = this.adjust_nan(res, &[f]);
78-
Scalar::from(res)
79-
}
80-
FloatTy::F128 => unimplemented!("f16_f128"),
67+
"fsqrt" => math::sqrt(f),
68+
"fsin" => f.to_host().sin().to_soft(),
69+
"fcos" => f.to_host().cos().to_soft(),
70+
"fexp" => f.to_host().exp().to_soft(),
71+
"fexp2" => f.to_host().exp2().to_soft(),
72+
"flog" => f.to_host().ln().to_soft(),
73+
"flog2" => f.to_host().log2().to_soft(),
74+
"flog10" => f.to_host().log10().to_soft(),
75+
_ => bug!(),
8176
};
77+
let res = this.adjust_nan(res, &[f]);
78+
Scalar::from(res)
79+
}
80+
FloatTy::F128 => unimplemented!("f16_f128"),
81+
};
8282

8383
this.write_scalar(val, &dest)?;
8484
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
extern crate rustc_abi;
5454
extern crate rustc_apfloat;
5555
extern crate rustc_ast;
56+
extern crate rustc_codegen_ssa;
5657
extern crate rustc_const_eval;
5758
extern crate rustc_data_structures;
5859
extern crate rustc_errors;

src/machine.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use rand::rngs::StdRng;
1212
use rand::{Rng, SeedableRng};
1313
use rustc_abi::{Align, ExternAbi, Size};
1414
use rustc_apfloat::{Float, FloatConvert};
15+
use rustc_ast::expand::allocator::{self, SpecialAllocatorMethod};
16+
use rustc_data_structures::either::Either;
1517
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1618
#[allow(unused)]
1719
use rustc_data_structures::static_assert_size;
@@ -27,6 +29,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2729
use rustc_session::config::InliningThreshold;
2830
use rustc_span::def_id::{CrateNum, DefId};
2931
use rustc_span::{Span, SpanData, Symbol};
32+
use rustc_symbol_mangling::mangle_internal_symbol;
3033
use rustc_target::callconv::FnAbi;
3134

3235
use crate::alloc_addresses::EvalContextExt;
@@ -652,6 +655,10 @@ pub struct MiriMachine<'tcx> {
652655
pub(crate) pthread_rwlock_sanity: Cell<bool>,
653656
pub(crate) pthread_condvar_sanity: Cell<bool>,
654657

658+
/// (Foreign) symbols that are synthesized as part of the allocator shim: the key indicates the
659+
/// name of the symbol being synthesized; the value indicates whether this should invoke some
660+
/// other symbol or whether this has special allocator semantics.
661+
pub(crate) allocator_shim_symbols: FxHashMap<Symbol, Either<Symbol, SpecialAllocatorMethod>>,
655662
/// Cache for `mangle_internal_symbol`.
656663
pub(crate) mangle_internal_symbol_cache: FxHashMap<&'static str, String>,
657664

@@ -819,6 +826,7 @@ impl<'tcx> MiriMachine<'tcx> {
819826
pthread_mutex_sanity: Cell::new(false),
820827
pthread_rwlock_sanity: Cell::new(false),
821828
pthread_condvar_sanity: Cell::new(false),
829+
allocator_shim_symbols: Self::allocator_shim_symbols(tcx),
822830
mangle_internal_symbol_cache: Default::default(),
823831
force_intrinsic_fallback: config.force_intrinsic_fallback,
824832
float_nondet: config.float_nondet,
@@ -827,6 +835,36 @@ impl<'tcx> MiriMachine<'tcx> {
827835
}
828836
}
829837

838+
fn allocator_shim_symbols(
839+
tcx: TyCtxt<'tcx>,
840+
) -> FxHashMap<Symbol, Either<Symbol, SpecialAllocatorMethod>> {
841+
use rustc_codegen_ssa::base::allocator_shim_contents;
842+
843+
// codegen uses `allocator_kind_for_codegen` here, but that's only needed to deal with
844+
// dylibs which we do not support.
845+
let Some(kind) = tcx.allocator_kind(()) else {
846+
return Default::default();
847+
};
848+
let methods = allocator_shim_contents(tcx, kind);
849+
let mut symbols = FxHashMap::default();
850+
for method in methods {
851+
let from_name = Symbol::intern(&mangle_internal_symbol(
852+
tcx,
853+
&allocator::global_fn_name(method.name),
854+
));
855+
let to = match method.special {
856+
Some(special) => Either::Right(special),
857+
None =>
858+
Either::Left(Symbol::intern(&mangle_internal_symbol(
859+
tcx,
860+
&allocator::default_fn_name(method.name),
861+
))),
862+
};
863+
symbols.try_insert(from_name, to).unwrap();
864+
}
865+
symbols
866+
}
867+
830868
pub(crate) fn late_init(
831869
ecx: &mut MiriInterpCx<'tcx>,
832870
config: &MiriConfig,
@@ -992,6 +1030,7 @@ impl VisitProvenance for MiriMachine<'_> {
9921030
pthread_mutex_sanity: _,
9931031
pthread_rwlock_sanity: _,
9941032
pthread_condvar_sanity: _,
1033+
allocator_shim_symbols: _,
9951034
mangle_internal_symbol_cache: _,
9961035
force_intrinsic_fallback: _,
9971036
float_nondet: _,

0 commit comments

Comments
 (0)