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

replace dynamic library module with libloading #90716

Merged
merged 1 commit into from Dec 12, 2021

Conversation

euclio
Copy link
Contributor

@euclio euclio commented Nov 8, 2021

This PR deletes the rustc_metadata::dynamic_lib module in favor of the popular and better tested libloading crate.

We don't benefit from libloading's symbol lifetimes since we end up leaking the loaded library in all cases, but the call-sites look much nicer by improving error handling and abstracting away some transmutes. We also can remove rustc_metadata's direct dependencies on libc and winapi.

This PR also adds an exception for libloading (and its license) to tidy, so this will need sign-off from the compiler team.

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(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 Nov 8, 2021
@rust-log-analyzer

This comment has been minimized.


extern crate rustc_metadata;

use rustc_metadata::dynamic_lib::DynamicLibrary;
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't remove the test itself, but symbols need to be checked in some other way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, took a page from run-make-fulldeps/symbol-visibility and used nm in the Makefile to just grep for the symbols.

@@ -40,6 +40,7 @@ const EXCEPTIONS: &[(&str, &str)] = &[
("snap", "BSD-3-Clause"), // rustc
// FIXME: this dependency violates the documentation comment above:
("fortanix-sgx-abi", "MPL-2.0"), // libstd but only for `sgx` target
("libloading", "ISC"), // MIT-like
Copy link
Contributor

Choose a reason for hiding this comment

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

The new license exception needs attention, but I'm not sure from whom exactly.
cc @Mark-Simulacrum

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK MIT and ISC are considered functionally equivalent, but I am not a lawyer. https://en.wikipedia.org/wiki/ISC_license

Copy link
Contributor

Choose a reason for hiding this comment

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

I can sign off on using ISC as a library exception as a member of core. I did consult the foundations lawyer before.

Copy link
Member

Choose a reason for hiding this comment

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

We should also add ISC to the LICENSES list (i.e., it can always be used). Thanks for the ping!

@petrochenkov petrochenkov removed their assignment Nov 9, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 11, 2021
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

I don't have a lot of knowledge of dynamic libraries. Left a few comments, nothing substantial.

compiler/rustc_plugin_impl/src/load.rs Show resolved Hide resolved
Err(e) => {

let backend_sym =
unsafe { lib.get::<fn() -> Box<dyn CodegenBackend>>(b"__rustc_codegen_backend") }
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a little trouble parsing this one. Can you create a type definition for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

compiler/rustc_codegen_llvm/src/llvm_util.rs Show resolved Hide resolved
@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 25, 2021
@bors
Copy link
Contributor

bors commented Nov 25, 2021

⌛ Trying commit 6ddfcfd156cc3ddcf3711d0f0a7e48b68ca69ab6 with merge ecb59a7e8817a96e09ca2e4b736c3dbd24003e2a...

@bors
Copy link
Contributor

bors commented Nov 25, 2021

☀️ Try build successful - checks-actions
Build commit: ecb59a7e8817a96e09ca2e4b736c3dbd24003e2a (ecb59a7e8817a96e09ca2e4b736c3dbd24003e2a)

@rust-timer
Copy link
Collaborator

Queued ecb59a7e8817a96e09ca2e4b736c3dbd24003e2a with parent 862962b, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ecb59a7e8817a96e09ca2e4b736c3dbd24003e2a): comparison url.

Summary: This change led to moderate relevant mixed results 🤷 in compiler performance.

  • Moderate improvement in instruction counts (up to -1.3% on incr-unchanged builds of wg-grammar)
  • Small regression in instruction counts (up to 0.4% on incr-unchanged builds of deeply-nested-closures)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 25, 2021
@cjgillot
Copy link
Contributor

cjgillot commented Dec 4, 2021

The perf results show a very small regression for check builds. The PR allows to rely on a better tested crate.
@nagisa, as crate author, do you have any remark?
Otherwise, r=me.

@cjgillot cjgillot added the perf-regression-triaged The performance regression has been triaged. label Dec 4, 2021
@nagisa
Copy link
Member

nagisa commented Dec 4, 2021

I don't have any concerns and the changes look fine.

In the past, years ago, when I was thinking about a change like this, the ISC license was the blocker. Glad to hear that this question finally reached a resolution.

Though also see @Mark-Simulacrum review comment above. I think it makes sense to just specify ISC as allowed always, rather than adding an exception for libloading.

@euclio
Copy link
Contributor Author

euclio commented Dec 6, 2021

@cjgillot Thanks for the review!

I pushed a new commit that sets ISC as an allowed license following the other review comments.

@cjgillot
Copy link
Contributor

cjgillot commented Dec 9, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Dec 9, 2021

📌 Commit 923f939 has been approved by cjgillot

@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 Dec 9, 2021
@bors
Copy link
Contributor

bors commented Dec 12, 2021

⌛ Testing commit 923f939 with merge 6bda5b3...

@bors
Copy link
Contributor

bors commented Dec 12, 2021

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 6bda5b3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 12, 2021
@bors bors merged commit 6bda5b3 into rust-lang:master Dec 12, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 12, 2021
@euclio euclio deleted the libloading branch December 12, 2021 20:32
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6bda5b3): comparison url.

Summary: This change led to moderate relevant improvements 🎉 in compiler performance.

  • Moderate improvement in instruction counts (up to -0.8% on incr-unchanged builds of externs)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@rustbot rustbot removed the perf-regression Performance regression. label Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet