Skip to content

Commit

Permalink
[eddyb] rustc_codegen_ssa: rename interfaces to traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 16, 2018
1 parent d1410ad commit 0b56924
Show file tree
Hide file tree
Showing 54 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use type_of::{LayoutLlvmExt, PointerKind};
use value::Value;
use rustc_target::abi::call::ArgType;

use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TyLayout, Abi as LayoutAbi};
use rustc::ty::{self, Ty, Instance};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use builder::Builder;
use value::Value;

use rustc::hir;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::mir::operand::OperandValue;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc::ty::query::Providers;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::FxHashMap;
use rustc_target::spec::PanicStrategy;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use attributes;
use llvm::{self, Attribute};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use back::bytecode::{DecodedBytecode, RLIB_BYTECODE_EXTENSION};
use rustc_codegen_ssa::back::symbol_export;
use rustc_codegen_ssa::back::write::{ModuleConfig, CodegenContext, pre_lto_bitcode_filename};
use rustc_codegen_ssa::back::lto::{SerializedModule, LtoModuleCodegen, ThinShared, ThinModule};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use back::write::{self, DiagnosticHandlers, with_llvm_pmb, save_temp_bitcode, get_llvm_opt_level};
use errors::{FatalError, Handler};
use llvm::archive_ro::ArchiveRO;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use attributes;
use back::bytecode::{self, RLIB_BYTECODE_EXTENSION};
use back::lto::ThinBuffer;
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use base;
use consts;
use rustc::session::config::{self, OutputType, Passes, Lto};
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 @@ -42,7 +42,7 @@ use monomorphize::partitioning::CodegenUnitExt;
use rustc_codegen_ssa::mono_item::MonoItemExt;
use rustc_data_structures::small_c_str::SmallCStr;

use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::back::write::submit_codegened_module_to_llvm;

use std::ffi::CString;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::layout::{self, Align, Size, TyLayout};
use rustc::session::config;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use syntax;
use rustc_codegen_ssa::base::to_immediate;
use rustc_codegen_ssa::mir::operand::{OperandValue, OperandRef};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use llvm;
use monomorphize::Instance;
use context::CodegenCx;
use value::Value;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc::ty::TypeFoldable;
use rustc::ty::layout::{LayoutOf, HasTyCtxt};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use consts;
use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc::ty::layout::{HasDataLayout, LayoutOf, self, TyLayout, Size};
use rustc::mir::interpret::{Scalar, AllocType, Allocation};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
use rustc::ty::{self, Ty};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc::ty::layout::{self, Size, Align, LayoutOf};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use value::Value;
use monomorphize::partitioning::CodegenUnit;
use type_::Type;
use type_of::PointeeInfo;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use libc::c_uint;

use rustc_data_structures::base_n;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use common::CodegenCx;
use builder::Builder;
use rustc::session::config::DebugInfo;
use value::Value;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use syntax::attr;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::utils::{debug_context, DIB, span_start,
use super::namespace::mangled_name_of_instance;
use super::type_names::compute_debuginfo_type_name;
use super::{CrateDebugContext};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use abi;
use value::Value;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use syntax_pos::{self, Span, Pos};
use syntax::ast;
use syntax::symbol::{Symbol, InternedString};
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

pub mod gdb;
mod utils;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/source_loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_codegen_ssa::debuginfo::FunctionDebugContext;
use llvm;
use llvm::debuginfo::DIScope;
use builder::Builder;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use libc::c_uint;
use syntax_pos::{Span, Pos};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use common::CodegenCx;
use rustc::hir::def_id::DefId;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc::hir;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc::ty::DefIdTree;
use llvm;
use llvm::debuginfo::{DIScope, DIBuilder, DIDescriptor, DIArray};
use common::{CodegenCx};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use syntax_pos::{self, Span};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use abi::{Abi, FnType, FnTypeExt};
use attributes;
use context::CodegenCx;
use type_::Type;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use value::Value;

/// Declare a function.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use syntax::symbol::Symbol;
use builder::Builder;
use value::Value;

use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use rustc::session::Session;
use syntax_pos::Span;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern crate cc; // Used to locate MSVC
extern crate tempfile;
extern crate memmap;

use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig};
use rustc_codegen_ssa::back::lto::{SerializedModule, LtoModuleCodegen, ThinModule};
use rustc_codegen_ssa::CompiledModule;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::mir::mono::{Linkage, Visibility};
use rustc::ty::TypeFoldable;
use rustc::ty::layout::{LayoutOf, HasTyCtxt};
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

pub use rustc::mir::mono::MonoItem;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use llvm::Type;
use llvm;
use llvm::{Bool, False, True};
use context::CodegenCx;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;
use value::Value;

use rustc::util::nodemap::FxHashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
use rustc_target::abi::FloatTy;
use rustc_mir::monomorphize::item::DefPathBasedNames;
use type_::Type;
use rustc_codegen_ssa::interfaces::*;
use rustc_codegen_ssa::traits::*;

use std::fmt::Write;

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For these reasons, the separation process involves two transformations that have
1. replace all the LLVM-specific types by generics inside function signatures and structure definitions;
2. encapsulate all functions calling the LLVM FFI inside a set of traits that will define the interface between backend-agnostic code and the backend.

While the LLVM-specific code will be left in `rustc_codegen_llvm`, all the new interfaces and backend-agnostic code will be moved in `rustc_codegen_ssa` (name suggestion by @eddyb).
While the LLVM-specific code will be left in `rustc_codegen_llvm`, all the new traits and backend-agnostic code will be moved in `rustc_codegen_ssa` (name suggestion by @eddyb).

## Generic types and structures

Expand Down Expand Up @@ -58,7 +58,7 @@ However, the two most important structures `CodegenCx` and `Builder` are not def

## Traits and interface

Because they have to be defined by the backend, `CodegenCx` and `Builder` will be the structures implementing all the traits defining the backend's interface. These traits are defined in the folder `rustc_codegen_ssa/interfaces` and all the backend-agnostic code is parametrized by them. For instance, let us explain how a function in `base.rs` is parametrized:
Because they have to be defined by the backend, `CodegenCx` and `Builder` will be the structures implementing all the traits defining the backend's interface. These traits are defined in the folder `rustc_codegen_ssa/traits` and all the backend-agnostic code is parametrized by them. For instance, let us explain how a function in `base.rs` is parametrized:

```rust
pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
Expand All @@ -71,7 +71,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(

In this signature, we have the two lifetime parameters explained earlier and the master type `Bx` which satisfies the trait `BuilderMethods` corresponding to the interface satisfied by the `Builder` struct. The `BuilderMethods` defines an associated type `Bx::CodegenCx` that itself satisfies the `CodegenMethods` traits implemented by the struct `CodegenCx`.

On the trait side, here is an example with part of the definition of `BuilderMethods` in `interfaces/builder.rs`:
On the trait side, here is an example with part of the definition of `BuilderMethods` in `traits/builder.rs`:

```rust
pub trait BuilderMethods<'a, 'tcx: 'a>:
Expand Down Expand Up @@ -116,6 +116,6 @@ However, the current separation between backend-agnostic and LLVM-specific code

The `debuginfo` folder has been left almost untouched by the splitting and is specific to LLVM. Only its high-level features have been traitified.

The new `interfaces` folder has 1500 LOC only for trait definitions. Overall, the 27,000 LOC-sized old `rustc_codegen_llvm` code has been split into the new 18,500 LOC-sized new `rustc_codegen_llvm` and the 12,000 LOC-sized `rustc_codegen_ssa`. We can say that this refactoring allowed the reuse of approximately 10,000 LOC that would otherwise have had to be duplicated between the multiple backends of `rustc`.
The new `traits` folder has 1500 LOC only for trait definitions. Overall, the 27,000 LOC-sized old `rustc_codegen_llvm` code has been split into the new 18,500 LOC-sized new `rustc_codegen_llvm` and the 12,000 LOC-sized `rustc_codegen_ssa`. We can say that this refactoring allowed the reuse of approximately 10,000 LOC that would otherwise have had to be duplicated between the multiple backends of `rustc`.

The refactored version of `rustc`'s backend introduced no regression over the test suite nor in performance benchmark, which is in coherence with the nature of the refactoring that used only compile-time parametricity (no trait objects).
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use super::write::CodegenContext;
use interfaces::*;
use traits::*;
use ModuleCodegen;

use rustc::util::time_graph::Timeline;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Sanitize
use rustc::session::Session;
use rustc::util::nodemap::FxHashMap;
use rustc::util::time_graph::{self, TimeGraph, Timeline};
use interfaces::*;
use traits::*;
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc::ty::TyCtxt;
use rustc::util::common::{time_depth, set_time_depth, print_time_passes_entry};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_codegen_utils::{symbol_names_test, check_for_rustc_errors_attr};
use rustc::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};

use interfaces::*;
use traits::*;

use std::any::Any;
use std::cmp;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use interfaces::*;
use traits::*;
use rustc::ty;
use rustc::ty::subst::Substs;
use rustc::hir::def_id::DefId;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use syntax_pos::{DUMMY_SP, Span};
use rustc::hir::def_id::DefId;
use rustc::middle::lang_items::LangItem;
use base;
use interfaces::*;
use traits::*;

use rustc::hir;
use interfaces::BuilderMethods;
use traits::BuilderMethods;

pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use common::IntPredicate;
use meth;
use rustc::ty::layout::LayoutOf;
use rustc::ty::{self, Ty};
use interfaces::*;
use traits::*;

pub fn size_and_align_of_dst<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use syntax_pos::symbol::Symbol;
mod diagnostics;

pub mod common;
pub mod interfaces;
pub mod traits;
pub mod mir;
pub mod debuginfo;
pub mod base;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_target::abi::call::FnType;
use callee;
use rustc_mir::monomorphize;

use interfaces::*;
use traits::*;

use rustc::ty::{self, Ty};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc::mir::traversal;
use rustc::ty;
use rustc::ty::layout::{LayoutOf, HasTyCtxt};
use super::FunctionCx;
use interfaces::*;
use traits::*;

pub fn non_ssa_locals<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
fx: &FunctionCx<'a, 'tcx, Bx>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use common::{self, IntPredicate};
use meth;
use rustc_mir::monomorphize;

use interfaces::*;
use traits::*;

use syntax::symbol::Symbol;
use syntax_pos::Pos;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc::mir::interpret::{GlobalId, ConstValue};
use rustc::ty::{self, Ty};
use rustc::ty::layout::{self, LayoutOf};
use syntax::source_map::Span;
use interfaces::*;
use traits::*;

use super::FunctionCx;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use base;
use debuginfo::{self, VariableAccess, VariableKind, FunctionDebugContext};
use rustc_mir::monomorphize::Instance;
use rustc_target::abi::call::{FnType, PassMode};
use interfaces::*;
use traits::*;

use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
use syntax::symbol::keywords;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use base;
use MemFlags;
use glue;

use interfaces::*;
use traits::*;

use std::fmt;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use MemFlags;
use common::IntPredicate;
use glue;

use interfaces::*;
use traits::*;

use super::{FunctionCx, LocalRef};
use super::operand::OperandValue;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use callee;
use common::{self, RealPredicate, IntPredicate};
use rustc_mir::monomorphize;

use interfaces::*;
use traits::*;

use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

use rustc::mir;

use interfaces::BuilderMethods;
use traits::BuilderMethods;
use super::FunctionCx;
use super::LocalRef;
use super::OperandValue;
use interfaces::*;
use traits::*;

impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_statement(
Expand Down
Loading

0 comments on commit 0b56924

Please sign in to comment.