Skip to content

Do not expect infer/bound/placeholder/error in v0 symbol mangling #130485

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

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
46 changes: 30 additions & 16 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
ty::Float(FloatTy::F128) => "C4f128",
ty::Never => "z",

// Placeholders (should be demangled as `_`).
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => "p",
// Should only be encountered with polymorphization,
// or within the identity-substituted impl header of an
// item nested within an impl item.
ty::Param(_) => "p",

ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => bug!(),

_ => "",
};
Expand Down Expand Up @@ -416,12 +420,18 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
// Mangle all nominal types as paths.
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
| ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args)
| ty::CoroutineClosure(def_id, args)
| ty::Coroutine(def_id, args) => {
self.print_def_path(def_id, args)?;
}

// We may still encounter projections here due to the printing
// logic sometimes passing identity-substituted impl headers.
ty::Alias(ty::Projection, ty::AliasTy { def_id, args, .. }) => {
self.print_def_path(def_id, args)?;
}

ty::Foreign(def_id) => {
self.print_def_path(def_id, &[])?;
}
Expand Down Expand Up @@ -467,8 +477,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
r.print(self)?;
}

ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"),
ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"),
ty::Alias(..) => bug!("symbol_names: unexpected alias"),
ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"),
}

Expand Down Expand Up @@ -550,21 +559,26 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
let (ct_ty, valtree) = match ct.kind() {
ty::ConstKind::Value(ty, val) => (ty, val),

// Placeholders (should be demangled as `_`).
// NOTE(eddyb) despite `Unevaluated` having a `DefId` (and therefore
// a path), even for it we still need to encode a placeholder, as
// the path could refer back to e.g. an `impl` using the constant.
ty::ConstKind::Unevaluated(_)
| ty::ConstKind::Expr(_)
| ty::ConstKind::Param(_)
| ty::ConstKind::Infer(_)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(_)
| ty::ConstKind::Error(_) => {
// Should only be encountered with polymorphization,
// or within the identity-substituted impl header of an
// item nested within an impl item.
ty::ConstKind::Param(_) => {
// Never cached (single-character).
self.push("p");
return Ok(());
}

// We may still encounter unevaluated consts due to the printing
// logic sometimes passing identity-substituted impl headers.
ty::Unevaluated(ty::UnevaluatedConst { def, args, .. }) => {
return self.print_def_path(def, args);
}

ty::ConstKind::Expr(_)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should either be normalized (expr), unconstructable (infer/placeholder), unreachable (bound) or already dealt with (error).

| ty::ConstKind::Infer(_)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(_)
| ty::ConstKind::Error(_) => bug!(),
};

if let Some(&i) = self.consts.get(&ct) {
Expand Down
Loading