Skip to content

Instantly share code, notes, and snippets.

View sdleffler's full-sized avatar

Shea Leffler sdleffler

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sdleffler on github.
  • I am sleffy (https://keybase.io/sleffy) on keybase.
  • I have a public key ASDeFKXDoBuAjNjxndRSbevpj1AfelNewvDXNvoPVIS7pgo

To claim this, I am signing this object:

@sdleffler
sdleffler / weird.rs
Last active September 23, 2017 04:55
#[test]
fn read_write_remove_async() {
let mut cluster = connect_to_cluster().unwrap();
let bytes: Vec<_> = (0..NUM_OBJECTS)
.map(|i| {
let mut buf = Vec::new();
buf.extend(
XorShiftRng::from_seed([i as u32 + 1, 2, 3, 4])
@sdleffler
sdleffler / last.hs
Created June 20, 2017 15:50
LiquidHaskell interaction with optimized Haskell
-- | Extract the last element of a list, which must be finite and non-empty.
last :: [a] -> a
#ifdef USE_REPORT_PRELUDE
last [x] = x
last (_:xs) = last xs
last [] = errorEmptyList "last"
#else
-- Use foldl to make last a good consumer.
-- This will compile to good code for the actual GHC.List.last.
-- (At least as long it is eta-expaned, otherwise it does not, #10260.)
sean@sean-Samus:~/Projects/Games/Swarm/obelisk/src$ cargo test
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running /home/sean/Projects/Games/Swarm/obelisk/target/debug/deps/obelisk-27dcc336d5707ebe
running 50 tests
test finger_tree::test::lazy_arc::fifo_backwards ... ok
test finger_tree::test::lazy_arc::fifo_forwards ... ok
error: test failed, to rerun pass '--lib'
sean@sean-Samus:~/Projects/Games/Swarm/obelisk/src$
#[bench]
fn push_front_arenaalloc_strict_10(b: &mut Bencher) {
let elements = Arena::new();
let branches = Arena::new();
let trees = Arena::new();
let alloc = StrictArena {
elements: &elements,
branches: &branches,
trees: &trees,
impl<T> LazyRef for Thunk<T> {
#[inline]
fn defer<'a, F: FnBox() -> T + 'a>(f: F) -> Thunk<T>
where T: 'a
{
let thunk =
unsafe { Box::from_raw(Box::into_raw(Box::new(f)) as *mut (FnBox() -> T + 'static)) };
Thunk {
flag: Cell::new(Flag::Deferred),
pub fn make_mut<'b>(this: &'b mut RcThunk<'a, T>) -> &'b mut T where T: Clone {
// No, moving it into a temp doesn't help. We just have to trust the CSE
// pass here.
if Rc::get_mut(&mut this.0).is_some() {
return &mut **Rc::get_mut(&mut this.0).unwrap();
}
let new_rc = Rc::new(Thunk::computed((*this.0).clone()));
this.0 = new_rc;
RcThunk::get_mut(this).unwrap()
@sdleffler
sdleffler / wtf.rs
Created May 27, 2017 00:29
wtf? borrowck pls
pub fn make_mut<'b>(this: &'b mut RcThunk<'a, T>) -> &'b mut T where T: Clone {
if let Some(thunk) = Rc::get_mut(&mut this.0) {
return &mut **thunk;
}
let new_rc = Rc::new(Thunk::computed((*this.0).clone()));
this.0 = new_rc;
RcThunk::get_mut(this).unwrap()
}
pub trait Running<B: StateTy>: ProgramTy {
type Output: StateTy;
}
pub type Run<A: ProgramTy, B: StateTy> = <A as Running<B>>::Output;
// [(Left P), (St Nil C R)] => (# P (St Nil F (Cons C R)))
impl<P: ProgramTy, C: Bit, R: List> Running<St<Nil, C, R>> for Left<P>
where P: Running<St<Nil, F, Cons<C, R>>>
@sdleffler
sdleffler / rust-smallfuck-concretes.rs
Last active March 11, 2017 14:54
`type_operators!` concrete definitions for the `tarpit-rs` Rust type-level Smallfuck interpreter.
// `Bit` trait and `T` and `F` types.
pub trait Bit {
fn reify() -> bool;
}
pub struct F;
pub struct T;