Remove statics from HAIR by lowering them to a pointer constant
This commit is contained in:
parent
35ef33a89d
commit
a1d04cc1d8
6 changed files with 26 additions and 15 deletions
|
|
@ -197,13 +197,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
};
|
||||
block.and(place_builder)
|
||||
}
|
||||
ExprKind::StaticRef { id } => block.and(PlaceBuilder::from(
|
||||
PlaceBase::Static(Box::new(Static {
|
||||
ty: expr.ty,
|
||||
kind: StaticKind::Static,
|
||||
def_id: id,
|
||||
}))
|
||||
)),
|
||||
|
||||
ExprKind::PlaceTypeAscription { source, user_ty } => {
|
||||
let source = this.hir.mirror(source);
|
||||
|
|
|
|||
|
|
@ -288,7 +288,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
| ExprKind::Continue { .. }
|
||||
| ExprKind::Return { .. }
|
||||
| ExprKind::InlineAsm { .. }
|
||||
| ExprKind::StaticRef { .. }
|
||||
| ExprKind::PlaceTypeAscription { .. }
|
||||
| ExprKind::ValueTypeAscription { .. } => {
|
||||
// these do not have corresponding `Rvalue` variants,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ impl Category {
|
|||
| ExprKind::Index { .. }
|
||||
| ExprKind::SelfRef
|
||||
| ExprKind::VarRef { .. }
|
||||
| ExprKind::StaticRef { .. }
|
||||
| ExprKind::PlaceTypeAscription { .. }
|
||||
| ExprKind::ValueTypeAscription { .. } => Some(Category::Place),
|
||||
|
||||
|
|
|
|||
|
|
@ -384,7 +384,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// Avoid creating a temporary
|
||||
ExprKind::VarRef { .. } |
|
||||
ExprKind::SelfRef |
|
||||
ExprKind::StaticRef { .. } |
|
||||
ExprKind::PlaceTypeAscription { .. } |
|
||||
ExprKind::ValueTypeAscription { .. } => {
|
||||
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::hair::cx::to_ref::ToRef;
|
|||
use crate::hair::util::UserAnnotatedTyHelpers;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
|
||||
use rustc::mir::interpret::{GlobalId, ErrorHandled};
|
||||
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue, Scalar};
|
||||
use rustc::ty::{self, AdtKind, Ty};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
|
||||
use rustc::ty::subst::{InternalSubsts, SubstsRef};
|
||||
|
|
@ -961,7 +961,31 @@ fn convert_path_expr<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
Res::Def(DefKind::Static, id) => ExprKind::StaticRef { id },
|
||||
// We encode uses of statics as a `*&STATIC` where the `&STATIC` part is
|
||||
// a constant reference (or constant raw pointer for `static mut`) in MIR
|
||||
Res::Def(DefKind::Static, id) => {
|
||||
let ty = cx.tcx.type_of(id);
|
||||
let ty = if cx.tcx.is_mutable_static(id) {
|
||||
cx.tcx.mk_mut_ptr(ty)
|
||||
} else if cx.tcx.is_foreign_item(id) {
|
||||
cx.tcx.mk_imm_ptr(ty)
|
||||
} else {
|
||||
cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_static, ty)
|
||||
};
|
||||
let ptr = cx.tcx.alloc_map.lock().create_static_alloc(id);
|
||||
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);
|
||||
ExprKind::Deref { arg: Expr {
|
||||
ty,
|
||||
temp_lifetime,
|
||||
span: expr.span,
|
||||
kind: ExprKind::Literal {
|
||||
literal: cx.tcx.mk_const(ty::Const {
|
||||
ty, val: ConstValue::Scalar(Scalar::Ptr(ptr.into())),
|
||||
}),
|
||||
user_ty: None,
|
||||
}
|
||||
}.to_ref() }
|
||||
},
|
||||
|
||||
Res::Local(var_hir_id) => convert_var(cx, expr, var_hir_id),
|
||||
|
||||
|
|
|
|||
|
|
@ -208,9 +208,6 @@ pub enum ExprKind<'tcx> {
|
|||
},
|
||||
/// first argument, used for self in a closure
|
||||
SelfRef,
|
||||
StaticRef {
|
||||
id: DefId,
|
||||
},
|
||||
Borrow {
|
||||
borrow_kind: BorrowKind,
|
||||
arg: ExprRef<'tcx>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue