Skip to content

Commit

Permalink
Allow Self::Module to be mutated.
Browse files Browse the repository at this point in the history
`codegen_allocator` and `write_metadata` mutate the underlying LLVM module. As
such, it makes sense for these two functions to receive a mutable reference to
the module (as opposed to an immutable one).
  • Loading branch information
gabi-250 committed Feb 20, 2019
1 parent f66e469 commit 36f18f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/lib.rs
Expand Up @@ -120,11 +120,11 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
fn write_metadata<'b, 'gcx>(
&self,
tcx: TyCtxt<'b, 'gcx, 'gcx>,
metadata: &ModuleLlvm
metadata: &mut ModuleLlvm
) -> EncodedMetadata {
base::write_metadata(tcx, metadata)
}
fn codegen_allocator(&self, tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind) {
fn codegen_allocator(&self, tcx: TyCtxt, mods: &mut ModuleLlvm, kind: AllocatorKind) {
unsafe { allocator::codegen(tcx, mods, kind) }
}
fn compile_codegen_unit<'a, 'tcx: 'a>(
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/base.rs
Expand Up @@ -551,9 +551,9 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
&["crate"],
Some("metadata")).as_str()
.to_string();
let metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name);
let mut metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name);
let metadata = time(tcx.sess, "write metadata", || {
backend.write_metadata(tcx, &metadata_llvm_module)
backend.write_metadata(tcx, &mut metadata_llvm_module)
});
tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen));

Expand Down Expand Up @@ -636,9 +636,9 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
&["crate"],
Some("allocator")).as_str()
.to_string();
let modules = backend.new_metadata(tcx, &llmod_id);
let mut modules = backend.new_metadata(tcx, &llmod_id);
time(tcx.sess, "write allocator module", || {
backend.codegen_allocator(tcx, &modules, kind)
backend.codegen_allocator(tcx, &mut modules, kind)
});

Some(ModuleCodegen {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/traits/backend.rs
Expand Up @@ -36,9 +36,9 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
fn write_metadata<'b, 'gcx>(
&self,
tcx: TyCtxt<'b, 'gcx, 'gcx>,
metadata: &Self::Module,
metadata: &mut Self::Module,
) -> EncodedMetadata;
fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
fn codegen_allocator(&self, tcx: TyCtxt, mods: &mut Self::Module, kind: AllocatorKind);
fn compile_codegen_unit<'a, 'tcx: 'a>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down

0 comments on commit 36f18f2

Please sign in to comment.