8000 Use explicit promotion for constants in repeat expressions by oli-obk · Pull Request #70042 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Use explicit promotion for constants in repeat expressions #70042

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

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Use ConstCx for validate_candidates
  • Loading branch information
oli-obk committed Apr 2, 2020
commit 29aebf498dff698dd20f37e0f2fccf7bcc01bde5
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// be mentioned, need to check if the rvalue is promotable.
let should_suggest =
should_suggest_const_in_array_repeat_expressions_attribute(
ccx, operand,
&ccx, operand,
);
debug!("check_rvalue: should_suggest={:?}", should_suggest);

Expand Down
17 changes: 7 additions & 10 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {

let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);

let promotable_candidates =
validate_candidates(tcx, read_only_body, def_id, &temps, &all_candidates);
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);

let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates);
self.promoted_fragments.set(promoted);
Expand Down Expand Up @@ -267,7 +266,7 @@ pub fn collect_temps_and_candidates(
///
/// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion.
struct Validator<'a, 'tcx> {
ccx: ConstCx<'a, 'tcx>,
ccx: &'a ConstCx<'a, 'tcx>,
temps: &'a IndexVec<Local, TempState>,

/// Explicit promotion happens e.g. for constant arguments declared via
Expand Down Expand Up @@ -720,13 +719,11 @@ impl<'tcx> Validator<'_, 'tcx> {

// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
pub fn validate_candidates(
tcx: TyCtxt<'tcx>,
body: ReadOnlyBodyAndCache<'_, 'tcx>,
def_id: DefId,
ccx: &ConstCx<'_, '_>,
temps: &IndexVec<Local, TempState>,
candidates: &[Candidate],
) -> Vec<Candidate> {
let mut validator = Validator { ccx: ConstCx::new(tcx, def_id, body), temps, explicit: false };
let mut validator = Validator { ccx, temps, explicit: false };

candidates
.iter()
Expand All @@ -740,9 +737,9 @@ pub fn validate_candidates(
let is_promotable = validator.validate_candidate(candidate).is_ok();
match candidate {
Candidate::Argument { bb, index } if !is_promotable => {
let span = body[bb].terminator().source_info.span;
let span = ccx.body[bb].terminator().source_info.span;
let msg = format!("argument {} is required to be a constant", index + 1);
tcx.sess.span_err(span, &msg);
ccx.tcx.sess.span_err(span, &msg);
}
_ => (),
}
Expand Down Expand Up @@ -1155,7 +1152,7 @@ pub fn promote_candidates<'tcx>(
/// Feature attribute should be suggested if `operand` can be promoted and the feature is not
/// enabled.
crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>(
ccx: ConstCx<'_, 'tcx>,
ccx: &ConstCx<'_, 'tcx>,
operand: &Operand<'tcx>,
) -> bool {
let mut rpo = traversal::reverse_postorder(&ccx.body);
Expand Down
0