rename mir -> thir around abstract consts
This commit is contained in:
parent
15101c8e95
commit
406d2ab95d
22 changed files with 287 additions and 284 deletions
|
@ -26,6 +26,7 @@ use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLib};
|
|||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
|
||||
use rustc_middle::mir::{self, Body, Promoted};
|
||||
use rustc_middle::thir;
|
||||
use rustc_middle::ty::codec::TyDecoder;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, Visibility};
|
||||
use rustc_serialize::{opaque, Decodable, Decoder};
|
||||
|
@ -540,7 +541,7 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [mir::abstract_const::Node<'tcx>] {
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [thir::abstract_const::Node<'tcx>] {
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result<Self, String> {
|
||||
ty::codec::RefDecodable::decode(d)
|
||||
}
|
||||
|
@ -1198,14 +1199,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||
.decode((self, tcx))
|
||||
}
|
||||
|
||||
fn get_mir_abstract_const(
|
||||
fn get_thir_abstract_const(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
id: DefIndex,
|
||||
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
self.root
|
||||
.tables
|
||||
.mir_abstract_consts
|
||||
.thir_abstract_consts
|
||||
.get(self, id)
|
||||
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
|
||||
mir_for_ctfe => { tcx.arena.alloc(cdata.get_mir_for_ctfe(tcx, def_id.index)) }
|
||||
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
|
||||
mir_abstract_const => { cdata.get_mir_abstract_const(tcx, def_id.index) }
|
||||
thir_abstract_const => { cdata.get_thir_abstract_const(tcx, def_id.index) }
|
||||
unused_generic_params => { cdata.get_unused_generic_params(def_id.index) }
|
||||
const_param_default => { tcx.mk_const(cdata.get_const_param_default(tcx, def_id.index)) }
|
||||
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
|
||||
|
|
|
@ -23,6 +23,7 @@ use rustc_middle::middle::exported_symbols::{
|
|||
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
|
||||
};
|
||||
use rustc_middle::mir::interpret;
|
||||
use rustc_middle::thir;
|
||||
use rustc_middle::traits::specialization_graph;
|
||||
use rustc_middle::ty::codec::TyEncoder;
|
||||
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
|
||||
|
@ -344,7 +345,7 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for &'tcx [mir::abstract_const::Node<'tcx>] {
|
||||
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for &'tcx [thir::abstract_const::Node<'tcx>] {
|
||||
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
|
||||
(**self).encode(s)
|
||||
}
|
||||
|
@ -1304,9 +1305,10 @@ impl EncodeContext<'a, 'tcx> {
|
|||
if encode_const {
|
||||
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
|
||||
|
||||
let abstract_const = self.tcx.mir_abstract_const(def_id);
|
||||
// FIXME this feels wrong to have in `encode_mir`
|
||||
let abstract_const = self.tcx.thir_abstract_const(def_id);
|
||||
if let Ok(Some(abstract_const)) = abstract_const {
|
||||
record!(self.tables.mir_abstract_consts[def_id.to_def_id()] <- abstract_const);
|
||||
record!(self.tables.thir_abstract_consts[def_id.to_def_id()] <- abstract_const);
|
||||
}
|
||||
}
|
||||
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
|
||||
|
|
|
@ -15,6 +15,7 @@ use rustc_middle::hir::exports::Export;
|
|||
use rustc_middle::middle::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib};
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::thir;
|
||||
use rustc_middle::ty::{self, ReprOptions, Ty};
|
||||
use rustc_serialize::opaque::Encoder;
|
||||
use rustc_session::config::SymbolManglingVersion;
|
||||
|
@ -305,7 +306,7 @@ define_tables! {
|
|||
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
|
||||
mir_for_ctfe: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
|
||||
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
|
||||
mir_abstract_consts: Table<DefIndex, Lazy!(&'tcx [mir::abstract_const::Node<'tcx>])>,
|
||||
thir_abstract_consts: Table<DefIndex, Lazy!(&'tcx [thir::abstract_const::Node<'tcx>])>,
|
||||
const_defaults: Table<DefIndex, Lazy<rustc_middle::ty::Const<'tcx>>>,
|
||||
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
|
||||
// `def_keys` and `def_path_hashes` represent a lazy version of a
|
||||
|
|
|
@ -40,7 +40,6 @@ use self::graph_cyclic_cache::GraphIsCyclicCache;
|
|||
use self::predecessors::{PredecessorCache, Predecessors};
|
||||
pub use self::query::*;
|
||||
|
||||
pub mod abstract_const;
|
||||
pub mod coverage;
|
||||
mod generic_graph;
|
||||
pub mod generic_graphviz;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Values computed by queries that use MIR.
|
||||
|
||||
use crate::mir::{abstract_const, Body, Promoted};
|
||||
use crate::mir::{Body, Promoted};
|
||||
use crate::thir::abstract_const;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
|
@ -433,14 +434,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mir_abstract_const_opt_const_arg(
|
||||
pub fn thir_abstract_const_opt_const_arg(
|
||||
self,
|
||||
def: ty::WithOptConstParam<DefId>,
|
||||
) -> Result<Option<&'tcx [abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
if let Some((did, param_did)) = def.as_const_arg() {
|
||||
self.mir_abstract_const_of_const_arg((did, param_did))
|
||||
self.thir_abstract_const_of_const_arg((did, param_did))
|
||||
} else {
|
||||
self.mir_abstract_const(def.did)
|
||||
self.thir_abstract_const(def.did)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,17 +295,17 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
/// Try to build an abstract representation of the given constant.
|
||||
query mir_abstract_const(
|
||||
query thir_abstract_const(
|
||||
key: DefId
|
||||
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
desc {
|
||||
|tcx| "building an abstract representation for {}", tcx.def_path_str(key),
|
||||
}
|
||||
}
|
||||
/// Try to build an abstract representation of the given constant.
|
||||
query mir_abstract_const_of_const_arg(
|
||||
query thir_abstract_const_of_const_arg(
|
||||
key: (LocalDefId, DefId)
|
||||
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
desc {
|
||||
|tcx|
|
||||
"building an abstract representation for the const argument {}",
|
||||
|
|
|
@ -33,6 +33,9 @@ use rustc_target::asm::InlineAsmRegOrRegClass;
|
|||
use std::fmt;
|
||||
use std::ops::Index;
|
||||
|
||||
pub mod abstract_const;
|
||||
pub mod visit;
|
||||
|
||||
newtype_index! {
|
||||
/// An index to an [`Arm`] stored in [`Thir::arms`]
|
||||
#[derive(HashStable)]
|
||||
|
@ -818,246 +821,3 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod visit {
|
||||
use super::*;
|
||||
pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
||||
fn thir(&self) -> &'a Thir<'tcx>;
|
||||
|
||||
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
||||
walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
|
||||
walk_stmt(self, stmt);
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &Block) {
|
||||
walk_block(self, block);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
|
||||
walk_arm(self, arm);
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
|
||||
walk_pat(self, pat);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, _cnst: &'tcx Const<'tcx>) {}
|
||||
}
|
||||
|
||||
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
|
||||
use ExprKind::*;
|
||||
match expr.kind {
|
||||
Scope { value, region_scope: _, lint_level: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
Box { value } => visitor.visit_expr(&visitor.thir()[value]),
|
||||
If { cond, then, else_opt, if_then_scope: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[cond]);
|
||||
visitor.visit_expr(&visitor.thir()[then]);
|
||||
if let Some(else_expr) = else_opt {
|
||||
visitor.visit_expr(&visitor.thir()[else_expr]);
|
||||
}
|
||||
}
|
||||
Call { fun, ref args, ty: _, from_hir_call: _, fn_span: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[fun]);
|
||||
for &arg in &**args {
|
||||
visitor.visit_expr(&visitor.thir()[arg]);
|
||||
}
|
||||
}
|
||||
Deref { arg } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Binary { lhs, rhs, op: _ } | LogicalOp { lhs, rhs, op: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[rhs]);
|
||||
}
|
||||
Unary { arg, op: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Cast { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Use { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
NeverToAny { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Pointer { source, cast: _ } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Let { expr, .. } => {
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
Loop { body } => visitor.visit_expr(&visitor.thir()[body]),
|
||||
Match { scrutinee, ref arms } => {
|
||||
visitor.visit_expr(&visitor.thir()[scrutinee]);
|
||||
for &arm in &**arms {
|
||||
visitor.visit_arm(&visitor.thir()[arm]);
|
||||
}
|
||||
}
|
||||
Block { ref body } => visitor.visit_block(body),
|
||||
Assign { lhs, rhs } | AssignOp { lhs, rhs, op: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[rhs]);
|
||||
}
|
||||
Field { lhs, name: _ } => visitor.visit_expr(&visitor.thir()[lhs]),
|
||||
Index { lhs, index } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[index]);
|
||||
}
|
||||
VarRef { id: _ } | UpvarRef { closure_def_id: _, var_hir_id: _ } => {}
|
||||
Borrow { arg, borrow_kind: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
AddressOf { arg, mutability: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Break { value, label: _ } => {
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
}
|
||||
Continue { label: _ } => {}
|
||||
Return { value } => {
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
}
|
||||
ConstBlock { value } => visitor.visit_const(value),
|
||||
Repeat { value, count } => {
|
||||
visitor.visit_expr(&visitor.thir()[value]);
|
||||
visitor.visit_const(count);
|
||||
}
|
||||
Array { ref fields } | Tuple { ref fields } => {
|
||||
for &field in &**fields {
|
||||
visitor.visit_expr(&visitor.thir()[field]);
|
||||
}
|
||||
}
|
||||
Adt(box crate::thir::Adt {
|
||||
ref fields,
|
||||
ref base,
|
||||
adt_def: _,
|
||||
variant_index: _,
|
||||
substs: _,
|
||||
user_ty: _,
|
||||
}) => {
|
||||
for field in &**fields {
|
||||
visitor.visit_expr(&visitor.thir()[field.expr]);
|
||||
}
|
||||
if let Some(base) = base {
|
||||
visitor.visit_expr(&visitor.thir()[base.base]);
|
||||
}
|
||||
}
|
||||
PlaceTypeAscription { source, user_ty: _ }
|
||||
| ValueTypeAscription { source, user_ty: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[source])
|
||||
}
|
||||
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
||||
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
|
||||
StaticRef { literal, def_id: _ } => visitor.visit_const(literal),
|
||||
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
|
||||
for op in &**operands {
|
||||
use InlineAsmOperand::*;
|
||||
match op {
|
||||
In { expr, reg: _ }
|
||||
| Out { expr: Some(expr), reg: _, late: _ }
|
||||
| InOut { expr, reg: _, late: _ }
|
||||
| SymFn { expr } => visitor.visit_expr(&visitor.thir()[*expr]),
|
||||
SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[*in_expr]);
|
||||
if let Some(out_expr) = out_expr {
|
||||
visitor.visit_expr(&visitor.thir()[*out_expr]);
|
||||
}
|
||||
}
|
||||
Out { expr: None, reg: _, late: _ }
|
||||
| Const { value: _, span: _ }
|
||||
| SymStatic { def_id: _ } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ThreadLocalRef(_) => {}
|
||||
LlvmInlineAsm { ref outputs, ref inputs, asm: _ } => {
|
||||
for &out_expr in &**outputs {
|
||||
visitor.visit_expr(&visitor.thir()[out_expr]);
|
||||
}
|
||||
for &in_expr in &**inputs {
|
||||
visitor.visit_expr(&visitor.thir()[in_expr]);
|
||||
}
|
||||
}
|
||||
Yield { value } => visitor.visit_expr(&visitor.thir()[value]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stmt<'tcx>) {
|
||||
match &stmt.kind {
|
||||
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
|
||||
StmtKind::Let {
|
||||
initializer,
|
||||
remainder_scope: _,
|
||||
init_scope: _,
|
||||
ref pattern,
|
||||
lint_level: _,
|
||||
} => {
|
||||
if let Some(init) = initializer {
|
||||
visitor.visit_expr(&visitor.thir()[*init]);
|
||||
}
|
||||
visitor.visit_pat(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &Block) {
|
||||
for &stmt in &*block.stmts {
|
||||
visitor.visit_stmt(&visitor.thir()[stmt]);
|
||||
}
|
||||
if let Some(expr) = block.expr {
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
|
||||
match arm.guard {
|
||||
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
|
||||
Some(Guard::IfLet(ref pat, expr)) => {
|
||||
visitor.visit_pat(pat);
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
visitor.visit_pat(&arm.pattern);
|
||||
visitor.visit_expr(&visitor.thir()[arm.body]);
|
||||
}
|
||||
|
||||
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
|
||||
use PatKind::*;
|
||||
match pat.kind.as_ref() {
|
||||
AscribeUserType { subpattern, ascription: _ }
|
||||
| Deref { subpattern }
|
||||
| Binding {
|
||||
subpattern: Some(subpattern),
|
||||
mutability: _,
|
||||
mode: _,
|
||||
var: _,
|
||||
ty: _,
|
||||
is_primary: _,
|
||||
name: _,
|
||||
} => visitor.visit_pat(&subpattern),
|
||||
Binding { .. } | Wild => {}
|
||||
Variant { subpatterns, adt_def: _, substs: _, variant_index: _ }
|
||||
| Leaf { subpatterns } => {
|
||||
for subpattern in subpatterns {
|
||||
visitor.visit_pat(&subpattern.pattern);
|
||||
}
|
||||
}
|
||||
Constant { value } => visitor.visit_const(value),
|
||||
Range(range) => {
|
||||
visitor.visit_const(range.lo);
|
||||
visitor.visit_const(range.hi);
|
||||
}
|
||||
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
|
||||
for subpattern in prefix {
|
||||
visitor.visit_pat(&subpattern);
|
||||
}
|
||||
if let Some(pat) = slice {
|
||||
visitor.visit_pat(pat);
|
||||
}
|
||||
for subpattern in suffix {
|
||||
visitor.visit_pat(&subpattern);
|
||||
}
|
||||
}
|
||||
Or { pats } => {
|
||||
for pat in pats {
|
||||
visitor.visit_pat(&pat);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
238
compiler/rustc_middle/src/thir/visit.rs
Normal file
238
compiler/rustc_middle/src/thir/visit.rs
Normal file
|
@ -0,0 +1,238 @@
|
|||
use super::*;
|
||||
pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
||||
fn thir(&self) -> &'a Thir<'tcx>;
|
||||
|
||||
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
||||
walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
|
||||
walk_stmt(self, stmt);
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &Block) {
|
||||
walk_block(self, block);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
|
||||
walk_arm(self, arm);
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
|
||||
walk_pat(self, pat);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, _cnst: &'tcx Const<'tcx>) {}
|
||||
}
|
||||
|
||||
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
|
||||
use ExprKind::*;
|
||||
match expr.kind {
|
||||
Scope { value, region_scope: _, lint_level: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
Box { value } => visitor.visit_expr(&visitor.thir()[value]),
|
||||
If { cond, then, else_opt, if_then_scope: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[cond]);
|
||||
visitor.visit_expr(&visitor.thir()[then]);
|
||||
if let Some(else_expr) = else_opt {
|
||||
visitor.visit_expr(&visitor.thir()[else_expr]);
|
||||
}
|
||||
}
|
||||
Call { fun, ref args, ty: _, from_hir_call: _, fn_span: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[fun]);
|
||||
for &arg in &**args {
|
||||
visitor.visit_expr(&visitor.thir()[arg]);
|
||||
}
|
||||
}
|
||||
Deref { arg } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Binary { lhs, rhs, op: _ } | LogicalOp { lhs, rhs, op: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[rhs]);
|
||||
}
|
||||
Unary { arg, op: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Cast { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Use { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
NeverToAny { source } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Pointer { source, cast: _ } => visitor.visit_expr(&visitor.thir()[source]),
|
||||
Let { expr, .. } => {
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
Loop { body } => visitor.visit_expr(&visitor.thir()[body]),
|
||||
Match { scrutinee, ref arms } => {
|
||||
visitor.visit_expr(&visitor.thir()[scrutinee]);
|
||||
for &arm in &**arms {
|
||||
visitor.visit_arm(&visitor.thir()[arm]);
|
||||
}
|
||||
}
|
||||
Block { ref body } => visitor.visit_block(body),
|
||||
Assign { lhs, rhs } | AssignOp { lhs, rhs, op: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[rhs]);
|
||||
}
|
||||
Field { lhs, name: _ } => visitor.visit_expr(&visitor.thir()[lhs]),
|
||||
Index { lhs, index } => {
|
||||
visitor.visit_expr(&visitor.thir()[lhs]);
|
||||
visitor.visit_expr(&visitor.thir()[index]);
|
||||
}
|
||||
VarRef { id: _ } | UpvarRef { closure_def_id: _, var_hir_id: _ } => {}
|
||||
Borrow { arg, borrow_kind: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
AddressOf { arg, mutability: _ } => visitor.visit_expr(&visitor.thir()[arg]),
|
||||
Break { value, label: _ } => {
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
}
|
||||
Continue { label: _ } => {}
|
||||
Return { value } => {
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(&visitor.thir()[value])
|
||||
}
|
||||
}
|
||||
ConstBlock { value } => visitor.visit_const(value),
|
||||
Repeat { value, count } => {
|
||||
visitor.visit_expr(&visitor.thir()[value]);
|
||||
visitor.visit_const(count);
|
||||
}
|
||||
Array { ref fields } | Tuple { ref fields } => {
|
||||
for &field in &**fields {
|
||||
visitor.visit_expr(&visitor.thir()[field]);
|
||||
}
|
||||
}
|
||||
Adt(box crate::thir::Adt {
|
||||
ref fields,
|
||||
ref base,
|
||||
adt_def: _,
|
||||
variant_index: _,
|
||||
substs: _,
|
||||
user_ty: _,
|
||||
}) => {
|
||||
for field in &**fields {
|
||||
visitor.visit_expr(&visitor.thir()[field.expr]);
|
||||
}
|
||||
if let Some(base) = base {
|
||||
visitor.visit_expr(&visitor.thir()[base.base]);
|
||||
}
|
||||
}
|
||||
PlaceTypeAscription { source, user_ty: _ } | ValueTypeAscription { source, user_ty: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[source])
|
||||
}
|
||||
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
||||
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
|
||||
StaticRef { literal, def_id: _ } => visitor.visit_const(literal),
|
||||
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
|
||||
for op in &**operands {
|
||||
use InlineAsmOperand::*;
|
||||
match op {
|
||||
In { expr, reg: _ }
|
||||
| Out { expr: Some(expr), reg: _, late: _ }
|
||||
| InOut { expr, reg: _, late: _ }
|
||||
| SymFn { expr } => visitor.visit_expr(&visitor.thir()[*expr]),
|
||||
SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[*in_expr]);
|
||||
if let Some(out_expr) = out_expr {
|
||||
visitor.visit_expr(&visitor.thir()[*out_expr]);
|
||||
}
|
||||
}
|
||||
Out { expr: None, reg: _, late: _ }
|
||||
| Const { value: _, span: _ }
|
||||
| SymStatic { def_id: _ } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ThreadLocalRef(_) => {}
|
||||
LlvmInlineAsm { ref outputs, ref inputs, asm: _ } => {
|
||||
for &out_expr in &**outputs {
|
||||
visitor.visit_expr(&visitor.thir()[out_expr]);
|
||||
}
|
||||
for &in_expr in &**inputs {
|
||||
visitor.visit_expr(&visitor.thir()[in_expr]);
|
||||
}
|
||||
}
|
||||
Yield { value } => visitor.visit_expr(&visitor.thir()[value]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stmt<'tcx>) {
|
||||
match &stmt.kind {
|
||||
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
|
||||
StmtKind::Let {
|
||||
initializer,
|
||||
remainder_scope: _,
|
||||
init_scope: _,
|
||||
ref pattern,
|
||||
lint_level: _,
|
||||
} => {
|
||||
if let Some(init) = initializer {
|
||||
visitor.visit_expr(&visitor.thir()[*init]);
|
||||
}
|
||||
visitor.visit_pat(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &Block) {
|
||||
for &stmt in &*block.stmts {
|
||||
visitor.visit_stmt(&visitor.thir()[stmt]);
|
||||
}
|
||||
if let Some(expr) = block.expr {
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
|
||||
match arm.guard {
|
||||
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
|
||||
Some(Guard::IfLet(ref pat, expr)) => {
|
||||
visitor.visit_pat(pat);
|
||||
visitor.visit_expr(&visitor.thir()[expr]);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
visitor.visit_pat(&arm.pattern);
|
||||
visitor.visit_expr(&visitor.thir()[arm.body]);
|
||||
}
|
||||
|
||||
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
|
||||
use PatKind::*;
|
||||
match pat.kind.as_ref() {
|
||||
AscribeUserType { subpattern, ascription: _ }
|
||||
| Deref { subpattern }
|
||||
| Binding {
|
||||
subpattern: Some(subpattern),
|
||||
mutability: _,
|
||||
mode: _,
|
||||
var: _,
|
||||
ty: _,
|
||||
is_primary: _,
|
||||
name: _,
|
||||
} => visitor.visit_pat(&subpattern),
|
||||
Binding { .. } | Wild => {}
|
||||
Variant { subpatterns, adt_def: _, substs: _, variant_index: _ } | Leaf { subpatterns } => {
|
||||
for subpattern in subpatterns {
|
||||
visitor.visit_pat(&subpattern.pattern);
|
||||
}
|
||||
}
|
||||
Constant { value } => visitor.visit_const(value),
|
||||
Range(range) => {
|
||||
visitor.visit_const(range.lo);
|
||||
visitor.visit_const(range.hi);
|
||||
}
|
||||
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
|
||||
for subpattern in prefix {
|
||||
visitor.visit_pat(&subpattern);
|
||||
}
|
||||
if let Some(pat) = slice {
|
||||
visitor.visit_pat(pat);
|
||||
}
|
||||
for subpattern in suffix {
|
||||
visitor.visit_pat(&subpattern);
|
||||
}
|
||||
}
|
||||
Or { pats } => {
|
||||
for pat in pats {
|
||||
visitor.visit_pat(&pat);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -9,7 +9,7 @@ pub mod specialization_graph;
|
|||
mod structural_impls;
|
||||
|
||||
use crate::infer::canonical::Canonical;
|
||||
use crate::mir::abstract_const::NotConstEvaluatable;
|
||||
use crate::thir::abstract_const::NotConstEvaluatable;
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{self, AdtKind, Ty, TyCtxt};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::mir::{
|
|||
self,
|
||||
interpret::{AllocId, Allocation},
|
||||
};
|
||||
use crate::thir;
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{self, List, Ty, TyCtxt};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
@ -362,7 +363,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [(ty::Predicate<'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::Node<'tcx>] {
|
||||
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [thir::abstract_const::Node<'tcx>] {
|
||||
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
|
||||
Ok(decoder.tcx().arena.alloc_from_iter(
|
||||
(0..decoder.read_usize()?)
|
||||
|
@ -372,7 +373,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::N
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::NodeId] {
|
||||
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [thir::abstract_const::NodeId] {
|
||||
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
|
||||
Ok(decoder.tcx().arena.alloc_from_iter(
|
||||
(0..decoder.read_usize()?)
|
||||
|
|
|
@ -48,11 +48,11 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
match def {
|
||||
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
|
||||
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did));
|
||||
tcx.ensure().mir_abstract_const_of_const_arg((did, const_param_did));
|
||||
tcx.ensure().thir_abstract_const_of_const_arg((did, const_param_did));
|
||||
}
|
||||
ty::WithOptConstParam { did, const_param_did: None } => {
|
||||
tcx.ensure().thir_check_unsafety(did);
|
||||
tcx.ensure().mir_abstract_const(did);
|
||||
tcx.ensure().thir_abstract_const(did);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -307,7 +307,6 @@ fn mir_promoted(
|
|||
// this point, before we steal the mir-const result.
|
||||
// Also this means promotion can rely on all const checks having been done.
|
||||
let _ = tcx.mir_const_qualif_opt_const_arg(def);
|
||||
let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global());
|
||||
let mut body = tcx.mir_const(def).steal();
|
||||
|
||||
let mut required_consts = Vec::new();
|
||||
|
|
|
@ -19,8 +19,8 @@ use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind};
|
|||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::middle::privacy::{AccessLevel, AccessLevels};
|
||||
use rustc_middle::mir::abstract_const::Node as ACNode;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::thir::abstract_const::Node as ACNode;
|
||||
use rustc_middle::ty::fold::TypeVisitor;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_index::vec::{Idx, IndexVec};
|
|||
use rustc_middle::dep_graph::{DepNode, DepNodeIndex, SerializedDepNodeIndex};
|
||||
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
|
||||
use rustc_middle::mir::{self, interpret};
|
||||
use rustc_middle::thir;
|
||||
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_query_system::dep_graph::DepContext;
|
||||
|
@ -906,7 +907,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [mir::abstract_const::Node<'tcx>] {
|
||||
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [thir::abstract_const::Node<'tcx>] {
|
||||
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
|
||||
RefDecodable::decode(d)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//! this is not as easy.
|
||||
//!
|
||||
//! In this case we try to build an abstract representation of this constant using
|
||||
//! `mir_abstract_const` which can then be checked for structural equality with other
|
||||
//! `thir_abstract_const` which can then be checked for structural equality with other
|
||||
//! generic constants mentioned in the `caller_bounds` of the current environment.
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::ErrorReported;
|
||||
|
@ -14,9 +14,9 @@ use rustc_hir::def::DefKind;
|
|||
use rustc_index::vec::IndexVec;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::abstract_const::{Node, NodeId, NotConstEvaluatable};
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::thir;
|
||||
use rustc_middle::thir::abstract_const::{Node, NodeId, NotConstEvaluatable};
|
||||
use rustc_middle::ty::subst::{Subst, SubstsRef};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
||||
use rustc_session::lint;
|
||||
|
@ -197,7 +197,7 @@ impl<'tcx> AbstractConst<'tcx> {
|
|||
tcx: TyCtxt<'tcx>,
|
||||
uv: ty::Unevaluated<'tcx, ()>,
|
||||
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
|
||||
let inner = tcx.mir_abstract_const_opt_const_arg(uv.def)?;
|
||||
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
|
||||
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
|
||||
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs(tcx) }))
|
||||
}
|
||||
|
@ -421,10 +421,10 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Builds an abstract const, do not use this directly, but use `AbstractConst::new` instead.
|
||||
pub(super) fn mir_abstract_const<'tcx>(
|
||||
pub(super) fn thir_abstract_const<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def: ty::WithOptConstParam<LocalDefId>,
|
||||
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||
if tcx.features().generic_const_exprs {
|
||||
match tcx.def_kind(def.did) {
|
||||
// FIXME(generic_const_exprs): We currently only do this for anonymous constants,
|
||||
|
|
|
@ -19,7 +19,7 @@ use rustc_hir::intravisit::Visitor;
|
|||
use rustc_hir::GenericParam;
|
||||
use rustc_hir::Item;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::fold::TypeFolder;
|
||||
use rustc_middle::ty::{
|
||||
|
|
|
@ -5,8 +5,8 @@ use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProce
|
|||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::traits::{SelectionError, TraitEngine, TraitEngineExt as _, TraitObligation};
|
||||
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
|
|
|
@ -827,16 +827,16 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
vtable_entries,
|
||||
vtable_trait_upcasting_coercion_new_vptr_slot,
|
||||
subst_and_check_impossible_predicates,
|
||||
mir_abstract_const: |tcx, def_id| {
|
||||
thir_abstract_const: |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.mir_abstract_const_of_const_arg(def)
|
||||
tcx.thir_abstract_const_of_const_arg(def)
|
||||
} else {
|
||||
const_evaluatable::mir_abstract_const(tcx, ty::WithOptConstParam::unknown(def_id))
|
||||
const_evaluatable::thir_abstract_const(tcx, ty::WithOptConstParam::unknown(def_id))
|
||||
}
|
||||
},
|
||||
mir_abstract_const_of_const_arg: |tcx, (did, param_did)| {
|
||||
const_evaluatable::mir_abstract_const(
|
||||
thir_abstract_const_of_const_arg: |tcx, (did, param_did)| {
|
||||
const_evaluatable::thir_abstract_const(
|
||||
tcx,
|
||||
ty::WithOptConstParam { did, const_param_did: Some(param_did) },
|
||||
)
|
||||
|
|
|
@ -836,7 +836,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
|
|||
//
|
||||
// This shouldn't really matter though as we can't really use any
|
||||
// constants which are not considered const evaluatable.
|
||||
use rustc_middle::mir::abstract_const::Node;
|
||||
use rustc_middle::thir::abstract_const::Node;
|
||||
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) {
|
||||
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() {
|
||||
Node::Leaf(leaf) => {
|
||||
|
|
|
@ -34,8 +34,8 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_infer::infer::LateBoundRegionConversionTime;
|
||||
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
|
||||
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::fast_reject;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::relate::TypeRelation;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue