Skip to content

Separate typeck/trans into distinct crates. #19362

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

Merged
merged 15 commits into from
Dec 5, 2014
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
22 changes: 15 additions & 7 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ TARGET_CRATES := libc std flate arena term \
serialize getopts collections test time rand \
log regex graphviz core rbml alloc rustrt \
unicode
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
rustc_llvm rustc_back
RUSTC_CRATES := rustc rustc_typeck rustc_driver rustc_trans rustc_back rustc_llvm
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc regex_macros fmt_macros
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc

Expand All @@ -67,12 +67,16 @@ DEPS_std := core libc rand alloc collections rustrt unicode \
native:rust_builtin native:backtrace
DEPS_graphviz := std
DEPS_syntax := std term serialize log fmt_macros arena libc
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back \
rustc_typeck log syntax serialize rustc_llvm rustc_trans
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
log syntax serialize rustc_llvm
DEPS_rustc_typeck := rustc syntax
DEPS_rustc := syntax flate arena serialize getopts rbml \
time log graphviz rustc_llvm rustc_back
DEPS_rustc_llvm := native:rustllvm libc std
DEPS_rustc_back := std syntax rustc_llvm flate log libc
DEPS_rustdoc := rustc rustc_trans native:hoedown serialize getopts \
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
test time
DEPS_flate := std native:miniz
DEPS_arena := std
Expand All @@ -94,7 +98,7 @@ DEPS_fmt_macros = std

TOOL_DEPS_compiletest := test getopts
TOOL_DEPS_rustdoc := rustdoc
TOOL_DEPS_rustc := rustc_trans
TOOL_DEPS_rustc := rustc_driver
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
Expand All @@ -110,8 +114,12 @@ ONLY_RLIB_unicode := 1
# You should not need to edit below this line
################################################################################

DOC_CRATES := $(filter-out rustc, $(filter-out rustc_trans, $(filter-out syntax, $(CRATES))))
COMPILER_DOC_CRATES := rustc rustc_trans syntax
DOC_CRATES := $(filter-out rustc, \
$(filter-out rustc_trans, \
$(filter-out rustc_typeck, \
$(filter-out rustc_driver, \
$(filter-out syntax, $(CRATES))))))
COMPILER_DOC_CRATES := rustc rustc_trans rustc_typeck rustc_driver syntax

# This macro creates some simple definitions for each crate being built, just
# some munging of all of the parameters above.
Expand Down
2 changes: 1 addition & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(eval $(call RUST_CRATE,coretest))

TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) coretest
TEST_DOC_CRATES = $(DOC_CRATES)
TEST_HOST_CRATES = $(HOST_CRATES)
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_trans,$(HOST_CRATES))
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)

######################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
extern crate "rustdoc" as this;

#[cfg(rustc)]
extern crate "rustc_trans" as this;
extern crate "rustc_driver" as this;

fn main() { this::main() }
3 changes: 2 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub mod back {
}

pub mod middle {
pub mod astconv_util;
pub mod astencode;
pub mod borrowck;
pub mod cfg;
Expand All @@ -79,6 +80,7 @@ pub mod middle {
pub mod fast_reject;
pub mod graph;
pub mod intrinsicck;
pub mod infer;
pub mod lang_items;
pub mod liveness;
pub mod mem_categorization;
Expand All @@ -93,7 +95,6 @@ pub mod middle {
pub mod traits;
pub mod ty;
pub mod ty_fold;
pub mod typeck;
pub mod weak_lang_items;
}

Expand Down
14 changes: 6 additions & 8 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ use self::MethodContext::*;
use metadata::csearch;
use middle::def::*;
use middle::ty::{mod, Ty};
use middle::typeck::astconv::ast_ty_to_ty;
use middle::typeck::{mod, infer};
use middle::{def, pat_util, stability};
use middle::const_eval::{eval_const_expr_partial, const_int, const_uint};
use util::ppaux::{ty_to_string};
Expand Down Expand Up @@ -84,7 +82,7 @@ impl LintPass for UnusedCasts {

fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
if let ast::ExprCast(ref expr, ref ty) = e.node {
let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty);
let t_t = ty::expr_ty(cx.tcx, e);
if ty::expr_ty(cx.tcx, &**expr) == t_t {
cx.span_lint(UNUSED_TYPECASTS, ty.span, "unnecessary type cast");
}
Expand Down Expand Up @@ -1589,22 +1587,22 @@ impl LintPass for Stability {
}
ast::ExprMethodCall(i, _, _) => {
span = i.span;
let method_call = typeck::MethodCall::expr(e.id);
let method_call = ty::MethodCall::expr(e.id);
match cx.tcx.method_map.borrow().get(&method_call) {
Some(method) => {
match method.origin {
typeck::MethodStatic(def_id) => {
ty::MethodStatic(def_id) => {
def_id
}
typeck::MethodStaticUnboxedClosure(def_id) => {
ty::MethodStaticUnboxedClosure(def_id) => {
def_id
}
typeck::MethodTypeParam(typeck::MethodParam {
ty::MethodTypeParam(ty::MethodParam {
ref trait_ref,
method_num: index,
..
}) |
typeck::MethodTraitObject(typeck::MethodObject {
ty::MethodTraitObject(ty::MethodObject {
ref trait_ref,
method_num: index,
..
Expand Down
40 changes: 0 additions & 40 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
use self::TargetLint::*;

use middle::privacy::ExportedItems;
use middle::subst;
use middle::ty::{mod, Ty};
use middle::typeck::astconv::AstConv;
use middle::typeck::infer;
use session::{early_error, Session};
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
use lint::builtin;
use util::nodemap::FnvHashMap;

use std::rc::Rc;
use std::cell::RefCell;
use std::tuple::Tuple2;
use std::mem;
Expand Down Expand Up @@ -541,42 +537,6 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
}
}

impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx }

fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> {
ty::lookup_item_type(self.tcx, id)
}

fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef<'tcx>> {
ty::lookup_trait_def(self.tcx, id)
}

fn ty_infer(&self, _span: Span) -> Ty<'tcx> {
infer::new_infer_ctxt(self.tcx).next_ty_var()
}

fn associated_types_of_trait_are_valid(&self, _: Ty<'tcx>, _: ast::DefId)
-> bool {
// FIXME(pcwalton): This is wrong.
true
}

fn associated_type_binding(&self,
_: Span,
_: Option<Ty<'tcx>>,
trait_id: ast::DefId,
associated_type_id: ast::DefId)
-> Ty<'tcx> {
// FIXME(pcwalton): This is wrong.
let trait_def = self.get_trait_def(trait_id);
let index = ty::associated_type_parameter_index(self.tcx,
&*trait_def,
associated_type_id);
ty::mk_param(self.tcx, subst::TypeSpace, index, associated_type_id)
}
}

impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
fn visit_item(&mut self, it: &ast::Item) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use middle::def;
use middle::lang_items;
use middle::resolve;
use middle::ty;
use middle::typeck;
use middle::subst::VecPerParamSpace;

use rbml;
Expand Down Expand Up @@ -268,7 +267,7 @@ pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>,
// Given a def_id for an impl, return information about its vtables
pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>,
def: ast::DefId)
-> typeck::vtable_res<'tcx> {
-> ty::vtable_res<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_vtables(&*cdata, def.node, tcx)
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use middle::resolve::{TraitItemKind, TypeTraitItemKind};
use middle::subst;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty::{mod, Ty};
use middle::typeck;
use middle::astencode::vtable_decoder_helpers;

use std::hash::Hash;
Expand Down Expand Up @@ -422,7 +421,7 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd,
pub fn get_impl_vtables<'tcx>(cdata: Cmd,
id: ast::NodeId,
tcx: &ty::ctxt<'tcx>)
-> typeck::vtable_res<'tcx>
-> ty::vtable_res<'tcx>
{
let item_doc = lookup_item(id, cdata.data());
let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);
Expand Down
89 changes: 89 additions & 0 deletions src/librustc/middle/astconv_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/*!
* This module contains a simple utility routine
* used by both `typeck` and `const_eval`.
* Almost certainly this could (and should) be refactored out of existence.
*/

use middle::def;
use middle::ty::{mod, Ty};
use syntax::ast;
use util::ppaux::Repr;

pub const NO_REGIONS: uint = 1;
pub const NO_TPS: uint = 2;

pub fn check_path_args(tcx: &ty::ctxt,
path: &ast::Path,
flags: uint) {
if (flags & NO_TPS) != 0u {
if path.segments.iter().any(|s| s.parameters.has_types()) {
span_err!(tcx.sess, path.span, E0109,
"type parameters are not allowed on this type");
}
}

if (flags & NO_REGIONS) != 0u {
if path.segments.iter().any(|s| s.parameters.has_lifetimes()) {
span_err!(tcx.sess, path.span, E0110,
"region parameters are not allowed on this type");
}
}
}

pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
-> Option<Ty<'tcx>> {
match ast_ty.node {
ast::TyPath(ref path, id) => {
let a_def = match tcx.def_map.borrow().get(&id) {
None => {
tcx.sess.span_bug(ast_ty.span,
format!("unbound path {}",
path.repr(tcx)).as_slice())
}
Some(&d) => d
};
match a_def {
def::DefPrimTy(nty) => {
match nty {
ast::TyBool => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
Some(ty::mk_bool())
}
ast::TyChar => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
Some(ty::mk_char())
}
ast::TyInt(it) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
Some(ty::mk_mach_int(it))
}
ast::TyUint(uit) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
Some(ty::mk_mach_uint(uit))
}
ast::TyFloat(ft) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
Some(ty::mk_mach_float(ft))
}
ast::TyStr => {
Some(ty::mk_str(tcx))
}
}
}
_ => None
}
}
_ => None
}
}

Loading