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

trans: Internalize symbols without relying on LLVM #43183

Merged

Conversation

michaelwoerister
Copy link
Member

This PR makes the compiler use the information gather by the trans collector in order to determine which symbols/trans-items can be made internal. This has the advantages:

  • of being LLVM independent,
  • of also working in incremental mode, and
  • of allowing to not keep all LLVM modules in memory at the same time.

This is in preparation for fixing issue #39280.

cc @rust-lang/compiler

@rust-highfive
Copy link
Collaborator

r? @eddyb

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

@@ -28,59 +27,87 @@ pub enum SymbolExportLevel {
}

/// The set of symbols exported from each crate in the crate graph.
#[derive(Clone, Debug)]
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be Clone? It looks like it's a fairly large structure that ideally we wouldn't clone. It seems like it's in an Arc most of the time anyway so this feels unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is indeed not necessary anymore. Will remove.

{
assert!(!self.index.contains_key(&source));

let start_index = self.targets.len();
self.targets.extend(targets);
let (targets_size_hint, targets_size_hint_max) = targets.size_hint();
debug_assert_eq!(targets_size_hint_max, Some(targets_size_hint));
Copy link
Member

Choose a reason for hiding this comment

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

It looks like what we really want here is an ExactSizeIterator?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into it.

cgu_name: cgu.name.clone()
};

'item:
Copy link
Member

Choose a reason for hiding this comment

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

This appears to no longer be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand. It's used in the nested continue below.

Copy link
Member

Choose a reason for hiding this comment

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

I'm probably just missing something, but I don't see a nested loop above it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, the only place those nested loops still exist is in my head :) Sorry for the confusion. I'll remove the label.

// Some accessors might not have been
// instantiated. We can safely ignore those.
trans_item_placements.get(accessor)
.cloned()
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to clone the option? It looks like that shouldn't be necessary -- we only use it for PartialEq?

Copy link
Member Author

Choose a reason for hiding this comment

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

cloned() (as opposed to clone()) turns the Option<&T> into an Option<T>, which is what we need for filter_map.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you meant now. Yes, cloning seems unnecessary.

hir::ItemFn(.., ref generics, _) => {
if !generics.is_type_parameterized() {
hir::ItemFn(_, _, constness, _, ref generics, _) => {
let is_const = match constness {
Copy link
Member

Choose a reason for hiding this comment

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

I recommend tcx.is_const_fn(def_id) - similarly for hir::Generics, ty::Generics should be preferred, although that one is preexisting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does is_const_fn do something differently than the code below? I'm not against changing, but the constness and generics from the HIR item are right there without the need for a hashtable lookup.

@@ -889,7 +956,14 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
}
};

if !generics.is_type_parameterized() && !is_impl_generic {
let is_const = match constness {
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@eddyb
Copy link
Member

eddyb commented Jul 12, 2017

r=me modulo nits and the build failure

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 13, 2017
@michaelwoerister michaelwoerister force-pushed the internalize-symbols-without-llvm branch from ad74e77 to 2b9ab65 Compare July 13, 2017 09:49
@michaelwoerister michaelwoerister force-pushed the internalize-symbols-without-llvm branch from 2b9ab65 to 2f07eb3 Compare July 13, 2017 11:28
@michaelwoerister michaelwoerister force-pushed the internalize-symbols-without-llvm branch from efdc922 to c93e62b Compare July 13, 2017 11:29
@michaelwoerister
Copy link
Member Author

@bors r=eddyb

All nits addressed, I think.

@bors
Copy link
Contributor

bors commented Jul 13, 2017

📌 Commit 678d377 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 15, 2017

⌛ Testing commit 678d377 with merge 685ccdf38707dc948ec9bbde82caa8c9e0ac5cdc...

@bors
Copy link
Contributor

bors commented Jul 15, 2017

💔 Test failed - status-travis

@Mark-Simulacrum
Copy link
Member

00:16:51] rustc: /checkout/src/llvm/include/llvm/IR/GlobalValue.h:227: void llvm::GlobalValue::setVisibility(llvm::GlobalValue::VisibilityTypes): Assertion `(!hasLocalLinkage() || V == DefaultVisibility) && "local linkage requires default visibility"' failed.
[00:16:51] �(B�[m�[31m�[1merror:�(B�[m Could not compile `core`.
[00:16:51] �(B�[m
[00:16:51] Caused by:
[00:16:51] �(B�[m�(B�[m  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name core /checkout/src/libcore/lib.rs --color always --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 -C metadata=a6117b7e5e0db06a -C extra-filename=-a6117b7e5e0db06a --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps -Zincremental=/tmp/rust-incr-cache` (signal: 6, SIGABRT: process abort signal)
[00:16:51] --- stderr
[00:16:51] rustc: /checkout/src/llvm/include/llvm/IR/GlobalValue.h:227: void llvm::GlobalValue::setVisibility(llvm::GlobalValue::VisibilityTypes): Assertion `(!hasLocalLinkage() || V == DefaultVisibility) && "local linkage requires default visibility"' failed.
[00:16:51] 
[00:16:51] �(B�[mthread 'main' panicked at 'command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-j" "4" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:16:51] expected success, got: exit code: 101', /checkout/src/bootstrap/compile.rs:586
[00:16:51] note: Run with `RUST_BACKTRACE=1` for a backtrace.

@michaelwoerister
Copy link
Member Author

@bors r=eddyb

That assertion should be fixed, hopefully.

@bors
Copy link
Contributor

bors commented Jul 17, 2017

📌 Commit 226bc92 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 18, 2017

⌛ Testing commit 226bc92 with merge 82e2f9ddd4d0d32bb1ab96928e099c49975d932c...

@bors
Copy link
Contributor

bors commented Jul 18, 2017

💔 Test failed - status-travis

@est31
Copy link
Member

est31 commented Jul 18, 2017

@bors retry

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 226bc92 with merge b45d8f0ebcf760610826ce2a43f5f3d437916086...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jul 19, 2017

Spurious. Could this be related to https://appveyor.statuspage.io/incidents/m2vdvw39kdk8?

  [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - The revocation function was unable to check revocation because the revocation server was offline.)

@michaelwoerister
Copy link
Member Author

@bors retry

(No harm in retrying while the queue is empty, I guess)

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 226bc92 with merge 49765af5c6bcd1182b8d279b404d79fdd8a81c18...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-appveyor

@nagbot-rs
Copy link

nagbot-rs commented Jul 19, 2017 via email

@bors
Copy link
Contributor

bors commented Jul 19, 2017

@nagbot-rs: 🔑 Insufficient privileges: and not in try users

@alexcrichton
Copy link
Member

@bors: retry

@Mark-Simulacrum
Copy link
Member

@bors retry -- appveyor revocation certs, appears to be fixed once #43333 lands.

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 226bc92 with merge 528330520a5ad6953e4a0f25f79d4db1ad019e7f...

@bors
Copy link
Contributor

bors commented Jul 20, 2017

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jul 20, 2017

x86_64-pc-windows-gnu failed to link stage1-std ("undefined reference to std::thread::local::os::destroy_value::hXXXXXX"). Seems legit.

error: linking with `gcc` failed: exit code: 1
  |
  = note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\dllcrt2.o" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\deps\\std-ac667c8bbd86e364.0.o" "-o" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\deps\\std-ac667c8bbd86e364.dll" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\deps\\std-ac667c8bbd86e364.crate.metadata.o" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\deps\\std-ac667c8bbd86e364.crate.allocator.o" "-nodefaultlibs" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\deps" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\release\\deps" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\native\\libbacktrace\\.libs" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\native\\jemalloc\\lib" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1-std\\x86_64-pc-windows-gnu\\release\\build\\compiler_builtins-3f52fffdb7374465\\out" "-L" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "backtrace" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-Wl,-Bstatic" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\libpanic_unwind-d7ba3ed13adbba78.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\libunwind-4a5bfaad61fe8668.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\liblibc-f12a6f077c568615.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\librand-fc4f55c30253478d.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\liballoc_system-fa945e0e44cf2c85.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\liballoc-7e25d9aea6733470.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\libstd_unicode-b2da6d85e26577df.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\libcore-133c3145709a073d.rlib" "-Wl,--no-whole-archive" "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\rustc.HACeg3fOyh3C\\libcompiler_builtins-b49c9299458b621e.rlib" "-l" "gcc_eh" "-l" "pthread" "-shared" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0xd8): undefined reference to `std::thread::local::os::destroy_value::ha44314076d36f203'
          C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0xe8): undefined reference to `std::thread::local::os::destroy_value::hc6b9798d5a01e96f'
          C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0xf8): undefined reference to `std::thread::local::os::destroy_value::hfc4011e45796e013'
          C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0x108): undefined reference to `std::thread::local::os::destroy_value::hc6b9798d5a01e96f'
          C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0x118): undefined reference to `std::thread::local::os::destroy_value::h96e432fe261f7344'
          C:\projects\rust\build\x86_64-pc-windows-gnu\stage1-std\x86_64-pc-windows-gnu\release\deps\std-ac667c8bbd86e364.0.o:(.data+0x128): undefined reference to `std::thread::local::os::destroy_value::h10f11fb8acf74f1c'
          collect2.exe: error: ld returned 1 exit status
          
error: aborting due to previous error
error: Could not compile `std`.

@michaelwoerister
Copy link
Member Author

Thanks, @kennytm!

@aidanhs
Copy link
Member

aidanhs commented Jul 20, 2017

[00:40:46] ---- [compile-fail] compile-fail/E0534.rs stdout ----
[00:40:46] 	
[00:40:46] error: compile-fail test compiled successfully!
[00:40:46] status: exit code: 0
[00:40:46] command: /checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc /checkout/src/test/compile-fail/E0534.rs -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail --target=x86_64-unknown-linux-gnu --error-format json -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/E0534.stage2-x86_64-unknown-linux-gnu.compile-fail.libaux -C prefer-dynamic -o /checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/E0534.stage2-x86_64-unknown-linux-gnu -Crpath -O -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers
[00:40:46] stdout:

(and a few more)

@michaelwoerister michaelwoerister force-pushed the internalize-symbols-without-llvm branch from 42c4564 to e8ff75b Compare July 20, 2017 14:35
@michaelwoerister michaelwoerister force-pushed the internalize-symbols-without-llvm branch from e8ff75b to f6e5416 Compare July 20, 2017 20:11
@michaelwoerister
Copy link
Member Author

@bors r=eddyb

@eddyb I pushed one more commit to fix the linker issue on Windows. It should be rather uncontroversial but feel free to take another look.

@bors
Copy link
Contributor

bors commented Jul 20, 2017

📌 Commit f6e5416 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 21, 2017

⌛ Testing commit f6e5416 with merge e3c8433...

bors added a commit that referenced this pull request Jul 21, 2017
…lvm, r=eddyb

trans: Internalize symbols without relying on LLVM

This PR makes the compiler use the information gather by the trans collector in order to determine which symbols/trans-items can be made internal. This has the advantages:
+ of being LLVM independent,
+ of also working in incremental mode, and
+ of allowing to not keep all LLVM modules in memory at the same time.

This is in preparation for fixing issue #39280.

cc @rust-lang/compiler
@bors
Copy link
Contributor

bors commented Jul 21, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants