Skip to content

Commit

Permalink
Removed phantomdata no longer necessary
Browse files Browse the repository at this point in the history
Because CodegenContext doesn't implement Backend anymore
  • Loading branch information
denismerigoux committed Sep 6, 2018
1 parent fed567a commit 5a880b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use rustc::util::common::time_ext;
use rustc_data_structures::fx::FxHashMap;
use time_graph::Timeline;
use {ModuleCodegen, ModuleLlvm, ModuleKind};
use std::marker::PhantomData;

use libc;

Expand Down Expand Up @@ -762,7 +761,6 @@ impl ThinModule {
llmod_raw,
llcx,
tm,
phantom: PhantomData
},
name: self.name().to_string(),
kind: ModuleKind::Regular,
Expand Down
17 changes: 6 additions & 11 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use context::{is_pie_binary, get_reloc_model};
use common;
use jobserver::{Client, Acquired};
use rustc_demangle;
use std::marker::PhantomData;

use std::any::Any;
use std::ffi::{CString, CStr};
Expand Down Expand Up @@ -345,7 +344,7 @@ struct AssemblerCommand {

/// Additional resources used by optimize_and_codegen (not module specific)
#[derive(Clone)]
pub struct CodegenContext<'ll> {
pub struct CodegenContext {
// Resources needed when running LTO
pub time_passes: bool,
pub lto: Lto,
Expand Down Expand Up @@ -384,13 +383,10 @@ pub struct CodegenContext<'ll> {
// measuring is disabled.
time_graph: Option<TimeGraph>,
// The assembler command if no_integrated_as option is enabled, None otherwise
assembler_cmd: Option<Arc<AssemblerCommand>>,
// This field is used to give a lifetime parameter to the struct so that it can implement
// the Backend trait.
phantom: PhantomData<&'ll ()>
assembler_cmd: Option<Arc<AssemblerCommand>>
}

impl CodegenContext<'ll> {
impl CodegenContext {
pub fn create_diag_handler(&self) -> Handler {
Handler::with_emitter(true, false, Box::new(self.diag_emitter.clone()))
}
Expand Down Expand Up @@ -419,12 +415,12 @@ impl CodegenContext<'ll> {
}

pub struct DiagnosticHandlers<'a> {
data: *mut (&'a CodegenContext<'a>, &'a Handler),
data: *mut (&'a CodegenContext, &'a Handler),
llcx: &'a llvm::Context,
}

impl<'a> DiagnosticHandlers<'a> {
pub fn new(cgcx: &'a CodegenContext<'a>,
pub fn new(cgcx: &'a CodegenContext,
handler: &'a Handler,
llcx: &'a llvm::Context) -> Self {
let data = Box::into_raw(Box::new((cgcx, handler)));
Expand Down Expand Up @@ -1625,7 +1621,6 @@ fn start_executing_work(tcx: TyCtxt,
target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
debuginfo: tcx.sess.opts.debuginfo,
assembler_cmd,
phantom: PhantomData
};

// This is the "main loop" of parallel work happening for parallel codegen.
Expand Down Expand Up @@ -2096,7 +2091,7 @@ pub const CODEGEN_WORK_PACKAGE_KIND: time_graph::WorkPackageKind =
const LLVM_WORK_PACKAGE_KIND: time_graph::WorkPackageKind =
time_graph::WorkPackageKind(&["#7DB67A", "#C6EEC4", "#ACDAAA", "#579354", "#3E6F3C"]);

fn spawn_work(cgcx: CodegenContext<'static>, work: WorkItem) {
fn spawn_work(cgcx: CodegenContext, work: WorkItem) {
let depth = time_depth();

thread::spawn(move || {
Expand Down
15 changes: 6 additions & 9 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub use llvm_util::target_features;
use std::any::Any;
use std::path::{PathBuf};
use std::sync::mpsc;
use std::marker::PhantomData;
use rustc_data_structures::sync::Lrc;

use rustc::dep_graph::DepGraph;
Expand Down Expand Up @@ -279,7 +278,7 @@ struct ModuleCodegen {
/// as the crate name and disambiguator.
/// We currently generate these names via CodegenUnit::build_cgu_name().
name: String,
module_llvm: ModuleLlvm<'static>,
module_llvm: ModuleLlvm,
kind: ModuleKind,
}

Expand Down Expand Up @@ -337,17 +336,16 @@ struct CompiledModule {
bytecode_compressed: Option<PathBuf>,
}

struct ModuleLlvm<'ll> {
struct ModuleLlvm {
llcx: &'static mut llvm::Context,
llmod_raw: *const llvm::Module,
tm: &'static mut llvm::TargetMachine,
phantom: PhantomData<&'ll ()>
}

unsafe impl Send for ModuleLlvm<'ll> { }
unsafe impl Sync for ModuleLlvm<'ll> { }
unsafe impl Send for ModuleLlvm { }
unsafe impl Sync for ModuleLlvm { }

impl ModuleLlvm<'ll> {
impl ModuleLlvm {
fn new(sess: &Session, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(sess.fewer_names());
Expand All @@ -357,7 +355,6 @@ impl ModuleLlvm<'ll> {
llmod_raw,
llcx,
tm: create_target_machine(sess, false),
phantom: PhantomData
}
}
}
Expand All @@ -369,7 +366,7 @@ impl ModuleLlvm<'ll> {
}
}

impl Drop for ModuleLlvm<'ll> {
impl Drop for ModuleLlvm {
fn drop(&mut self) {
unsafe {
llvm::LLVMContextDispose(&mut *(self.llcx as *mut _));
Expand Down

0 comments on commit 5a880b7

Please sign in to comment.