Skip to content
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

Encode MIR for const ctors in metadata and allow eval for them #134873

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::Ordering::Relaxed;

use either::{Left, Right};
use rustc_abi::{self as abi, BackendRepr};
use rustc_hir::def::DefKind;
use rustc_hir::def::{CtorKind, DefKind};
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
use rustc_middle::query::TyCtxtAt;
Expand Down Expand Up @@ -41,6 +41,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
| DefKind::AnonConst
| DefKind::InlineConst
| DefKind::AssocConst
| DefKind::Ctor(_, CtorKind::Const)
),
"Unexpected DefKind: {:?}",
ecx.tcx.def_kind(cid.instance.def_id())
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_const_eval::util;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::steal::Steal;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_index::IndexVec;
use rustc_middle::mir::{
Expand Down Expand Up @@ -324,7 +324,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
for item in tcx.hir_crate_items(()).free_items() {
if let DefKind::Struct | DefKind::Enum = tcx.def_kind(item.owner_id) {
for variant in tcx.adt_def(item.owner_id).variants() {
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
if let Some((_, ctor_def_id)) = variant.ctor {
set.insert(ctor_def_id.expect_local());
}
}
Expand Down
17 changes: 0 additions & 17 deletions tests/crashes/132985.rs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/crashes/auxiliary/aux132985.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui-fulldeps/stable-mir/check_item_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const CRATE_NAME: &str = "input";
/// This function uses the Stable MIR APIs to get information about the test crate.
fn test_item_kind() -> ControlFlow<()> {
let items = stable_mir::all_local_items();
assert_eq!(items.len(), 4);
assert_eq!(items.len(), 5);
// Constructor item.
for item in items {
let expected_kind = match item.name().as_str() {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/const-generics/auxiliary/xcrate-const-ctor-a.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// NOTE: This aux file inherits revisions from its parent tests.

#![feature(adt_const_params)]
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]

use std::marker::ConstParamTy;

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/const-generics/xcrate-const-ctor-b.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//@ check-pass
//@ revisions: normal mgca
//@ aux-build:xcrate-const-ctor-a.rs

#![feature(adt_const_params)]
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]

extern crate xcrate_const_ctor_a;
use xcrate_const_ctor_a::Foo;
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/stable-mir-print/operands.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) -
return;
}
}
fn Ctors::Unit() -> Ctors {
let mut _0: Ctors;
bb0: {
_0 = Ctors::Unit;
return;
}
}
fn Ctors::TupLike(_1: bool) -> Ctors {
let mut _0: Ctors;
bb0: {
Expand Down
Loading