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

Make it possible to construct TargetInfo without Context #5355

Merged
merged 6 commits into from
Apr 13, 2018

Conversation

djc
Copy link
Contributor

@djc djc commented Apr 13, 2018

This should make stuff like #5349 easier.

@rust-highfive
Copy link

r? @alexcrichton

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

cx.build_config
.requested_target
.as_ref()
.map(|s| s.as_ref()),
Copy link
Member

Choose a reason for hiding this comment

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

Could we make some of this fields into methods of build_config, so that the callers need not to worry about moving out of it and turning an &Option<String> into Option<&str>? Could we make some of BuildConfig fields private?

Copy link
Contributor Author

@djc djc Apr 13, 2018

Choose a reason for hiding this comment

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

For requested_target, sure, I think such a method could make sense. As for making the fields private, I'm not really sure what the point would be? It looks like it was defined very much just as a bag of properties, and the stuff in there is straightforward enough (and typed in such a way) that there doesn't seem to be much downside to just exposing them like they are now. (I should mention that my previous language of choice was Python, where the "consenting adults" philosophy very much reigned supreme, so my take might be more controversial if you're coming from C++ or Java.)

Copy link
Member

Choose a reason for hiding this comment

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

I have no strong opinions about this, but to me "using only fields" or "using only methods" seems slightly superior to "use fields for some stuff and methods for some other stuff",

Code like

                Kind::Host => &cx.build_config.host_triple,
                Kind::Target => cx.build_config.target_triple(),

seems slightly funny, and makes you pause for a split second.

And looks like after #5354 we might need less public access to fields?

But, as I've said, it's an ultra minor issue :)

Copy link
Contributor Author

@djc djc Apr 13, 2018

Choose a reason for hiding this comment

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

If you want to go all or none I would leave it as none. :) After replacing all instances of .requested_target with a method .requested_target() (a diff which in itself is +13/-13), there are 38 instances of build_config\., about 14 of which are method calls, so that's a slight minority.

@@ -150,7 +168,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
files: None,
};

cx.probe_target_info()?;
cx.compilation.host_dylib_path = cx.host_info.sysroot_libdir.clone();
cx.compilation.target_dylib_path = cx.target_info.sysroot_libdir.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this into Compilation::new as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely thought about it. I decided against it for now mostly on style (passing around long names is kind of ugly). I just looked into how the rest of Compilation gets initialized, and it looks like pretty much everything gets initialized after the fact from throughout Context, so passing these two in at new() is not a win for consistency. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's leave it as is

@matklad
Copy link
Member

matklad commented Apr 13, 2018

@bors r+

Thanks @djc! This looks much nicer now!

@bors
Copy link
Contributor

bors commented Apr 13, 2018

📌 Commit 3ec14e0 has been approved by matklad

@bors
Copy link
Contributor

bors commented Apr 13, 2018

⌛ Testing commit 3ec14e0 with merge 74e658c...

bors added a commit that referenced this pull request Apr 13, 2018
Make it possible to construct TargetInfo without Context

This should make stuff like #5349 easier.
@djc
Copy link
Contributor Author

djc commented Apr 13, 2018

@matklad and thank you for the quick and thorough review!

@bors
Copy link
Contributor

bors commented Apr 13, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: matklad
Pushing 74e658c to master...

@bors bors merged commit 3ec14e0 into rust-lang:master Apr 13, 2018
@djc djc deleted the target-info-no-context branch April 13, 2018 19:58
@ehuss ehuss added this to the 1.27.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants