From 05454ab9936514409e1b3c97e36f3fb476d532ba Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 16 Mar 2019 23:21:51 +0100 Subject: Use Rc instead of Box in AST to allow structural sharing Closes #29 --- dhall_generator/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'dhall_generator/src/lib.rs') diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs index 1a74f4f..26be4c4 100644 --- a/dhall_generator/src/lib.rs +++ b/dhall_generator/src/lib.rs @@ -4,11 +4,12 @@ use dhall_core::*; use proc_macro2::TokenStream; use quote::quote; use std::collections::BTreeMap; +use std::rc::Rc; #[proc_macro] pub fn dhall_expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input_str = input.to_string(); - let expr: Box> = parser::parse_expr(&input_str).unwrap(); + let expr: Rc> = parser::parse_expr(&input_str).unwrap(); let no_import = |_: &Import| -> X { panic!("Don't use import in dhall!()") }; let expr = expr.map_embed(&no_import); @@ -17,7 +18,7 @@ pub fn dhall_expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { } // Returns an expression of type Expr<_, _>. Expects input variables -// to be of type Box> (future-proof for structural sharing). +// to be of type Rc>. fn dhall_to_tokenstream( expr: &Expr, ctx: &Context, @@ -77,7 +78,7 @@ fn dhall_to_tokenstream( } } -// Returns an expression of type Box> +// Returns an expression of type Rc> fn dhall_to_tokenstream_bx( expr: &Expr, ctx: &Context, @@ -97,7 +98,7 @@ fn dhall_to_tokenstream_bx( // TODO: insert appropriate shifts ? let v: TokenStream = s.parse().unwrap(); quote! { { - let x: Box> = #v.clone(); + let x: Rc> = #v.clone(); x } } } @@ -125,7 +126,7 @@ fn label_to_tokenstream(l: &Label) -> TokenStream { } fn map_to_tokenstream( - m: &BTreeMap>>, + m: &BTreeMap>>, ctx: &Context, ) -> TokenStream { let (keys, values): (Vec, Vec) = m @@ -142,7 +143,7 @@ fn map_to_tokenstream( } fn option_to_tokenstream( - e: &Option>>, + e: &Option>>, ctx: &Context, ) -> TokenStream { let e = e.as_ref().map(|x| dhall_to_tokenstream_bx(x, ctx)); @@ -153,7 +154,7 @@ fn option_to_tokenstream( } fn vec_to_tokenstream( - e: &Vec>>, + e: &Vec>>, ctx: &Context, ) -> TokenStream { let e = e.iter().map(|x| dhall_to_tokenstream_bx(&**x, ctx)); -- cgit v1.2.3