-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rewrite emit
, mixing-formats
and bare-outfile
run-make
tests in rmake.rs
format
#125383
Conversation
Some changes occurred in run-make tests. cc @jieyouxu |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
tests/run-make/bare-outfile/rmake.rs
Outdated
env::set_current_dir(tmp_dir()); | ||
rustc().output("foo").input("foo.rs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: I think this is cleaner if it's written with -o foo
+ --out-dir tmp_dir()
The output filename can be set with the -o flag. A suffix may be added to the filename with the -C extra-filename flag. The files are written to the current directory unless the --out-dir flag is used.
That way, we don't need the explicit copy of foo.rs
at all.
i.e. rustc().out_dir("foo").output("foo")
, depending on what you think about the name of output
-- should it be renamed output_filename
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that rustc()
will always pass through the function I copied below (I think you wrote it). So, logically, we wouldn't need to specify the --out-dir tmp_dir()
, as it's already set?
I'm not too sure I understand your suggestion. In rustc().out_dir("foo").output("foo")
, .out_dir("foo")
is setting the file name foo
as the output directory, but it's a filename, not a directory. I could certainly rename output
to output_filename
, but that would require replacing every instance of it in already ported tests.
fn setup_common() -> Command {
let rustc = env::var("RUSTC").unwrap();
let mut cmd = Command::new(rustc);
set_host_rpath(&mut cmd);
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
cmd
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I forgot by default the Rustc
instance returned by rustc()
we already set --out-dir
to tmp_dir()
, so env::set_current_dir
and fs::copy
etc. wasn't needed in the first place I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yeah, ignore the output_filename
comment, I was just thinking if output()
and out_dir()
can become confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I forgot by default the
Rustc
instance returned byrustc()
we already set--out-dir
totmp_dir()
, soenv::set_current_dir
andfs::copy
etc. wasn't needed in the first place I think?
I will remove those 2 commands and see if that causes CI to fail.
tests/run-make/emit/rmake.rs
Outdated
// in the same rustc call. A fix was created in #30452. This test checks that | ||
// the fix did not accidentally break compilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: probably more straightforward to say "the test checks that rustc still compiles a source file successfully when emission of multiple output artifacts are requested"? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, and it's something that came up a few times, too. A lot of these tests come from "person fixes non-critical but annoying bug in rustc, maintainer asks for a test to make sure the fix did not break anything". It's important to be specific.
rustc().crate_type("rlib").input("foo.rs").run(); | ||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run(); | ||
rustc().crate_type("dylib,rlib").input("baz.rs").arg("-Cprefer-dynamic").run(); | ||
rustc().crate_type("bin").input("baz.rs").run(); | ||
fs::remove_dir_all(tmp_dir()).unwrap(); | ||
fs::create_dir(tmp_dir()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: it might be cleaner to create a helper to abstract the "clean tmp_dir()
functionality, i.e.
// helper
fn test_with_teardown(f: Fn()) {
f();
fs::remove_dir_all(tmp_dir()).unwrap();
fs::create_dir(tmp_dir()).unwrap();
}
// callsite
fn main() {
test_with_teardown(|| {
// Building just baz
rustc().crate_type("rlib").input("foo.rs").run();
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
rustc().crate_type("dylib,rlib").input("baz.rs").arg("-Cprefer-dynamic").run();
rustc().crate_type("bin").input("baz.rs").run();
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's a lot cleaner! I wanted to abstract over this test a lot initially, making a Flags struct with fields crate_type
, prefers_dynamic
and should_fail
, but I think writing everything out is clearer... with the slight improvement of your helper teardown function. Added.
@rustbot author |
@rustbot review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The error message seems to indicate that they were needed. I am restoring them now. |
use run_make_support::{rustc, tmp_dir}; | ||
use std::fs; | ||
|
||
fn test_with_teardown(rustc_calls: &dyn Fn()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can't this just be f: Fn()
, it doesn't need to be &dyn Fn()
AFAICT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it that way initially, but this triggers the following error message:
2024-05-22T18:08:36.1683386Z --- stderr -------------------------------
2024-05-22T18:08:36.1684109Z error[E0277]: the size for values of type `(dyn Fn() + 'static)` cannot be known at compilation time
2024-05-22T18:08:36.1703969Z ##[error] --> /checkout/tests/run-make/mixing-formats/rmake.rs:18:23
2024-05-22T18:08:36.1711694Z |
2024-05-22T18:08:36.1712020Z 18 | fn test_with_teardown(rustc_calls: Fn()) {
2024-05-22T18:08:36.1712621Z | ^^^^^^^^^^^ doesn't have a size known at compile-time
2024-05-22T18:08:36.1713013Z |
2024-05-22T18:08:36.1713456Z = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)`
2024-05-22T18:08:36.1714031Z = help: unsized fn params are gated as an unstable feature
2024-05-22T18:08:36.1714497Z help: you can use `impl Trait` as the argument type
2024-05-22T18:08:36.1714858Z |
2024-05-22T18:08:36.1715140Z 18 | fn test_with_teardown(rustc_calls: impl Fn()) {
2024-05-22T18:08:36.1715523Z | ++++
2024-05-22T18:08:36.1716122Z help: function arguments must have a statically known size, borrowed types always have a known size
2024-05-22T18:08:36.1716913Z |
2024-05-22T18:08:36.1717197Z 18 | fn test_with_teardown(rustc_calls: &dyn Fn()) {
2024-05-22T18:08:36.1717580Z | ++++
2024-05-22T18:08:36.1717817Z
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dumb and forgor the impl
lol (sorry for misleading)
fn foo(f: impl Fn()) {
f()
}
fn main() {
foo(|| { println!("hello world") })
}
Thanks, r=me after CI is green. |
✌️ @Oneirical, you can now approve this pull request! If @jieyouxu told you to " |
@bors rollup |
@bors try |
Rewrite `emit`, `mixing-formats` and `bare-outfile` `run-make` tests in `rmake.rs` format Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). try-job: x86_64-msvc
☀️ Try build successful - checks-actions |
Thanks! @bors r+ rollup=iffy |
Rewrite `emit`, `mixing-formats` and `bare-outfile` `run-make` tests in `rmake.rs` format Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). try-job: x86_64-msvc
💔 Test failed - checks-actions |
💡 This pull request was already approved, no need to approve it again.
|
☀️ Test successful - checks-actions |
Finished benchmarking commit (7c52d2d): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -3.0%, secondary -3.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 672.681s -> 671.059s (-0.24%) |
Part of #121876 and the associated Google Summer of Code project.
try-job: x86_64-msvc