Interning Orchid string literals
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user