Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the struct ParamTy #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
match predicate.self_ty().kind() {
ty::Param(param_ty) => Ok((
generics.type_param(param_ty, tcx),
generics.type_param(*param_ty, tcx),
predicate.trait_ref.print_only_trait_path().to_string(),
)),
ty::HKT(_param_ty, ..) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_middle::mir;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty, HKT,
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty, HKT, TypeParameter
};
use rustc_middle::ty::{Binder, TraitRef};
use rustc_session::parse::feature_err;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_middle::middle::stability::EvalResult;
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeParameter};
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
use rustc_span::symbol::sym;
use rustc_span::{self, Span};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor;
use rustc_index::bit_set::BitSet;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter};
use rustc_middle::ty::{InternalSubsts, SubstsRef};
use rustc_session::parse::feature_err;
use rustc_span::source_map::DUMMY_SP;
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{
self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
TypeVisitable, TypeVisitor,
};
use rustc_middle::ty::{self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeParameter, TypeSuperVisitable, TypeVisitable, TypeVisitor};
use rustc_middle::ty::{GenericArgKind, InternalSubsts};
use rustc_session::parse::feature_err;
use rustc_span::symbol::{sym, Ident, Symbol};
Expand Down Expand Up @@ -592,7 +589,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
// `Self` in the GAT.
let ty_param = gat_generics.param_at(*ty_idx, tcx);
let ty_param = tcx
.mk_ty(ty::Param(ty::ParamTy::Param { index: ty_param.index, name: ty_param.name }));
.mk_ty(ty::Param(ty::ParamTy::new(ty_param.index, ty_param.name)));
// Same for the region. In our example, 'a corresponds
// to the 'me parameter.
let region_param = gat_generics.param_at(*region_a_idx, tcx);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeNa
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_lifetime::*;
use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor};
use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor, TypeParameter};
use rustc_span::def_id::DefId;
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{ArgumentDef, GenericParamDefKind, ParamEnv, ToPredicate};
use rustc_middle::ty::{ArgumentDef, GenericParamDefKind, ParamEnv, ToPredicate, TypeParameter};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::symbol::{sym, Ident};
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -208,7 +208,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
GenericParamKind::Lifetime { .. } => (),
GenericParamKind::Type { .. } => {
let name = param.name.ident().name;
let param_ty = ty::ParamTy::new_param(index, name).to_ty(tcx);
let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
index += 1;

let mut bounds = Bounds::default();
Expand All @@ -230,8 +230,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
}
GenericParamKind::HKT(..) => {
let name = param.name.ident().name;
let param_ty = ty::ParamTy::new_hkt(param.def_id.to_def_id(), index, name).to_ty(tcx);

let param_ty = ty::HKTTy::new(param.def_id.to_def_id(), index, name).to_ty(tcx);

let mut bounds = Bounds::default();
// Params are implicitly sized unless a `?Sized` bound is found
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter};
use rustc_span::source_map::Span;
use std::ops::ControlFlow;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_errors::struct_span_err;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
use rustc_middle::ty::{self, TyCtxt, TypeParameter, TypeVisitable};
use rustc_span::{Span, Symbol};

mod min_specialization;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeParameter};
use rustc_span::Span;
use smallvec::smallvec;
use std::collections::BTreeMap;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use hir::def_id::{DefId, LocalDefId};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter};

use super::terms::VarianceTerm::*;
use super::terms::*;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

fn point_at_param_definition(&self, err: &mut Diagnostic, param: ty::ParamTy) {
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
let generic_param = generics.type_param(&param, self.tcx);
let generic_param = generics.type_param(param, self.tcx);
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
return;
}
Expand Down
25 changes: 17 additions & 8 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_infer::infer::InferOk;
use rustc_infer::infer::TypeTrace;
use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor};
use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeParameter, TypeParamResult, TypeSuperVisitable, TypeVisitor};
use rustc_session::Session;
use rustc_span::symbol::{kw, Ident};
use rustc_span::{self, sym, Span};
Expand Down Expand Up @@ -1790,18 +1790,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => ty::List::empty(),
};

let find_param_matching = |matches: &dyn Fn(&ty::ParamTy) -> bool| {
let find_param_matching = |matches: &dyn Fn(&TypeParamResult) -> bool| {
predicate_substs.types().find_map(|ty| {
ty.walk().find_map(|arg| {
// TODO(hoch)
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Param(param_ty) = ty.kind()
&& matches(param_ty)
&& matches(&TypeParamResult::Param(*param_ty))
{
Some(arg)
} else if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::HKT(_, param_ty, ..) = ty.kind()
&& matches(param_ty)
&& matches(&TypeParamResult::HKT(*param_ty))
{
todo!("hoch")
} else {
Expand All @@ -1815,13 +1815,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Prefer generics that are local to the fn item, since these are likely
// to be the cause of the unsatisfied predicate.
let mut param_to_point_at = find_param_matching(&|param_ty| {
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) == def_id
match param_ty {
TypeParamResult::Param(p) => self.tcx.parent(generics.type_param(*p, self.tcx).def_id) == def_id,
TypeParamResult::HKT(h) => self.tcx.parent(generics.type_param(*h, self.tcx).def_id) == def_id
}

});
// Fall back to generic that isn't local to the fn item. This will come
// from a trait or impl, for example.
let mut fallback_param_to_point_at = find_param_matching(&|param_ty| {
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) != def_id
&& param_ty.name() != rustc_span::symbol::kw::SelfUpper
match param_ty {
TypeParamResult::Param(p) => self.tcx.parent(generics.type_param(*p, self.tcx).def_id) != def_id
&& p.name() != rustc_span::symbol::kw::SelfUpper,
TypeParamResult::HKT(h) => self.tcx.parent(generics.type_param(*h, self.tcx).def_id) != def_id
&& h.name() != rustc_span::symbol::kw::SelfUpper
}

});
// Finally, the `Self` parameter is possibly the reason that the predicate
// is unsatisfied. This is less likely to be true for methods, because
Expand Down Expand Up @@ -2155,7 +2164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ty::Param(ref param) => {
let param =
self.tcx.generics_of(self.body_id.owner).type_param(param, self.tcx);
self.tcx.generics_of(self.body_id.owner).type_param(*param, self.tcx);
if param.kind.is_synthetic() {
// if it's `impl Fn() -> ..` then just fall down to the def-id based logic
def_id = param.def_id;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_infer::traits::{self, StatementAsExpression};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{
self, suggest_constraining_type_params, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty,
TypeVisitable,
TypeVisitable, TypeParameter
};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned;
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
}
ty::Param(ref param) => {
let def_id = self.tcx.generics_of(self.body_id.owner).type_param(param, self.tcx).def_id;
let def_id = self.tcx.generics_of(self.body_id.owner).type_param(*param, self.tcx).def_id;
self.tcx.predicates_of(self.body_id.owner).predicates.iter().find_map(|(pred, _)| {
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
Expand Down
21 changes: 14 additions & 7 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::middle::stability;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::AssocItem;
use rustc_middle::ty::{AssocItem, TypeParamResult};
use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitable};
Expand Down Expand Up @@ -680,10 +680,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}
ty::Param(ref p) => {
self.assemble_inherent_candidates_from_param(p.clone());
self.assemble_inherent_candidates_from_param(TypeParamResult::Param(p.clone()));
}
ty::HKT(_, ref p, ..) => {
self.assemble_inherent_candidates_from_param(p.clone());
self.assemble_inherent_candidates_from_param(TypeParamResult::HKT(p.clone()));
}
ty::Bool
| ty::Char
Expand Down Expand Up @@ -812,19 +812,26 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
});
}

fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
fn assemble_inherent_candidates_from_param(&mut self, param_ty: TypeParamResult) {
// FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
match param_ty {
TypeParamResult::Param(p) => {
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", p);
}
TypeParamResult::HKT(h) => {
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", h);
}
}

let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
match *trait_predicate.trait_ref.self_ty().kind() {
ty::Param(ref p) if p.clone() == param_ty => {
ty::Param(ref p) if let TypeParamResult::Param(param) = param_ty && p.clone() == param => {
Some(bound_predicate.rebind(trait_predicate.trait_ref))
}
ty::HKT(_, ref p, ..) if p.clone() == param_ty => {
ty::HKT(_, ref p, ..) if let TypeParamResult::HKT(param) = param_ty && p.clone() == param => {
// TODO(hoch)
Some(bound_predicate.rebind(trait_predicate.trait_ref))
}
Expand Down
Loading