lexer: move arena to be behind NonNull<T>

This commit is contained in:
Guillem L. Jara
2026-05-14 09:17:02 +02:00
parent 624f410af0
commit e18f0f0995
2 changed files with 9 additions and 16 deletions
+5 -4
View File
@@ -10,6 +10,7 @@ use core::str;
use std::{
cmp::Ordering,
fmt::{Debug, Display},
ptr::NonNull,
slice::SliceIndex,
};
@@ -228,10 +229,10 @@ pub enum Token<'a> {
Semicolon,
}
#[derive(Debug, Default, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Extra {
ctx: Context,
arena: *const Bump,
arena: NonNull<Bump>,
posix_strict: bool,
gnu_strict: bool,
}
@@ -279,7 +280,7 @@ impl<'a> Token<'a> {
source,
Extra {
ctx: Context::AcceptExpression,
arena,
arena: NonNull::from_ref(arena),
posix_strict,
gnu_strict,
},
@@ -582,6 +583,6 @@ impl Extra {
fn arena<'a>(&self) -> &'a Bump {
// SAFETY: lives for as long as self because it's the same lifetime as
// the source being lexed; Logos just can't take lifetimes on extras.
unsafe { &*self.arena }
unsafe { self.arena.as_ref() }
}
}
+4 -12
View File
@@ -5,7 +5,7 @@
use std::io::Write;
use crate::{Context, Extra, Identifier, Lexer, Token};
use crate::{Identifier, Token};
use bumpalo::{
Bump,
collections::{CollectIn, Vec},
@@ -17,17 +17,9 @@ fn lex<'a>(
posix_strict: bool,
gnu_strict: bool,
) -> Vec<'a, Token<'a>> {
Lexer::with_extras(
src,
Extra {
ctx: Context::AcceptExpression,
arena,
posix_strict,
gnu_strict,
},
)
.collect_in::<Result<Vec<_>, _>>(arena)
.unwrap()
Token::lex(src, arena, posix_strict, gnu_strict)
.collect_in::<Result<Vec<_>, _>>(arena)
.unwrap()
}
#[test]