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

Remove the __log function for __log_level #9005

Closed
wants to merge 1 commit into from
Closed
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/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ impl CFGBuilder {
self.straightline(expr, pred, [r, l])
}

ast::ExprLog(l, r) |
ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r])
Expand All @@ -405,6 +404,7 @@ impl CFGBuilder {
self.straightline(expr, pred, [e])
}

ast::ExprLogLevel |
ast::ExprMac(*) |
ast::ExprInlineAsm(*) |
ast::ExprSelf |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,12 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
join_bits(&self.dfcx.oper, temp, in_out);
}

ast::ExprLog(l, r) |
ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) => {
self.walk_exprs([l, r], in_out, loop_scopes);
}

ast::ExprLogLevel |
ast::ExprLit(*) |
ast::ExprPath(*) |
ast::ExprSelf => {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub enum LangItem {

StrEqFnLangItem, // 19
UniqStrEqFnLangItem, // 20
LogTypeFnLangItem, // 21
FailFnLangItem, // 22
FailBoundsCheckFnLangItem, // 23
ExchangeMallocFnLangItem, // 24
Expand Down Expand Up @@ -238,9 +237,6 @@ impl LanguageItems {
pub fn uniq_str_eq_fn(&self) -> Option<DefId> {
self.items[UniqStrEqFnLangItem as uint]
}
pub fn log_type_fn(&self) -> Option<DefId> {
self.items[LogTypeFnLangItem as uint]
}
pub fn fail_fn(&self) -> Option<DefId> {
self.items[FailFnLangItem as uint]
}
Expand Down Expand Up @@ -357,7 +353,6 @@ impl<'self> LanguageItemCollector<'self> {

item_refs.insert(@"str_eq", StrEqFnLangItem as uint);
item_refs.insert(@"uniq_str_eq", UniqStrEqFnLangItem as uint);
item_refs.insert(@"log_type", LogTypeFnLangItem as uint);
item_refs.insert(@"fail_", FailFnLangItem as uint);
item_refs.insert(@"fail_bounds_check",
FailBoundsCheckFnLangItem as uint);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: @Expr, this: @mut IrMaps) {

// otherwise, live nodes are not required:
ExprIndex(*) | ExprField(*) | ExprVstore(*) | ExprVec(*) |
ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLog(*) |
ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLogLevel |
ExprBinary(*) | ExprAddrOf(*) |
ExprDoBody(*) | ExprCast(*) | ExprUnary(*) | ExprBreak(_) |
ExprAgain(_) | ExprLit(_) | ExprRet(*) | ExprBlock(*) |
Expand Down Expand Up @@ -1217,7 +1217,6 @@ impl Liveness {
self.propagate_through_expr(l, ln)
}

ExprLog(l, r) |
ExprIndex(_, l, r) |
ExprBinary(_, _, l, r) => {
self.propagate_through_exprs([l, r], succ)
Expand All @@ -1240,6 +1239,7 @@ impl Liveness {
}
}

ExprLogLevel |
ExprLit(*) => {
succ
}
Expand Down Expand Up @@ -1496,7 +1496,7 @@ fn check_expr(vt: &mut ErrorCheckVisitor, expr: @Expr, this: @Liveness) {
// no correctness conditions related to liveness
ExprCall(*) | ExprMethodCall(*) | ExprIf(*) | ExprMatch(*) |
ExprWhile(*) | ExprLoop(*) | ExprIndex(*) | ExprField(*) |
ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLog(*) |
ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLogLevel |
ExprBinary(*) | ExprDoBody(*) |
ExprCast(*) | ExprUnary(*) | ExprRet(*) | ExprBreak(*) |
ExprAgain(*) | ExprLit(_) | ExprBlock(*) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl mem_categorization_ctxt {
ast::ExprDoBody(*) | ast::ExprUnary(*) |
ast::ExprMethodCall(*) | ast::ExprCast(*) | ast::ExprVstore(*) |
ast::ExprVec(*) | ast::ExprTup(*) | ast::ExprIf(*) |
ast::ExprLog(*) | ast::ExprBinary(*) | ast::ExprWhile(*) |
ast::ExprLogLevel | ast::ExprBinary(*) | ast::ExprWhile(*) |
ast::ExprBlock(*) | ast::ExprLoop(*) | ast::ExprMatch(*) |
ast::ExprLit(*) | ast::ExprBreak(*) | ast::ExprMac(*) |
ast::ExprAgain(*) | ast::ExprStruct(*) | ast::ExprRepeat(*) |
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ impl VisitContext {
self.use_expr(base, Read, visitor);
}

ExprLogLevel |
ExprInlineAsm(*) |
ExprBreak(*) |
ExprAgain(*) |
Expand All @@ -489,11 +490,6 @@ impl VisitContext {
self.consume_block(blk, visitor);
}

ExprLog(a_expr, b_expr) => {
self.consume_expr(a_expr, visitor);
self.use_expr(b_expr, Read, visitor);
}

ExprWhile(cond_expr, ref blk) => {
self.consume_expr(cond_expr, visitor);
self.consume_block(blk, visitor);
Expand Down
72 changes: 0 additions & 72 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::c_str::ToCStr;

use back::link;
use lib;
use lib::llvm::*;
use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
use middle::lang_items::LogTypeFnLangItem;
use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::callee;
Expand All @@ -28,7 +23,6 @@ use middle::trans::type_::Type;

use syntax::ast;
use syntax::ast::Ident;
use syntax::ast_map::path_mod;
use syntax::ast_util;
use syntax::codemap::Span;

Expand Down Expand Up @@ -206,72 +200,6 @@ pub fn trans_loop(bcx:@mut Block,
return next_bcx;
}

pub fn trans_log(log_ex: &ast::Expr,
lvl: @ast::Expr,
bcx: @mut Block,
e: @ast::Expr) -> @mut Block {
let _icx = push_ctxt("trans_log");
let ccx = bcx.ccx();
let mut bcx = bcx;
if ty::type_is_bot(expr_ty(bcx, lvl)) {
return expr::trans_into(bcx, lvl, expr::Ignore);
}

let (modpath, modname) = {
let path = &mut bcx.fcx.path;
let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
for e in path.iter() {
match *e {
path_mod(_) => { modpath.push(*e) }
_ => {}
}
}
let modname = path_str(ccx.sess, modpath);
(modpath, modname)
};

let global = if ccx.module_data.contains_key(&modname) {
ccx.module_data.get_copy(&modname)
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, "loglevel");
let global;
unsafe {
global = do s.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
};
llvm::LLVMSetGlobalConstant(global, False);
llvm::LLVMSetInitializer(global, C_null(Type::i32()));
lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
}
ccx.module_data.insert(modname, global);
global
};
let current_level = Load(bcx, global);
let level = unpack_result!(bcx, {
do with_scope_result(bcx, lvl.info(), "level") |bcx| {
expr::trans_to_datum(bcx, lvl).to_result()
}
});

let llenabled = ICmp(bcx, lib::llvm::IntUGE, current_level, level);
do with_cond(bcx, llenabled) |bcx| {
do with_scope(bcx, log_ex.info(), "log") |bcx| {
let mut bcx = bcx;

// Translate the value to be logged
let val_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, e));

// Call the polymorphic log function
let val = val_datum.to_ref_llval(bcx);
let did = langcall(bcx, Some(e.span), "", LogTypeFnLangItem);
let bcx = callee::trans_lang_call_with_type_params(
bcx, did, [level, val], [val_datum.ty], expr::Ignore);
bcx
}
}
}

pub fn trans_break_cont(bcx: @mut Block,
opt_label: Option<Ident>,
to_end: bool)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ fn populate_scope_map(cx: &mut CrateContext,
scope_map.insert(exp.id, scope_stack.last().scope_metadata);

match exp.node {
ast::ExprLogLevel |
ast::ExprSelf |
ast::ExprLit(_) |
ast::ExprBreak(_) |
Expand Down Expand Up @@ -2028,7 +2029,6 @@ fn populate_scope_map(cx: &mut CrateContext,
}

ast::ExprAssign(@ref sub_exp1, @ref sub_exp2) |
ast::ExprLog(@ref sub_exp1, @ref sub_exp2) |
ast::ExprRepeat(@ref sub_exp1, @ref sub_exp2, _) => {
walk_expr(cx, sub_exp1, scope_stack, scope_map);
walk_expr(cx, sub_exp2, scope_stack, scope_map);
Expand Down
48 changes: 44 additions & 4 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ return type, such as `while` loops or assignments (`a = b`).


use back::abi;
use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage};
use back::link;
use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage, False};
use lib;
use metadata::csearch;
use middle::trans::_match;
Expand Down Expand Up @@ -150,6 +151,7 @@ use std::hashmap::HashMap;
use std::vec;
use syntax::print::pprust::{expr_to_str};
use syntax::ast;
use syntax::ast_map::path_mod;
use syntax::codemap;

// Destinations
Expand Down Expand Up @@ -578,6 +580,9 @@ fn trans_rvalue_datum_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> DatumBloc
ast::ExprParen(e) => {
return trans_rvalue_datum_unadjusted(bcx, e);
}
ast::ExprLogLevel => {
return trans_log_level(bcx);
}
_ => {
bcx.tcx().sess.span_bug(
expr.span,
Expand Down Expand Up @@ -608,9 +613,6 @@ fn trans_rvalue_stmt_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> @mut Block
ast::ExprRet(ex) => {
return controlflow::trans_ret(bcx, ex);
}
ast::ExprLog(lvl, a) => {
return controlflow::trans_log(expr, lvl, bcx, a);
}
ast::ExprWhile(cond, ref body) => {
return controlflow::trans_while(bcx, cond, body);
}
Expand Down Expand Up @@ -1755,3 +1757,41 @@ fn trans_assign_op(bcx: @mut Block,
fn shorten(x: &str) -> @str {
(if x.char_len() > 60 {x.slice_chars(0, 60)} else {x}).to_managed()
}

pub fn trans_log_level(bcx: @mut Block) -> DatumBlock {
let _icx = push_ctxt("trans_log_level");
let ccx = bcx.ccx();

let (modpath, modname) = {
let path = &mut bcx.fcx.path;
let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
for e in path.iter() {
match *e {
path_mod(_) => { modpath.push(*e) }
_ => {}
}
}
let modname = path_str(ccx.sess, modpath);
(modpath, modname)
};

let global = if ccx.module_data.contains_key(&modname) {
ccx.module_data.get_copy(&modname)
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, "loglevel");
let global;
unsafe {
global = do s.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
};
llvm::LLVMSetGlobalConstant(global, False);
llvm::LLVMSetInitializer(global, C_null(Type::i32()));
lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
}
ccx.module_data.insert(modname, global);
global
};

return immediate_rvalue_bcx(bcx, Load(bcx, global), ty::mk_u32());
}
5 changes: 1 addition & 4 deletions src/librustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@ pub fn mark_for_expr(cx: &Context, e: &Expr) {
let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id);
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
}
ExprLog(_, val) => {
node_type_needs(cx, use_tydesc, val.id);
}
ExprCall(f, _, _) => {
let r = ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id));
for a in r.iter() {
Expand Down Expand Up @@ -411,7 +408,7 @@ pub fn mark_for_expr(cx: &Context, e: &Expr) {
ExprMatch(*) | ExprBlock(_) | ExprIf(*) | ExprWhile(*) |
ExprBreak(_) | ExprAgain(_) | ExprUnary(*) | ExprLit(_) |
ExprMac(_) | ExprAddrOf(*) | ExprRet(_) | ExprLoop(*) |
ExprDoBody(_) => (),
ExprDoBody(_) | ExprLogLevel => (),

ExprForLoop(*) => fail!("non-desugared expr_for_loop")
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,6 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprBreak(*) |
ast::ExprAgain(*) |
ast::ExprRet(*) |
ast::ExprLog(*) |
ast::ExprWhile(*) |
ast::ExprLoop(*) |
ast::ExprAssign(*) |
Expand All @@ -3331,6 +3330,7 @@ pub fn expr_kind(tcx: ctxt,

ast::ExprForLoop(*) => fail!("non-desugared expr_for_loop"),

ast::ExprLogLevel |
ast::ExprLit(_) | // Note: lit_str is carved out above
ast::ExprUnary(*) |
ast::ExprAddrOf(*) |
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,18 +2526,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
}
fcx.write_bot(id);
}
ast::ExprLog(lv, e) => {
check_expr_has_type(fcx, lv,
ty::mk_mach_uint(ast::ty_u32));

// Note: this does not always execute, so do not propagate bot:
check_expr(fcx, e);
if ty::type_is_error(fcx.expr_ty(e)) {
fcx.write_error(id);
}
else {
fcx.write_nil(id);
}
ast::ExprLogLevel => {
fcx.write_ty(id, ty::mk_u32())
}
ast::ExprParen(a) => {
check_expr_with_opt_hint(fcx, a, expected);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ pub mod guarantor {
ast::ExprBreak(*) |
ast::ExprAgain(*) |
ast::ExprRet(*) |
ast::ExprLog(*) |
ast::ExprLogLevel |
ast::ExprWhile(*) |
ast::ExprLoop(*) |
ast::ExprAssign(*) |
Expand Down
9 changes: 8 additions & 1 deletion src/libstd/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn console_off() {
rt::logging::console_off();
}

#[cfg(not(test))]
#[cfg(not(test), stage0)]
#[lang="log_type"]
#[allow(missing_doc)]
pub fn log_type<T>(_level: u32, object: &T) {
Expand Down Expand Up @@ -67,3 +67,10 @@ fn newsched_log_str(msg: ~str) {
}
}
}

// XXX: This will change soon to not require an allocation. This is an unstable
// api which should not be used outside of the macros in ext/expand.
#[doc(hidden)]
pub fn log(_level: u32, msg: ~str) {
newsched_log_str(msg);
}
Loading