Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
nightly-2023-07-18
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanventer committed Jul 26, 2023
1 parent d163cf4 commit 3787414
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 214 deletions.
155 changes: 79 additions & 76 deletions checker/src/block_visitor.rs

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions checker/src/body_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use mirai_annotations::*;
use rustc_errors::DiagnosticBuilder;
use rustc_hir::def_id::DefId;
use rustc_middle::mir;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{AdtDef, Const, Ty, TyCtxt, TyKind, TypeAndMut, UintTy};
use rustc_middle::ty::{AdtDef, Const, GenericArgsRef, Ty, TyCtxt, TyKind, TypeAndMut, UintTy};

use crate::abstract_value::{self, AbstractValue, AbstractValueTrait, BOTTOM};
use crate::block_visitor::BlockVisitor;
Expand Down Expand Up @@ -634,7 +633,7 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
if self.active_calls_map.contains_key(&def_id) {
return;
}
let generic_args = self.cv.substs_cache.get(&def_id).cloned();
let generic_args = self.cv.generic_args_cache.get(&def_id).cloned();
let callee_generic_argument_map = if let Some(generic_args) = generic_args {
self.type_visitor()
.get_generic_arguments_map(def_id, generic_args, &[])
Expand Down Expand Up @@ -1723,13 +1722,13 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
let union_type = self
.type_visitor()
.get_path_rustc_type(qualifier, self.current_span);
if let TyKind::Adt(def, substs) = union_type.kind() {
let substs = self
if let TyKind::Adt(def, args) = union_type.kind() {
let args = self
.type_visitor
.specialize_substs(substs, &self.type_visitor().generic_argument_map);
.specialize_generic_args(args, &self.type_visitor().generic_argument_map);
for (i, field) in def.all_fields().enumerate() {
let target_type = self.type_visitor().specialize_generic_argument_type(
field.ty(self.tcx, substs),
field.ty(self.tcx, args),
&self.type_visitor().generic_argument_map,
);
let target_path = Path::new_union_field(qualifier.clone(), i, *num_cases);
Expand Down Expand Up @@ -1794,7 +1793,7 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
fn add_leaf_fields_for<'a>(
path: Rc<Path>,
def: &'a AdtDef,
substs: SubstsRef<'a>,
args: GenericArgsRef<'a>,
tcx: TyCtxt<'a>,
accumulator: &mut Vec<(Rc<Path>, Ty<'a>)>,
) {
Expand Down Expand Up @@ -1823,9 +1822,9 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
let variant = def.variants().iter().next().expect("at least one variant");
for (i, field) in variant.fields.iter().enumerate() {
let field_path = Path::new_field(path.clone(), i);
let field_ty = field.ty(tcx, substs);
if let TyKind::Adt(def, substs) = field_ty.kind() {
add_leaf_fields_for(field_path, def, substs, tcx, accumulator)
let field_ty = field.ty(tcx, args);
if let TyKind::Adt(def, args) = field_ty.kind() {
add_leaf_fields_for(field_path, def, args, tcx, accumulator)
} else {
accumulator.push((field_path, field_ty))
}
Expand Down Expand Up @@ -2674,18 +2673,19 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
let union_type = self
.type_visitor()
.get_path_rustc_type(qualifier, self.current_span);
if let TyKind::Adt(def, substs) = union_type.kind() {
let substs = self
.type_visitor
.specialize_substs(substs, &self.type_visitor().generic_argument_map);
if let TyKind::Adt(def, args) = union_type.kind() {
let generic_args = self.type_visitor.specialize_generic_args(
args,
&self.type_visitor().generic_argument_map,
);
let source_field = def.all_fields().nth(*case_index).unwrap();
let source_type = self.type_visitor().specialize_generic_argument_type(
source_field.ty(self.tcx, substs),
source_field.ty(self.tcx, generic_args),
&self.type_visitor().generic_argument_map,
);
for (i, field) in def.all_fields().enumerate() {
let target_type = self.type_visitor().specialize_generic_argument_type(
field.ty(self.tcx, substs),
field.ty(self.tcx, generic_args),
&self.type_visitor().generic_argument_map,
);
let target_path =
Expand Down
67 changes: 36 additions & 31 deletions checker/src/call_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use log_derive::*;
use mirai_annotations::*;
use rustc_hir::def_id::DefId;
use rustc_middle::mir;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{Ty, TyKind, UintTy};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef, Ty, TyKind, UintTy};
use rustc_target::abi::VariantIdx;

use crate::abstract_value::{AbstractValue, AbstractValueTrait};
Expand All @@ -38,7 +37,7 @@ pub struct CallVisitor<'call, 'block, 'analysis, 'compilation, 'tcx> {
pub callee_def_id: DefId,
pub callee_func_ref: Option<Rc<FunctionReference>>,
pub callee_fun_val: Rc<AbstractValue>,
pub callee_generic_arguments: Option<SubstsRef<'tcx>>,
pub callee_generic_arguments: Option<GenericArgsRef<'tcx>>,
pub callee_known_name: KnownNames,
pub callee_generic_argument_map: Option<HashMap<rustc_span::Symbol, GenericArg<'tcx>>>,
pub unwind: mir::UnwindAction,
Expand All @@ -63,7 +62,7 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
pub(crate) fn new(
block_visitor: &'call mut BlockVisitor<'block, 'analysis, 'compilation, 'tcx>,
callee_def_id: DefId,
callee_generic_arguments: Option<SubstsRef<'tcx>>,
callee_generic_arguments: Option<GenericArgsRef<'tcx>>,
callee_generic_argument_map: Option<HashMap<rustc_span::Symbol, GenericArg<'tcx>>>,
environment_before_call: Environment,
func_const: ConstantDomain,
Expand Down Expand Up @@ -244,7 +243,7 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
let resolved_ty = tcx.type_of(resolved_def_id).skip_binder();
let resolved_map = self.type_visitor().get_generic_arguments_map(
resolved_def_id,
instance.substs,
instance.args,
&[],
);
let specialized_resolved_ty = self
Expand All @@ -260,7 +259,7 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
.visit_function_reference(
resolved_def_id,
specialized_resolved_ty,
Some(instance.substs),
Some(instance.args),
)
.clone();
self.callee_func_ref = if let ConstantDomain::Function(fr) = &func_const {
Expand All @@ -270,10 +269,10 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
None
};
self.callee_fun_val = Rc::new(func_const.into());
self.callee_generic_arguments = Some(instance.substs);
self.callee_generic_arguments = Some(instance.args);
self.callee_generic_argument_map = self.type_visitor().get_generic_arguments_map(
resolved_def_id,
instance.substs,
instance.args,
&self.actual_argument_types,
);
if has_mir && specialized_resolved_ty.is_closure() {
Expand Down Expand Up @@ -666,7 +665,7 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
fn handled_clone(&mut self) -> bool {
precondition!(self.actual_argument_types.len() == 1);
if let TyKind::Ref(_, t, _) = self.actual_argument_types[0].kind() {
if let TyKind::Adt(def, substs) = t.kind() {
if let TyKind::Adt(def, args) = t.kind() {
if def.variants().is_empty() {
return false;
}
Expand Down Expand Up @@ -707,9 +706,11 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
{
// The caller might be able to avoid the diagnostic because it
// knows the actual argument whereas here we only know the type.
let specialized_substs = self
.type_visitor()
.specialize_substs(substs, &self.callee_generic_argument_map);
let specialized_substs =
self.type_visitor().specialize_generic_args(
args,
&self.callee_generic_argument_map,
);
if !utils::are_concrete(specialized_substs) {
// The clone method will not resolve, but we don't want visit_caller
// to issue a diagnostic because is_zero might refine to true
Expand Down Expand Up @@ -1266,31 +1267,35 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>

// Get the generic argument map for the indirectly called function
let generic_arguments = match callee_ty.kind() {
TyKind::Closure(_, substs) => Some(self.type_visitor().specialize_substs(
substs.as_closure().substs,
TyKind::Closure(_, args) => Some(self.type_visitor().specialize_generic_args(
args.as_closure().args,
&self.type_visitor().generic_argument_map,
)),
TyKind::Generator(_, substs, _) => Some(self.type_visitor().specialize_substs(
substs.as_generator().substs,
TyKind::Generator(_, args, _) => Some(self.type_visitor().specialize_generic_args(
args.as_generator().args,
&self.type_visitor().generic_argument_map,
)),
TyKind::FnDef(_, substs)
| TyKind::Alias(
rustc_middle::ty::Opaque,
rustc_middle::ty::AliasTy { substs, .. },
) => Some(
self.type_visitor()
.specialize_substs(substs, &self.type_visitor().generic_argument_map),
),
_ => self.block_visitor.bv.cv.substs_cache.get(&def_id).cloned(),
TyKind::FnDef(_, args)
| TyKind::Alias(rustc_middle::ty::Opaque, rustc_middle::ty::AliasTy { args, .. }) => {
Some(
self.type_visitor().specialize_generic_args(
args,
&self.type_visitor().generic_argument_map,
),
)
}
_ => self
.block_visitor
.bv
.cv
.generic_args_cache
.get(&def_id)
.cloned(),
};

let argument_map = if let Some(substs) = generic_arguments {
self.type_visitor().get_generic_arguments_map(
def_id,
substs,
&actual_argument_types,
)
let argument_map = if let Some(args) = generic_arguments {
self.type_visitor()
.get_generic_arguments_map(def_id, args, &actual_argument_types)
} else {
None
};
Expand Down
2 changes: 1 addition & 1 deletion checker/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl MiraiCallbacks {
known_names_cache: KnownNamesCache::create_cache_from_language_items(),
options: &std::mem::take(&mut self.options),
session: compiler.session(),
substs_cache: HashMap::new(),
generic_args_cache: HashMap::new(),
summary_cache: PersistentSummaryCache::new(tcx, summary_store_path),
tcx,
test_run: self.test_run,
Expand Down
7 changes: 3 additions & 4 deletions checker/src/constant_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use serde::{Deserialize, Serialize};

use mirai_annotations::*;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_middle::ty::{GenericArgsRef, Ty, TyCtxt};

use crate::expression::{Expression, ExpressionType};
use crate::known_names::{KnownNames, KnownNamesCache};
Expand Down Expand Up @@ -114,7 +113,7 @@ impl ConstantDomain {
pub fn for_function<'a, 'tcx>(
function_id: usize,
def_id: DefId,
generic_args: Option<SubstsRef<'tcx>>,
generic_args: Option<GenericArgsRef<'tcx>>,
tcx: TyCtxt<'tcx>,
known_names_cache: &mut KnownNamesCache,
summary_cache: &mut PersistentSummaryCache<'tcx>,
Expand Down Expand Up @@ -1260,7 +1259,7 @@ impl<'tcx> ConstantValueCache<'tcx> {
&mut self,
def_id: DefId,
ty: Ty<'tcx>,
generic_args: Option<SubstsRef<'tcx>>,
generic_args: Option<GenericArgsRef<'tcx>>,
tcx: TyCtxt<'tcx>,
known_names_cache: &mut KnownNamesCache,
summary_cache: &mut PersistentSummaryCache<'tcx>,
Expand Down
5 changes: 2 additions & 3 deletions checker/src/crate_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use mirai_annotations::*;
use rustc_errors::{Diagnostic, DiagnosticBuilder};
use rustc_hir::def_id::{DefId, DefIndex};
use rustc_middle::mir;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{TyCtxt, UnevaluatedConst};
use rustc_middle::ty::{GenericArgsRef, TyCtxt, UnevaluatedConst};
use rustc_session::Session;

use crate::body_visitor::BodyVisitor;
Expand All @@ -50,10 +49,10 @@ pub struct CrateVisitor<'compilation, 'tcx> {
pub constant_value_cache: ConstantValueCache<'tcx>,
pub diagnostics_for: HashMap<DefId, Vec<DiagnosticBuilder<'compilation, ()>>>,
pub file_name: &'compilation str,
pub generic_args_cache: HashMap<DefId, GenericArgsRef<'tcx>>,
pub known_names_cache: KnownNamesCache,
pub options: &'compilation Options,
pub session: &'compilation Session,
pub substs_cache: HashMap<DefId, SubstsRef<'tcx>>,
pub summary_cache: PersistentSummaryCache<'tcx>,
pub tcx: TyCtxt<'tcx>,
pub type_cache: Rc<RefCell<TypeCache<'tcx>>>,
Expand Down
Loading

0 comments on commit 3787414

Please sign in to comment.