Skip to content

Commit 9f4fd91

Browse files
authored
chore: make more arena functions public (#27)
1 parent c74034a commit 9f4fd91

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/arena.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ impl StringArena {
3434
}
3535
}
3636

37+
/// If that value has already been interned, it returns the string pointer in the arena.
38+
pub fn str_ref(&self, value: &str) -> Option<StrRef> {
39+
self.cache.get(&self.hasher.hash_one(value)).copied()
40+
}
41+
3742
/// Interns a string using case-insensitive hashing.
3843
///
3944
/// Two strings that differ only in ASCII case will resolve to the same [`StrRef`].
@@ -345,6 +350,11 @@ impl Arena {
345350
self.strings.get(key)
346351
}
347352

353+
/// If that value has already been interned, it returns the string pointer in the arena.
354+
pub fn str_ref(&self, key: &str) -> Option<StrRef> {
355+
self.strings.str_ref(key)
356+
}
357+
348358
/// Retrieves the expression node associated with the given [`ExprRef`].
349359
pub fn get_expr(&self, key: ExprRef) -> Expr {
350360
self.exprs.get(key)

src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub enum SourceKind<A> {
270270
/// In `ORDER BY e.timestamp DESC`, this would be represented as:
271271
/// - `expr`: expression for `e.timestamp`
272272
/// - `order`: `Order::Desc`
273-
#[derive(Debug, Clone, Serialize)]
273+
#[derive(Debug, Clone, Copy, Serialize)]
274274
pub struct OrderBy {
275275
/// Expression to sort by
276276
pub expr: ExprRef,

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod typing;
1616
use crate::arena::Arena;
1717
use crate::lexer::tokenize;
1818
use crate::prelude::{
19-
Analysis, AnalysisOptions, FunArgs, Typed, display_type, name_to_type, parse,
19+
Analysis, AnalysisOptions, FunArgs, Scope, Typed, display_type, name_to_type, parse,
2020
};
2121
use crate::token::Token;
2222
pub use ast::*;
@@ -550,8 +550,8 @@ impl Session {
550550
/// - `"date"` → [`Type::Date`]
551551
/// - `"time"` → [`Type::Time`]
552552
/// - `"datetime"` → [`Type::DateTime`]
553-
pub fn get_type_from_name(&mut self, name: &str) -> Option<Type> {
554-
let str_ref = self.arena.strings.alloc(name);
553+
pub fn get_type_from_name(&self, name: &str) -> Option<Type> {
554+
let str_ref = self.arena.strings.str_ref(name)?;
555555
name_to_type(&self.arena, &self.options, str_ref)
556556
}
557557

@@ -560,8 +560,8 @@ impl Session {
560560
/// Function types display optional parameters with a `?` suffix. For example,
561561
/// a function with signature `(boolean, number?) -> string` accepts 1 or 2 arguments.
562562
/// Aggregate functions use `=>` instead of `->` in their signature.
563-
pub fn display_type(&self, tpe: &Type) -> String {
564-
display_type(&self.arena, *tpe)
563+
pub fn display_type(&self, tpe: Type) -> String {
564+
display_type(&self.arena, tpe)
565565
}
566566

567567
/// Creates an [`Analysis`] instance for fine-grained control over static analysis.
@@ -581,4 +581,9 @@ impl Session {
581581
pub fn arena_mut(&mut self) -> &mut Arena {
582582
&mut self.arena
583583
}
584+
585+
/// Returns the global [`Scope`]
586+
pub fn global_scope(&self) -> &Scope {
587+
&self.options.default_scope
588+
}
584589
}

0 commit comments

Comments
 (0)