1
Fork 0

Auto merge of #82936 - oli-obk:valtree, r=RalfJung,lcnr,matthewjasper

Implement (but don't use) valtree and refactor in preparation of use

This PR does not cause any functional change. It refactors various things that are needed to make valtrees possible. This refactoring got big enough that I decided I'd want it reviewed as a PR instead of trying to make one huge PR with all the changes.

cc `@rust-lang/wg-const-eval` on the following commits:

* 2027184 implement valtree
* eeecea9 fallible Scalar -> ScalarInt
* 042f663 ScalarInt convenience methods

cc `@eddyb` on ef04a6d

cc `@rust-lang/wg-mir-opt` for cf1700c (`mir::Constant` can now represent either a `ConstValue` or a `ty::Const`, and it is totally possible to have two different representations for the same value)
This commit is contained in:
bors 2021-03-16 22:42:56 +00:00
commit e655fb6221
56 changed files with 783 additions and 331 deletions

View file

@ -68,7 +68,7 @@ impl<'tcx> CFG<'tcx> {
Rvalue::Use(Operand::Constant(box Constant {
span: source_info.span,
user_ty: None,
literal: ty::Const::zero_sized(tcx, tcx.types.unit),
literal: ty::Const::zero_sized(tcx, tcx.types.unit).into(),
})),
);
}

View file

@ -11,7 +11,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> {
let this = self;
let Expr { ty, temp_lifetime: _, span, ref kind } = *expr;
match kind {
match *kind {
ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(value),
ExprKind::Literal { literal, user_ty, const_id: _ } => {
let user_ty = user_ty.map(|user_ty| {
@ -22,11 +22,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
});
assert_eq!(literal.ty, ty);
Constant { span, user_ty, literal }
Constant { span, user_ty, literal: literal.into() }
}
ExprKind::StaticRef { literal, .. } => {
Constant { span, user_ty: None, literal: literal.into() }
}
ExprKind::StaticRef { literal, .. } => Constant { span, user_ty: None, literal },
ExprKind::ConstBlock { value } => {
Constant { span: span, user_ty: None, literal: value }
Constant { span: span, user_ty: None, literal: value.into() }
}
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
}

View file

@ -255,7 +255,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(Rvalue::Use(Operand::Constant(box Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::zero_sized(this.tcx, this.tcx.types.unit),
literal: ty::Const::zero_sized(this.tcx, this.tcx.types.unit).into(),
})))
}
ExprKind::Yield { .. }

View file

@ -146,7 +146,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::from_bool(this.tcx, true),
literal: ty::Const::from_bool(this.tcx, true).into(),
},
);
@ -157,7 +157,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::from_bool(this.tcx, false),
literal: ty::Const::from_bool(this.tcx, false).into(),
},
);

View file

@ -438,7 +438,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Need to experiment.
user_ty: None,
literal: method,
literal: method.into(),
}),
args: vec![val, expect],
destination: Some((eq_result, eq_block)),

View file

@ -30,6 +30,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: Span,
literal: &'tcx ty::Const<'tcx>,
) -> Operand<'tcx> {
let literal = literal.into();
let constant = box Constant { span, user_ty: None, literal };
Operand::Constant(constant)
}
@ -57,7 +58,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: source_info.span,
user_ty: None,
literal: ty::Const::from_usize(self.tcx, value),
literal: ty::Const::from_usize(self.tcx, value).into(),
},
);
temp

View file

@ -68,11 +68,11 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
// FIXME(#31407) this is only necessary because float parsing is buggy
self.tcx.sess.span_err(sp, "could not evaluate float literal (see issue #31407)");
// create a dummy value and continue compiling
Const::from_bits(self.tcx, 0, self.param_env.and(ty))
self.tcx.const_error(ty)
}
Err(LitToConstError::Reported) => {
// create a dummy value and continue compiling
Const::from_bits(self.tcx, 0, self.param_env.and(ty))
self.tcx.const_error(ty)
}
Err(LitToConstError::TypeError) => bug!("const_eval_literal: had type error"),
}