librustc: De-export typeck. rs=deexporting

This commit is contained in:
Patrick Walton 2013-01-29 16:26:16 -08:00
parent c25703ccb8
commit bae4821851
16 changed files with 377 additions and 458 deletions

View File

@ -81,9 +81,10 @@ pub trait ast_conv {
fn ty_infer(span: span) -> ty::t;
}
fn get_region_reporting_err(tcx: ty::ctxt,
span: span,
res: Result<ty::Region, ~str>) -> ty::Region {
pub fn get_region_reporting_err(tcx: ty::ctxt,
span: span,
res: Result<ty::Region, ~str>)
-> ty::Region {
match res {
result::Ok(r) => r,
@ -94,7 +95,7 @@ fn get_region_reporting_err(tcx: ty::ctxt,
}
}
fn ast_region_to_region<AC: ast_conv, RS: region_scope Copy Durable>(
pub fn ast_region_to_region<AC: ast_conv, RS: region_scope Copy Durable>(
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::Region {
let res = match a_r.node {
@ -107,7 +108,7 @@ fn ast_region_to_region<AC: ast_conv, RS: region_scope Copy Durable>(
get_region_reporting_err(self.tcx(), span, res)
}
fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope Copy Durable>(
pub fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope Copy Durable>(
self: AC, rscope: RS, did: ast::def_id,
path: @ast::path) -> ty_param_substs_and_ty {
@ -174,13 +175,13 @@ pub fn ast_path_to_ty<AC: ast_conv, RS: region_scope Copy Durable>(
return {substs: substs, ty: ty};
}
const NO_REGIONS: uint = 1;
const NO_TPS: uint = 2;
pub const NO_REGIONS: uint = 1;
pub const NO_TPS: uint = 2;
// Parses the programmer's textual representation of a type into our
// internal notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID:
fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Durable>(
pub fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Durable>(
self: AC, rscope: RS, &&ast_ty: @ast::Ty) -> ty::t {
fn ast_mt_to_mt<AC: ast_conv, RS: region_scope Copy Durable>(
@ -405,7 +406,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Durable>(
return typ;
}
fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Durable>(
pub fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Durable>(
self: AC, rscope: RS, a: ast::arg,
expected_ty: Option<ty::arg>) -> ty::arg {
@ -451,10 +452,10 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Durable>(
arg {mode: mode, ty: ty}
}
type expected_tys = Option<{inputs: ~[ty::arg],
output: ty::t}>;
pub type expected_tys = Option<{inputs: ~[ty::arg],
output: ty::t}>;
fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Durable>(
pub fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Durable>(
self: AC, rscope: RS,
ast_proto: ast::Proto,
purity: ast::purity,
@ -463,8 +464,7 @@ fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Durable>(
opt_region: Option<@ast::region>,
decl: ast::fn_decl,
expected_tys: expected_tys,
span: span) -> ty::FnTy
{
span: span) -> ty::FnTy {
debug!("ty_of_fn_decl");
do indent {
// resolve the function bound region in the original region

View File

@ -156,7 +156,7 @@ pub type self_info = {
/// Here, the function `foo()` and the closure passed to
/// `bar()` will each have their own `fn_ctxt`, but they will
/// share the inherited fields.
struct inherited {
pub struct inherited {
infcx: @infer::InferCtxt,
locals: HashMap<ast::node_id, ty::t>,
node_types: HashMap<ast::node_id, ty::t>,
@ -164,7 +164,7 @@ struct inherited {
adjustments: HashMap<ast::node_id, @ty::AutoAdjustment>
}
enum FnKind { ForLoop, DoBlock, Vanilla }
pub enum FnKind { ForLoop, DoBlock, Vanilla }
pub struct fn_ctxt {
// var_bindings, locals and next_var_id are shared
@ -206,7 +206,7 @@ pub struct fn_ctxt {
ccx: @crate_ctxt,
}
fn blank_inherited(ccx: @crate_ctxt) -> @inherited {
pub fn blank_inherited(ccx: @crate_ctxt) -> @inherited {
@inherited {
infcx: infer::new_infer_ctxt(ccx.tcx),
locals: HashMap(),
@ -217,8 +217,8 @@ fn blank_inherited(ccx: @crate_ctxt) -> @inherited {
}
// Used by check_const and check_enum_variants
fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
region_bnd: ast::node_id) -> @fn_ctxt {
pub fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
region_bnd: ast::node_id) -> @fn_ctxt {
// It's kind of a kludge to manufacture a fake function context
// and statement context, but we might as well do write the code only once
@fn_ctxt {
@ -242,11 +242,11 @@ pub fn check_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
visit::visit_crate(*crate, (), visit);
}
fn check_bare_fn(ccx: @crate_ctxt,
decl: &ast::fn_decl,
body: ast::blk,
id: ast::node_id,
self_info: Option<self_info>) {
pub fn check_bare_fn(ccx: @crate_ctxt,
decl: &ast::fn_decl,
body: ast::blk,
id: ast::node_id,
self_info: Option<self_info>) {
let fty = ty::node_id_to_type(ccx.tcx, id);
match ty::get(fty).sty {
ty::ty_fn(ref fn_ty) => {
@ -257,13 +257,13 @@ fn check_bare_fn(ccx: @crate_ctxt,
}
}
fn check_fn(ccx: @crate_ctxt,
self_info: Option<self_info>,
fn_ty: &ty::FnTy,
decl: &ast::fn_decl,
body: ast::blk,
fn_kind: FnKind,
old_fcx: Option<@fn_ctxt>) {
pub fn check_fn(ccx: @crate_ctxt,
self_info: Option<self_info>,
fn_ty: &ty::FnTy,
decl: &ast::fn_decl,
body: ast::blk,
fn_kind: FnKind,
old_fcx: Option<@fn_ctxt>) {
let tcx = ccx.tcx;
let indirect_ret = match fn_kind {
@ -487,8 +487,8 @@ fn check_fn(ccx: @crate_ctxt,
}
}
fn check_method(ccx: @crate_ctxt, method: @ast::method,
self_ty: ty::t, self_impl_def_id: ast::def_id) {
pub fn check_method(ccx: @crate_ctxt, method: @ast::method,
self_ty: ty::t, self_impl_def_id: ast::def_id) {
let self_info = {self_ty: self_ty,
self_id: method.self_id,
def_id: self_impl_def_id,
@ -496,8 +496,8 @@ fn check_method(ccx: @crate_ctxt, method: @ast::method,
check_bare_fn(ccx, &method.decl, method.body, method.id, Some(self_info));
}
fn check_no_duplicate_fields(tcx: ty::ctxt, fields:
~[(ast::ident, span)]) {
pub fn check_no_duplicate_fields(tcx: ty::ctxt,
fields: ~[(ast::ident, span)]) {
let field_names = HashMap();
for fields.each |p| {
@ -516,11 +516,10 @@ fn check_no_duplicate_fields(tcx: ty::ctxt, fields:
}
}
}
}
fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
id: ast::node_id, span: span) {
pub fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
id: ast::node_id, span: span) {
let tcx = ccx.tcx;
let self_ty = ty::node_id_to_type(tcx, id);
@ -542,7 +541,7 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
check_instantiable(ccx.tcx, span, id);
}
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
pub fn check_item(ccx: @crate_ctxt, it: @ast::item) {
debug!("check_item(it.id=%d, it.ident=%s)",
it.id,
ty::item_path_str(ccx.tcx, local_def(it.id)));
@ -617,7 +616,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
}
}
impl @fn_ctxt: ast_conv {
pub impl @fn_ctxt: ast_conv {
fn tcx() -> ty::ctxt { self.ccx.tcx }
fn ccx() -> @crate_ctxt { self.ccx }
@ -630,7 +629,7 @@ impl @fn_ctxt: ast_conv {
}
}
impl @fn_ctxt {
pub impl @fn_ctxt {
fn infcx() -> @infer::InferCtxt { self.inh.infcx }
fn search_in_scope_regions(br: ty::bound_region)
-> Result<ty::Region, ~str>
@ -650,7 +649,7 @@ impl @fn_ctxt {
}
}
impl @fn_ctxt: region_scope {
pub impl @fn_ctxt: region_scope {
fn anon_region(span: span) -> Result<ty::Region, ~str> {
result::Ok(self.infcx().next_region_var_nb(span))
}
@ -662,7 +661,7 @@ impl @fn_ctxt: region_scope {
}
}
impl @fn_ctxt {
pub impl @fn_ctxt {
fn tag() -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) }
fn local_ty(span: span, nid: ast::node_id) -> ty::t {
@ -874,7 +873,7 @@ impl @fn_ctxt {
}
}
fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) {
pub fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) {
/*!
*
* Autoderefs the type `t` as many times as possible, returning
@ -931,7 +930,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) {
}
// AST fragment checking
fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
pub fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
let tcx = fcx.ccx.tcx;
match lit.node {
@ -961,37 +960,33 @@ pub fn valid_range_bounds(ccx: @crate_ctxt, from: @ast::expr, to: @ast::expr)
pub fn check_expr_has_type(
fcx: @fn_ctxt, expr: @ast::expr,
expected: ty::t) -> bool
{
expected: ty::t) -> bool {
do check_expr_with_unifier(fcx, expr, Some(expected)) {
demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr));
}
}
fn check_expr_coercable_to_type(
pub fn check_expr_coercable_to_type(
fcx: @fn_ctxt, expr: @ast::expr,
expected: ty::t) -> bool
{
expected: ty::t) -> bool {
do check_expr_with_unifier(fcx, expr, Some(expected)) {
demand::coerce(fcx, expr.span, expected, expr)
}
}
fn check_expr_with_hint(
pub fn check_expr_with_hint(
fcx: @fn_ctxt, expr: @ast::expr,
expected: ty::t) -> bool
{
expected: ty::t) -> bool {
check_expr_with_unifier(fcx, expr, Some(expected), || ())
}
fn check_expr_with_opt_hint(
pub fn check_expr_with_opt_hint(
fcx: @fn_ctxt, expr: @ast::expr,
expected: Option<ty::t>) -> bool
{
expected: Option<ty::t>) -> bool {
check_expr_with_unifier(fcx, expr, expected, || ())
}
fn check_expr(fcx: @fn_ctxt, expr: @ast::expr) -> bool {
pub fn check_expr(fcx: @fn_ctxt, expr: @ast::expr) -> bool {
check_expr_with_unifier(fcx, expr, None, || ())
}
@ -1060,11 +1055,11 @@ pub fn impl_self_ty(vcx: &VtableContext,
// Only for fields! Returns <none> for methods>
// Indifferent to privacy flags
fn lookup_field_ty(tcx: ty::ctxt,
class_id: ast::def_id,
items: &[ty::field_ty],
fieldname: ast::ident,
substs: &ty::substs) -> Option<ty::t> {
pub fn lookup_field_ty(tcx: ty::ctxt,
class_id: ast::def_id,
items: &[ty::field_ty],
fieldname: ast::ident,
substs: &ty::substs) -> Option<ty::t> {
let o_field = vec::find(items, |f| f.ident == fieldname);
do o_field.map() |f| {
@ -1079,15 +1074,14 @@ pub enum DerefArgs {
DoDerefArgs
}
fn break_here() {
pub fn break_here() {
debug!("break here!");
}
fn check_expr_with_unifier(fcx: @fn_ctxt,
expr: @ast::expr,
expected: Option<ty::t>,
unifier: fn()) -> bool
{
pub fn check_expr_with_unifier(fcx: @fn_ctxt,
expr: @ast::expr,
expected: Option<ty::t>,
unifier: fn()) -> bool {
debug!(">> typechecking %s", fcx.expr_to_str(expr));
// A generic function to factor out common logic from call and
@ -2522,7 +2516,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
return bot;
}
fn require_integral(fcx: @fn_ctxt, sp: span, t: ty::t) {
pub fn require_integral(fcx: @fn_ctxt, sp: span, t: ty::t) {
if !type_is_integral(fcx, sp, t) {
fcx.type_error_message(sp, |actual| {
fmt!("mismatched types: expected integral type but found `%s`",
@ -2531,13 +2525,13 @@ fn require_integral(fcx: @fn_ctxt, sp: span, t: ty::t) {
}
}
fn check_decl_initializer(fcx: @fn_ctxt, nid: ast::node_id,
init: @ast::expr) -> bool {
pub fn check_decl_initializer(fcx: @fn_ctxt, nid: ast::node_id,
init: @ast::expr) -> bool {
let local_ty = fcx.local_ty(init.span, nid);
return check_expr_coercable_to_type(fcx, init, local_ty);
}
fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool {
pub fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool {
let mut bot = false;
let tcx = fcx.ccx.tcx;
@ -2563,7 +2557,7 @@ fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool {
return bot;
}
fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
pub fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
let mut node_id;
let mut bot = false;
match stmt.node {
@ -2590,7 +2584,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
return bot;
}
fn check_block_no_value(fcx: @fn_ctxt, blk: ast::blk) -> bool {
pub fn check_block_no_value(fcx: @fn_ctxt, blk: ast::blk) -> bool {
let bot = check_block(fcx, blk);
if !bot {
let blkty = fcx.node_ty(blk.node.id);
@ -2604,9 +2598,9 @@ pub fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
check_block_with_expected(fcx0, blk, None)
}
fn check_block_with_expected(fcx0: @fn_ctxt,
blk: ast::blk,
expected: Option<ty::t>) -> bool {
pub fn check_block_with_expected(fcx0: @fn_ctxt,
blk: ast::blk,
expected: Option<ty::t>) -> bool {
let fcx = match blk.node.rules {
ast::unsafe_blk => @fn_ctxt {purity: ast::unsafe_fn,.. copy *fcx0},
ast::default_blk => fcx0
@ -2647,15 +2641,18 @@ fn check_block_with_expected(fcx0: @fn_ctxt,
}
}
fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
pub fn check_const(ccx: @crate_ctxt,
_sp: span,
e: @ast::expr,
id: ast::node_id) {
let rty = ty::node_id_to_type(ccx.tcx, id);
let fcx = blank_fn_ctxt(ccx, rty, e.id);
let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty;
check_const_with_ty(fcx, _sp, e, declty);
}
fn check_const_with_ty(fcx: @fn_ctxt, _sp: span, e: @ast::expr,
declty: ty::t) {
pub fn check_const_with_ty(fcx: @fn_ctxt, _sp: span, e: @ast::expr,
declty: ty::t) {
check_expr(fcx, e);
let cty = fcx.expr_ty(e);
demand::suptype(fcx, e.span, declty, cty);
@ -2674,9 +2671,9 @@ fn check_const_with_ty(fcx: @fn_ctxt, _sp: span, e: @ast::expr,
/// enum foo { Some(@foo) }
///
/// is representable, but not instantiable.
fn check_instantiable(tcx: ty::ctxt,
sp: span,
item_id: ast::node_id) {
pub fn check_instantiable(tcx: ty::ctxt,
sp: span,
item_id: ast::node_id) {
let item_ty = ty::node_id_to_type(tcx, item_id);
if !ty::is_instantiable(tcx, item_ty) {
tcx.sess.span_err(sp, fmt!("this type cannot be instantiated \
@ -2686,10 +2683,10 @@ fn check_instantiable(tcx: ty::ctxt,
}
}
fn check_enum_variants(ccx: @crate_ctxt,
sp: span,
+vs: ~[ast::variant],
id: ast::node_id) {
pub fn check_enum_variants(ccx: @crate_ctxt,
sp: span,
+vs: ~[ast::variant],
id: ast::node_id) {
fn do_check(ccx: @crate_ctxt, sp: span, vs: ~[ast::variant],
id: ast::node_id, disr_vals: &mut ~[int], disr_val: &mut int,
variants: &mut ~[ty::VariantInfo]) {
@ -2806,8 +2803,10 @@ pub fn lookup_def(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> ast::def {
}
// Returns the type parameter count and the type for the given definition.
fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
ty_param_bounds_and_ty {
pub fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt,
sp: span,
defn: ast::def)
-> ty_param_bounds_and_ty {
match defn {
ast::def_arg(nid, _, _) | ast::def_local(nid, _) |
@ -2949,23 +2948,23 @@ pub fn structure_of(fcx: @fn_ctxt, sp: span, typ: ty::t) -> ty::sty {
/*bad*/copy ty::get(structurally_resolved_type(fcx, sp, typ)).sty
}
fn type_is_integral(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
pub fn type_is_integral(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_integral(typ_s);
}
fn type_is_scalar(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
pub fn type_is_scalar(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_scalar(typ_s);
}
fn type_is_c_like_enum(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
pub fn type_is_c_like_enum(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_c_like_enum(fcx.ccx.tcx, typ_s);
}
fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
v: ast::expr_vstore) -> ty::vstore {
pub fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
v: ast::expr_vstore) -> ty::vstore {
match v {
ast::expr_vstore_fixed(None) => ty::vstore_fixed(n),
ast::expr_vstore_fixed(Some(u)) => {
@ -2985,7 +2984,7 @@ fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
}
// Returns true if b contains a break that can exit from b
fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool {
pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool {
// First: is there an unlabeled break immediately
// inside the loop?
(loop_query(b, |e| {
@ -3007,10 +3006,10 @@ fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool {
}}))
}
fn check_bounds_are_used(ccx: @crate_ctxt,
span: span,
tps: ~[ast::ty_param],
ty: ty::t) {
pub fn check_bounds_are_used(ccx: @crate_ctxt,
span: span,
tps: ~[ast::ty_param],
ty: ty::t) {
debug!("check_bounds_are_used(n_tps=%u, ty=%s)",
tps.len(), ppaux::ty_to_str(ccx.tcx, ty));
@ -3041,7 +3040,7 @@ fn check_bounds_are_used(ccx: @crate_ctxt,
}
}
fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
fn param(ccx: @crate_ctxt, n: uint) -> ty::t {
ty::mk_param(ccx.tcx, n, local_def(0))
}

View File

@ -65,15 +65,16 @@ use core::vec::{len, push};
use core::vec;
use std::map::HashMap;
struct UniversalQuantificationResult {
pub struct UniversalQuantificationResult {
monotype: t,
type_variables: ~[ty::t],
bounds: @~[param_bounds]
}
fn get_base_type(inference_context: @InferCtxt, span: span, original_type: t)
-> Option<t> {
pub fn get_base_type(inference_context: @InferCtxt,
span: span,
original_type: t)
-> Option<t> {
let resolved_type;
match resolve_type(inference_context,
original_type,
@ -118,11 +119,10 @@ fn get_base_type(inference_context: @InferCtxt, span: span, original_type: t)
}
// Returns the def ID of the base type, if there is one.
fn get_base_type_def_id(inference_context: @InferCtxt,
span: span,
original_type: t)
-> Option<def_id> {
pub fn get_base_type_def_id(inference_context: @InferCtxt,
span: span,
original_type: t)
-> Option<def_id> {
match get_base_type(inference_context, span, original_type) {
None => {
return None;
@ -144,7 +144,7 @@ fn get_base_type_def_id(inference_context: @InferCtxt,
}
fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
@{
did: local_def(ast_method.id),
n_tps: ast_method.tps.len(),
@ -153,7 +153,7 @@ fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
}
}
struct CoherenceInfo {
pub struct CoherenceInfo {
// Contains implementations of methods that are inherent to a type.
// Methods in these implementations don't need to be exported.
inherent_methods: HashMap<def_id,@DVec<@Impl>>,
@ -164,14 +164,14 @@ struct CoherenceInfo {
}
fn CoherenceInfo() -> CoherenceInfo {
pub fn CoherenceInfo() -> CoherenceInfo {
CoherenceInfo {
inherent_methods: HashMap(),
extension_methods: HashMap(),
}
}
fn CoherenceChecker(crate_context: @crate_ctxt) -> CoherenceChecker {
pub fn CoherenceChecker(crate_context: @crate_ctxt) -> CoherenceChecker {
CoherenceChecker {
crate_context: crate_context,
inference_context: new_infer_ctxt(crate_context.tcx),
@ -181,7 +181,7 @@ fn CoherenceChecker(crate_context: @crate_ctxt) -> CoherenceChecker {
}
}
struct CoherenceChecker {
pub struct CoherenceChecker {
crate_context: @crate_ctxt,
inference_context: @InferCtxt,
@ -196,7 +196,7 @@ struct CoherenceChecker {
privileged_implementations: HashMap<node_id,()>,
}
impl CoherenceChecker {
pub impl CoherenceChecker {
fn check_coherence(crate: @crate) {
// Check implementations and traits. This populates the tables
// containing the inherent methods and extension methods. It also
@ -1011,7 +1011,7 @@ impl CoherenceChecker {
}
}
fn check_coherence(crate_context: @crate_ctxt, crate: @crate) {
pub fn check_coherence(crate_context: @crate_ctxt, crate: @crate) {
let coherence_checker = @CoherenceChecker(crate_context);
(*coherence_checker).check_coherence(crate);
}

View File

@ -61,7 +61,7 @@ use syntax::codemap;
use syntax::print::pprust::path_to_str;
use syntax::visit;
fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
pub fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
// FIXME (#2592): hooking into the "intrinsic" root module is crude.
// There ought to be a better approach. Attributes?
@ -114,7 +114,7 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
}));
}
impl @crate_ctxt {
pub impl @crate_ctxt {
fn to_ty<RS: region_scope Copy Durable>(
rs: RS, ast_ty: @ast::Ty) -> ty::t {
@ -122,7 +122,7 @@ impl @crate_ctxt {
}
}
impl @crate_ctxt: ast_conv {
pub impl @crate_ctxt: ast_conv {
fn tcx() -> ty::ctxt { self.tcx }
fn ccx() -> @crate_ctxt { self }
@ -151,11 +151,11 @@ impl @crate_ctxt: ast_conv {
}
}
fn get_enum_variant_types(ccx: @crate_ctxt,
enum_ty: ty::t,
variants: ~[ast::variant],
ty_params: ~[ast::ty_param],
rp: Option<ty::region_variance>) {
pub fn get_enum_variant_types(ccx: @crate_ctxt,
enum_ty: ty::t,
variants: ~[ast::variant],
ty_params: ~[ast::ty_param],
rp: Option<ty::region_variance>) {
let tcx = ccx.tcx;
// Create a set of parameter types shared among all the variants.
@ -237,7 +237,9 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
}
}
fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id, trait_ty: ty::t) {
pub fn ensure_trait_methods(ccx: @crate_ctxt,
id: ast::node_id,
trait_ty: ty::t) {
fn store_methods<T>(ccx: @crate_ctxt, id: ast::node_id,
stuff: ~[T], f: &fn(v: &T) -> ty::method) {
ty::store_trait_methods(ccx.tcx, id, @vec::map(stuff, f));
@ -318,11 +320,11 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id, trait_ty: ty::t) {
}
}
fn ensure_supertraits(ccx: @crate_ctxt,
id: ast::node_id,
sp: codemap::span,
rp: Option<ty::region_variance>,
trait_refs: &[@ast::trait_ref]) {
pub fn ensure_supertraits(ccx: @crate_ctxt,
id: ast::node_id,
sp: codemap::span,
rp: Option<ty::region_variance>,
trait_refs: &[@ast::trait_ref]) {
let tcx = ccx.tcx;
if tcx.supertraits.contains_key(local_def(id)) { return; }
@ -355,13 +357,12 @@ fn ensure_supertraits(ccx: @crate_ctxt,
* - trait_substs: the substitutions used on the type of the trait
* - self_ty: the self type of the impl
*/
fn compare_impl_method(tcx: ty::ctxt,
impl_tps: uint,
cm: &ConvertedMethod,
trait_m: &ty::method,
trait_substs: &ty::substs,
self_ty: ty::t)
{
pub fn compare_impl_method(tcx: ty::ctxt,
impl_tps: uint,
cm: &ConvertedMethod,
trait_m: &ty::method,
trait_substs: &ty::substs,
self_ty: ty::t) {
debug!("compare_impl_method()");
let _indenter = indenter();
@ -503,12 +504,12 @@ fn compare_impl_method(tcx: ty::ctxt,
}
}
fn check_methods_against_trait(ccx: @crate_ctxt,
tps: ~[ast::ty_param],
rp: Option<ty::region_variance>,
selfty: ty::t,
a_trait_ty: @ast::trait_ref,
impl_ms: ~[ConvertedMethod]) {
pub fn check_methods_against_trait(ccx: @crate_ctxt,
tps: ~[ast::ty_param],
rp: Option<ty::region_variance>,
selfty: ty::t,
a_trait_ty: @ast::trait_ref,
impl_ms: ~[ConvertedMethod]) {
let tcx = ccx.tcx;
let (did, tpt) = instantiate_trait_ref(ccx, a_trait_ty, rp);
@ -554,10 +555,10 @@ fn check_methods_against_trait(ccx: @crate_ctxt,
}
} // fn
fn convert_field(ccx: @crate_ctxt,
rp: Option<ty::region_variance>,
bounds: @~[ty::param_bounds],
v: @ast::struct_field) {
pub fn convert_field(ccx: @crate_ctxt,
rp: Option<ty::region_variance>,
bounds: @~[ty::param_bounds],
v: @ast::struct_field) {
let tt = ccx.to_ty(type_rscope(rp), v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */
@ -567,17 +568,18 @@ fn convert_field(ccx: @crate_ctxt,
ty: tt});
}
struct ConvertedMethod {
pub struct ConvertedMethod {
mty: ty::method,
id: ast::node_id,
span: span,
body_id: ast::node_id
}
fn convert_methods(ccx: @crate_ctxt,
ms: ~[@ast::method],
rp: Option<ty::region_variance>,
rcvr_bounds: @~[ty::param_bounds]) -> ~[ConvertedMethod] {
pub fn convert_methods(ccx: @crate_ctxt,
ms: ~[@ast::method],
rp: Option<ty::region_variance>,
rcvr_bounds: @~[ty::param_bounds])
-> ~[ConvertedMethod] {
let tcx = ccx.tcx;
do vec::map(ms) |m| {
@ -598,10 +600,10 @@ fn convert_methods(ccx: @crate_ctxt,
}
}
fn ensure_no_ty_param_bounds(ccx: @crate_ctxt,
span: span,
ty_params: &[ast::ty_param],
thing: &static/str) {
pub fn ensure_no_ty_param_bounds(ccx: @crate_ctxt,
span: span,
ty_params: &[ast::ty_param],
thing: &static/str) {
for ty_params.each |ty_param| {
if ty_param.bounds.len() > 0 {
ccx.tcx.sess.span_err(
@ -612,7 +614,7 @@ fn ensure_no_ty_param_bounds(ccx: @crate_ctxt,
}
}
fn convert(ccx: @crate_ctxt, it: @ast::item) {
pub fn convert(ccx: @crate_ctxt, it: @ast::item) {
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.find(it.id);
debug!("convert: item %s with id %d rp %?",
@ -683,12 +685,12 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
}
}
fn convert_struct(ccx: @crate_ctxt,
rp: Option<ty::region_variance>,
struct_def: @ast::struct_def,
+tps: ~[ast::ty_param],
tpt: ty::ty_param_bounds_and_ty,
id: ast::node_id) {
pub fn convert_struct(ccx: @crate_ctxt,
rp: Option<ty::region_variance>,
struct_def: @ast::struct_def,
+tps: ~[ast::ty_param],
tpt: ty::ty_param_bounds_and_ty,
id: ast::node_id) {
let tcx = ccx.tcx;
do option::iter(&struct_def.dtor) |dtor| {
@ -755,7 +757,7 @@ fn convert_struct(ccx: @crate_ctxt,
}
}
fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) {
pub fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) {
// As above, this call populates the type table with the converted
// type of the foreign item. We simply write it into the node type
// table.
@ -764,9 +766,9 @@ fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) {
ccx.tcx.tcache.insert(local_def(i.id), tpt);
}
fn ty_of_method(ccx: @crate_ctxt,
m: @ast::method,
rp: Option<ty::region_variance>) -> ty::method {
pub fn ty_of_method(ccx: @crate_ctxt,
m: @ast::method,
rp: Option<ty::region_variance>) -> ty::method {
{ident: m.ident,
tps: ty_param_bounds(ccx, /*bad*/copy m.tps),
fty: ty_of_fn_decl(ccx, type_rscope(rp), ast::ProtoBare,
@ -778,10 +780,10 @@ fn ty_of_method(ccx: @crate_ctxt,
def_id: local_def(m.id)}
}
fn ty_of_ty_method(self: @crate_ctxt,
m: ast::ty_method,
rp: Option<ty::region_variance>,
id: ast::def_id) -> ty::method {
pub fn ty_of_ty_method(self: @crate_ctxt,
m: ast::ty_method,
rp: Option<ty::region_variance>,
id: ast::def_id) -> ty::method {
{ident: m.ident,
tps: ty_param_bounds(self, /*bad*/copy m.tps),
fty: ty_of_fn_decl(self, type_rscope(rp), ast::ProtoBare,
@ -799,8 +801,8 @@ fn ty_of_ty_method(self: @crate_ctxt,
it's bound to a valid trait type. Returns the def_id for the defining
trait. Fails if the type is a type other than an trait type.
*/
fn instantiate_trait_ref(ccx: @crate_ctxt, t: @ast::trait_ref,
rp: Option<ty::region_variance>)
pub fn instantiate_trait_ref(ccx: @crate_ctxt, t: @ast::trait_ref,
rp: Option<ty::region_variance>)
-> (ast::def_id, ty_param_substs_and_ty) {
let sp = t.path.span, err = ~"can only implement trait types",
@ -823,7 +825,7 @@ fn instantiate_trait_ref(ccx: @crate_ctxt, t: @ast::trait_ref,
}
}
fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
-> ty::ty_param_bounds_and_ty {
let def_id = local_def(it.id);
@ -916,7 +918,7 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
}
}
fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item)
pub fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item)
-> ty::ty_param_bounds_and_ty {
match /*bad*/copy it.node {
ast::foreign_item_fn(fn_decl, _, params) => {
@ -937,9 +939,9 @@ fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item)
// of a newtyped Ty or a region) to ty's notion of ty param bounds, which can
// either be user-defined traits, or one of the four built-in traits (formerly
// known as kinds): Const, Copy, Durable, and Send.
fn compute_bounds(ccx: @crate_ctxt,
ast_bounds: @~[ast::ty_param_bound])
-> ty::param_bounds {
pub fn compute_bounds(ccx: @crate_ctxt,
ast_bounds: @~[ast::ty_param_bound])
-> ty::param_bounds {
@do vec::flat_map(*ast_bounds) |b| {
match b {
&TraitTyParamBound(b) => {
@ -973,10 +975,8 @@ fn compute_bounds(ccx: @crate_ctxt,
}
}
fn ty_param_bounds(ccx: @crate_ctxt,
params: ~[ast::ty_param]) -> @~[ty::param_bounds] {
pub fn ty_param_bounds(ccx: @crate_ctxt,
params: ~[ast::ty_param]) -> @~[ty::param_bounds] {
@do params.map |param| {
match ccx.tcx.ty_param_bounds.find(param.id) {
Some(bs) => bs,
@ -989,10 +989,11 @@ fn ty_param_bounds(ccx: @crate_ctxt,
}
}
fn ty_of_foreign_fn_decl(ccx: @crate_ctxt,
decl: ast::fn_decl,
+ty_params: ~[ast::ty_param],
def_id: ast::def_id) -> ty::ty_param_bounds_and_ty {
pub fn ty_of_foreign_fn_decl(ccx: @crate_ctxt,
decl: ast::fn_decl,
+ty_params: ~[ast::ty_param],
def_id: ast::def_id)
-> ty::ty_param_bounds_and_ty {
let bounds = ty_param_bounds(ccx, ty_params);
let rb = in_binding_rscope(empty_rscope);
let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, rb, *a, None) );
@ -1012,7 +1013,7 @@ fn ty_of_foreign_fn_decl(ccx: @crate_ctxt,
return tpt;
}
fn mk_ty_params(ccx: @crate_ctxt, atps: ~[ast::ty_param])
pub fn mk_ty_params(ccx: @crate_ctxt, atps: ~[ast::ty_param])
-> {bounds: @~[ty::param_bounds], params: ~[ty::t]} {
let mut i = 0u;
@ -1026,10 +1027,10 @@ fn mk_ty_params(ccx: @crate_ctxt, atps: ~[ast::ty_param])
})}
}
fn mk_substs(ccx: @crate_ctxt,
+atps: ~[ast::ty_param],
rp: Option<ty::region_variance>)
-> {bounds: @~[ty::param_bounds], substs: ty::substs} {
pub fn mk_substs(ccx: @crate_ctxt,
+atps: ~[ast::ty_param],
rp: Option<ty::region_variance>)
-> {bounds: @~[ty::param_bounds], substs: ty::substs} {
let {bounds, params} = mk_ty_params(ccx, atps);
let self_r = rscope::bound_self_region(rp);
{

View File

@ -72,9 +72,12 @@ use syntax::ast::{Onceness, purity, ret_style};
use syntax::ast;
use syntax::codemap::span;
fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
pub fn macros() {
// FIXME(#3114): Macro import/export.
include!("macros.rs");
}
trait Combine {
pub trait Combine {
fn infcx() -> @InferCtxt;
fn tag() -> ~str;
fn a_is_expected() -> bool;
@ -112,9 +115,8 @@ pub struct CombineFields {
span: span,
}
fn expected_found<C:Combine,T>(
self: &C, +a: T, +b: T) -> ty::expected_found<T>
{
pub fn expected_found<C:Combine,T>(
self: &C, +a: T, +b: T) -> ty::expected_found<T> {
if self.a_is_expected() {
ty::expected_found {expected: move a, found: move b}
} else {
@ -131,7 +133,8 @@ pub fn eq_tys<C:Combine>(self: &C, a: ty::t, b: ty::t) -> ures {
}
}
fn eq_regions<C:Combine>(self: &C, a: ty::Region, b: ty::Region) -> ures {
pub fn eq_regions<C:Combine>(self: &C, a: ty::Region, b: ty::Region)
-> ures {
debug!("eq_regions(%s, %s)",
a.inf_str(self.infcx()),
b.inf_str(self.infcx()));
@ -153,7 +156,7 @@ fn eq_regions<C:Combine>(self: &C, a: ty::Region, b: ty::Region) -> ures {
}
}
fn eq_opt_regions<C:Combine>(
pub fn eq_opt_regions<C:Combine>(
self: &C,
a: Option<ty::Region>,
b: Option<ty::Region>) -> cres<Option<ty::Region>> {
@ -181,7 +184,7 @@ fn eq_opt_regions<C:Combine>(
}
}
fn super_substs<C:Combine>(
pub fn super_substs<C:Combine>(
self: &C, did: ast::def_id,
a: &ty::substs, b: &ty::substs) -> cres<ty::substs> {
@ -243,7 +246,7 @@ fn super_substs<C:Combine>(
}
}
fn super_tps<C:Combine>(
pub fn super_tps<C:Combine>(
self: &C, as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> {
// Note: type parameters are always treated as *invariant*
@ -261,7 +264,7 @@ fn super_tps<C:Combine>(
}
}
fn super_self_tys<C:Combine>(
pub fn super_self_tys<C:Combine>(
self: &C, a: Option<ty::t>, b: Option<ty::t>) -> cres<Option<ty::t>> {
// Note: the self type parameter is (currently) always treated as
@ -284,9 +287,8 @@ fn super_self_tys<C:Combine>(
}
}
fn super_protos<C: Combine>(
self: &C, p1: ast::Proto, p2: ast::Proto) -> cres<ast::Proto>
{
pub fn super_protos<C: Combine>(
self: &C, p1: ast::Proto, p2: ast::Proto) -> cres<ast::Proto> {
if p1 == p2 {
Ok(p1)
} else {
@ -294,7 +296,7 @@ fn super_protos<C: Combine>(
}
}
fn super_flds<C:Combine>(
pub fn super_flds<C:Combine>(
self: &C, a: ty::field, b: ty::field) -> cres<ty::field> {
if a.ident == b.ident {
@ -307,7 +309,7 @@ fn super_flds<C:Combine>(
}
}
fn super_modes<C:Combine>(
pub fn super_modes<C:Combine>(
self: &C, a: ast::mode, b: ast::mode)
-> cres<ast::mode> {
@ -326,10 +328,9 @@ fn super_args<C:Combine>(
}
}
fn super_vstores<C:Combine>(
pub fn super_vstores<C:Combine>(
self: &C, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore>
{
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
debug!("%s.super_vstores(a=%?, b=%?)", self.tag(), a, b);
match (a, b) {
@ -349,9 +350,8 @@ fn super_vstores<C:Combine>(
}
}
fn super_fn_metas<C:Combine>(
self: &C, a_f: &ty::FnMeta, b_f: &ty::FnMeta) -> cres<ty::FnMeta>
{
pub fn super_fn_metas<C:Combine>(
self: &C, a_f: &ty::FnMeta, b_f: &ty::FnMeta) -> cres<ty::FnMeta> {
let p = if_ok!(self.protos(a_f.proto, b_f.proto));
let r = if_ok!(self.contraregions(a_f.region, b_f.region));
let purity = if_ok!(self.purities(a_f.purity, b_f.purity));
@ -363,9 +363,8 @@ fn super_fn_metas<C:Combine>(
bounds: a_f.bounds}) // XXX: This is wrong!
}
fn super_fn_sigs<C:Combine>(
self: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres<ty::FnSig>
{
pub fn super_fn_sigs<C:Combine>(
self: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres<ty::FnSig> {
fn argvecs<C:Combine>(self: &C,
+a_args: ~[ty::arg],
+b_args: ~[ty::arg]) -> cres<~[ty::arg]>
@ -385,17 +384,15 @@ fn super_fn_sigs<C:Combine>(
}
}
fn super_fns<C:Combine>(
self: &C, a_f: &ty::FnTy, b_f: &ty::FnTy) -> cres<ty::FnTy>
{
pub fn super_fns<C:Combine>(
self: &C, a_f: &ty::FnTy, b_f: &ty::FnTy) -> cres<ty::FnTy> {
let m = if_ok!(self.fn_metas(&a_f.meta, &b_f.meta));
let s = if_ok!(self.fn_sigs(&a_f.sig, &b_f.sig));
Ok(FnTyBase {meta: m, sig: s})
}
fn super_tys<C:Combine>(
self: &C, a: ty::t, b: ty::t) -> cres<ty::t>
{
pub fn super_tys<C:Combine>(
self: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
let tcx = self.infcx().tcx;
return match (/*bad*/copy ty::get(a).sty, /*bad*/copy ty::get(b).sty) {
// The "subtype" ought to be handling cases involving bot or var:

View File

@ -25,9 +25,9 @@ use util::ppaux::mt_to_str;
use std::list;
enum Glb = CombineFields; // "greatest lower bound" (common subtype)
pub enum Glb = CombineFields; // "greatest lower bound" (common subtype)
impl Glb: Combine {
pub impl Glb: Combine {
fn infcx() -> @InferCtxt { self.infcx }
fn tag() -> ~str { ~"glb" }
fn a_is_expected() -> bool { self.a_is_expected }

View File

@ -49,15 +49,15 @@ use middle::typeck::infer::to_str::InferStr;
use std::list;
trait LatticeValue {
pub trait LatticeValue {
static fn sub(cf: &CombineFields, a: &self, b: &self) -> ures;
static fn lub(cf: &CombineFields, a: &self, b: &self) -> cres<self>;
static fn glb(cf: &CombineFields, a: &self, b: &self) -> cres<self>;
}
type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
pub type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
impl ty::t: LatticeValue {
pub impl ty::t: LatticeValue {
static fn sub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures {
Sub(*cf).tys(*a, *b).to_ures()
}
@ -71,7 +71,7 @@ impl ty::t: LatticeValue {
}
}
impl FnMeta: LatticeValue {
pub impl FnMeta: LatticeValue {
static fn sub(cf: &CombineFields,
a: &FnMeta, b: &FnMeta) -> ures {
Sub(*cf).fn_metas(a, b).to_ures()
@ -88,7 +88,7 @@ impl FnMeta: LatticeValue {
}
}
impl CombineFields {
pub impl CombineFields {
fn var_sub_var<T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
&self,
@ -309,17 +309,17 @@ impl CombineFields {
// This is common code used by both LUB and GLB to compute the LUB/GLB
// for pairs of variables or for variables and values.
trait LatticeDir {
pub trait LatticeDir {
fn combine_fields() -> CombineFields;
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T>;
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T>;
}
trait TyLatticeDir {
pub trait TyLatticeDir {
fn ty_bot(t: ty::t) -> cres<ty::t>;
}
impl Lub: LatticeDir {
pub impl Lub: LatticeDir {
fn combine_fields() -> CombineFields { *self }
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T> { b.ub }
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T> {
@ -327,13 +327,13 @@ impl Lub: LatticeDir {
}
}
impl Lub: TyLatticeDir {
pub impl Lub: TyLatticeDir {
fn ty_bot(t: ty::t) -> cres<ty::t> {
Ok(t)
}
}
impl Glb: LatticeDir {
pub impl Glb: LatticeDir {
fn combine_fields() -> CombineFields { *self }
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T> { b.lb }
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T> {
@ -341,17 +341,16 @@ impl Glb: LatticeDir {
}
}
impl Glb: TyLatticeDir {
pub impl Glb: TyLatticeDir {
fn ty_bot(_t: ty::t) -> cres<ty::t> {
Ok(ty::mk_bot(self.infcx.tcx))
}
}
fn super_lattice_tys<L:LatticeDir TyLatticeDir Combine>(
pub fn super_lattice_tys<L:LatticeDir TyLatticeDir Combine>(
self: &L,
a: ty::t,
b: ty::t) -> cres<ty::t>
{
b: ty::t) -> cres<ty::t> {
debug!("%s.lattice_tys(%s, %s)", self.tag(),
a.inf_str(self.infcx()),
b.inf_str(self.infcx()));
@ -392,9 +391,9 @@ fn super_lattice_tys<L:LatticeDir TyLatticeDir Combine>(
}
}
type LatticeDirOp<T> = &fn(a: &T, b: &T) -> cres<T>;
pub type LatticeDirOp<T> = &fn(a: &T, b: &T) -> cres<T>;
enum LatticeVarResult<V,T> {
pub enum LatticeVarResult<V,T> {
VarResult(V),
ValueResult(T)
}
@ -414,15 +413,14 @@ enum LatticeVarResult<V,T> {
* the variables and return the unified variable, in which case the
* result is a variable. This is indicated with a `VarResult`
* return. */
fn lattice_vars<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
pub fn lattice_vars<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
self: &L, // defines whether we want LUB or GLB
+a_vid: V, // first variable
+b_vid: V, // second variable
lattice_dir_op: LatticeDirOp<T>) // LUB or GLB operation on types
-> cres<LatticeVarResult<V,T>>
{
-> cres<LatticeVarResult<V,T>> {
let nde_a = self.infcx().get(a_vid);
let nde_b = self.infcx().get(b_vid);
let a_vid = nde_a.root;
@ -461,15 +459,14 @@ fn lattice_vars<L:LatticeDir Combine,
}
}
fn lattice_var_and_t<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
pub fn lattice_var_and_t<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
self: &L,
+a_id: V,
b: &T,
lattice_dir_op: LatticeDirOp<T>)
-> cres<T>
{
-> cres<T> {
let nde_a = self.infcx().get(a_id);
let a_id = nde_a.root;
let a_bounds = &nde_a.possible_types;
@ -506,7 +503,7 @@ fn lattice_var_and_t<L:LatticeDir Combine,
// Random utility functions used by LUB/GLB when computing LUB/GLB of
// fn types
fn var_ids<T: Combine>(self: &T, isr: isr_alist) -> ~[RegionVid] {
pub fn var_ids<T: Combine>(self: &T, isr: isr_alist) -> ~[RegionVid] {
let mut result = ~[];
for list::each(isr) |pair| {
match pair.second() {
@ -521,7 +518,7 @@ fn var_ids<T: Combine>(self: &T, isr: isr_alist) -> ~[RegionVid] {
return result;
}
fn is_var_in_set(new_vars: &[RegionVid], r: ty::Region) -> bool {
pub fn is_var_in_set(new_vars: &[RegionVid], r: ty::Region) -> bool {
match r {
ty::re_infer(ty::ReVar(ref v)) => new_vars.contains(v),
_ => false

View File

@ -24,16 +24,19 @@ use std::list;
use syntax::ast::{Many, Once, extern_fn, m_const, impure_fn, noreturn};
use syntax::ast::{pure_fn, ret_style, return_val, unsafe_fn};
fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
pub fn macros() {
// FIXME(#3114): Macro import/export.
include!("macros.rs");
}
enum Lub = CombineFields; // least-upper-bound: common supertype
pub enum Lub = CombineFields; // least-upper-bound: common supertype
impl Lub {
pub impl Lub {
fn bot_ty(b: ty::t) -> cres<ty::t> { Ok(b) }
fn ty_bot(b: ty::t) -> cres<ty::t> { self.bot_ty(b) } // commutative
}
impl Lub: Combine {
pub impl Lub: Combine {
fn infcx() -> @InferCtxt { self.infcx }
fn tag() -> ~str { ~"lub" }
fn a_is_expected() -> bool { self.a_is_expected }

View File

@ -242,16 +242,23 @@ section on "Type Combining" below for details.
*/
#[legacy_exports];
#[warn(deprecated_mode)];
#[warn(deprecated_pattern)];
use core::prelude::*;
pub use middle::ty::IntVarValue;
pub use middle::typeck::infer::resolve::resolve_and_force_all_but_regions;
pub use middle::typeck::infer::resolve::{force_all, not_regions};
pub use middle::typeck::infer::resolve::{force_ivar};
pub use middle::typeck::infer::resolve::{force_tvar, force_rvar};
pub use middle::typeck::infer::resolve::{resolve_ivar, resolve_all};
pub use middle::typeck::infer::resolve::{resolve_nested_tvar};
pub use middle::typeck::infer::resolve::{resolve_rvar};
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid};
use middle::ty::{mk_fn, type_is_bot};
use middle::ty::{ty_int, ty_uint, get, terr_fn, TyVar, IntVar, FloatVar};
use middle::ty::IntVarValue;
use middle::ty;
use middle::typeck::check::regionmanip::{replace_bound_regions_in_fn_sig};
use middle::typeck::infer::coercion::Coerce;
@ -259,11 +266,6 @@ use middle::typeck::infer::combine::{Combine, CombineFields, eq_tys};
use middle::typeck::infer::glb::Glb;
use middle::typeck::infer::lub::Lub;
use middle::typeck::infer::region_inference::{RegionVarBindings};
use middle::typeck::infer::resolve::{force_all, not_regions};
use middle::typeck::infer::resolve::{force_tvar, force_rvar, force_ivar};
use middle::typeck::infer::resolve::{resolve_and_force_all_but_regions};
use middle::typeck::infer::resolve::{resolve_ivar, resolve_all};
use middle::typeck::infer::resolve::{resolve_nested_tvar, resolve_rvar};
use middle::typeck::infer::resolve::{resolver};
use middle::typeck::infer::sub::Sub;
use middle::typeck::infer::to_str::InferStr;
@ -288,69 +290,26 @@ use syntax::ast_util::dummy_sp;
use syntax::ast_util;
use syntax::codemap::span;
export InferCtxt;
export new_infer_ctxt;
export mk_subty, can_mk_subty;
export mk_subr;
export mk_eqty;
export mk_coercety, can_mk_coercety;
export resolve_nested_tvar, resolve_rvar, resolve_ivar, resolve_all;
export force_tvar, force_rvar, force_ivar, force_all;
export resolve_and_force_all_but_regions, not_regions;
export resolve_type, resolve_region;
export resolve_borrowings;
export cres, fres, fixup_err, fixup_err_to_str;
export root, to_str;
export int_ty_set_all;
export combine;
export glb;
export integral;
export lattice;
export lub;
export region_inference;
export resolve;
export sub;
export coercion;
export to_str;
export unify;
export uok;
export cyclic_ty, unresolved_ty, region_var_bound_by_region_var;
export Bound, Bounds;
export ures;
export CoerceResult;
export infer_ctxt;
export fixup_err;
export IntVarValue, IntType, UintType;
pub mod combine;
pub mod glb;
pub mod lattice;
pub mod lub;
pub mod region_inference;
pub mod resolve;
pub mod sub;
pub mod to_str;
pub mod unify;
pub mod coercion;
#[legacy_exports]
mod combine;
#[legacy_exports]
mod glb;
#[legacy_exports]
mod lattice;
#[legacy_exports]
mod lub;
#[legacy_exports]
mod region_inference;
#[legacy_exports]
mod resolve;
#[legacy_exports]
mod sub;
#[legacy_exports]
mod to_str;
#[legacy_exports]
mod unify;
mod coercion;
pub type Bound<T> = Option<T>;
pub type Bounds<T> = {lb: Bound<T>, ub: Bound<T>};
type Bound<T> = Option<T>;
type Bounds<T> = {lb: Bound<T>, ub: Bound<T>};
pub type cres<T> = Result<T,ty::type_err>; // "combine result"
pub type ures = cres<()>; // "unify result"
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
pub type CoerceResult = cres<Option<@ty::AutoAdjustment>>;
type cres<T> = Result<T,ty::type_err>; // "combine result"
type ures = cres<()>; // "unify result"
type fres<T> = Result<T, fixup_err>; // "fixup result"
type CoerceResult = cres<Option<@ty::AutoAdjustment>>;
struct InferCtxt {
pub struct InferCtxt {
tcx: ty::ctxt,
// We instantiate ValsAndBindings with bounds<ty::t> because the
@ -371,7 +330,7 @@ struct InferCtxt {
region_vars: RegionVarBindings,
}
enum fixup_err {
pub enum fixup_err {
unresolved_int_ty(IntVid),
unresolved_ty(TyVid),
cyclic_ty(TyVid),
@ -379,7 +338,7 @@ enum fixup_err {
region_var_bound_by_region_var(RegionVid, RegionVid)
}
fn fixup_err_to_str(f: fixup_err) -> ~str {
pub fn fixup_err_to_str(f: fixup_err) -> ~str {
match f {
unresolved_int_ty(_) => ~"unconstrained integral type",
unresolved_ty(_) => ~"unconstrained type",
@ -399,7 +358,7 @@ fn new_ValsAndBindings<V:Copy, T:Copy>() -> ValsAndBindings<V, T> {
}
}
fn new_infer_ctxt(tcx: ty::ctxt) -> @InferCtxt {
pub fn new_infer_ctxt(tcx: ty::ctxt) -> @InferCtxt {
@InferCtxt {
tcx: tcx,
@ -416,8 +375,8 @@ fn new_infer_ctxt(tcx: ty::ctxt) -> @InferCtxt {
}
}
fn mk_subty(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> ures {
pub fn mk_subty(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> ures {
debug!("mk_subty(%s <: %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.commit {
@ -426,7 +385,7 @@ fn mk_subty(cx: @InferCtxt, a_is_expected: bool, span: span,
}.to_ures()
}
fn can_mk_subty(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
pub fn can_mk_subty(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
debug!("can_mk_subty(%s <: %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.probe {
@ -435,8 +394,8 @@ fn can_mk_subty(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
}.to_ures()
}
fn mk_subr(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::Region, b: ty::Region) -> ures {
pub fn mk_subr(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::Region, b: ty::Region) -> ures {
debug!("mk_subr(%s <: %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.commit {
@ -445,8 +404,8 @@ fn mk_subr(cx: @InferCtxt, a_is_expected: bool, span: span,
}.to_ures()
}
fn mk_eqty(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> ures {
pub fn mk_eqty(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> ures {
debug!("mk_eqty(%s <: %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.commit {
@ -456,9 +415,8 @@ fn mk_eqty(cx: @InferCtxt, a_is_expected: bool, span: span,
}.to_ures()
}
fn mk_coercety(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> CoerceResult
{
pub fn mk_coercety(cx: @InferCtxt, a_is_expected: bool, span: span,
a: ty::t, b: ty::t) -> CoerceResult {
debug!("mk_coercety(%s -> %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.commit {
@ -467,7 +425,7 @@ fn mk_coercety(cx: @InferCtxt, a_is_expected: bool, span: span,
}
}
fn can_mk_coercety(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
pub fn can_mk_coercety(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
debug!("can_mk_coercety(%s -> %s)", a.inf_str(cx), b.inf_str(cx));
do indent {
do cx.probe {
@ -478,13 +436,12 @@ fn can_mk_coercety(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
}
// See comment on the type `resolve_state` below
fn resolve_type(cx: @InferCtxt, a: ty::t, modes: uint)
-> fres<ty::t> {
pub fn resolve_type(cx: @InferCtxt, a: ty::t, modes: uint) -> fres<ty::t> {
resolver(cx, modes).resolve_type_chk(a)
}
fn resolve_region(cx: @InferCtxt, r: ty::Region, modes: uint)
-> fres<ty::Region> {
pub fn resolve_region(cx: @InferCtxt, r: ty::Region, modes: uint)
-> fres<ty::Region> {
resolver(cx, modes).resolve_region_chk(r)
}

View File

@ -565,11 +565,6 @@ use std::list::{List, Nil, Cons};
use syntax::codemap::span;
use syntax::codemap;
export RegionVarBindings;
export make_subregion;
export lub_regions;
export glb_regions;
enum Constraint {
ConstrainVarSubVar(RegionVid, RegionVid),
ConstrainRegSubVar(Region, RegionVid),
@ -638,7 +633,7 @@ enum UndoLogEntry {
type CombineMap = HashMap<TwoRegions, RegionVid>;
struct RegionVarBindings {
pub struct RegionVarBindings {
tcx: ty::ctxt,
var_spans: DVec<span>,
constraints: HashMap<Constraint, span>,
@ -663,7 +658,7 @@ struct RegionVarBindings {
values: Cell<~[GraphNodeValue]>,
}
fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
RegionVarBindings {
tcx: tcx,
var_spans: DVec(),
@ -684,7 +679,7 @@ fn CombineMap() -> CombineMap {
return HashMap();
}
impl RegionVarBindings {
pub impl RegionVarBindings {
fn in_snapshot(&self) -> bool {
self.undo_log.len() > 0
}

View File

@ -63,26 +63,26 @@ use syntax::ast;
use core::uint;
use core::vec;
const resolve_nested_tvar: uint = 0b0000000001;
const resolve_rvar: uint = 0b0000000010;
const resolve_ivar: uint = 0b0000000100;
const resolve_fvar: uint = 0b0000001000;
const resolve_fnvar: uint = 0b0000010000;
const resolve_all: uint = 0b0000011111;
const force_tvar: uint = 0b0000100000;
const force_rvar: uint = 0b0001000000;
const force_ivar: uint = 0b0010000000;
const force_fvar: uint = 0b0100000000;
const force_fnvar: uint = 0b1000000000;
const force_all: uint = 0b1111100000;
pub const resolve_nested_tvar: uint = 0b0000000001;
pub const resolve_rvar: uint = 0b0000000010;
pub const resolve_ivar: uint = 0b0000000100;
pub const resolve_fvar: uint = 0b0000001000;
pub const resolve_fnvar: uint = 0b0000010000;
pub const resolve_all: uint = 0b0000011111;
pub const force_tvar: uint = 0b0000100000;
pub const force_rvar: uint = 0b0001000000;
pub const force_ivar: uint = 0b0010000000;
pub const force_fvar: uint = 0b0100000000;
pub const force_fnvar: uint = 0b1000000000;
pub const force_all: uint = 0b1111100000;
const not_regions: uint = !(force_rvar | resolve_rvar);
pub const not_regions: uint = !(force_rvar | resolve_rvar);
const try_resolve_tvar_shallow: uint = 0;
const resolve_and_force_all_but_regions: uint =
pub const try_resolve_tvar_shallow: uint = 0;
pub const resolve_and_force_all_but_regions: uint =
(resolve_all | force_all) & not_regions;
struct ResolveState {
pub struct ResolveState {
infcx: @InferCtxt,
modes: uint,
mut err: Option<fixup_err>,
@ -90,7 +90,7 @@ struct ResolveState {
mut type_depth: uint
}
fn resolver(infcx: @InferCtxt, modes: uint) -> ResolveState {
pub fn resolver(infcx: @InferCtxt, modes: uint) -> ResolveState {
ResolveState {
infcx: infcx,
modes: modes,
@ -100,7 +100,7 @@ fn resolver(infcx: @InferCtxt, modes: uint) -> ResolveState {
}
}
impl ResolveState {
pub impl ResolveState {
fn should(&self, mode: uint) -> bool {
(self.modes & mode) == mode
}

View File

@ -25,11 +25,14 @@ use std::list::Nil;
use std::list;
use syntax::ast::{m_const, purity, ret_style};
fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
pub fn macros() {
// FIXME(#3114): Macro import/export.
include!("macros.rs");
}
enum Sub = CombineFields; // "subtype", "subregion" etc
pub enum Sub = CombineFields; // "subtype", "subregion" etc
impl Sub: Combine {
pub impl Sub: Combine {
fn infcx() -> @InferCtxt { self.infcx }
fn tag() -> ~str { ~"sub" }
fn a_is_expected() -> bool { self.a_is_expected }

View File

@ -28,19 +28,19 @@ pub trait InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str;
}
impl ty::t : InferStr {
pub impl ty::t : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
ty_to_str(cx.tcx, *self)
}
}
impl FnMeta : InferStr {
pub impl FnMeta : InferStr {
fn inf_str(&self, _cx: &InferCtxt) -> ~str {
fmt!("%?", *self)
}
}
impl FnSig : InferStr {
pub impl FnSig : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
fmt!("(%s) -> %s",
str::connect(self.inputs.map(|a| a.ty.inf_str(cx)), ", "),
@ -48,25 +48,25 @@ impl FnSig : InferStr {
}
}
impl<M:InferStr> FnTyBase<M> : InferStr {
pub impl<M:InferStr> FnTyBase<M> : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
fmt!("%s%s", self.meta.inf_str(cx), self.sig.inf_str(cx))
}
}
impl ty::mt : InferStr {
pub impl ty::mt : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
mt_to_str(cx.tcx, *self)
}
}
impl ty::Region : InferStr {
pub impl ty::Region : InferStr {
fn inf_str(&self, _cx: &InferCtxt) -> ~str {
fmt!("%?", *self)
}
}
impl<V:InferStr> Bound<V> : InferStr {
pub impl<V:InferStr> Bound<V> : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
match *self {
Some(ref v) => v.inf_str(cx),
@ -75,7 +75,7 @@ impl<V:InferStr> Bound<V> : InferStr {
}
}
impl<T:InferStr> Bounds<T> : InferStr {
pub impl<T:InferStr> Bounds<T> : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
fmt!("{%s <: %s}",
self.lb.inf_str(cx),
@ -83,7 +83,7 @@ impl<T:InferStr> Bounds<T> : InferStr {
}
}
impl<V:Vid ToStr, T:InferStr> VarValue<V, T> : InferStr {
pub impl<V:Vid ToStr, T:InferStr> VarValue<V, T> : InferStr {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
match *self {
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
@ -93,13 +93,13 @@ impl<V:Vid ToStr, T:InferStr> VarValue<V, T> : InferStr {
}
}
impl IntVarValue : InferStr {
pub impl IntVarValue : InferStr {
fn inf_str(&self, _cx: &InferCtxt) -> ~str {
self.to_str()
}
}
impl ast::float_ty : InferStr {
pub impl ast::float_ty : InferStr {
fn inf_str(&self, _cx: &InferCtxt) -> ~str {
self.to_str()
}

View File

@ -21,28 +21,28 @@ use middle::typeck::infer::to_str::InferStr;
use syntax::ast;
use util::common::{indent, indenter};
enum VarValue<V, T> {
pub enum VarValue<V, T> {
Redirect(V),
Root(T, uint),
}
struct ValsAndBindings<V, T> {
pub struct ValsAndBindings<V, T> {
vals: SmallIntMap<VarValue<V, T>>,
mut bindings: ~[(V, VarValue<V, T>)],
}
struct Node<V, T> {
pub struct Node<V, T> {
root: V,
possible_types: T,
rank: uint,
}
trait UnifyVid<T> {
pub trait UnifyVid<T> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<self, T>;
}
impl InferCtxt {
pub impl InferCtxt {
fn get<T:Copy, V:Copy Eq Vid UnifyVid<T>>(
&self,
+vid: V) -> Node<V, T>
@ -135,14 +135,13 @@ impl InferCtxt {
// Code to handle simple variables like ints, floats---anything that
// doesn't have a subtyping relationship we need to worry about.
trait SimplyUnifiable {
pub trait SimplyUnifiable {
static fn to_type_err(expected_found<self>) -> ty::type_err;
}
fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,
+a_t: T,
+b_t: T) -> ures
{
pub fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,
+a_t: T,
+b_t: T) -> ures {
if a_is_expected {
Err(SimplyUnifiable::to_type_err(
ty::expected_found {expected: a_t, found: b_t}))
@ -152,7 +151,7 @@ fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,
}
}
impl InferCtxt {
pub impl InferCtxt {
fn simple_vars<T:Copy Eq InferStr SimplyUnifiable,
V:Copy Eq Vid ToStr UnifyVid<Option<T>>>(
&self,
@ -227,7 +226,7 @@ impl InferCtxt {
// ______________________________________________________________________
impl ty::TyVid : UnifyVid<Bounds<ty::t>> {
pub impl ty::TyVid : UnifyVid<Bounds<ty::t>> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<ty::TyVid, Bounds<ty::t>>
{
@ -235,7 +234,7 @@ impl ty::TyVid : UnifyVid<Bounds<ty::t>> {
}
}
impl ty::IntVid : UnifyVid<Option<IntVarValue>> {
pub impl ty::IntVid : UnifyVid<Option<IntVarValue>> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<ty::IntVid, Option<IntVarValue>>
{
@ -243,7 +242,7 @@ impl ty::IntVid : UnifyVid<Option<IntVarValue>> {
}
}
impl IntVarValue : SimplyUnifiable {
pub impl IntVarValue : SimplyUnifiable {
static fn to_type_err(err: expected_found<IntVarValue>)
-> ty::type_err
{
@ -251,7 +250,7 @@ impl IntVarValue : SimplyUnifiable {
}
}
impl ty::FloatVid : UnifyVid<Option<ast::float_ty>> {
pub impl ty::FloatVid : UnifyVid<Option<ast::float_ty>> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<ty::FloatVid, Option<ast::float_ty>>
{
@ -259,7 +258,7 @@ impl ty::FloatVid : UnifyVid<Option<ast::float_ty>> {
}
}
impl ast::float_ty : SimplyUnifiable {
pub impl ast::float_ty : SimplyUnifiable {
static fn to_type_err(err: expected_found<ast::float_ty>)
-> ty::type_err
{

View File

@ -48,8 +48,6 @@ independently:
*/
#[legacy_exports];
use core::prelude::*;
use metadata::csearch;
@ -81,45 +79,13 @@ use syntax::print::pprust::*;
use syntax::visit;
use syntax::{ast, ast_util, ast_map};
export check;
export check_crate;
export infer;
export method_map;
export method_origin;
export method_map_entry;
export vtable_map;
export vtable_res;
export vtable_origin;
export method_static, method_param, method_trait, method_self;
export vtable_static, vtable_param, vtable_trait;
export provided_methods_map;
export coherence;
export check;
export rscope;
export astconv;
export infer;
export collect;
export coherence;
export deriving;
export crate_ctxt;
export write_ty_to_tcx, write_substs_to_tcx;
export no_params;
export isr_alist;
export require_same_types;
export lookup_def_ccx, lookup_def_tcx;
#[legacy_exports]
#[path = "check/mod.rs"]
pub mod check;
#[legacy_exports]
pub mod rscope;
#[legacy_exports]
pub mod astconv;
#[path = "infer/mod.rs"]
pub mod infer;
#[legacy_exports]
pub mod collect;
#[legacy_exports]
pub mod coherence;
#[auto_encode]
@ -142,7 +108,7 @@ pub enum method_origin {
// with a bounded trait.
#[auto_encode]
#[auto_decode]
struct method_param {
pub struct method_param {
// the trait containing the method to be invoked
trait_id: ast::def_id,
@ -199,7 +165,7 @@ pub enum vtable_origin {
vtable_trait(ast::def_id, ~[ty::t]),
}
impl vtable_origin {
pub impl vtable_origin {
fn to_str(tcx: ty::ctxt) -> ~str {
match self {
vtable_static(def_id, ref tys, ref vtable_res) => {
@ -222,7 +188,7 @@ impl vtable_origin {
}
}
type vtable_map = HashMap<ast::node_id, vtable_res>;
pub type vtable_map = HashMap<ast::node_id, vtable_res>;
struct crate_ctxt__ {
// A mapping from method call sites to traits that have that method.
@ -238,13 +204,13 @@ pub enum crate_ctxt {
}
// Functions that write types into the node type table
fn write_ty_to_tcx(tcx: ty::ctxt, node_id: ast::node_id, ty: ty::t) {
pub fn write_ty_to_tcx(tcx: ty::ctxt, node_id: ast::node_id, ty: ty::t) {
debug!("write_ty_to_tcx(%d, %s)", node_id, ppaux::ty_to_str(tcx, ty));
smallintmap::insert(*tcx.node_types, node_id as uint, ty);
}
fn write_substs_to_tcx(tcx: ty::ctxt,
node_id: ast::node_id,
+substs: ~[ty::t]) {
pub fn write_substs_to_tcx(tcx: ty::ctxt,
node_id: ast::node_id,
+substs: ~[ty::t]) {
if substs.len() > 0u {
debug!("write_substs_to_tcx(%d, %?)", node_id,
substs.map(|t| ppaux::ty_to_str(tcx, *t)));
@ -252,7 +218,7 @@ fn write_substs_to_tcx(tcx: ty::ctxt,
}
}
fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
pub fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
match tcx.def_map.find(id) {
Some(x) => x,
_ => {
@ -261,15 +227,16 @@ fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
}
}
fn lookup_def_ccx(ccx: @crate_ctxt, sp: span, id: ast::node_id) -> ast::def {
pub fn lookup_def_ccx(ccx: @crate_ctxt, sp: span, id: ast::node_id)
-> ast::def {
lookup_def_tcx(ccx.tcx, sp, id)
}
fn no_params(t: ty::t) -> ty::ty_param_bounds_and_ty {
pub fn no_params(t: ty::t) -> ty::ty_param_bounds_and_ty {
{bounds: @~[], region_param: None, ty: t}
}
fn require_same_types(
pub fn require_same_types(
tcx: ty::ctxt,
maybe_infcx: Option<@infer::InferCtxt>,
t1_is_expected: bool,
@ -303,7 +270,7 @@ fn require_same_types(
// a list of mapping from in-scope-region-names ("isr") to the
// corresponding ty::Region
type isr_alist = @List<(ty::bound_region, ty::Region)>;
pub type isr_alist = @List<(ty::bound_region, ty::Region)>;
trait get_and_find_region {
fn get(br: ty::bound_region) -> ty::Region;
@ -397,10 +364,10 @@ fn check_for_main_fn(ccx: @crate_ctxt) {
}
}
fn check_crate(tcx: ty::ctxt,
trait_map: resolve::TraitMap,
crate: @ast::crate)
-> (method_map, vtable_map) {
pub fn check_crate(tcx: ty::ctxt,
trait_map: resolve::TraitMap,
crate: @ast::crate)
-> (method_map, vtable_map) {
let ccx = @crate_ctxt_(crate_ctxt__ {
trait_map: trait_map,

View File

@ -18,14 +18,14 @@ use syntax::ast;
use syntax::codemap::span;
use syntax::parse::token::special_idents;
trait region_scope {
pub trait region_scope {
fn anon_region(span: span) -> Result<ty::Region, ~str>;
fn self_region(span: span) -> Result<ty::Region, ~str>;
fn named_region(span: span, id: ast::ident) -> Result<ty::Region, ~str>;
}
enum empty_rscope { empty_rscope }
impl empty_rscope: region_scope {
pub enum empty_rscope { empty_rscope }
pub impl empty_rscope: region_scope {
fn anon_region(_span: span) -> Result<ty::Region, ~str> {
result::Ok(ty::re_static)
}
@ -39,8 +39,8 @@ impl empty_rscope: region_scope {
}
}
enum type_rscope = Option<ty::region_variance>;
impl type_rscope: region_scope {
pub enum type_rscope = Option<ty::region_variance>;
pub impl type_rscope: region_scope {
fn anon_region(_span: span) -> Result<ty::Region, ~str> {
match *self {
Some(_) => result::Ok(ty::re_bound(ty::br_self)),
@ -59,19 +59,20 @@ impl type_rscope: region_scope {
}
}
fn bound_self_region(rp: Option<ty::region_variance>) -> Option<ty::Region> {
pub fn bound_self_region(rp: Option<ty::region_variance>)
-> Option<ty::Region> {
match rp {
Some(_) => Some(ty::re_bound(ty::br_self)),
None => None
}
}
enum anon_rscope = {anon: ty::Region, base: region_scope};
fn in_anon_rscope<RS: region_scope Copy Durable>(self: RS, r: ty::Region)
pub enum anon_rscope = {anon: ty::Region, base: region_scope};
pub fn in_anon_rscope<RS: region_scope Copy Durable>(self: RS, r: ty::Region)
-> @anon_rscope {
@anon_rscope({anon: r, base: self as region_scope})
}
impl @anon_rscope: region_scope {
pub impl @anon_rscope: region_scope {
fn anon_region(_span: span) -> Result<ty::Region, ~str> {
result::Ok(self.anon)
}
@ -83,16 +84,16 @@ impl @anon_rscope: region_scope {
}
}
struct binding_rscope {
pub struct binding_rscope {
base: region_scope,
mut anon_bindings: uint,
}
fn in_binding_rscope<RS: region_scope Copy Durable>(self: RS)
pub fn in_binding_rscope<RS: region_scope Copy Durable>(self: RS)
-> @binding_rscope {
let base = self as region_scope;
@binding_rscope { base: base, anon_bindings: 0 }
}
impl @binding_rscope: region_scope {
pub impl @binding_rscope: region_scope {
fn anon_region(_span: span) -> Result<ty::Region, ~str> {
let idx = self.anon_bindings;
self.anon_bindings += 1;