2011-08-15 18:38:23 -05:00
|
|
|
import std::vec;
|
2011-07-09 00:05:30 -05:00
|
|
|
import std::int::str;
|
2011-06-22 17:41:39 -05:00
|
|
|
import std::str;
|
2011-05-14 21:02:30 -05:00
|
|
|
import std::option;
|
2011-07-09 00:05:30 -05:00
|
|
|
import std::option::*;
|
2011-07-06 09:46:17 -05:00
|
|
|
import std::int;
|
|
|
|
import std::uint;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::ast::*;
|
2011-08-21 23:44:41 -05:00
|
|
|
import syntax::ast_util::*;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::codemap::span;
|
2011-07-12 13:26:14 -05:00
|
|
|
import syntax::visit;
|
2011-05-14 21:02:30 -05:00
|
|
|
import util::common;
|
|
|
|
import util::common::log_block;
|
2011-07-06 09:46:17 -05:00
|
|
|
import std::map::new_int_hash;
|
|
|
|
import std::map::new_uint_hash;
|
2011-05-14 21:02:30 -05:00
|
|
|
import util::common::log_expr_err;
|
2011-06-01 20:10:10 -05:00
|
|
|
import util::common::lit_eq;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::print::pprust::path_to_str;
|
2011-05-14 21:02:30 -05:00
|
|
|
import tstate::ann::pre_and_post;
|
|
|
|
import tstate::ann::pre_and_post_state;
|
|
|
|
import tstate::ann::empty_ann;
|
|
|
|
import tstate::ann::prestate;
|
|
|
|
import tstate::ann::poststate;
|
|
|
|
import tstate::ann::precond;
|
|
|
|
import tstate::ann::postcond;
|
|
|
|
import tstate::ann::empty_states;
|
|
|
|
import tstate::ann::pps_len;
|
|
|
|
import tstate::ann::set_prestate;
|
|
|
|
import tstate::ann::set_poststate;
|
2011-07-09 00:05:30 -05:00
|
|
|
import tstate::ann::set_in_poststate_;
|
2011-05-14 21:02:30 -05:00
|
|
|
import tstate::ann::extend_prestate;
|
|
|
|
import tstate::ann::extend_poststate;
|
|
|
|
import tstate::ann::set_precondition;
|
|
|
|
import tstate::ann::set_postcondition;
|
2011-07-09 00:05:30 -05:00
|
|
|
import tstate::ann::set_in_postcond_;
|
2011-05-26 18:02:25 -05:00
|
|
|
import tstate::ann::ts_ann;
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
import tstate::ann::clear_in_postcond;
|
|
|
|
import tstate::ann::clear_in_poststate;
|
2011-06-25 00:17:17 -05:00
|
|
|
import tstate::ann::clear_in_poststate_;
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
import tritv::*;
|
2011-07-09 00:05:30 -05:00
|
|
|
import bitvectors::promises_;
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::print::pprust::constr_args_to_str;
|
2011-07-09 00:05:30 -05:00
|
|
|
import syntax::print::pprust::constr_arg_to_str;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::print::pprust::lit_to_str;
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-09 00:05:30 -05:00
|
|
|
// Used to communicate which operands should be invalidated
|
|
|
|
// to helper functions
|
|
|
|
tag oper_type {
|
|
|
|
oper_move;
|
|
|
|
oper_swap;
|
|
|
|
oper_assign;
|
|
|
|
oper_assign_op;
|
|
|
|
oper_pure;
|
|
|
|
}
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
/* logging funs */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn def_id_to_str(d: def_id) -> str {
|
2011-07-26 07:06:02 -05:00
|
|
|
ret int::str(d.crate) + "," + int::str(d.node);
|
2011-07-06 09:46:17 -05:00
|
|
|
}
|
2011-05-26 18:02:25 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn comma_str(args: &[@constr_arg_use]) -> str {
|
2011-07-27 07:19:39 -05:00
|
|
|
let rslt = "";
|
|
|
|
let comma = false;
|
2011-08-15 23:54:52 -05:00
|
|
|
for a: @constr_arg_use in args {
|
2011-07-27 07:19:39 -05:00
|
|
|
if comma { rslt += ", "; } else { comma = true; }
|
|
|
|
alt a.node {
|
|
|
|
carg_base. { rslt += "*"; }
|
|
|
|
carg_ident(i) { rslt += i.ident; }
|
|
|
|
carg_lit(l) { rslt += lit_to_str(l); }
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 12:04:08 -05:00
|
|
|
ret rslt;
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str {
|
|
|
|
alt c.node {
|
|
|
|
ninit(_, i) {
|
|
|
|
ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])";
|
|
|
|
}
|
|
|
|
npred(p, _, args) {
|
|
|
|
ret path_to_str(p) + "(" + comma_str(args) + ")" + "[" +
|
|
|
|
tcx.sess.span_str(c.span) + "]";
|
|
|
|
}
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str {
|
|
|
|
let s = "";
|
|
|
|
let comma = false;
|
2011-08-15 23:54:52 -05:00
|
|
|
for p: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt tritv_get(v, p.bit_num) {
|
|
|
|
dont_care. { }
|
|
|
|
t {
|
|
|
|
s +=
|
|
|
|
if comma { ", " } else { comma = true; "" } +
|
|
|
|
if t == tfalse { "!" } else { "" } +
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
constraint_to_str(fcx.ccx.tcx, p.c);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret s;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_tritv(fcx: &fn_ctxt, v: &tritv::t) { log tritv_to_str(fcx, v); }
|
2011-05-26 18:02:25 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t,
|
|
|
|
actual: &tritv::t) -> str {
|
|
|
|
let s: str = "";
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if tritv_get(expected, c.bit_num) == ttrue &&
|
|
|
|
tritv_get(actual, c.bit_num) != ttrue {
|
2011-06-29 13:50:02 -05:00
|
|
|
ret constraint_to_str(fcx.ccx.tcx, c.c);
|
2011-05-26 18:02:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret s;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_tritv_err(fcx: fn_ctxt, v: tritv::t) { log_err tritv_to_str(fcx, v); }
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn tos(v: &[uint]) -> str {
|
2011-07-27 07:19:39 -05:00
|
|
|
let rslt = "";
|
2011-08-15 23:54:52 -05:00
|
|
|
for i: uint in v {
|
2011-07-27 07:19:39 -05:00
|
|
|
if i == 0u {
|
|
|
|
rslt += "0";
|
2011-08-19 17:16:48 -05:00
|
|
|
} else if i == 1u { rslt += "1"; } else { rslt += "?"; }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-24 12:04:08 -05:00
|
|
|
ret rslt;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn log_cond(v: &[uint]) { log tos(v); }
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn log_cond_err(v: &[uint]) { log_err tos(v); }
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_pp(pp: &pre_and_post) {
|
|
|
|
let p1 = tritv::to_vec(pp.precondition);
|
|
|
|
let p2 = tritv::to_vec(pp.postcondition);
|
2011-06-15 13:19:50 -05:00
|
|
|
log "pre:";
|
|
|
|
log_cond(p1);
|
|
|
|
log "post:";
|
|
|
|
log_cond(p2);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_pp_err(pp: &pre_and_post) {
|
|
|
|
let p1 = tritv::to_vec(pp.precondition);
|
|
|
|
let p2 = tritv::to_vec(pp.postcondition);
|
2011-06-15 13:19:50 -05:00
|
|
|
log_err "pre:";
|
|
|
|
log_cond_err(p1);
|
|
|
|
log_err "post:";
|
|
|
|
log_cond_err(p2);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_states(pp: &pre_and_post_state) {
|
|
|
|
let p1 = tritv::to_vec(pp.prestate);
|
|
|
|
let p2 = tritv::to_vec(pp.poststate);
|
2011-06-15 13:19:50 -05:00
|
|
|
log "prestate:";
|
|
|
|
log_cond(p1);
|
|
|
|
log "poststate:";
|
|
|
|
log_cond(p2);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn log_states_err(pp: &pre_and_post_state) {
|
|
|
|
let p1 = tritv::to_vec(pp.prestate);
|
|
|
|
let p2 = tritv::to_vec(pp.poststate);
|
2011-06-15 13:19:50 -05:00
|
|
|
log_err "prestate:";
|
|
|
|
log_cond_err(p1);
|
|
|
|
log_err "poststate:";
|
|
|
|
log_cond_err(p2);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn print_ident(i: &ident) { log " " + i + " "; }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn print_idents(idents: &mutable [ident]) {
|
2011-08-13 02:09:25 -05:00
|
|
|
if vec::len::<ident>(idents) == 0u { ret; }
|
|
|
|
log "an ident: " + vec::pop::<ident>(idents);
|
2011-07-05 01:29:15 -05:00
|
|
|
print_idents(idents);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* data structures */
|
|
|
|
|
|
|
|
/**********************************************************************/
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-13 20:10:33 -05:00
|
|
|
/* Two different data structures represent constraints in different
|
|
|
|
contexts: constraint and norm_constraint.
|
2011-06-01 20:10:10 -05:00
|
|
|
|
2011-06-13 20:10:33 -05:00
|
|
|
constraint gets used to record constraints in a table keyed by def_ids.
|
|
|
|
cinit constraints represent a single constraint, for the initialization
|
|
|
|
state of a variable; a cpred constraint, with a single operator and a
|
|
|
|
list of possible argument lists, could represent several constraints at
|
|
|
|
once.
|
|
|
|
|
|
|
|
norm_constraint, in contrast, gets used when handling an instance
|
|
|
|
of a constraint rather than a definition of a constraint. It can
|
|
|
|
also be init or pred (ninit or npred), but the npred case just has
|
2011-07-13 17:44:09 -05:00
|
|
|
a single argument list.
|
2011-06-13 20:10:33 -05:00
|
|
|
|
|
|
|
The representation of constraints, where multiple instances of the
|
|
|
|
same predicate are collapsed into one entry in the table, makes it
|
|
|
|
easier to look up a specific instance.
|
|
|
|
|
|
|
|
Both types are in constrast with the constraint type defined in
|
2011-07-05 04:48:19 -05:00
|
|
|
syntax::ast, which is for predicate constraints only, and is what
|
2011-06-13 20:10:33 -05:00
|
|
|
gets generated by the parser. aux and ast share the same type
|
|
|
|
to represent predicate *arguments* however. This type
|
2011-07-05 04:48:19 -05:00
|
|
|
(constr_arg_general) is parameterized (see comments in syntax::ast).
|
2011-06-13 20:10:33 -05:00
|
|
|
|
|
|
|
Both types store an ident and span, for error-logging purposes.
|
|
|
|
*/
|
2011-08-04 18:20:09 -05:00
|
|
|
type pred_args_ = {args: [@constr_arg_use], bit_num: uint};
|
2011-06-16 18:55:46 -05:00
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type pred_args = spanned<pred_args_>;
|
2011-06-15 17:14:30 -05:00
|
|
|
|
2011-07-19 19:52:34 -05:00
|
|
|
// The attached node ID is the *defining* node ID
|
|
|
|
// for this local.
|
2011-08-12 09:15:18 -05:00
|
|
|
type constr_arg_use = spanned<constr_arg_general_<inst>>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-01 20:10:10 -05:00
|
|
|
tag constraint {
|
2011-06-13 20:10:33 -05:00
|
|
|
cinit(uint, span, ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2011-07-19 19:52:34 -05:00
|
|
|
// FIXME: really only want it to be mutable during collect_locals.
|
|
|
|
// freeze it after that.
|
2011-08-04 18:20:09 -05:00
|
|
|
cpred(path, @mutable [pred_args]);
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-07-19 19:52:34 -05:00
|
|
|
// An ninit variant has a node_id because it refers to a local var.
|
|
|
|
// An npred has a def_id since the definition of the typestate
|
|
|
|
// predicate need not be local.
|
|
|
|
// FIXME: would be nice to give both a def_id field,
|
|
|
|
// and give ninit a constraint saying it's local.
|
|
|
|
tag tsconstr {
|
|
|
|
ninit(node_id, ident);
|
2011-08-04 18:20:09 -05:00
|
|
|
npred(path, def_id, [@constr_arg_use]);
|
2011-07-05 01:29:15 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type sp_constr = spanned<tsconstr>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type norm_constraint = {bit_num: uint, c: sp_constr};
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type constr_map = @std::map::hashmap<def_id, constraint>;
|
2011-06-01 20:10:10 -05:00
|
|
|
|
2011-08-01 22:55:04 -05:00
|
|
|
/* Contains stuff that has to be computed up front */
|
2011-08-19 17:16:48 -05:00
|
|
|
/* For easy access, the fn_info stores two special constraints for each
|
|
|
|
function. i_return holds if all control paths in this function terminate
|
|
|
|
in either a return expression, or an appropriate tail expression.
|
|
|
|
i_diverge holds if all control paths in this function terminate in a fail
|
|
|
|
or diverging call.
|
|
|
|
|
|
|
|
It might be tempting to use a single constraint C for both properties,
|
|
|
|
where C represents i_return and !C represents i_diverge. This is
|
|
|
|
inadvisable, because then the sense of the bit depends on context. If we're
|
|
|
|
inside a ! function, that reverses the sense of the bit: C would be
|
|
|
|
i_diverge and !C would be i_return. That's awkward, because we have to
|
|
|
|
pass extra context around to functions that shouldn't care.
|
|
|
|
|
|
|
|
Okay, suppose C represents i_return and !C represents i_diverge, regardless
|
|
|
|
of context. Consider this code:
|
|
|
|
|
|
|
|
if (foo) { ret; } else { fail; }
|
|
|
|
|
|
|
|
C is true in the consequent and false in the alternative. What's T `join`
|
|
|
|
F, then? ? doesn't work, because this code should definitely-return if the
|
|
|
|
context is a returning function (and be definitely-rejected if the context
|
|
|
|
is a ! function). F doesn't work, because then the code gets incorrectly
|
|
|
|
rejected if the context is a returning function. T would work, but it
|
|
|
|
doesn't make sense for T `join` F to be T (consider init constraints, for
|
|
|
|
example).;
|
|
|
|
|
|
|
|
So we need context. And so it seems clearer to just have separate
|
|
|
|
constraints.
|
|
|
|
*/
|
2011-07-27 07:19:39 -05:00
|
|
|
type fn_info =
|
|
|
|
{constrs: constr_map,
|
|
|
|
num_constraints: uint,
|
|
|
|
cf: controlflow,
|
2011-08-01 22:55:04 -05:00
|
|
|
i_return: tsconstr,
|
|
|
|
i_diverge: tsconstr,
|
2011-08-19 17:16:48 -05:00
|
|
|
/* list, accumulated during pre/postcondition
|
2011-08-01 22:55:04 -05:00
|
|
|
computation, of all local variables that may be
|
|
|
|
used */
|
2011-08-19 17:16:48 -05:00
|
|
|
// Doesn't seem to work without the @ -- bug
|
2011-08-04 18:20:09 -05:00
|
|
|
used_vars: @mutable [node_id]};
|
2011-07-27 07:19:39 -05:00
|
|
|
|
|
|
|
fn tsconstr_to_def_id(t: &tsconstr) -> def_id {
|
|
|
|
alt t { ninit(id, _) { local_def(id) } npred(_, id, _) { id } }
|
2011-07-19 19:52:34 -05:00
|
|
|
}
|
2011-05-18 17:43:05 -05:00
|
|
|
|
2011-08-01 22:55:04 -05:00
|
|
|
fn tsconstr_to_node_id(t: &tsconstr) -> node_id {
|
2011-08-19 17:16:48 -05:00
|
|
|
alt t {
|
|
|
|
ninit(id, _) { id }
|
|
|
|
npred(_, id, _) { fail "tsconstr_to_node_id called on pred constraint" }
|
|
|
|
}
|
2011-08-01 22:55:04 -05:00
|
|
|
}
|
|
|
|
|
2011-05-18 17:43:05 -05:00
|
|
|
/* mapping from node ID to typestate annotation */
|
2011-08-04 18:20:09 -05:00
|
|
|
type node_ann_table = @mutable [mutable ts_ann];
|
2011-05-18 17:43:05 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
/* mapping from function name to fn_info map */
|
2011-08-12 09:15:18 -05:00
|
|
|
type fn_info_map = @std::map::hashmap<node_id, fn_info>;
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type fn_ctxt =
|
2011-08-19 17:16:48 -05:00
|
|
|
{enclosing: fn_info, id: node_id, name: ident, ccx: crate_ctxt};
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type crate_ctxt = {tcx: ty::ctxt, node_anns: node_ann_table, fm: fn_info_map};
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn get_fn_info(ccx: &crate_ctxt, id: node_id) -> fn_info {
|
2011-06-19 15:41:21 -05:00
|
|
|
assert (ccx.fm.contains_key(id));
|
|
|
|
ret ccx.fm.get(id);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) {
|
2011-08-15 18:38:23 -05:00
|
|
|
let sz = vec::len(*ccx.node_anns);
|
2011-07-27 07:19:39 -05:00
|
|
|
if sz <= i as uint {
|
2011-08-15 18:38:23 -05:00
|
|
|
vec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
|
2011-06-19 15:41:21 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
ccx.node_anns[i] = a;
|
2011-05-20 18:53:24 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> {
|
2011-08-15 18:38:23 -05:00
|
|
|
if i as uint < vec::len(*ccx.node_anns) {
|
2011-08-19 17:16:48 -05:00
|
|
|
ret some::<ts_ann>(ccx.node_anns[i]);
|
2011-08-13 02:09:25 -05:00
|
|
|
} else { ret none::<ts_ann>; }
|
2011-05-20 18:53:24 -05:00
|
|
|
}
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
/********* utils ********/
|
2011-07-27 07:19:39 -05:00
|
|
|
fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann {
|
|
|
|
alt get_ts_ann(ccx, id) {
|
|
|
|
none. {
|
|
|
|
log_err "node_id_to_ts_ann: no ts_ann for node_id " + int::str(id);
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
some(t) { ret t; }
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn node_id_to_poststate(ccx: &crate_ctxt, id: node_id) -> poststate {
|
2011-06-19 15:41:21 -05:00
|
|
|
log "node_id_to_poststate";
|
|
|
|
ret node_id_to_ts_ann(ccx, id).states.poststate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "stmt_to_ann";
|
2011-07-27 07:19:39 -05:00
|
|
|
alt s.node {
|
|
|
|
stmt_decl(_, id) { ret node_id_to_ts_ann(ccx, id); }
|
|
|
|
stmt_expr(_, id) { ret node_id_to_ts_ann(ccx, id); }
|
|
|
|
stmt_crate_directive(_) {
|
|
|
|
log_err "expecting an annotated statement here";
|
|
|
|
fail;
|
|
|
|
}
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
/* fails if e has no annotation */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_states(ccx: &crate_ctxt, e: @expr) -> pre_and_post_state {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "expr_states";
|
2011-06-21 15:16:40 -05:00
|
|
|
ret node_id_to_ts_ann(ccx, e.id).states;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
/* fails if e has no annotation */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_pp(ccx: &crate_ctxt, e: @expr) -> pre_and_post {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "expr_pp";
|
2011-06-21 15:16:40 -05:00
|
|
|
ret node_id_to_ts_ann(ccx, e.id).conditions;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_pp(ccx: &crate_ctxt, s: &stmt) -> pre_and_post {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_to_ann(ccx, s).conditions;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
/* fails if b has no annotation */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_pp(ccx: &crate_ctxt, b: &blk) -> pre_and_post {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "block_pp";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret node_id_to_ts_ann(ccx, b.node.id).conditions;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn clear_pp(pp: pre_and_post) {
|
2011-05-18 17:43:05 -05:00
|
|
|
ann::clear(pp.precondition);
|
|
|
|
ann::clear(pp.postcondition);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn clear_precond(ccx: &crate_ctxt, id: node_id) {
|
|
|
|
let pp = node_id_to_ts_ann(ccx, id);
|
2011-05-18 17:43:05 -05:00
|
|
|
ann::clear(pp.conditions.precondition);
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_states(ccx: &crate_ctxt, b: &blk) -> pre_and_post_state {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "block_states";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret node_id_to_ts_ann(ccx, b.node.id).states;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_states(ccx: &crate_ctxt, s: &stmt) -> pre_and_post_state {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_to_ann(ccx, s).states;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_precond(ccx: &crate_ctxt, e: @expr) -> precond {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret expr_pp(ccx, e).precondition;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_postcond(ccx: &crate_ctxt, e: @expr) -> postcond {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret expr_pp(ccx, e).postcondition;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_prestate(ccx: &crate_ctxt, e: @expr) -> prestate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret expr_states(ccx, e).prestate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_poststate(ccx: &crate_ctxt, e: @expr) -> poststate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret expr_states(ccx, e).poststate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_precond(ccx: &crate_ctxt, s: &stmt) -> precond {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_pp(ccx, s).precondition;
|
2011-05-18 17:43:05 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_postcond(ccx: &crate_ctxt, s: &stmt) -> postcond {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_pp(ccx, s).postcondition;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn states_to_poststate(ss: &pre_and_post_state) -> poststate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret ss.poststate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_prestate(ccx: &crate_ctxt, s: &stmt) -> prestate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_states(ccx, s).prestate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn stmt_poststate(ccx: &crate_ctxt, s: &stmt) -> poststate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret stmt_states(ccx, s).poststate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_precond(ccx: &crate_ctxt, b: &blk) -> precond {
|
2011-06-17 21:07:23 -05:00
|
|
|
ret block_pp(ccx, b).precondition;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_postcond(ccx: &crate_ctxt, b: &blk) -> postcond {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret block_pp(ccx, b).postcondition;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_prestate(ccx: &crate_ctxt, b: &blk) -> prestate {
|
2011-06-17 21:07:23 -05:00
|
|
|
ret block_states(ccx, b).prestate;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn block_poststate(ccx: &crate_ctxt, b: &blk) -> poststate {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret block_states(ccx, b).poststate;
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn set_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) -> bool {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "set_prestate_ann";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret set_prestate(node_id_to_ts_ann(ccx, id), pre);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn extend_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) ->
|
|
|
|
bool {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "extend_prestate_ann";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn set_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
|
|
|
|
bool {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "set_poststate_ann";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret set_poststate(node_id_to_ts_ann(ccx, id), post);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn extend_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
|
|
|
|
bool {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "extend_poststate_ann";
|
2011-06-19 15:41:21 -05:00
|
|
|
ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn set_pre_and_post(ccx: &crate_ctxt, id: node_id, pre: &precond,
|
|
|
|
post: &postcond) {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "set_pre_and_post";
|
2011-07-27 07:19:39 -05:00
|
|
|
let t = node_id_to_ts_ann(ccx, id);
|
2011-05-18 17:43:05 -05:00
|
|
|
set_precondition(t, pre);
|
|
|
|
set_postcondition(t, post);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn copy_pre_post(ccx: &crate_ctxt, id: node_id, sub: &@expr) {
|
2011-05-18 17:43:05 -05:00
|
|
|
log "set_pre_and_post";
|
2011-07-27 07:19:39 -05:00
|
|
|
let p = expr_pp(ccx, sub);
|
2011-06-19 15:41:21 -05:00
|
|
|
copy_pre_post_(ccx, id, p.precondition, p.postcondition);
|
2011-05-18 17:43:05 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate,
|
|
|
|
post: &poststate) {
|
2011-06-17 21:07:23 -05:00
|
|
|
log "set_pre_and_post";
|
2011-07-27 07:19:39 -05:00
|
|
|
let t = node_id_to_ts_ann(ccx, id);
|
2011-06-17 21:07:23 -05:00
|
|
|
set_precondition(t, pre);
|
|
|
|
set_postcondition(t, post);
|
|
|
|
}
|
2011-05-18 17:43:05 -05:00
|
|
|
|
|
|
|
/* sets all bits to *1* */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn set_postcond_false(ccx: &crate_ctxt, id: node_id) {
|
|
|
|
let p = node_id_to_ts_ann(ccx, id);
|
2011-05-18 17:43:05 -05:00
|
|
|
ann::set(p.conditions.postcondition);
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn pure_exp(ccx: &crate_ctxt, id: node_id, p: &prestate) -> bool {
|
|
|
|
ret set_prestate_ann(ccx, id, p) | set_poststate_ann(ccx, id, p);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn num_constraints(m: fn_info) -> uint { ret m.num_constraints; }
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt {
|
2011-08-19 17:16:48 -05:00
|
|
|
let na: [mutable ts_ann] = [mutable];
|
2011-08-13 02:09:25 -05:00
|
|
|
ret {tcx: cx, node_anns: @mutable na, fm: @new_int_hash::<fn_info>()};
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2011-05-20 16:15:39 -05:00
|
|
|
/* Use e's type to determine whether it returns.
|
|
|
|
If it has a function type with a ! annotation,
|
|
|
|
the answer is noreturn. */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn controlflow_expr(ccx: &crate_ctxt, e: @expr) -> controlflow {
|
|
|
|
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) {
|
|
|
|
ty::ty_fn(_, _, _, cf, _) { ret cf; }
|
|
|
|
_ { ret return; }
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn constraints_expr(cx: &ty::ctxt, e: @expr) -> [@ty::constr] {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt ty::struct(cx, ty::node_id_to_type(cx, e.id)) {
|
|
|
|
ty::ty_fn(_, _, _, _, cs) { ret cs; }
|
2011-08-19 17:16:48 -05:00
|
|
|
_ { ret []; }
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn node_id_to_def_upvar_strict(cx: &fn_ctxt, id: node_id) -> def {
|
|
|
|
alt freevars::def_lookup(cx.ccx.tcx, cx.id, id) {
|
|
|
|
none. {
|
|
|
|
log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
some(d) { ret d; }
|
2011-07-22 20:04:40 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def {
|
|
|
|
alt cx.def_map.find(id) {
|
|
|
|
none. {
|
|
|
|
log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
some(d) { ret d; }
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn node_id_to_def(ccx: &crate_ctxt, id: node_id) -> option::t<def> {
|
2011-06-19 15:41:21 -05:00
|
|
|
ret ccx.tcx.def_map.find(id);
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
2011-08-12 09:15:18 -05:00
|
|
|
fn node_id_to_def_upvar(cx: &fn_ctxt, id: node_id) -> option::t<def> {
|
2011-07-29 17:10:10 -05:00
|
|
|
ret freevars::def_lookup(cx.ccx.tcx, cx.id, id);
|
|
|
|
}
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn norm_a_constraint(id: def_id, c: &constraint) -> [norm_constraint] {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt c {
|
|
|
|
cinit(n, sp, i) {
|
2011-08-19 17:16:48 -05:00
|
|
|
ret [{bit_num: n, c: respan(sp, ninit(id.node, i))}];
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
cpred(p, descs) {
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt: [norm_constraint] = [];
|
2011-08-15 23:54:52 -05:00
|
|
|
for pd: pred_args in *descs {
|
2011-07-27 07:19:39 -05:00
|
|
|
rslt +=
|
2011-08-19 17:16:48 -05:00
|
|
|
[{bit_num: pd.node.bit_num,
|
|
|
|
c: respan(pd.span, npred(p, id, pd.node.args))}];
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
ret rslt;
|
|
|
|
}
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-01 20:10:10 -05:00
|
|
|
// Tried to write this as an iterator, but I got a
|
|
|
|
// non-exhaustive match in trans.
|
2011-08-04 18:20:09 -05:00
|
|
|
fn constraints(fcx: &fn_ctxt) -> [norm_constraint] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt: [norm_constraint] = [];
|
|
|
|
for each p: @{key: def_id, val: constraint} in
|
2011-07-27 07:19:39 -05:00
|
|
|
fcx.enclosing.constrs.items() {
|
2011-07-26 07:06:02 -05:00
|
|
|
rslt += norm_a_constraint(p.key, p.val);
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
2011-06-24 12:04:08 -05:00
|
|
|
ret rslt;
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
|
2011-07-19 19:52:34 -05:00
|
|
|
// FIXME
|
|
|
|
// Would rather take an immutable vec as an argument,
|
|
|
|
// should freeze it at some earlier point.
|
2011-08-04 18:20:09 -05:00
|
|
|
fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args],
|
|
|
|
occ: &[@constr_arg_use]) -> uint {
|
2011-06-16 18:55:46 -05:00
|
|
|
log "match_args: looking at " +
|
2011-07-27 07:19:39 -05:00
|
|
|
constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, occ);
|
2011-08-15 23:54:52 -05:00
|
|
|
for pd: pred_args in *occs {
|
2011-07-19 19:52:34 -05:00
|
|
|
log "match_args: candidate " + pred_args_to_str(pd);
|
2011-07-27 07:19:39 -05:00
|
|
|
fn eq(p: &inst, q: &inst) -> bool { ret p.node == q.node; }
|
|
|
|
if ty::args_eq(eq, pd.node.args, occ) { ret pd.node.bit_num; }
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id {
|
|
|
|
alt tcx.def_map.find(t) {
|
|
|
|
none. {
|
|
|
|
tcx.sess.bug("node_id_for_constr: bad node_id " + int::str(t));
|
|
|
|
}
|
|
|
|
some(def_fn(i, _)) { ret i; }
|
|
|
|
_ { tcx.sess.bug("node_id_for_constr: pred is not a function"); }
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use {
|
|
|
|
alt e.node {
|
|
|
|
expr_path(p) {
|
|
|
|
alt tcx.def_map.find(e.id) {
|
|
|
|
some(def_local(l_id)) {
|
|
|
|
ret @respan(p.span,
|
2011-08-19 17:16:48 -05:00
|
|
|
carg_ident({ident: p.node.idents[0],
|
2011-07-27 07:19:39 -05:00
|
|
|
node: l_id.node}));
|
|
|
|
}
|
|
|
|
some(def_arg(a_id)) {
|
|
|
|
ret @respan(p.span,
|
2011-08-19 17:16:48 -05:00
|
|
|
carg_ident({ident: p.node.idents[0],
|
2011-07-27 07:19:39 -05:00
|
|
|
node: a_id.node}));
|
|
|
|
}
|
2011-08-26 02:39:50 -05:00
|
|
|
some (def_binding(b_id)) {
|
|
|
|
ret @respan(p.span,
|
|
|
|
carg_ident({ident: p.node.idents[0],
|
|
|
|
node: b_id.node}));
|
|
|
|
}
|
|
|
|
some(_) {
|
2011-07-27 07:19:39 -05:00
|
|
|
tcx.sess.bug("exprs_to_constr_args: non-local variable " +
|
|
|
|
"as pred arg");
|
2011-08-26 02:39:50 -05:00
|
|
|
}
|
|
|
|
none {
|
|
|
|
tcx.sess.bug("exprs_to_constr_args: NONE " +
|
|
|
|
"as pred arg");
|
2011-07-27 07:19:39 -05:00
|
|
|
|
|
|
|
}
|
2011-06-10 21:12:42 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_lit(l) { ret @respan(e.span, carg_lit(l)); }
|
|
|
|
_ {
|
|
|
|
tcx.sess.span_fatal(e.span,
|
|
|
|
"Arguments to constrained functions must be " +
|
|
|
|
"literals or local variables");
|
|
|
|
}
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
2011-06-10 21:12:42 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn exprs_to_constr_args(tcx: ty::ctxt, args: &[@expr]) -> [@constr_arg_use] {
|
2011-07-27 07:19:39 -05:00
|
|
|
let f = bind expr_to_constr_arg(tcx, _);
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt: [@constr_arg_use] = [];
|
|
|
|
for e: @expr in args { rslt += [f(e)]; }
|
2011-07-09 00:05:30 -05:00
|
|
|
rslt
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr {
|
|
|
|
alt e.node {
|
|
|
|
expr_call(operator, args) {
|
|
|
|
alt operator.node {
|
|
|
|
expr_path(p) {
|
|
|
|
ret respan(e.span,
|
|
|
|
npred(p, def_id_for_constr(tcx, operator.id),
|
|
|
|
exprs_to_constr_args(tcx, args)));
|
|
|
|
}
|
|
|
|
_ {
|
|
|
|
tcx.sess.span_fatal(operator.span,
|
|
|
|
"Internal error: " +
|
|
|
|
" ill-formed operator \
|
2011-06-15 13:19:50 -05:00
|
|
|
in predicate");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ {
|
|
|
|
tcx.sess.span_fatal(e.span,
|
|
|
|
"Internal error: " + " ill-formed predicate");
|
|
|
|
}
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn pred_args_to_str(p: &pred_args) -> str {
|
2011-07-09 00:05:30 -05:00
|
|
|
"<" + uint::str(p.node.bit_num) + ", " +
|
2011-07-27 07:19:39 -05:00
|
|
|
constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, p.node.args)
|
|
|
|
+ ">"
|
2011-06-09 11:48:16 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr)
|
2011-07-27 07:19:39 -05:00
|
|
|
-> tsconstr {
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt: [@constr_arg_use] = [];
|
2011-08-15 23:54:52 -05:00
|
|
|
for a: @constr_arg in c.node.args {
|
2011-08-19 17:16:48 -05:00
|
|
|
rslt += [substitute_arg(cx, actuals, a)];
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
2011-07-19 19:52:34 -05:00
|
|
|
ret npred(c.node.path, c.node.id, rslt);
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn substitute_arg(cx: &ty::ctxt, actuals: &[@expr], a: @constr_arg) ->
|
2011-06-15 13:19:50 -05:00
|
|
|
@constr_arg_use {
|
2011-08-15 18:38:23 -05:00
|
|
|
let num_actuals = vec::len(actuals);
|
2011-07-27 07:19:39 -05:00
|
|
|
alt a.node {
|
|
|
|
carg_ident(i) {
|
|
|
|
if i < num_actuals {
|
2011-08-19 17:16:48 -05:00
|
|
|
ret expr_to_constr_arg(cx, actuals[i]);
|
2011-07-27 07:19:39 -05:00
|
|
|
} else {
|
|
|
|
cx.sess.span_fatal(a.span, "Constraint argument out of bounds");
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
carg_base. { ret @respan(a.span, carg_base); }
|
|
|
|
carg_lit(l) { ret @respan(a.span, carg_lit(l)); }
|
2011-06-01 20:10:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn pred_args_matches(pattern: &[constr_arg_general_<inst>], desc: &pred_args)
|
|
|
|
-> bool {
|
2011-07-27 07:19:39 -05:00
|
|
|
let i = 0u;
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: @constr_arg_use in desc.node.args {
|
2011-08-19 17:16:48 -05:00
|
|
|
let n = pattern[i];
|
2011-07-27 07:19:39 -05:00
|
|
|
alt c.node {
|
|
|
|
carg_ident(p) {
|
|
|
|
alt n {
|
|
|
|
carg_ident(q) { if p.node != q.node { ret false; } }
|
|
|
|
_ { ret false; }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
carg_base. { if n != carg_base { ret false; } }
|
|
|
|
carg_lit(l) {
|
|
|
|
alt n {
|
|
|
|
carg_lit(m) { if !lit_eq(l, m) { ret false; } }
|
|
|
|
_ { ret false; }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn find_instance_(pattern: &[constr_arg_general_<inst>], descs: &[pred_args])
|
|
|
|
-> option::t<uint> {
|
2011-08-15 23:54:52 -05:00
|
|
|
for d: pred_args in descs {
|
2011-07-27 07:19:39 -05:00
|
|
|
if pred_args_matches(pattern, d) { ret some(d.node.bit_num); }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
ret none;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type inst = {ident: ident, node: node_id};
|
2011-08-04 18:20:09 -05:00
|
|
|
type subst = [{from: inst, to: inst}];
|
2011-07-09 00:05:30 -05:00
|
|
|
|
2011-08-18 03:01:39 -05:00
|
|
|
fn find_instances(_fcx: &fn_ctxt, subst: &subst, c: &constraint) ->
|
2011-08-04 18:20:09 -05:00
|
|
|
[{from: uint, to: uint}] {
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt = [];
|
2011-08-15 18:38:23 -05:00
|
|
|
if vec::len(subst) == 0u { ret rslt; }
|
2011-07-09 00:05:30 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
alt c {
|
|
|
|
cinit(_, _, _) {/* this is dealt with separately */ }
|
|
|
|
cpred(p, descs) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for d: pred_args in *descs {
|
2011-07-27 07:19:39 -05:00
|
|
|
if args_mention(d.node.args, find_in_subst_bool, subst) {
|
|
|
|
let old_bit_num = d.node.bit_num;
|
|
|
|
let new = replace(subst, d);
|
|
|
|
alt find_instance_(new, *descs) {
|
2011-08-19 17:16:48 -05:00
|
|
|
some(d1) { rslt += [{from: old_bit_num, to: d1}]; }
|
2011-07-27 07:19:39 -05:00
|
|
|
_ { }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
rslt
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn find_in_subst(id: node_id, s: &subst) -> option::t<inst> {
|
2011-08-15 23:54:52 -05:00
|
|
|
for p: {from: inst, to: inst} in s {
|
2011-07-27 07:19:39 -05:00
|
|
|
if id == p.from.node { ret some(p.to); }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
ret none;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn find_in_subst_bool(s: &subst, id: node_id) -> bool {
|
2011-07-09 00:05:30 -05:00
|
|
|
is_some(find_in_subst(id, s))
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn insts_to_str(stuff: &[constr_arg_general_<inst>]) -> str {
|
2011-07-27 07:19:39 -05:00
|
|
|
let rslt = "<";
|
2011-08-12 09:15:18 -05:00
|
|
|
for i: constr_arg_general_<inst> in stuff {
|
2011-07-27 07:19:39 -05:00
|
|
|
rslt +=
|
|
|
|
" " +
|
|
|
|
alt i {
|
|
|
|
carg_ident(p) { p.ident }
|
|
|
|
carg_base. { "*" }
|
|
|
|
carg_lit(_) { "[lit]" }
|
|
|
|
} + " ";
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
rslt += ">";
|
|
|
|
rslt
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn replace(subst: subst, d: pred_args) -> [constr_arg_general_<inst>] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let rslt: [constr_arg_general_<inst>] = [];
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: @constr_arg_use in d.node.args {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt c.node {
|
|
|
|
carg_ident(p) {
|
|
|
|
alt find_in_subst(p.node, subst) {
|
2011-08-19 17:16:48 -05:00
|
|
|
some(new) { rslt += [carg_ident(new)]; }
|
|
|
|
_ { rslt += [c.node]; }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ {
|
|
|
|
// log_err "##";
|
2011-08-19 17:16:48 -05:00
|
|
|
rslt += [c.node];
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2011-07-09 00:05:30 -05:00
|
|
|
/*
|
2011-08-12 09:15:18 -05:00
|
|
|
for (constr_arg_general_<tup(ident, def_id)> p in rslt) {
|
2011-07-09 00:05:30 -05:00
|
|
|
alt (p) {
|
|
|
|
case (carg_ident(?p)) {
|
|
|
|
log_err p._0;
|
|
|
|
}
|
|
|
|
case (_) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret rslt;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident {
|
2011-08-15 18:38:23 -05:00
|
|
|
alt vec::last(p.node.idents) {
|
2011-07-27 07:19:39 -05:00
|
|
|
none. { cx.sess.span_fatal(p.span, "Malformed path"); }
|
|
|
|
some(i) { ret i; }
|
2011-06-13 20:10:33 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-17 21:07:23 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
tag if_ty { if_check; plain_if; }
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) ->
|
|
|
|
def_id {
|
|
|
|
alt local_node_id_to_def(fcx, i) {
|
|
|
|
some(def_local(d_id)) { ret d_id; }
|
|
|
|
some(def_arg(a_id)) { ret a_id; }
|
|
|
|
some(_) {
|
|
|
|
fcx.ccx.tcx.sess.span_fatal(sp,
|
|
|
|
"local_node_id_to_def_id: id \
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
isn't a local");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
none. {
|
|
|
|
// should really be bug. span_bug()?
|
|
|
|
fcx.ccx.tcx.sess.span_fatal(sp,
|
|
|
|
"local_node_id_to_def_id: id \
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
is unbound");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn local_node_id_to_def(fcx: &fn_ctxt, i: &node_id) -> option::t<def> {
|
2011-07-27 07:19:39 -05:00
|
|
|
fcx.ccx.tcx.def_map.find(i)
|
|
|
|
}
|
2011-06-25 00:17:17 -05:00
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt local_node_id_to_def(fcx, i) {
|
|
|
|
some(def_local(d_id)) { some(d_id) }
|
|
|
|
some(def_arg(a_id)) { some(a_id) }
|
|
|
|
_ { none }
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) ->
|
2011-08-12 09:15:18 -05:00
|
|
|
option::t<node_id> {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt local_node_id_to_def(fcx, i) {
|
|
|
|
some(def_local(d_id)) { some(d_id.node) }
|
|
|
|
some(def_arg(a_id)) { some(a_id.node) }
|
|
|
|
_ { none }
|
2011-07-19 19:52:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
|
|
|
|
ty: oper_type) {
|
|
|
|
let post =
|
|
|
|
node_id_to_ts_ann(fcx.ccx, parent_exp).conditions.postcondition;
|
2011-07-09 00:05:30 -05:00
|
|
|
copy_in_poststate_two(fcx, post, post, dest, src, ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME refactor
|
2011-07-27 07:19:39 -05:00
|
|
|
fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst,
|
|
|
|
ty: oper_type) {
|
2011-07-09 00:05:30 -05:00
|
|
|
copy_in_poststate_two(fcx, post, post, dest, src, ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// In target_post, set the bits corresponding to copies of any
|
|
|
|
// constraints mentioning src that are set in src_post, with
|
|
|
|
// dest substituted for src.
|
|
|
|
// (This doesn't create any new constraints. If a new, substituted
|
|
|
|
// constraint isn't already in the bit vector, it's ignored.)
|
2011-07-27 07:19:39 -05:00
|
|
|
fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate,
|
|
|
|
target_post: &poststate, dest: inst, src: inst,
|
|
|
|
ty: oper_type) {
|
|
|
|
let subst;
|
|
|
|
alt ty {
|
2011-08-19 17:16:48 -05:00
|
|
|
oper_swap. { subst = [{from: dest, to: src}, {from: src, to: dest}]; }
|
2011-07-27 07:19:39 -05:00
|
|
|
oper_assign_op. {
|
|
|
|
ret; // Don't do any propagation
|
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
_ { subst = [{from: src, to: dest}]; }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
for each p: @{key: def_id, val: constraint} in
|
2011-07-27 07:19:39 -05:00
|
|
|
fcx.enclosing.constrs.items() {
|
2011-07-09 00:05:30 -05:00
|
|
|
// replace any occurrences of the src def_id with the
|
|
|
|
// dest def_id
|
2011-07-27 07:19:39 -05:00
|
|
|
let insts = find_instances(fcx, subst, p.val);
|
2011-08-15 23:54:52 -05:00
|
|
|
for p: {from: uint, to: uint} in insts {
|
2011-07-27 07:19:39 -05:00
|
|
|
if promises_(p.from, src_post) {
|
2011-07-26 07:06:02 -05:00
|
|
|
set_in_poststate_(p.to, target_post);
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-25 00:17:17 -05:00
|
|
|
/* FIXME should refactor this better */
|
2011-07-27 07:19:39 -05:00
|
|
|
fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) {
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
// In the postcondition given by parent_exp, clear the bits
|
|
|
|
// for any constraints mentioning dead_v
|
2011-07-27 07:19:39 -05:00
|
|
|
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
|
|
|
alt d {
|
|
|
|
some(d_id) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if constraint_mentions(fcx, c, d_id) {
|
|
|
|
clear_in_postcond(c.bit_num,
|
|
|
|
node_id_to_ts_ann(fcx.ccx,
|
|
|
|
parent_exp).conditions);
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ { }
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id,
|
|
|
|
dead_v: node_id) {
|
2011-06-25 00:17:17 -05:00
|
|
|
// In the postcondition given by parent_exp, clear the bits
|
|
|
|
// for any constraints mentioning dead_v
|
2011-07-27 07:19:39 -05:00
|
|
|
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
|
|
|
alt d {
|
|
|
|
some(d_id) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if non_init_constraint_mentions(fcx, c, d_id) {
|
|
|
|
clear_in_postcond(c.bit_num,
|
|
|
|
node_id_to_ts_ann(fcx.ccx,
|
|
|
|
parent_exp).conditions);
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ { }
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) ->
|
|
|
|
bool {
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
// In the poststate given by parent_exp, clear the bits
|
|
|
|
// for any constraints mentioning dead_v
|
2011-07-27 07:19:39 -05:00
|
|
|
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
|
|
|
let changed = false;
|
|
|
|
alt d {
|
|
|
|
some(d_id) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if constraint_mentions(fcx, c, d_id) {
|
|
|
|
changed |= clear_in_poststate_(c.bit_num, p);
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ { }
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
ret changed;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate,
|
|
|
|
dead_v: node_id) -> bool {
|
2011-06-25 00:17:17 -05:00
|
|
|
// In the poststate given by parent_exp, clear the bits
|
|
|
|
// for any constraints mentioning dead_v
|
2011-07-27 07:19:39 -05:00
|
|
|
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
|
|
|
let changed = false;
|
|
|
|
alt d {
|
|
|
|
some(d_id) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for c: norm_constraint in constraints(fcx) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if non_init_constraint_mentions(fcx, c, d_id) {
|
|
|
|
changed |= clear_in_poststate_(c.bit_num, p);
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ { }
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
|
|
|
ret changed;
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn any_eq(v: &[node_id], d: node_id) -> bool {
|
2011-08-15 23:54:52 -05:00
|
|
|
for i: node_id in v { if i == d { ret true; } }
|
2011-07-09 00:05:30 -05:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:01:39 -05:00
|
|
|
fn constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, v: node_id) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
bool {
|
|
|
|
ret alt c.c.node {
|
|
|
|
ninit(id, _) { v == id }
|
2011-08-19 17:16:48 -05:00
|
|
|
npred(_, _, args) { args_mention(args, any_eq, [v]) }
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
|
|
|
|
2011-08-18 03:01:39 -05:00
|
|
|
fn non_init_constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint,
|
2011-07-27 07:19:39 -05:00
|
|
|
v: &node_id) -> bool {
|
|
|
|
ret alt c.c.node {
|
|
|
|
ninit(_, _) { false }
|
2011-08-19 17:16:48 -05:00
|
|
|
npred(_, _, args) { args_mention(args, any_eq, [v]) }
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-06-25 00:17:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn args_mention<T>(args: &[@constr_arg_use], q: fn(&[T], node_id) -> bool,
|
2011-08-04 18:20:09 -05:00
|
|
|
s: &[T]) -> bool {
|
2011-07-09 00:05:30 -05:00
|
|
|
/*
|
|
|
|
FIXME
|
|
|
|
The following version causes an assertion in trans to fail
|
|
|
|
(something about type_is_tup_like)
|
2011-08-12 08:36:51 -05:00
|
|
|
fn mentions<T>(&[T] s, &fn(&[T], def_id) -> bool q,
|
2011-07-09 00:05:30 -05:00
|
|
|
&@constr_arg_use a) -> bool {
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
alt (a.node) {
|
2011-07-09 00:05:30 -05:00
|
|
|
case (carg_ident(?p1)) {
|
|
|
|
auto res = q(s, p1._1);
|
|
|
|
log_err (res);
|
|
|
|
res
|
|
|
|
}
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
case (_) { false }
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 18:38:23 -05:00
|
|
|
ret vec::any(bind mentions(s,q,_), args);
|
2011-07-09 00:05:30 -05:00
|
|
|
*/
|
|
|
|
|
2011-08-15 23:54:52 -05:00
|
|
|
for a: @constr_arg_use in args {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt a.node { carg_ident(p1) { if q(s, p1.node) { ret true; } } _ { } }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
|
|
|
ret false;
|
Compute typestate properly for move
typestate now drops constraints correctly in the post-state of
a move expression or a declaration whose op is a move. It doesn't
yet drop constraints mentioning variables that get updated.
To do this, I had to change typestate to use trit-vectors instead
of bit-vectors, because for every constraint, there are three
possible values: known-to-be-false (e.g. after x <- y, init(y) is
known-to-be-false), known-to-be-true, and unknown. Before, we
conflated known-to-be-false with unknown. But move requires them
to be treated differently. Consider:
(program a)
(a1) x = 1;
(a2) y <- x;
(a3) log x;
(program b)
(b1) x = 1;
(b2) y <- z;
(b3) log x;
With only two values, the postcondition of statement a2 for
constraint init(x) is the same as that of b2: 0. But in (a2)'s
postcondition, init(x) *must* be false, but in (b2)'s condition,
it's just whatever it was in the postcondition of the preceding statement.
2011-06-22 23:26:34 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn use_var(fcx: &fn_ctxt, v: &node_id) { *fcx.enclosing.used_vars += [v]; }
|
2011-06-30 02:18:41 -05:00
|
|
|
|
2011-08-15 18:38:23 -05:00
|
|
|
// FIXME: This should be a function in std::vec::.
|
2011-08-04 18:20:09 -05:00
|
|
|
fn vec_contains(v: &@mutable [node_id], i: &node_id) -> bool {
|
2011-08-15 23:54:52 -05:00
|
|
|
for d: node_id in *v { if d == i { ret true; } }
|
2011-06-30 02:18:41 -05:00
|
|
|
ret false;
|
|
|
|
}
|
2011-07-05 01:29:15 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn op_to_oper_ty(io: init_op) -> oper_type {
|
|
|
|
alt io { init_move. { oper_move } _ { oper_assign } }
|
2011-07-09 00:05:30 -05:00
|
|
|
}
|
2011-07-12 13:26:14 -05:00
|
|
|
|
|
|
|
// default function visitor
|
2011-08-18 03:01:39 -05:00
|
|
|
fn do_nothing<T>(_f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident,
|
|
|
|
_iid: node_id, _cx: &T, _v: &visit::vt<T>) {
|
2011-07-12 13:26:14 -05:00
|
|
|
}
|
2011-07-21 18:03:30 -05:00
|
|
|
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn args_to_constr_args(sp: &span, args: &[arg]) -> [@constr_arg_use] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let actuals: [@constr_arg_use] = [];
|
2011-08-15 23:54:52 -05:00
|
|
|
for a: arg in args {
|
2011-08-19 17:16:48 -05:00
|
|
|
actuals += [@respan(sp, carg_ident({ident: a.ident, node: a.id}))];
|
2011-07-21 18:03:30 -05:00
|
|
|
}
|
|
|
|
ret actuals;
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn ast_constr_to_ts_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
tsconstr {
|
|
|
|
let tconstr = ty::ast_constr_to_constr(tcx, c);
|
2011-07-21 18:03:30 -05:00
|
|
|
ret npred(tconstr.node.path, tconstr.node.id,
|
2011-07-27 07:19:39 -05:00
|
|
|
args_to_constr_args(tconstr.span, args));
|
2011-07-21 18:03:30 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
sp_constr {
|
|
|
|
let tconstr = ast_constr_to_ts_constr(tcx, args, c);
|
2011-07-21 18:03:30 -05:00
|
|
|
ret respan(c.span, tconstr);
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type binding = {lhs: [inst], rhs: option::t<initializer>};
|
2011-07-29 17:59:38 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn local_to_bindings(loc: &@local) -> binding {
|
|
|
|
let lhs = [];
|
2011-08-03 03:19:36 -05:00
|
|
|
for each p: @pat in pat_bindings(loc.node.pat) {
|
2011-07-28 05:01:45 -05:00
|
|
|
let ident = alt p.node { pat_bind(name) { name } };
|
2011-08-19 17:16:48 -05:00
|
|
|
lhs += [{ident: ident, node: p.id}];
|
2011-07-28 05:01:45 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
{lhs: lhs, rhs: loc.node.init}
|
2011-07-29 17:59:38 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn locals_to_bindings(locals: &[@local]) -> [binding] {
|
2011-08-15 18:38:23 -05:00
|
|
|
vec::map(local_to_bindings, locals)
|
2011-07-29 17:59:38 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn callee_modes(fcx: &fn_ctxt, callee: node_id) -> [ty::mode] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let ty =
|
|
|
|
ty::type_autoderef(fcx.ccx.tcx,
|
|
|
|
ty::node_id_to_type(fcx.ccx.tcx, callee));
|
2011-08-08 21:38:19 -05:00
|
|
|
alt ty::struct(fcx.ccx.tcx, ty) {
|
2011-08-19 17:16:48 -05:00
|
|
|
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(_, args, _) {
|
|
|
|
let modes = [];
|
|
|
|
for arg: ty::arg in args { modes += [arg.mode]; }
|
2011-08-08 21:38:19 -05:00
|
|
|
ret modes;
|
|
|
|
}
|
|
|
|
_ {
|
|
|
|
// Shouldn't happen; callee should be ty_fn.
|
2011-08-19 17:16:48 -05:00
|
|
|
fcx.ccx.tcx.sess.bug("non-fn callee type in callee_modes: " +
|
|
|
|
util::ppaux::ty_to_str(fcx.ccx.tcx, ty));
|
2011-08-08 21:38:19 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|
2011-08-08 21:38:19 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn callee_arg_init_ops(fcx: &fn_ctxt, callee: node_id) -> [init_op] {
|
2011-08-08 21:38:19 -05:00
|
|
|
fn mode_to_op(m: &ty::mode) -> init_op {
|
2011-08-19 17:16:48 -05:00
|
|
|
alt m { ty::mo_move. { init_move } _ { init_assign } }
|
2011-08-08 21:38:19 -05:00
|
|
|
}
|
2011-08-15 18:38:23 -05:00
|
|
|
vec::map(mode_to_op, callee_modes(fcx, callee))
|
2011-08-08 21:38:19 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn anon_bindings(ops: &[init_op], es: &[@expr]) -> [binding] {
|
|
|
|
let bindings: [binding] = [];
|
2011-08-08 21:38:19 -05:00
|
|
|
let i = 0;
|
|
|
|
for op: init_op in ops {
|
2011-08-19 17:16:48 -05:00
|
|
|
bindings += [{lhs: [], rhs: some({op: op, expr: es[i]})}];
|
2011-08-08 21:38:19 -05:00
|
|
|
i += 1;
|
2011-07-29 17:59:38 -05:00
|
|
|
}
|
2011-08-08 21:38:19 -05:00
|
|
|
ret bindings;
|
2011-07-29 17:59:38 -05:00
|
|
|
}
|
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|