Skip to content
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
12 changes: 9 additions & 3 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
// deforested) style because I have found that, in practice, this is
// the most concise way to do things. That means that they do not not
// terminate with a call to `ok(v)` but rather `nxt(v)`. If you would
// like to just get the result, just pass in `ok` as `nxt`.
// like to just get the result, just pass in `ok1` as `nxt`.

#[doc = "An annoying helper function for bridging argument modes when
using deforested functions."]
fn ok1<T:copy,U>(x: T) -> result<T,U> {
ok(x)
}

#[doc = "
Maps each element in the vector `ts` using the operation `op`. Should an
Expand All @@ -118,7 +124,7 @@ checking for overflow:
}

Note: if you have to combine a deforested style transform with map,
you should use `ok` for the `nxt` operation, as shown here (this is an
you should use `ok1` for the `nxt` operation, as shown here (this is an
alternate version of the previous example where the
`inc_conditionally()` routine is deforested):

Expand All @@ -127,7 +133,7 @@ alternate version of the previous example where the
if x == uint::max_value { ret err(\"overflow\"); }
else { ret nxt(x+1u); }
}
map([1u, 2u, 3u], inc_conditionally(_, ok)) {|incd|
map([1u, 2u, 3u], inc_conditionally(_, ok1)) {|incd|
assert incd == [2u, 3u, 4u];
}
"]
Expand Down
1 change: 1 addition & 0 deletions src/rustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import tydecode::{parse_ty_data, parse_def_id, parse_bounds_data,
import syntax::print::pprust;
import cmd=cstore::crate_metadata;
import middle::trans::common::maps;
import ty::ty_ops;

export get_class_items;
export get_symbol;
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import syntax::ast_util::local_def;
import common::*;
import middle::trans::common::crate_ctxt;
import middle::ty;
import middle::ty::node_id_to_type;
import middle::ty::{node_id_to_type, ty_ops};
import middle::ast_map;
import front::attr;
import driver::session::session;
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import syntax::ast::*;
import syntax::ast_util;
import syntax::ast_util::respan;
import middle::ty;
import middle::ty::ty_ops;
import std::map::hashmap;

export parse_ty_data, parse_def_id, parse_ident;
Expand Down Expand Up @@ -265,7 +266,6 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
st.pos = st.pos + 1u;
ret ty::mk_res(st.tcx, def, inner, params);
}
'X' { ret ty::mk_var(st.tcx, parse_int(st)); }
'Y' { ret ty::mk_type(st.tcx); }
'C' {
let ck = alt check next(st) {
Expand Down
1 change: 0 additions & 1 deletion src/rustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
for t: ty::t in tps { enc_ty(w, cx, t); }
w.write_char(']');
}
ty::ty_var(id) { w.write_char('X'); w.write_str(int::str(id)); }
ty::ty_param(id, did) {
w.write_char('p');
w.write_str(cx.ds(did));
Expand Down
52 changes: 52 additions & 0 deletions src/rustc/middle/ast_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import std::map;
import std::map::hashmap;
import syntax::ast::*;
import syntax::print::pprust;
import syntax::ast_util;
import syntax::ast_util::inlined_item_methods;
import syntax::{visit, codemap};
Expand All @@ -24,6 +25,14 @@ fn path_to_str(p: path) -> str {
path_to_str_with_sep(p, "::")
}

fn path_ident_to_str(p: path, i: ident) -> str {
if vec::is_empty(p) {
i
} else {
#fmt["%s::%s", path_to_str(p), i]
}
}

enum ast_node {
node_item(@item, @path),
node_native_item(@native_item, native_abi, @path),
Expand All @@ -44,6 +53,49 @@ type ctx = {map: map, mutable path: path,
mutable local_id: uint, sess: session};
type vt = visit::vt<ctx>;

fn node_str(map: map, id: node_id) -> str {
alt map.find(id) {
none {
#fmt["unknown node (id=%d)", id]
}
some(node_item(item, path)) {
#fmt["item %s (id=%?)", path_ident_to_str(*path, item.ident), id]
}
some(node_native_item(item, abi, path)) {
#fmt["native item %s with abi %? (id=%?)",
path_ident_to_str(*path, item.ident), abi, id]
}
some(node_method(m, impl_did, path)) {
#fmt["method %s in %s (id=%?)",
m.ident, path_to_str(*path), id]
}
some(node_variant(variant, def_id, path)) {
#fmt["variant %s in %s (id=%?)",
variant.node.name, path_to_str(*path), id]
}
some(node_expr(expr)) {
#fmt["expr %s (id=%?)",
pprust::expr_to_str(expr), id]
}
some(node_export(_, path)) {
#fmt["export %s (id=%?)", // FIXME: add more info here
path_to_str(*path), id]
}
some(node_arg(_, _)) { // FIXME: add more info here
#fmt["arg (id=%?)", id]
}
some(node_local(_)) { // FIXME: add more info here
#fmt["local (id=%?)", id]
}
some(node_ctor(_, _)) { // FIXME: add more info here
#fmt["node_ctor (id=%?)", id]
}
some(node_block(_)) {
#fmt["block"]
}
}
}

fn extend(cx: ctx, elt: str) -> @path {
@(cx.path + [path_name(elt)])
}
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/fn_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn fn_usage_expr(expr: @ast::expr,
alt ctx.tcx.def_map.find(expr.id) {
some(ast::def_fn(_, ast::unsafe_fn)) {
log(error, ("expr=", expr_to_str(expr)));
ctx.tcx.sess.span_fatal(
ctx.tcx.sess.span_err(
expr.span,
"unsafe functions can only be called");
}
Expand All @@ -33,7 +33,7 @@ fn fn_usage_expr(expr: @ast::expr,
&& ty::expr_has_ty_params(ctx.tcx, expr) {
alt ty::get(ty::expr_ty(ctx.tcx, expr)).struct {
ty::ty_fn({proto: ast::proto_bare, _}) {
ctx.tcx.sess.span_fatal(
ctx.tcx.sess.span_err(
expr.span,
"generic bare functions can only be called or bound");
}
Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import syntax::print::pprust::pat_to_str;
import back::abi;
import resolve::def_map;
import std::map::hashmap;
import ty::ty_ops;

import common::*;

Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import link::{mangle_internal_name_by_type_only,
mangle_exported_name};
import metadata::{csearch, cstore};
import util::ppaux::{ty_to_str, ty_to_short_str};
import ty::ty_ops;

import common::*;
import build::*;
Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import util::ppaux::ty_to_str;
import ast_map::{path, path_mod, path_name};
import driver::session::session;
import std::map::hashmap;
import ty::ty_ops;

// ___Good to know (tm)__________________________________________________
//
Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
import lib::llvm::{True, False, Bool};
import metadata::csearch;
import ast_map::path;
import ty::ty_ops;

type namegen = fn@(str) -> str;
fn new_namegen() -> namegen {
Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ast::ty;
import pat_util::*;
import util::ppaux::ty_to_str;
import driver::session::session;
import ty::ty_ops;

export create_local_var;
export create_function;
Expand Down
3 changes: 2 additions & 1 deletion src/rustc/middle/trans/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import lib::llvm::{ValueRef, TypeRef};
import lib::llvm::llvm::LLVMGetParam;
import ast_map::{path, path_mod, path_name};
import std::map::hashmap;
import ty::ty_ops;

fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
methods: [@ast::method], tps: [ast::ty_param]) {
Expand Down Expand Up @@ -238,7 +239,7 @@ fn make_impl_vtable(ccx: @crate_ctxt, impl_id: ast::def_id, substs: [ty::t],
make_vtable(ccx, vec::map(*ty::iface_methods(tcx, ifce_id), {|im|
let fty = ty::substitute_type_params(tcx, substs,
ty::mk_fn(tcx, im.fty));
if (*im.tps).len() > 0u || ty::type_has_vars(fty) {
if (*im.tps).len() > 0u || ty::type_has_self(fty) {
C_null(T_ptr(T_nil()))
} else {
let m_id = method_with_name(ccx, impl_id, im.ident);
Expand Down
6 changes: 3 additions & 3 deletions src/rustc/middle/trans/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import middle::trans::common::*;
import back::abi;
import middle::ty;
import middle::ty::field;
import middle::ty::ty_ops;
import syntax::ast;
import syntax::ast_util::dummy_sp;
import syntax::util::interner;
import util::common;
import trans::build::{Load, Store, Add, GEPi};
import syntax::codemap::span;

import std::map::hashmap;

import ty_ctxt = middle::ty::ctxt;
Expand Down Expand Up @@ -405,7 +405,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
ty::ty_fn({proto: ast::proto_bare, _}) { [shape_bare_fn] }
ty::ty_opaque_closure_ptr(_) { [shape_opaque_closure_ptr] }
ty::ty_constr(inner_t, _) { shape_of(ccx, inner_t, ty_param_map) }
ty::ty_var(_) | ty::ty_self(_) {
ty::ty_self(_) {
ccx.sess.bug("shape_of: unexpected type struct found");
}
}
Expand Down Expand Up @@ -635,7 +635,7 @@ fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
_ { typ }
}
}
ty::fold_ty(tcx, ty::fm_general(bind simplifier(tcx, _)), typ)
ty::fold(tcx, typ) {|t| simplifier(tcx, t) }
}

// Given a tag type `ty`, returns the offset of the payload.
Expand Down
1 change: 1 addition & 0 deletions src/rustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import base::{call_memmove, trans_shared_malloc,
import shape::llsize_of;
import build::*;
import common::*;
import ty::ty_ops;

fn get_fill(bcx: block, vptr: ValueRef) -> ValueRef {
Load(bcx, GEPi(bcx, vptr, [0, abi::vec_elt_fill]))
Expand Down
14 changes: 5 additions & 9 deletions src/rustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ fn type_of_fn_from_ty(cx: @crate_ctxt, fty: ty::t) -> TypeRef {
}

fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
assert !ty::type_has_vars(t);
// Check the cache.

if cx.lltypes.contains_key(t) { ret cx.lltypes.get(t); }
let llty = alt ty::get(t).struct {
ty::ty_nil | ty::ty_bot { T_nil() }
Expand Down Expand Up @@ -87,18 +84,17 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
for ci in cls_items {
// only instance vars are record fields at runtime
alt ci.contents {
var_ty(t) {
let fty = type_of(cx, t);
tys += [fty];
}
_ {}
var_ty(t) {
let fty = type_of(cx, t);
tys += [fty];
}
_ {}
}
}
T_struct(tys)
}
ty::ty_self(_) { cx.tcx.sess.unimpl("type_of: ty_self \
not implemented"); }
ty::ty_var(_) { cx.tcx.sess.bug("type_of shouldn't see a ty_var"); }
};
cx.lltypes.insert(t, llty);
ret llty;
Expand Down
Loading