Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/eval/shim.rs')
| -rw-r--r-- | crates/hir-ty/src/mir/eval/shim.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs index d4aab2d094..4b1adecf8c 100644 --- a/crates/hir-ty/src/mir/eval/shim.rs +++ b/crates/hir-ty/src/mir/eval/shim.rs @@ -3,11 +3,9 @@ //! use std::cmp::{self, Ordering}; -use hir_def::{ - CrateRootModuleId, attrs::AttrFlags, resolver::HasResolver, signatures::FunctionSignature, -}; +use hir_def::{CrateRootModuleId, resolver::HasResolver, signatures::FunctionSignature}; use hir_expand::name::Name; -use intern::sym; +use intern::{Symbol, sym}; use rustc_type_ir::inherent::{AdtDef, IntoKind, SliceLike, Ty as _}; use stdx::never; @@ -55,7 +53,7 @@ impl<'db> Evaluator<'db> { } let function_data = self.db.function_signature(def); - let attrs = AttrFlags::query(self.db, def.into()); + let attrs = self.db.attrs(def.into()); let is_intrinsic = FunctionSignature::is_intrinsic(self.db, def); if is_intrinsic { @@ -67,7 +65,7 @@ impl<'db> Evaluator<'db> { locals, span, !function_data.has_body() - || attrs.contains(AttrFlags::RUSTC_INTRINSIC_MUST_BE_OVERRIDDEN), + || attrs.by_key(sym::rustc_intrinsic_must_be_overridden).exists(), ); } let is_extern_c = match def.lookup(self.db).container { @@ -87,13 +85,18 @@ impl<'db> Evaluator<'db> { .map(|()| true); } - if attrs.intersects( - AttrFlags::RUSTC_ALLOCATOR - | AttrFlags::RUSTC_DEALLOCATOR - | AttrFlags::RUSTC_REALLOCATOR - | AttrFlags::RUSTC_ALLOCATOR_ZEROED, - ) { - self.exec_alloc_fn(attrs, args, destination)?; + let alloc_fn = + attrs.iter().filter_map(|it| it.path().as_ident()).map(|it| it.symbol()).find(|it| { + [ + &sym::rustc_allocator, + &sym::rustc_deallocator, + &sym::rustc_reallocator, + &sym::rustc_allocator_zeroed, + ] + .contains(it) + }); + if let Some(alloc_fn) = alloc_fn { + self.exec_alloc_fn(alloc_fn, args, destination)?; return Ok(true); } if let Some(it) = self.detect_lang_function(def) { @@ -242,14 +245,12 @@ impl<'db> Evaluator<'db> { fn exec_alloc_fn( &mut self, - alloc_fn: AttrFlags, + alloc_fn: &Symbol, args: &[IntervalAndTy<'db>], destination: Interval, ) -> Result<'db, ()> { match alloc_fn { - _ if alloc_fn - .intersects(AttrFlags::RUSTC_ALLOCATOR_ZEROED | AttrFlags::RUSTC_ALLOCATOR) => - { + _ if *alloc_fn == sym::rustc_allocator_zeroed || *alloc_fn == sym::rustc_allocator => { let [size, align] = args else { return Err(MirEvalError::InternalError( "rustc_allocator args are not provided".into(), @@ -260,8 +261,8 @@ impl<'db> Evaluator<'db> { let result = self.heap_allocate(size, align)?; destination.write_from_bytes(self, &result.to_bytes())?; } - _ if alloc_fn.contains(AttrFlags::RUSTC_DEALLOCATOR) => { /* no-op for now */ } - _ if alloc_fn.contains(AttrFlags::RUSTC_REALLOCATOR) => { + _ if *alloc_fn == sym::rustc_deallocator => { /* no-op for now */ } + _ if *alloc_fn == sym::rustc_reallocator => { let [ptr, old_size, align, new_size] = args else { return Err(MirEvalError::InternalError( "rustc_allocator args are not provided".into(), @@ -287,14 +288,14 @@ impl<'db> Evaluator<'db> { fn detect_lang_function(&self, def: FunctionId) -> Option<LangItem> { use LangItem::*; - let attrs = AttrFlags::query(self.db, def.into()); + let attrs = self.db.attrs(def.into()); - if attrs.contains(AttrFlags::RUSTC_CONST_PANIC_STR) { + if attrs.by_key(sym::rustc_const_panic_str).exists() { // `#[rustc_const_panic_str]` is treated like `lang = "begin_panic"` by rustc CTFE. return Some(LangItem::BeginPanic); } - let candidate = attrs.lang_item_with_attrs(self.db, def.into())?; + let candidate = attrs.lang_item()?; // We want to execute these functions with special logic // `PanicFmt` is not detected here as it's redirected later. if [BeginPanic, SliceLen, DropInPlace].contains(&candidate) { |