Skip to content

Commit

Permalink
Remove over-zealous assertion in my PR: just do replacement unconditi…
Browse files Browse the repository at this point in the history
…onally.
  • Loading branch information
pnkfelix committed Dec 5, 2019
1 parent 1d594c4 commit f29e4bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,28 +872,14 @@ pub struct ThinLTOImports {

impl ThinLTOImports {
/// Records `llvm_module_name` as importing `prev_imports` rather than what
/// we have currently computed. Ensures that the previous imports are a
/// superset of what imports LLVM currently computed.
/// we have currently computed.
fn overwrite_with_past_import_state(&mut self,
llvm_module_name: &str,
prev_imports: &[String]) {
// There were imports used to previous LTO optimize the module; make
// sure they are a superset of whatever we have in our current state,
// and then store them as our new current state.
let curr_imports_for_mod = self.modules_imported_by(llvm_module_name);
for imported in curr_imports_for_mod {
assert!(prev_imports.contains(imported));
}
// We can avoid doing the insertion entirely if the sets are equivalent,
// and we can determine equivalence cheaply via a length comparison,
// since we have already asserted the past state to be a superset of the
// current state.
if prev_imports.len() != curr_imports_for_mod.len() {
debug!("ThinLTOImports::restore_past_import_state \
mod: {:?} replacing curr state: {:?} with prev state: {:?}",
llvm_module_name, curr_imports_for_mod, prev_imports);
self.imports.insert(llvm_module_name.to_owned(), prev_imports.to_vec());
}
debug!("ThinLTOImports::overwrite_with_past_import_state \
mod: {:?} replacing curr state: {:?} with prev state: {:?}",
llvm_module_name, self.modules_imported_by(llvm_module_name), prev_imports);
self.imports.insert(llvm_module_name.to_owned(), prev_imports.to_vec());
}

fn modules_imported_by(&self, llvm_module_name: &str) -> &[String] {
Expand Down
9 changes: 9 additions & 0 deletions src/test/run-make/removing-code-and-incremental-lto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,12 @@ all:
$(RUSTC) --crate-name rubble $(TMPDIR)/rubble.rs --crate-type bin --emit=link -C opt-level=s --out-dir $(RUBBLE1_OUT_DIR) --target $(TARGET) -C incremental=$(INCREMENTAL_DIR) -L dependency=$(OUT_DIR) --extern nrf52810_hal=$(OUT_DIR)/libnrf52810_hal.rlib -C link-arg=-Tlink.x.in -L $(LINK_X_DIR) -C linker-flavor=ld.lld -C codegen-units=2
cp rubble.rs.v2 $(TMPDIR)/rubble.rs
$(RUSTC) --crate-name rubble $(TMPDIR)/rubble.rs --crate-type bin --emit=link -C opt-level=s --out-dir $(RUBBLE2_OUT_DIR) --target $(TARGET) -C incremental=$(INCREMENTAL_DIR) -L dependency=$(OUT_DIR) --extern nrf52810_hal=$(OUT_DIR)/libnrf52810_hal.rlib -C link-arg=-Tlink.x.in -L $(LINK_X_DIR) -C linker-flavor=ld.lld -C codegen-units=2
echo Now testing the reverse direction
rm -rf $(INCREMENTAL_DIR)
mkdir -p $(INCREMENTAL_DIR)
cp rubble.rs.v2 $(TMPDIR)/rubble.rs
$(RUSTC) --crate-name rubble $(TMPDIR)/rubble.rs --crate-type bin --emit=link -C opt-level=s --out-dir $(RUBBLE2_OUT_DIR) --target $(TARGET) -C incremental=$(INCREMENTAL_DIR) -L dependency=$(OUT_DIR) --extern nrf52810_hal=$(OUT_DIR)/libnrf52810_hal.rlib -C link-arg=-Tlink.x.in -L $(LINK_X_DIR) -C linker-flavor=ld.lld -C codegen-units=2
cp rubble.rs.v1 $(TMPDIR)/rubble.rs
$(RUSTC) --crate-name rubble $(TMPDIR)/rubble.rs --crate-type bin --emit=link -C opt-level=s --out-dir $(RUBBLE1_OUT_DIR) --target $(TARGET) -C incremental=$(INCREMENTAL_DIR) -L dependency=$(OUT_DIR) --extern nrf52810_hal=$(OUT_DIR)/libnrf52810_hal.rlib -C link-arg=-Tlink.x.in -L $(LINK_X_DIR) -C linker-flavor=ld.lld -C codegen-units=2

endif

0 comments on commit f29e4bd

Please sign in to comment.