1use crate::token::{Id, Span};
2use std::cell::Cell;
3
4thread_local!(static NEXT: Cell<u32> = Cell::new(0));
5
6pub fn reset() {
7 NEXT.with(|c: &Cell| c.set(val:0));
8}
9
10pub fn generate(span: Span) -> Id<'static> {
11 NEXT.with(|next: &Cell| {
12 let generation: u32 = next.get() + 1;
13 next.set(val:generation);
14 Id::gensym(span, generation)
15 })
16}
17
18pub fn fill<'a>(span: Span, slot: &mut Option<Id<'a>>) -> Id<'a> {
19 *slot.get_or_insert_with(|| generate(span))
20}
21