diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/imports.rs | 4 | ||||
-rw-r--r-- | dhall/src/main.rs | 2 | ||||
-rw-r--r-- | dhall_core/src/core.rs | 17 | ||||
-rw-r--r-- | dhall_core/src/printer.rs | 10 | ||||
-rw-r--r-- | dhall_generator/src/dhall_expr.rs | 2 |
5 files changed, 20 insertions, 15 deletions
diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 8df4e97..96268ca 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -79,9 +79,9 @@ pub fn load_dhall_file( let resolve = |import: &Import| -> Expr<X, X> { resolve_import(import, &root).unwrap() }; - expr.map_embed(&resolve).squash_embed() + expr.as_ref().map_embed(&resolve).squash_embed() } else { - panic_imports(&expr) + panic_imports(expr.as_ref()) }; Ok(expr) } diff --git a/dhall/src/main.rs b/dhall/src/main.rs index eb2206b..77f558c 100644 --- a/dhall/src/main.rs +++ b/dhall/src/main.rs @@ -65,7 +65,7 @@ fn main() { } }; - let expr: SubExpr<_, _> = rc(imports::panic_imports(&expr)); + let expr: SubExpr<_, _> = rc(imports::panic_imports(expr.as_ref())); let type_expr = match typecheck::type_of(expr.clone()) { Err(e) => { diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 2d11068..3f01b55 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -305,30 +305,25 @@ impl<S: Clone, A: Clone> Expr<S, Expr<S, A>> { } impl<N, E> Clone for SubExpr<N, E> { + #[inline(always)] fn clone(&self) -> Self { SubExpr(Rc::clone(&self.0)) } } -impl<N, E> std::ops::Deref for SubExpr<N, E> { - type Target = Rc<Expr<N, E>>; +impl<N, E> SubExpr<N, E> { #[inline(always)] - fn deref(&self) -> &Self::Target { - &self.0 + pub fn as_ref(&self) -> &Expr<N, E> { + self.0.as_ref() } } -// impl<N, E> SubExpr<N, E> { -// pub fn as_ref(&self) -> &Expr<N, E> { -// self.0.as_ref() -// } -// } - // Remains of a previous life, where everything was in Boxes pub fn bx<N, E>(x: Expr<N, E>) -> SubExpr<N, E> { SubExpr(Rc::new(x)) } +// Should probably rename this too pub fn rc<N, E>(x: Expr<N, E>) -> SubExpr<N, E> { SubExpr(Rc::new(x)) } @@ -414,7 +409,7 @@ where ExprF::Note(_, e) => { map_subexpr_rc_binder(e, map_expr, map_under_binder) } - _ => rc(map_subexpr( + e => rc(map_subexpr( e, map_expr, |_| unreachable!(), diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index b7d7506..fb3b8e8 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -217,6 +217,16 @@ impl<S, A: Display> Expr<S, A> { } } +impl<S, A: Display> SubExpr<S, A> { + fn fmt_phase( + &self, + f: &mut fmt::Formatter, + phase: PrintPhase, + ) -> Result<(), fmt::Error> { + self.0.as_ref().fmt_phase(f, phase) + } +} + fn fmt_list<T, I, F>( open: &str, sep: &str, diff --git a/dhall_generator/src/dhall_expr.rs b/dhall_generator/src/dhall_expr.rs index c4b15e8..2e3adf7 100644 --- a/dhall_generator/src/dhall_expr.rs +++ b/dhall_generator/src/dhall_expr.rs @@ -10,7 +10,7 @@ pub fn dhall_expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let expr: SubExpr<X, Import> = parse_expr(&input_str).unwrap(); let no_import = |_: &Import| -> X { panic!("Don't use import in dhall!()") }; - let expr = rc(expr.map_embed(&no_import)); + let expr = rc(expr.as_ref().map_embed(&no_import)); let output = dhall_to_tokenstream_bx(&expr, &Context::new()); output.into() } |