mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 22:13:39 +00:00
Support atomic fence intrinsic
This commit is contained in:
parent
b7d91ca5b2
commit
17cc813e92
5 changed files with 24 additions and 6 deletions
|
@ -2521,12 +2521,16 @@ fn const_trait_assoc() {
|
||||||
);
|
);
|
||||||
check_number(
|
check_number(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: size_of
|
//- minicore: size_of, fn
|
||||||
//- /a/lib.rs crate:a
|
//- /a/lib.rs crate:a
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
pub struct S<T>(T);
|
pub struct S<T>(T);
|
||||||
impl<T> S<T> {
|
impl<T> S<T> {
|
||||||
pub const X: usize = core::mem::size_of::<T>();
|
pub const X: usize = {
|
||||||
|
let k: T;
|
||||||
|
let f = || core::mem::size_of::<T>();
|
||||||
|
f()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
//- /main.rs crate:main deps:a
|
//- /main.rs crate:main deps:a
|
||||||
use a::{S};
|
use a::{S};
|
||||||
|
|
|
@ -438,6 +438,8 @@ fn atomic() {
|
||||||
pub fn atomic_nand_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
|
pub fn atomic_nand_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
|
||||||
pub fn atomic_or_release<T: Copy>(dst: *mut T, src: T) -> T;
|
pub fn atomic_or_release<T: Copy>(dst: *mut T, src: T) -> T;
|
||||||
pub fn atomic_xor_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
|
pub fn atomic_xor_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
|
||||||
|
pub fn atomic_fence_seqcst();
|
||||||
|
pub fn atomic_singlethreadfence_acqrel();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_not_reach() {
|
fn should_not_reach() {
|
||||||
|
@ -452,6 +454,7 @@ fn atomic() {
|
||||||
if (30, true) != atomic_cxchg_release_seqcst(&mut y, 30, 40) {
|
if (30, true) != atomic_cxchg_release_seqcst(&mut y, 30, 40) {
|
||||||
should_not_reach();
|
should_not_reach();
|
||||||
}
|
}
|
||||||
|
atomic_fence_seqcst();
|
||||||
if (40, false) != atomic_cxchg_release_seqcst(&mut y, 30, 50) {
|
if (40, false) != atomic_cxchg_release_seqcst(&mut y, 30, 50) {
|
||||||
should_not_reach();
|
should_not_reach();
|
||||||
}
|
}
|
||||||
|
@ -459,6 +462,7 @@ fn atomic() {
|
||||||
should_not_reach();
|
should_not_reach();
|
||||||
}
|
}
|
||||||
let mut z = atomic_xsub_seqcst(&mut x, -200);
|
let mut z = atomic_xsub_seqcst(&mut x, -200);
|
||||||
|
atomic_singlethreadfence_acqrel();
|
||||||
atomic_xor_seqcst(&mut x, 1024);
|
atomic_xor_seqcst(&mut x, 1024);
|
||||||
atomic_load_seqcst(&x) + z * 3 + atomic_load_seqcst(&y) * 2
|
atomic_load_seqcst(&x) + z * 3 + atomic_load_seqcst(&y) * 2
|
||||||
};
|
};
|
||||||
|
|
|
@ -702,9 +702,7 @@ impl Evaluator<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_adt(&self, adt: AdtId, subst: Substitution) -> Result<Arc<Layout>> {
|
fn layout_adt(&self, adt: AdtId, subst: Substitution) -> Result<Arc<Layout>> {
|
||||||
self.db.layout_of_adt(adt, subst.clone(), self.trait_env.clone()).map_err(|e| {
|
self.layout(&TyKind::Adt(chalk_ir::AdtId(adt), subst).intern(Interner))
|
||||||
MirEvalError::LayoutError(e, TyKind::Adt(chalk_ir::AdtId(adt), subst).intern(Interner))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn place_ty<'a>(&'a self, p: &Place, locals: &'a Locals) -> Result<Ty> {
|
fn place_ty<'a>(&'a self, p: &Place, locals: &'a Locals) -> Result<Ty> {
|
||||||
|
|
|
@ -1057,7 +1057,14 @@ impl Evaluator<'_> {
|
||||||
_span: MirSpan,
|
_span: MirSpan,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// We are a single threaded runtime with no UB checking and no optimization, so
|
// We are a single threaded runtime with no UB checking and no optimization, so
|
||||||
// we can implement these as normal functions.
|
// we can implement atomic intrinsics as normal functions.
|
||||||
|
|
||||||
|
if name.starts_with("singlethreadfence_") || name.starts_with("fence_") {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// The rest of atomic intrinsics have exactly one generic arg
|
||||||
|
|
||||||
let Some(ty) = generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner)) else {
|
let Some(ty) = generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner)) else {
|
||||||
return Err(MirEvalError::TypeError("atomic intrinsic generic arg is not provided"));
|
return Err(MirEvalError::TypeError("atomic intrinsic generic arg is not provided"));
|
||||||
};
|
};
|
||||||
|
|
|
@ -660,6 +660,11 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
||||||
expr_id.into(),
|
expr_id.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
TyKind::Closure(_, _) => {
|
||||||
|
not_supported!(
|
||||||
|
"method resolution not emitted for closure (Are Fn traits available?)"
|
||||||
|
);
|
||||||
|
}
|
||||||
TyKind::Error => {
|
TyKind::Error => {
|
||||||
return Err(MirLowerError::MissingFunctionDefinition(self.owner, expr_id))
|
return Err(MirLowerError::MissingFunctionDefinition(self.owner, expr_id))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue