Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove Mut from libcore #5678

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ pub mod rand;
pub mod run;
pub mod sys;
pub mod cast;
pub mod mutable;
pub mod flate;
pub mod repr;
pub mod cleanup;
Expand Down
158 changes: 0 additions & 158 deletions src/libcore/mutable.rs

This file was deleted.

132 changes: 60 additions & 72 deletions src/libstd/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use core::run;
use core::hashmap::linear::LinearMap;
use core::task;
use core::to_bytes;
use core::mutable::Mut;

/**
*
Expand Down Expand Up @@ -168,7 +167,7 @@ impl<D:Decoder> Decodable<D> for WorkMap {
struct Database {
db_filename: Path,
db_cache: LinearMap<~str, ~str>,
mut db_dirty: bool
db_dirty: bool
}

pub impl Database {
Expand Down Expand Up @@ -210,8 +209,8 @@ pub impl Logger {
}

struct Context {
db: @Mut<Database>,
logger: @Mut<Logger>,
db: @mut Database,
logger: @mut Logger,
cfg: @json::Object,
freshness: LinearMap<~str,@fn(&str,&str)->bool>
}
Expand All @@ -228,7 +227,7 @@ struct Exec {
}

struct Work<T> {
prep: @Mut<Prep>,
prep: @mut Prep,
res: Option<Either<T,PortOne<(Exec,T)>>>
}

Expand Down Expand Up @@ -261,8 +260,8 @@ fn digest_file(path: &Path) -> ~str {

pub impl Context {

fn new(db: @Mut<Database>,
lg: @Mut<Logger>,
fn new(db: @mut Database,
lg: @mut Logger,
cfg: @json::Object) -> Context {
Context {
db: db,
Expand All @@ -277,19 +276,19 @@ pub impl Context {
Decodable<json::Decoder>>( // FIXME(#5121)
@self,
fn_name:&str,
blk: &fn(@Mut<Prep>)->Work<T>) -> Work<T> {
let p = @Mut(Prep {
blk: &fn(@mut Prep)->Work<T>) -> Work<T> {
let p = @mut Prep {
ctxt: self,
fn_name: fn_name.to_owned(),
declared_inputs: WorkMap::new()
});
};
blk(p)
}
}


trait TPrep {
fn declare_input(&self, kind:&str, name:&str, val:&str);
fn declare_input(&mut self, kind:&str, name:&str, val:&str);
fn is_fresh(&self, cat:&str, kind:&str, name:&str, val:&str) -> bool;
fn all_fresh(&self, cat:&str, map:&WorkMap) -> bool;
fn exec<T:Owned +
Expand All @@ -298,30 +297,25 @@ trait TPrep {
&self, blk: ~fn(&Exec) -> T) -> Work<T>;
}

impl TPrep for @Mut<Prep> {
fn declare_input(&self, kind:&str, name:&str, val:&str) {
do self.borrow_mut |p| {
p.declared_inputs.insert(WorkKey::new(kind, name),
val.to_owned());
}
impl TPrep for Prep {
fn declare_input(&mut self, kind:&str, name:&str, val:&str) {
self.declared_inputs.insert(WorkKey::new(kind, name),
val.to_owned());
}

fn is_fresh(&self, cat: &str, kind: &str,
name: &str, val: &str) -> bool {
do self.borrow_imm |p| {
let k = kind.to_owned();
let f = (*p.ctxt.freshness.get(&k))(name, val);
do p.ctxt.logger.borrow_imm |lg| {
if f {
lg.info(fmt!("%s %s:%s is fresh",
cat, kind, name));
} else {
lg.info(fmt!("%s %s:%s is not fresh",
cat, kind, name))
}
let k = kind.to_owned();
let f = (*self.ctxt.freshness.get(&k))(name, val);
let lg = self.ctxt.logger;
if f {
lg.info(fmt!("%s %s:%s is fresh",
cat, kind, name));
} else {
lg.info(fmt!("%s %s:%s is not fresh",
cat, kind, name))
}
f
}
f
}

fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool {
Expand All @@ -339,38 +333,34 @@ impl TPrep for @Mut<Prep> {
&self, blk: ~fn(&Exec) -> T) -> Work<T> {
let mut bo = Some(blk);

do self.borrow_imm |p| {
let cached = do p.ctxt.db.borrow_mut |db| {
db.prepare(p.fn_name, &p.declared_inputs)
};
let cached = self.ctxt.db.prepare(self.fn_name, &self.declared_inputs);

match cached {
Some((ref disc_in, ref disc_out, ref res))
if self.all_fresh("declared input",
&p.declared_inputs) &&
self.all_fresh("discovered input", disc_in) &&
self.all_fresh("discovered output", disc_out) => {
Work::new(*self, Left(json_decode(*res)))
}
match cached {
Some((ref disc_in, ref disc_out, ref res))
if self.all_fresh("declared input",
&self.declared_inputs) &&
self.all_fresh("discovered input", disc_in) &&
self.all_fresh("discovered output", disc_out) => {
Work::new(@mut *self, Left(json_decode(*res)))
}

_ => {
let (chan, port) = oneshot::init();
let mut blk = None;
blk <-> bo;
let blk = blk.unwrap();
let chan = Cell(chan);
do task::spawn || {
let exe = Exec {
discovered_inputs: WorkMap::new(),
discovered_outputs: WorkMap::new(),
};
let chan = chan.take();
let v = blk(&exe);
send_one(chan, (exe, v));
}

Work::new(*self, Right(port))
_ => {
let (chan, port) = oneshot::init();
let mut blk = None;
blk <-> bo;
let blk = blk.unwrap();
let chan = Cell(chan);

do task::spawn || {
let exe = Exec {
discovered_inputs: WorkMap::new(),
discovered_outputs: WorkMap::new(),
};
let chan = chan.take();
let v = blk(&exe);
send_one(chan, (exe, v));
}
Work::new(@mut *self, Right(port))
}
}
}
Expand All @@ -379,7 +369,7 @@ impl TPrep for @Mut<Prep> {
pub impl<T:Owned +
Encodable<json::Encoder> +
Decodable<json::Decoder>> Work<T> { // FIXME(#5121)
fn new(p: @Mut<Prep>, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
fn new(p: @mut Prep, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
Work { prep: p, res: Some(e) }
}
}
Expand All @@ -404,15 +394,13 @@ fn unwrap<T:Owned +

let s = json_encode(&v);

do ww.prep.borrow_imm |p| {
do p.ctxt.db.borrow_mut |db| {
db.cache(p.fn_name,
&p.declared_inputs,
&exe.discovered_inputs,
&exe.discovered_outputs,
s);
}
}
let p = &*ww.prep;
let db = p.ctxt.db;
db.cache(p.fn_name,
&p.declared_inputs,
&exe.discovered_inputs,
&exe.discovered_outputs,
s);
v
}
}
Expand All @@ -422,10 +410,10 @@ fn unwrap<T:Owned +
fn test() {
use core::io::WriterUtil;

let db = @Mut(Database { db_filename: Path("db.json"),
let db = @mut Database { db_filename: Path("db.json"),
db_cache: LinearMap::new(),
db_dirty: false });
let lg = @Mut(Logger { a: () });
db_dirty: false };
let lg = @mut Logger { a: () };
let cfg = @LinearMap::new();
let cx = @Context::new(db, lg, cfg);
let w:Work<~str> = do cx.prep("test1") |prep| {
Expand Down