Skip to content

Commit

Permalink
Fix compilation after changes to trait and run
Browse files Browse the repository at this point in the history
The following PRs needed to be addressed:
  - rust-lang/rust#119833
  - rust-lang/rust#119790

Note that the rustc tests are no longer passing, but the failures
are unrelated to these changes and need further investigation.
  • Loading branch information
celinval committed Jan 22, 2024
1 parent 8ec26c6 commit d8c4e6e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/scripts/run_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ function run_tests() {
--target=${HOST} \
--llvm-filecheck="${FILE_CHECK}" \
--channel=nightly \
--git-repository="rust-lang/project-stable-mir" \
--nightly-branch="main" \
--target-rustcflags="--smir-check" \
--host-rustcflags="--smir-check"
done
Expand Down
2 changes: 0 additions & 2 deletions tests/fixme/associated-items/methods.stderr

This file was deleted.

File renamed without changes.
12 changes: 10 additions & 2 deletions tools/test-drive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ description = "A rustc wrapper that can be used to test stable-mir on a crate"
version = "0.0.0"
edition = "2021"

[dependencies]

[package.metadata.rust-analyzer]
# This crate uses #[feature(rustc_private)].
# See https://github.com/rust-analyzer/rust-analyzer/pull/7891
rustc_private = true

[features]
clion = ["rustc_smir", "stable_mir"]

[target.'cfg(unix)'.dependencies]
# Adjust the path here to point to a local copy of the rust compiler.
# The best way is to use the rustup path. Replace <toolchain> with the
# proper name to your toolchain.
rustc_smir = { path = "/home/ANT.AMAZON.COM/celinval/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/rustc_smir", optional = true}
stable_mir = { path = "/home/ANT.AMAZON.COM/celinval/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/stable_mir", optional = true}
10 changes: 4 additions & 6 deletions tools/test-drive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

#![feature(rustc_private)]
#![feature(assert_matches)]
#![feature(result_option_inspect)]

mod sanity_checks;

extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_middle;
#[macro_use]
extern crate rustc_smir;
extern crate stable_mir;

use rustc_middle::ty::TyCtxt;
use rustc_smir::{run, rustc_internal};
use stable_mir::CompilerError;
use std::ops::ControlFlow;
Expand Down Expand Up @@ -50,9 +48,9 @@ fn main() -> ExitCode {
smir_args.contains(&FIXME_ARG.to_string()),
Ordering::Relaxed,
);
run!(rustc_args, tcx, test_stable_mir(tcx))
run!(rustc_args, test_stable_mir)
} else {
run!(rustc_args, ControlFlow::<()>::Continue(()))
run!(rustc_args, || ControlFlow::<()>::Continue(()))
};
if result.is_ok() || matches!(result, Err(CompilerError::Skipped)) {
ExitCode::SUCCESS
Expand All @@ -78,7 +76,7 @@ fn info(msg: String) {

/// This function invoke other tests and process their results.
/// Tests should avoid panic,
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
fn test_stable_mir() -> ControlFlow<()> {
let mut results = Vec::from(run_tests![
sanity_checks::test_entry_fn,
sanity_checks::test_all_fns,
Expand Down
19 changes: 4 additions & 15 deletions tools/test-drive/src/sanity_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! These checks should only depend on StableMIR APIs. See other modules for tests that compare
//! the result between StableMIR and internal APIs.
use crate::TestResult;
use stable_mir::ty::{ImplDef, TraitDef};
use stable_mir::{self, mir, mir::MirVisitor, ty, CrateDef};
use std::collections::HashSet;
use std::fmt::Debug;
Expand Down Expand Up @@ -60,24 +61,12 @@ pub fn test_all_fns() -> TestResult {
Ok(())
}

/// Using these structures will always follow calls to get more details about those structures.
/// Unless user is trying to find a specific type, this will get repetitive.
/// Test that we can retrieve information about the trait declaration for every trait implementation.
pub fn test_traits() -> TestResult {
// FIXME: All trait declarations only return local traits.
// See https://github.com/rust-lang/project-stable-mir/issues/37
let all_traits = stable_mir::all_trait_decls();
for trait_decl in all_traits.iter().map(stable_mir::trait_decl) {
// Can't compare trait_decl, so just compare a field for now.
check_equal(
stable_mir::trait_decl(&trait_decl.def_id).specialization_kind,
trait_decl.specialization_kind,
"external crate mismatch",
)?;
}

let all_traits = HashSet::<TraitDef>::from_iter(stable_mir::all_trait_decls().into_iter());
for trait_impl in stable_mir::all_trait_impls()
.iter()
.map(stable_mir::trait_impl)
.map(ImplDef::trait_impl)
{
check(
all_traits.contains(&trait_impl.value.def_id),
Expand Down

0 comments on commit d8c4e6e

Please sign in to comment.