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

Remove AST export run and fix AST export compile pass #51

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/nightly_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Edition {
/// All compiler kinds used in the testsuite
#[derive(Clone, Copy)]
pub enum Kind {
Rust1,
Crab1,
RustcBootstrap,
}

Expand All @@ -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,
}
}
Expand All @@ -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"),
}
}
Expand Down Expand Up @@ -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"),
};

Expand All @@ -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"),
};

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ fn pass_dispatch(pass: &PassKind) -> Vec<Box<dyn Pass>> {
.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)],
}
}

Expand Down
105 changes: 18 additions & 87 deletions src/passes/ast_export.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -23,84 +19,31 @@ fn get_original_file_from_pretty(pretty_file: &Path) -> PathBuf {
fn adapt_compilation(args: &Args, pretty_file: &Path) -> Result<TestCase, Error> {
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<TestCase, Error> {
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 {
Expand All @@ -109,53 +52,41 @@ 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 <file>
// cp gccrs.ast-pretty.dump <new_path>
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=<file>?
.into_iter()
.map(|entry| {
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)?;
fs::copy("gccrs.ast-pretty.dump", &new_path)?;

Ok(new_path)
})
.collect::<Result<Vec<PathBuf>, Error>>()?;

Ok(new_files)
.collect()
}

fn adapt(&self, args: &Args, pretty_file: &Path) -> Result<TestCase, Error> {
match self {
AstExport::Compile => adapt_compilation(args, pretty_file),
AstExport::Run => adapt_run(args, pretty_file),
}
}
}
2 changes: 1 addition & 1 deletion src/passes/blake3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/passes/gccrs_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/passes/gccrs_rustc_successes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/passes/libcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Pass for LibCore {
}

fn adapt(&self, args: &Args, file: &Path) -> Result<TestCase, Error> {
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(),
Expand Down
Loading