Misc fixes (pattern type lowering, cfi, pretty printing)

This commit is contained in:
Boxy 2024-06-03 03:38:09 +01:00
parent a454da3b1c
commit 56092a345b
4 changed files with 36 additions and 40 deletions

View File

@ -2160,17 +2160,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
_ => (expr, None),
};
let c = match &expr.kind {
let (c, c_ty) = match &expr.kind {
hir::ExprKind::Lit(lit) => {
let lit_input =
LitToConstInput { lit: &lit.node, ty, neg: neg.is_some() };
match tcx.lit_to_const(lit_input) {
let ct = match tcx.lit_to_const(lit_input) {
Ok(c) => c,
Err(LitToConstError::Reported(err)) => {
ty::Const::new_error(tcx, err)
}
Err(LitToConstError::TypeError) => todo!(),
}
};
(ct, ty)
}
hir::ExprKind::Path(hir::QPath::Resolved(
@ -2188,20 +2189,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.type_of(def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic");
self.lower_const_param(expr.hir_id)
let ct = self.lower_const_param(expr.hir_id);
(ct, ty)
}
_ => {
let err = tcx
.dcx()
.emit_err(crate::errors::NonConstRange { span: expr.span });
ty::Const::new_error(tcx, err)
(ty::Const::new_error(tcx, err), Ty::new_error(tcx, err))
}
};
// THISPR
self.record_ty(expr.hir_id, todo!(), expr.span);
self.record_ty(expr.hir_id, c_ty, expr.span);
if let Some((id, span)) = neg {
self.record_ty(id, todo!(), span);
self.record_ty(id, c_ty, span);
}
c
};

View File

@ -143,10 +143,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// `trait_object_dummy_self`, so check for that.
let references_self = match pred.skip_binder().term.unpack() {
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
ty::TermKind::Const(c) => {
// THISPR
false
}
// FIXME(associated_const_equality): We should walk the const instead of not doing anything
ty::TermKind::Const(_) => false,
};
// If the projection output contains `Self`, force the user to

View File

@ -1459,23 +1459,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
return Ok(());
}
macro_rules! print_underscore {
() => {{
if print_ty {
self.typed_value(
|this| {
write!(this, "_")?;
Ok(())
},
|this| this.print_type(todo!()),
": ",
)?;
} else {
write!(self, "_")?;
}
}};
}
match ct.kind() {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
match self.tcx().def_kind(def) {
@ -1508,7 +1491,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::InferConst::Var(ct_vid) if let Some(name) = self.const_infer_name(ct_vid) => {
p!(write("{}", name))
}
_ => print_underscore!(),
_ => write!(self, "_")?,
},
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
ty::ConstKind::Value(ty, value) => {

View File

@ -68,6 +68,8 @@ fn compress<'tcx>(
fn encode_args<'tcx>(
tcx: TyCtxt<'tcx>,
args: GenericArgsRef<'tcx>,
for_def: DefId,
has_erased_self: bool,
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
options: EncodeTyOptions,
) -> String {
@ -76,7 +78,8 @@ fn encode_args<'tcx>(
let args: Vec<GenericArg<'_>> = args.iter().collect();
if !args.is_empty() {
s.push('I');
for arg in args {
let def_generics = tcx.generics_of(for_def);
for (n, arg) in args.iter().enumerate() {
match arg.unpack() {
GenericArgKind::Lifetime(region) => {
s.push_str(&encode_region(region, dict));
@ -85,7 +88,10 @@ fn encode_args<'tcx>(
s.push_str(&encode_ty(tcx, ty, dict, options));
}
GenericArgKind::Const(c) => {
s.push_str(&encode_const(tcx, c, dict, options));
let n = n + (has_erased_self as usize);
let ct_ty =
tcx.type_of(def_generics.param_at(n, tcx).def_id).instantiate_identity();
s.push_str(&encode_const(tcx, c, ct_ty, dict, options));
}
}
}
@ -99,6 +105,7 @@ fn encode_args<'tcx>(
fn encode_const<'tcx>(
tcx: TyCtxt<'tcx>,
c: Const<'tcx>,
ct_ty: Ty<'tcx>,
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
options: EncodeTyOptions,
) -> String {
@ -111,8 +118,7 @@ fn encode_const<'tcx>(
// L<element-type>E as literal argument
// Element type
// THISPR
s.push_str(&encode_ty(tcx, todo!(), dict, options));
s.push_str(&encode_ty(tcx, ct_ty, dict, options));
}
// Literal arguments
@ -232,15 +238,21 @@ fn encode_predicate<'tcx>(
ty::ExistentialPredicate::Trait(trait_ref) => {
let name = encode_ty_name(tcx, trait_ref.def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
s.push_str(&encode_args(tcx, trait_ref.args, dict, options));
s.push_str(&encode_args(tcx, trait_ref.args, trait_ref.def_id, true, dict, options));
}
ty::ExistentialPredicate::Projection(projection) => {
let name = encode_ty_name(tcx, projection.def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
s.push_str(&encode_args(tcx, projection.args, dict, options));
s.push_str(&encode_args(tcx, projection.args, projection.def_id, true, dict, options));
match projection.term.unpack() {
TermKind::Ty(ty) => s.push_str(&encode_ty(tcx, ty, dict, options)),
TermKind::Const(c) => s.push_str(&encode_const(tcx, c, dict, options)),
TermKind::Const(c) => s.push_str(&encode_const(
tcx,
c,
tcx.type_of(projection.def_id).instantiate(tcx, projection.args),
dict,
options,
)),
}
}
ty::ExistentialPredicate::AutoTrait(def_id) => {
@ -486,7 +498,7 @@ pub fn encode_ty<'tcx>(
// <subst>, as vendor extended type.
let name = encode_ty_name(tcx, def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
s.push_str(&encode_args(tcx, args, dict, options));
s.push_str(&encode_args(tcx, args, def_id, false, dict, options));
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
}
typeid.push_str(&s);
@ -530,7 +542,7 @@ pub fn encode_ty<'tcx>(
let mut s = String::new();
let name = encode_ty_name(tcx, *def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
s.push_str(&encode_args(tcx, args, dict, options));
s.push_str(&encode_args(tcx, args, *def_id, false, dict, options));
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
typeid.push_str(&s);
}
@ -542,7 +554,7 @@ pub fn encode_ty<'tcx>(
let name = encode_ty_name(tcx, *def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
let parent_args = tcx.mk_args(args.as_coroutine_closure().parent_args());
s.push_str(&encode_args(tcx, parent_args, dict, options));
s.push_str(&encode_args(tcx, parent_args, *def_id, false, dict, options));
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
typeid.push_str(&s);
}
@ -557,6 +569,8 @@ pub fn encode_ty<'tcx>(
s.push_str(&encode_args(
tcx,
tcx.mk_args(args.as_coroutine().parent_args()),
*def_id,
false,
dict,
options,
));