Skip to content

Instantly share code, notes, and snippets.

View Manishearth's full-sized avatar
🍃
yahaha! you found me!

Manish Goregaokar Manishearth

🍃
yahaha! you found me!
View GitHub Profile
@Manishearth
Manishearth / hodor.rs
Last active January 1, 2023 00:34
yo dawg
#![recursion_limit = "300000"]
type CellType = u8;
const MEM_SIZE: usize = 30_000;
macro_rules! Hodor_impl {
/*
# Loop Extraction
@Manishearth
Manishearth / gate.md
Last active August 29, 2015 14:22
Servo unstable feature usage

The following gates: plugin, box_syntax, custom_derive, custom_attribute were ignored for this analysis because these are features we don't plan on moving off unless absolutely necessary. Nevertheless, they're not strictly necessary for Servo to work; they just make some code nicer.

The main point of this exercise was to find what unstable APIs Servo uses/needs a lot, which might probably be needed by others too. Most of these have workarounds, and most of these are blocked on trivial things like naming (and could be easily stabilized). While I did remove some unstable usage in Servo, I didn't fix the majority of these even though it was easy to fix because we use nightly anyway (plugins, etc) and it would be nice to end up with the final, polished, performant APIs instead of a slightly more verbose workaround that we'll forget about.

Really common APIs

collections almost everywhere is just blocked on Vec.push_all(). We can immediately use extend() here if we want, or a for loop, but if this

@Manishearth
Manishearth / gc2.md
Created June 7, 2015 18:16
Gc dsign #2: No owned Gc on the stack

Three GC pointers: Gc<T>, GcRef<'a, T>, and GcMove<T> (aka GcRoot<T>). T: Trace for all three

GcRef<'a, T> is really just &'a Gc<T> without the extra indirection. Moving on.

Gc<T> is never to be used on the stack. it is only to be used inside struct fields. It implements Trace. On the stack, it must be referred to via GcRef or &Gc

We abuse the fact that rust doesn't let one move out of a borrow to enforce this. The only thing that is allowed is taking borrows of it.

The idea is:

@Manishearth
Manishearth / post_no_trans
Created May 22, 2015 15:48
Massif data for MultiItemDecorator removal
This file has been truncated, but you can view the full file.
desc: (none)
cmd: x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 -O --cfg rtopt --cfg ndebug -C rpath -C prefer-dynamic --target=x86_64-unknown-linux-gnu -D warnings -L x86_64-unknown-linux-gnu/rt -L /home/manishearth/Mozilla/rust/x86_64-unknown-linux-gnu/llvm/Release/lib --out-dir x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib -C extra-filename=-d8ace771 /home/manishearth/Mozilla/rust/src/librustc/lib.rs -Z no-trans
time_unit: i
#-----------
snapshot=0
#-----------
time=0
mem_heap_B=0
mem_heap_extra_B=0
mem_stacks_B=0
fn rockstar_interview_swap(x: &mut u8, y: &mut u8) {
// Look, ma, no temporary variables!
*x = *x + *y;
*y = *x - *y;
*x = *x - *y;
}
Very high level intro to Rust
Goals: speed, safety, concurency
Ownership and move semantics
Zero-cost abstractions
1.0 is out! (release planned for the day before !!Con)
What does “stable” mean?
Semantic versioning
Release trains (nightly/beta/stable) and rapid release, à la Firefox
@Manishearth
Manishearth / Cargo.toml
Created February 12, 2015 12:02
Broken reexport generation
[package]
name = "gen"
version = "0.0.1"
authors = ["Manish Goregaokar <manishsmail@gmail.com>"]
[lib]
name = "gen"
path = "lib.rs"
@Manishearth
Manishearth / fetch.sh
Created February 6, 2015 17:49
Deps for Servo on the Flame
# The function name lies
shallowclone() {
mkdir $2
cd $2
git init
git remote add origin $1
# Unfortunately, `git fetch origin $SHA --depth n` isn't working
# perhaps git.mozilla.org doesn't support such fetches?
git fetch origin
git checkout $3
@Manishearth
Manishearth / gist:f2971973e164be03890a
Last active August 29, 2015 14:14
Smarter build system

Here's a design for a smarter build system that I've been toying with. It tweaks the current build system so that it is possible to solve the problem of PRs piling up by getting more build machines -- this isn't possible right now since PRs need to be tested sequentially for a 100% guarantee that they won't break anything.

It introduces three priority levels:

  • p=rollup: Treat as usual. Rollup into a big ball every few days.

  • p != rollup:

    • Lets say we have X extra build machines. Take X such PRs. First see if they can all be merged without conflicts, else choose a different set of X PRs
    • Test these PRs in parallel on the extra build machines, applied on top of master. This can be done whilst another build is running, provided these PRs apply cleanly on top of both master and the current build. (If not, pick a different set of PRs)
  • A slightly improved way of doing this is instead of testing A,B,C,D on tryservers, we test A, A+B, A+B+C, A+B+C+D. This makes it easier to identify which PRs are con

@Manishearth
Manishearth / pem_extract.js
Last active February 9, 2018 08:54
Certificate PEM extractor
// http://mxr.mozilla.org/mozilla-central/source/security/manager/pki/resources/content/pippki.js
function getDERString(cert)
{
var length = {};
var derArray = cert.getRawDER(length);
var derString = '';
for (var i = 0; i < derArray.length; i++) {
derString += String.fromCharCode(derArray[i]);
}