Skip to content

Instantly share code, notes, and snippets.

View jprochazk's full-sized avatar
💭
📦

Jan Procházka jprochazk

💭
📦
View GitHub Profile
@jprochazk
jprochazk / text.md
Last active November 11, 2024 15:07
gc woes

The goal of a GC is to automatically manage memory. When something isn't being used anymore, it should be freed. But that implies it should never free anything that is still in use, because that could lead to a use-after-free. You don't typically think about this when using a language with garbage collection, because it has managed references which the compiler and GC know about and so it all just works and you as the user don't have to worry that something will be freed from under your nose.

But it's different when you're the one implementing the language and its runtime. Remember how Crafting Interpreters does it, with pushing temporary values onto the runtime stack so that the GC can find them there. Which is very error-prone. That's where what I'm trying to do comes in. There are already a few Rust GC implementations that are memory safe, in that there's no possible way to introduce a use-after-free without unsafe code, because the garbage collector is made aware of every reference for as long as you'r

use std::marker::PhantomData;
use std::ops::{Deref, DerefMut, Index, IndexMut};
pub struct EnumArray<const LEN: usize, E: Into<usize>, V: Copy> {
array: [V; LEN],
index: PhantomData<fn() -> E>,
}
impl<const LEN: usize, E: Into<usize>, V: Copy> EnumArray<LEN, E, V> {
pub fn new(v: V) -> Self {
@jprochazk
jprochazk / data.json
Created February 7, 2024 19:14
parse-rosetta-rs benchmark data
{
"timestamp": "2024-02-07",
"hostname": "DESKTOP-HLQEUO4",
"os": "Linux",
"os_ver": "5.15.133.1-microsoft-standard-WSL2",
"arch": "x86_64",
"cpus": 32,
"libs": {
"examples/chumsky-app/Cargo.toml": {
"name": "chumsky",
@jprochazk
jprochazk / Dockerfile
Created January 9, 2024 09:29
minimal rust dockerfile
# syntax = docker/dockerfile:experimental
# Replace `THE_PROGRAM` with the name of your binary
FROM rust:1.75 as builder
RUN useradd -m rust
ENV HOME /home/rust
@jprochazk
jprochazk / dag.py
Last active October 9, 2023 12:02
python parallel DAG
from __future__ import annotations
import time
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Event, cpu_count
from multiprocessing.synchronize import Event as EventClass
from queue import Empty, Queue
from typing import Callable, Generic, Hashable, TypeVar
T = TypeVar("T", bound=Hashable)
<script>
import { count } from "./state";
</script>
<h2>{$count}</h2>
<button on:click={() => $count += 1}>Inc</button>
import { writable } from "svelte/store";
export const count = writable(0);
<script>
import { count } from "./state";
</script>
<h2>{$count}</h2>
<button on:click={() => $count += 1}>Inc</button>