Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkov
Use AnonConst for asm! constants This replaces the old system which used explicit promotion. See #83169 for more background. The syntax for `const` operands is still the same as before: `const <expr>`. Fixes #83169 Because the implementation is heavily based on inline consts, we suffer from the same issues: - We lose the ability to use expressions derived from generics. See the deleted tests in `src/test/ui/asm/const.rs`. - We are hitting the same ICEs as inline consts, for example #78174. It is unlikely that we will be able to stabilize this before inline consts are stabilized.
This commit is contained in:
commit
b81c6cdb57
37 changed files with 281 additions and 242 deletions
|
@ -2087,7 +2087,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>) -> Ty<'tcx> {
|
||||
for (op, _op_sp) in asm.operands {
|
||||
match op {
|
||||
hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Const { expr } => {
|
||||
hir::InlineAsmOperand::In { expr, .. } => {
|
||||
self.check_expr_asm_operand(expr, true);
|
||||
}
|
||||
hir::InlineAsmOperand::Out { expr, .. } => {
|
||||
|
@ -2104,6 +2104,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
self.check_expr_asm_operand(out_expr, false);
|
||||
}
|
||||
}
|
||||
hir::InlineAsmOperand::Const { anon_const } => {
|
||||
self.to_const(anon_const);
|
||||
}
|
||||
hir::InlineAsmOperand::Sym { expr } => {
|
||||
self.check_expr(expr);
|
||||
}
|
||||
|
|
|
@ -540,6 +540,19 @@ fn typeck_with_fallback<'tcx>(
|
|||
kind: TypeVariableOriginKind::TypeInference,
|
||||
span,
|
||||
}),
|
||||
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(ia), .. })
|
||||
if ia.operands.iter().any(|(op, _op_sp)| match op {
|
||||
hir::InlineAsmOperand::Const { anon_const } => {
|
||||
anon_const.hir_id == id
|
||||
}
|
||||
_ => false,
|
||||
}) =>
|
||||
{
|
||||
fcx.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
span,
|
||||
})
|
||||
}
|
||||
_ => fallback(),
|
||||
},
|
||||
_ => fallback(),
|
||||
|
|
|
@ -430,6 +430,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
tcx.typeck(def_id).node_type(anon_const.hir_id)
|
||||
}
|
||||
|
||||
Node::Expr(&Expr { kind: ExprKind::InlineAsm(ia), .. })
|
||||
if ia.operands.iter().any(|(op, _op_sp)| match op {
|
||||
hir::InlineAsmOperand::Const { anon_const } => anon_const.hir_id == hir_id,
|
||||
_ => false,
|
||||
}) =>
|
||||
{
|
||||
tcx.typeck(def_id).node_type(hir_id)
|
||||
}
|
||||
|
||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
|
||||
.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id())
|
||||
.repr
|
||||
|
|
|
@ -318,7 +318,6 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
for (op, _op_sp) in asm.operands {
|
||||
match op {
|
||||
hir::InlineAsmOperand::In { expr, .. }
|
||||
| hir::InlineAsmOperand::Const { expr, .. }
|
||||
| hir::InlineAsmOperand::Sym { expr, .. } => self.consume_expr(expr),
|
||||
hir::InlineAsmOperand::Out { expr, .. } => {
|
||||
if let Some(expr) = expr {
|
||||
|
@ -334,6 +333,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
self.mutate_expr(out_expr);
|
||||
}
|
||||
}
|
||||
hir::InlineAsmOperand::Const { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue