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

Allow Self::Module to be mutated. #58609

Merged
merged 2 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_allocator::{ALLOCATOR_METHODS, AllocatorTy};
use crate::ModuleLlvm;
use crate::llvm::{self, False, True};

pub(crate) unsafe fn codegen(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind) {
pub(crate) unsafe fn codegen(tcx: TyCtxt, mods: &mut ModuleLlvm, kind: AllocatorKind) {
let llcx = &*mods.llcx;
let llmod = mods.llmod();
let usize = match &tcx.sess.target.target.target_pointer_width[..] {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::value::Value;

pub fn write_metadata<'a, 'gcx>(
tcx: TyCtxt<'a, 'gcx, 'gcx>,
llvm_module: &ModuleLlvm
llvm_module: &mut ModuleLlvm
) -> EncodedMetadata {
use std::io::Write;
use flate2::Compression;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

write_metadata should also take &mut ModuleLlvm to properly signal the mutability.

}
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) }
Copy link
Contributor

Choose a reason for hiding this comment

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

please change the codegen function to also take a &mut ModuleLlvm

}
fn compile_codegen_unit<'a, 'tcx: 'a>(
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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