Skip to content

migrate LinearMap<T, ()> to LinearSet<T> #4585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use io;
use libc::{size_t, uintptr_t};
use option::{None, Option, Some};
use ptr;
use send_map::linear::LinearMap;
use send_map::linear::LinearSet;
use stackwalk;
use sys;

Expand Down Expand Up @@ -294,12 +294,6 @@ pub fn gc() {
}
}

type RootSet = LinearMap<*Word,()>;

fn RootSet() -> RootSet {
LinearMap()
}

#[cfg(gc)]
fn expect_sentinel() -> bool { true }

Expand Down Expand Up @@ -337,13 +331,13 @@ pub fn cleanup_stack_for_failure() {
ptr::null()
};

let mut roots = ~RootSet();
let mut roots = LinearSet::new();
for walk_gc_roots(need_cleanup, sentinel) |root, tydesc| {
// Track roots to avoid double frees.
if roots.find(&*root).is_some() {
if roots.contains(&*root) {
loop;
}
roots.insert(*root, ());
roots.insert(*root);

if ptr::is_null(tydesc) {
// FIXME #4420: Destroy this box
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/send_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ pub mod linear {
fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
}

impl <T: Hash IterBytes Eq> LinearSet<T> {
pub impl <T: Hash IterBytes Eq> LinearSet<T> {
/// Create an empty LinearSet
static fn new() -> LinearSet<T> { LinearSet{map: LinearMap()} }
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ macro_rules! move_it (
{ $x:expr } => ( unsafe { let y = move *ptr::addr_of(&($x)); move y } )
)

type TaskSet = send_map::linear::LinearMap<*rust_task,()>;
type TaskSet = send_map::linear::LinearSet<*rust_task>;

fn new_taskset() -> TaskSet {
send_map::linear::LinearMap()
send_map::linear::LinearSet::new()
}
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
let didnt_overwrite = tasks.insert(task, ());
let didnt_overwrite = tasks.insert(task);
assert didnt_overwrite;
}
fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
let was_present = tasks.remove(&task);
assert was_present;
}
pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
tasks.each_key(|k| blk(*k))
tasks.each(|k| blk(*k))
}

// One of these per group of linked-failure tasks.
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use util::common::indenter;
use util::ppaux::{expr_repr, region_to_str};

use core::dvec;
use core::send_map::linear::LinearMap;
use core::send_map::linear::LinearSet;
use core::vec;
use std::map::HashMap;
use syntax::ast::{m_const, m_imm, m_mutbl};
Expand Down Expand Up @@ -73,15 +73,15 @@ enum gather_loan_ctxt = @{bccx: borrowck_ctxt,
req_maps: req_maps,
mut item_ub: ast::node_id,
mut root_ub: ast::node_id,
mut ignore_adjustments: LinearMap<ast::node_id,()>};
mut ignore_adjustments: LinearSet<ast::node_id>};

fn gather_loans(bccx: borrowck_ctxt, crate: @ast::crate) -> req_maps {
let glcx = gather_loan_ctxt(@{bccx: bccx,
req_maps: {req_loan_map: HashMap(),
pure_map: HashMap()},
mut item_ub: 0,
mut root_ub: 0,
mut ignore_adjustments: LinearMap()});
mut ignore_adjustments: LinearSet::new()});
let v = visit::mk_vt(@visit::Visitor {visit_expr: req_loans_in_expr,
visit_fn: req_loans_in_fn,
visit_stmt: add_stmt_to_map,
Expand Down Expand Up @@ -126,7 +126,7 @@ fn req_loans_in_expr(ex: @ast::expr,
ex.id, pprust::expr_to_str(ex, tcx.sess.intr()));

// If this expression is borrowed, have to ensure it remains valid:
if !self.ignore_adjustments.contains_key(&ex.id) {
if !self.ignore_adjustments.contains(&ex.id) {
for tcx.adjustments.find(ex.id).each |adjustments| {
self.guarantee_adjustments(ex, *adjustments);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ fn req_loans_in_expr(ex: @ast::expr,

// FIXME (#3387): Total hack: Ignore adjustments for the left-hand
// side. Their regions will be inferred to be too large.
self.ignore_adjustments.insert(rcvr.id, ());
self.ignore_adjustments.insert(rcvr.id);

visit::visit_expr(ex, self, vt);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,18 +693,18 @@ impl CoherenceChecker {

let tcx = self.crate_context.tcx;

let mut provided_names = send_map::linear::LinearMap();
let mut provided_names = send_map::linear::LinearSet::new();
// Implemented methods
for uint::range(0, all_methods.len()) |i| {
provided_names.insert(all_methods[i].ident, ());
provided_names.insert(all_methods[i].ident);
}
// Default methods
for ty::provided_trait_methods(tcx, trait_did).each |ident| {
provided_names.insert(*ident, ());
provided_names.insert(*ident);
}

for (*ty::trait_methods(tcx, trait_did)).each |method| {
if provided_names.contains_key(&method.ident) { loop; }
if provided_names.contains(&method.ident) { loop; }

tcx.sess.span_err(trait_ref_span,
fmt!("missing method `%s`",
Expand Down