From 3f81b13ea371d452ddf3921647243453bc5bf251 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 27 Jun 2023 13:21:38 +0200 Subject: [PATCH 1/4] anyhow: Use `backtrace` feature --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4bb24d23..59b00c34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ edition = "2021" name = "testsuite-adaptor" version = "0.1.0" [dependencies] -anyhow = "1.0" +anyhow = { version = "1.0", features = ["backtrace"] } colored = "2.0" rayon = "1.5" structopt = "0.3" From 74d22aedfe86b7a61a11603f940e6a0896ce6275 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 27 Jun 2023 13:21:53 +0200 Subject: [PATCH 2/4] ci: Add `ast-export` back to the nightly runs --- .github/workflows/nightly_run.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 8fcb8034..b69debd1 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -11,7 +11,7 @@ jobs: container: philberty/gccrs:latest strategy: matrix: - testsuite: [rustc-dejagnu, gccrs-parsing, gccrs-rustc-success, gccrs-rustc-success-no-std, gccrs-rustc-success-no-core, blake3, libcore] + testsuite: [rustc-dejagnu, gccrs-parsing, gccrs-rustc-success, gccrs-rustc-success-no-std, gccrs-rustc-success-no-core, blake3, libcore, ast-export] # testsuite: [blake3] steps: - name: Fetch dependencies From fc4a2b52fd7b192e5c96e08c7da4e90d2ce73e5c Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 27 Jun 2023 13:22:33 +0200 Subject: [PATCH 3/4] ast-export: Remove `AstExport::Run` pass --- src/passes/ast_export.rs | 105 +++++++-------------------------------- 1 file changed, 18 insertions(+), 87 deletions(-) diff --git a/src/passes/ast_export.rs b/src/passes/ast_export.rs index 23a6e368..1aca4791 100644 --- a/src/passes/ast_export.rs +++ b/src/passes/ast_export.rs @@ -1,9 +1,5 @@ use std::fs; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; -use std::time::Duration; - -use wait_timeout::ChildExt; use crate::args::Args; use crate::compiler::{Compiler, Kind}; @@ -23,84 +19,31 @@ fn get_original_file_from_pretty(pretty_file: &Path) -> PathBuf { fn adapt_compilation(args: &Args, pretty_file: &Path) -> Result { let original_file = get_original_file_from_pretty(pretty_file); - let is_valid = Compiler::new(Kind::Rust1, args) + let is_valid = Compiler::new(Kind::Crab1, args) .command() .arg(original_file.as_os_str()) .status()? .success(); - let test_case = TestCase::from_compiler(Compiler::new(Kind::Rust1, args)) - .with_name(format!("Compile prettified `{}`", original_file.display())) - .with_exit_code(u8::from(!is_valid)) - .with_arg(pretty_file.display()); + // what we want to do is: + // if the file compiles, then we want its prettified version to compile as well + // if the file does not compile, then we want the same errors as the original on the prettified file + // but this is waaaaay harder to do :( and probably not worth it - Ok(test_case) -} - -fn adapt_run(args: &Args, pretty_file: &Path) -> Result { - let original_file = get_original_file_from_pretty(pretty_file); - let binary_name = original_file.with_extension(""); - - // Build the original binary - if !Compiler::new(Kind::Rust1, args) - .command() - .arg(original_file.as_os_str()) - .arg("-o") - .arg(binary_name.as_os_str()) - .status()? - .success() - { - // This will be handled by the `AstExport::Compile` part - return Ok(TestCase::Skip); - } - - let mut child = Command::new(binary_name.as_os_str()) - .stderr(Stdio::null()) - .stdout(Stdio::null()) - .spawn()?; - - // Run the original binary - let binary_exit_code = if let Some(exit_status) = child.wait_timeout(Duration::from_secs(5))? { - exit_status.code() + let test_case = if is_valid { + TestCase::from_compiler(Compiler::new(Kind::Crab1, args)) + .with_name(format!("Compile prettified `{}`", original_file.display())) + .with_exit_code(0) + .with_arg(pretty_file.display()) } else { - child.kill()?; - return Ok(TestCase::Skip); + TestCase::Skip }; - match binary_exit_code { - None => Ok(TestCase::Skip), - Some(code) => { - let binary_name = binary_name.with_extension("pretty"); - // We now build the "prettified binary". If that fails, skip it as that's been handled by the `Compile` phase - if !Compiler::new(Kind::Rust1, args) - .command() - .arg(pretty_file) - .arg("-o") - .arg(binary_name.as_os_str()) - .status()? - .success() - { - return Ok(TestCase::Skip); - } - - // TODO: Should we also check that the output is the same? - // TODO: Maybe just for stdout but not stderr as we do not guarantee the same exact output? So location info might be different - let test_case = TestCase::default() - .with_name(format!( - "Run prettified binary from `{}`", - original_file.display() - )) - .with_binary(binary_name.display()) - .with_exit_code(u8::try_from(code)?); - - Ok(test_case) - } - } + Ok(test_case) } pub enum AstExport { Compile, - Run, } impl Pass for AstExport { @@ -109,19 +52,10 @@ impl Pass for AstExport { let tests_path = gccrs_path.join("gcc").join("testsuite").join("rust"); let output_dir = args.output_dir.join("ast-export"); - // Figure out a nice way to cache things since we don't need to do the copy twice - // if let AstExport::Run = self { - // // The copies are already created in the `Compile` phase - // return Ok(fetch_rust_files(&output_dir) - // .into_iter() - // .map(|entry| entry.path().to_owned()) - // .collect()); - // } - // For each file: // gccrs -frust-dump-ast-pretty // cp gccrs.ast-pretty.dump - let new_files = fetch_rust_files(&tests_path) + fetch_rust_files(&tests_path) // FIXME: Cannot parallelize this since the AST dump is always the same file... // Think about -frust-dump-ast-pretty=? .into_iter() @@ -129,17 +63,17 @@ impl Pass for AstExport { let new_path_original = output_dir.join(entry.path()); let new_path = output_dir.join(entry.path()).with_extension("pretty-rs"); - Compiler::new(Kind::Rust1, args) + Compiler::new(Kind::Crab1, args) .command() .arg(entry.path()) .arg("-frust-dump-ast-pretty") - // No need to go further in the pipeline - .arg("-frust-compile-until=lowering") .status()?; // Make sure the directory exists if let Some(parent) = new_path.parent() { - fs::create_dir_all(parent)?; + if !parent.exists() { + fs::create_dir_all(parent)?; + } } fs::copy(entry.path(), new_path_original)?; @@ -147,15 +81,12 @@ impl Pass for AstExport { Ok(new_path) }) - .collect::, Error>>()?; - - Ok(new_files) + .collect() } fn adapt(&self, args: &Args, pretty_file: &Path) -> Result { match self { AstExport::Compile => adapt_compilation(args, pretty_file), - AstExport::Run => adapt_run(args, pretty_file), } } } From 04222fd23aaa0f784415742ac635fd679f8cc4c1 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 27 Jun 2023 13:23:15 +0200 Subject: [PATCH 4/4] misc: Rename `Compiler::Rust1` to `Compiler::Crab1` --- src/compiler.rs | 12 ++++++------ src/error.rs | 2 +- src/main.rs | 5 +---- src/passes/blake3.rs | 2 +- src/passes/gccrs_parsing.rs | 2 +- src/passes/gccrs_rustc_successes.rs | 2 +- src/passes/libcore.rs | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 3e4f9619..6ba66861 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -24,7 +24,7 @@ impl Edition { /// All compiler kinds used in the testsuite #[derive(Clone, Copy)] pub enum Kind { - Rust1, + Crab1, RustcBootstrap, } @@ -38,7 +38,7 @@ impl Kind { /// Get the path associated with a specific compiler kind fn as_path_from_args(self, args: &Args) -> &Path { match self { - Kind::Rust1 => &args.gccrs, + Kind::Crab1 => &args.gccrs, Kind::RustcBootstrap => &args.rustc, } } @@ -58,14 +58,14 @@ impl CommandExt for Command { match kind { // specify Rust language by default, which allows us to compile Rust files with funny extensions // use experimental flag - Kind::Rust1 => self.arg("-frust-incomplete-and-experimental-compiler-do-not-use"), + Kind::Crab1 => self.arg("-frust-incomplete-and-experimental-compiler-do-not-use"), Kind::RustcBootstrap => self, } } fn default_env(&mut self, kind: Kind) -> &mut Command { match kind { - Kind::Rust1 => self, + Kind::Crab1 => self, Kind::RustcBootstrap => self.env("RUSTC_BOOTSTRAP", "1"), } } @@ -98,7 +98,7 @@ impl Compiler { /// to `--crate-name` for `rustc` and `-frust-crate-name` for `gccrs` pub fn crate_name(mut self, crate_name: &str) -> Compiler { match self.kind() { - Kind::Rust1 => self.cmd.arg("-frust-crate-name"), + Kind::Crab1 => self.cmd.arg("-frust-crate-name"), Kind::RustcBootstrap => self.cmd.arg("--crate-name"), }; @@ -122,7 +122,7 @@ impl Compiler { /// `--edition` for `rustc` and `-frust-edition` for `gccrs` pub fn edition(mut self, edition: Edition) -> Compiler { match self.kind() { - Kind::Rust1 => self.cmd.arg("-frust-edition"), + Kind::Crab1 => self.cmd.arg("-frust-edition"), Kind::RustcBootstrap => self.cmd.arg("--edition"), }; diff --git a/src/error.rs b/src/error.rs index 6a999922..b65219d1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,7 +12,7 @@ pub enum MiscKind { #[derive(Debug, thiserror::Error)] pub enum Error { - #[error("{0}")] + #[error("i/o error: {0}")] Io(std::io::Error), #[error("given path to `rust` does not exist: {0}")] NoRust(std::path::PathBuf), diff --git a/src/main.rs b/src/main.rs index 4ad89641..df1028ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,10 +94,7 @@ fn pass_dispatch(pass: &PassKind) -> Vec> { .into_iter() .flatten() .collect(), - PassKind::AstExport => vec![ - Box::new(passes::AstExport::Compile), - Box::new(passes::AstExport::Run), - ], + PassKind::AstExport => vec![Box::new(passes::AstExport::Compile)], } } diff --git a/src/passes/blake3.rs b/src/passes/blake3.rs index 4b205929..7c6b2349 100644 --- a/src/passes/blake3.rs +++ b/src/passes/blake3.rs @@ -66,7 +66,7 @@ impl Pass for Blake3 { }; let compiler = match self { - Blake3::GccrsOriginal | Blake3::GccrsPrelude => Compiler::new(Kind::Rust1, args), + Blake3::GccrsOriginal | Blake3::GccrsPrelude => Compiler::new(Kind::Crab1, args), Blake3::RustcNoStd | Blake3::RustcNoCore => Compiler::new(Kind::RustcBootstrap, args), } .crate_type(CrateType::Library); diff --git a/src/passes/gccrs_parsing.rs b/src/passes/gccrs_parsing.rs index e49d9328..a5d23b77 100644 --- a/src/passes/gccrs_parsing.rs +++ b/src/passes/gccrs_parsing.rs @@ -28,7 +28,7 @@ impl Pass for GccrsParsing { .status()? .success(); - let test_case = TestCase::from_compiler(Compiler::new(Kind::Rust1, args)) + let test_case = TestCase::from_compiler(Compiler::new(Kind::Crab1, args)) .with_name(format!("Parse `{}`", file.display())) .with_exit_code(u8::from(!is_valid)) .with_timeout(1) diff --git a/src/passes/gccrs_rustc_successes.rs b/src/passes/gccrs_rustc_successes.rs index 8b8d3ae0..af2fbee5 100644 --- a/src/passes/gccrs_rustc_successes.rs +++ b/src/passes/gccrs_rustc_successes.rs @@ -86,7 +86,7 @@ impl Pass for GccrsRustcSuccesses { } } - let test_case = TestCase::from_compiler(Compiler::new(Kind::Rust1, args)) + let test_case = TestCase::from_compiler(Compiler::new(Kind::Crab1, args)) .with_name(format!("Compile {} success `{}`", self, file.display())) .with_exit_code(0) // FIXME: Use proper duration here (#10) diff --git a/src/passes/libcore.rs b/src/passes/libcore.rs index f4064d99..0dad8c10 100644 --- a/src/passes/libcore.rs +++ b/src/passes/libcore.rs @@ -68,7 +68,7 @@ impl Pass for LibCore { } fn adapt(&self, args: &Args, file: &Path) -> Result { - Ok(TestCase::from_compiler(Compiler::new(Kind::Rust1, args)) + Ok(TestCase::from_compiler(Compiler::new(Kind::Crab1, args)) .with_name(format!( "Compiling libcore {} ({} step)", self.tag(),