Interning Orchid string literals

This commit is contained in:
2023-08-19 14:35:24 +01:00
parent 0b887ced70
commit 6693d93944
10 changed files with 96 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::rc::Rc;
use crate::foreign::ExternError;
use crate::systems::cast_exprinst::with_str;
@@ -6,7 +7,7 @@ use crate::{define_fn, ConstTree, Interner};
/// An unrecoverable error in Orchid land. Because Orchid is lazy, this only
/// invalidates expressions that reference the one that generated it.
pub struct OrchidPanic(String);
pub struct OrchidPanic(Rc<String>);
impl Display for OrchidPanic {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -18,7 +19,10 @@ impl ExternError for OrchidPanic {}
define_fn! {
/// Takes a message, returns an [ExternError] unconditionally.
Panic = |x| with_str(x, |s| Err(OrchidPanic(s.clone()).into_extern()))
Panic = |x| with_str(x, |s| {
let msg = Rc::new(s.get_string());
Err(OrchidPanic(msg).into_extern())
})
}
pub fn panic(i: &Interner) -> ConstTree {