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

Cleanup rustc/driver #55008

Merged
merged 10 commits into from
Oct 15, 2018
Merged

Cleanup rustc/driver #55008

merged 10 commits into from
Oct 15, 2018

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Oct 12, 2018

  • improve/remove allocations
  • simplify profile::trace::cons*
  • don't sort base if it only has one element
  • use Cow<str> where applicable
  • use unwrap_or_else with function calls
  • remove an explicit return, add an explicit None
  • remove lifetimes from consts
  • improve common patterns
  • improve macro calls
  • whitespace & formatting fixes

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2018
@rust-highfive

This comment has been minimized.

@ljedrz
Copy link
Contributor Author

ljedrz commented Oct 12, 2018

Hmm, I'm not sure if this is spurious or not; I'll verify shortly.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, couple of nitpicks.

@@ -1472,7 +1473,7 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[Pa
.collect();
let mut file = fs::File::create(&deps_filename)?;
for path in out_filenames {
write!(file, "{}: {}\n\n", path.display(), files.join(" "))?;
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering wether the previous version was like that to avoid flushing on every line (I believe that is a behavior difference between write and writeln, although looking around https://llogiq.github.io/2017/06/01/perf-pitfalls.html https://www.reddit.com/r/rust/comments/6hoayo/how_do_i_write_to_stdout_without_line_buffering/ it seems like I might be wrong).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; this change is contained in a single commit, so in case of any issues it can be easily reverted. I can also pull it back if you prefer.

Some(ref d) => d.clone(),
None => PathBuf::new(),
};
let dirpath = (*odir).as_ref().cloned().unwrap_or_else(|| PathBuf::new());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap_or_else(PathBuf::new);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or unwrap_or_default that I forgot existed ^^.


// If a crate name is present, we use it as the link name
let stem = sess.opts
.crate_name
.clone()
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
.unwrap_or(input.filestem());
.unwrap_or_else(|| input.filestem());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work: .unwrap_or_else(input.filestem);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be cool, but unfortunately the compiler recognizes this as E0615.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's annoying but can see how it happens. Thanks for checking.

false);
None,
true,
false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the indentation here, wouldn't the following be better?

	                        let emitter = errors::emitter::EmitterWriter::stderr(
	                            errors::ColorConfig::Auto,
	                            None,
	                            true,
	                            false,
	                        );

output_filenames: &OutputFilenames,
id: &str,
f: F)
-> A
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When encountering these I usually change them to be

fn foo(
    &self,
    bar,
) -> A {
}

That way we won't have to worry about the function name changing length or adding/removing type args/lifetimes requiring reindenting of the arguments.

@estebank
Copy link
Contributor

[00:21:43] error: unused attribute
[00:21:43]  --> rustc/compiler_builtins_shim/../../libcompiler_builtins/src/lib.rs:5:1
[00:21:43]   |
[00:21:43] 5 | #![crate_type = "rlib"]
[00:21:43]   | ^^^^^^^^^^^^^^^^^^^^^^^
[00:21:43]   |
[00:21:43] note: lint level defined here
[00:21:43]  --> rustc/compiler_builtins_shim/../../libcompiler_builtins/src/lib.rs:1:31
[00:21:43]   |
[00:21:43] 1 | #![cfg_attr(not(stage0), deny(warnings))]
[00:21:43]   |                               ^^^^^^^^
[00:21:43]   = note: #[deny(unused_attributes)] implied by #[deny(warnings)]
[00:21:43] 
[00:21:43] error: crate-level attribute should be in the root module
[00:21:43]  --> rustc/compiler_builtins_shim/../../libcompiler_builtins/src/lib.rs:5:1
[00:21:43]   |
[00:21:43] 5 | #![crate_type = "rlib"]
[00:21:43]   | ^^^^^^^^^^^^^^^^^^^^^^^
[00:21:43] 
[00:21:43] error: aborting due to 2 previous errors
[00:21:43] 
[00:21:43] error: Could not compile `compiler_builtins`.

@ljedrz ljedrz force-pushed the cleanup_rustc_driver branch from 9c69caa to b03a82c Compare October 13, 2018 08:16
@ljedrz
Copy link
Contributor Author

ljedrz commented Oct 13, 2018

Error fixed, comments addressed.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 14, 2018

📌 Commit b03a82c has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2018
@bors
Copy link
Contributor

bors commented Oct 15, 2018

⌛ Testing commit b03a82c with merge f02768b...

bors added a commit that referenced this pull request Oct 15, 2018
Cleanup rustc/driver

- improve/remove allocations
- simplify `profile::trace::cons*`
- don't sort `base` if it only has one element
- use `Cow<str>` where applicable
- use `unwrap_or_else` with function calls
- remove an explicit `return`, add an explicit `None`
- remove lifetimes from `const`s
- improve common patterns
- improve macro calls
- whitespace & formatting fixes
@bors
Copy link
Contributor

bors commented Oct 15, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing f02768b to master...

@bors bors merged commit b03a82c into rust-lang:master Oct 15, 2018
@bors bors mentioned this pull request Oct 15, 2018
@ljedrz ljedrz deleted the cleanup_rustc_driver branch October 15, 2018 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants