@@ -64,6 +64,74 @@ pub type ConstructNode<J> = Node<WithNames<node::Construct<J>>>;
6464pub type CommitNode < J > = Node < WithNames < node:: Commit < J > > > ;
6565
6666// FIXME: The following methods cannot be implemented for simplicity::node::Node because that is a foreign type
67+ pub fn finalize_types < J : Jet > (
68+ node : & Node < WithNames < node:: Construct < J > > > ,
69+ ) -> Result < Arc < Node < WithNames < node:: Commit < J > > > > , types:: Error > {
70+ // We finalize all types but don't bother to set the root source and target
71+ // to unit. This is a bit annoying to do, and anyway these types will already
72+ // be unit by construction.
73+ translate ( node, |node, inner| {
74+ let inner = inner. map_witness ( |_| & NoWitness ) ;
75+ node:: CommitData :: new ( node. cached_data ( ) . arrow ( ) , inner) . map ( Arc :: new)
76+ } )
77+ }
78+
79+ fn translate < M , N , F , E > (
80+ node : & Node < WithNames < M > > ,
81+ translatefn : F ,
82+ ) -> Result < Arc < Node < WithNames < N > > > , E >
83+ where
84+ M : node:: Marker ,
85+ N : node:: Marker < Jet = M :: Jet > ,
86+ N :: Witness : Nullable ,
87+ F : FnMut (
88+ & Node < WithNames < M > > ,
89+ Inner < & N :: CachedData , N :: Jet , & NoDisconnect , & WitnessName > ,
90+ ) -> Result < N :: CachedData , E > ,
91+ {
92+ struct Translator < F > ( F ) ;
93+
94+ impl < M , N , F , E > Converter < WithNames < M > , WithNames < N > > for Translator < F >
95+ where
96+ M : node:: Marker ,
97+ N : node:: Marker < Jet = M :: Jet > ,
98+ N :: Witness : Nullable ,
99+ F : FnMut (
100+ & Node < WithNames < M > > ,
101+ Inner < & N :: CachedData , N :: Jet , & NoDisconnect , & WitnessName > ,
102+ ) -> Result < N :: CachedData , E > ,
103+ {
104+ type Error = E ;
105+
106+ fn convert_witness (
107+ & mut self ,
108+ _: & PostOrderIterItem < & Node < WithNames < M > > > ,
109+ wit : & WitnessName ,
110+ ) -> Result < WitnessName , Self :: Error > {
111+ Ok ( wit. shallow_clone ( ) )
112+ }
113+
114+ fn convert_disconnect (
115+ & mut self ,
116+ _: & PostOrderIterItem < & Node < WithNames < M > > > ,
117+ _: Option < & Arc < Node < WithNames < N > > > > ,
118+ _: & NoDisconnect ,
119+ ) -> Result < NoDisconnect , Self :: Error > {
120+ Ok ( NoDisconnect )
121+ }
122+
123+ fn convert_data (
124+ & mut self ,
125+ data : & PostOrderIterItem < & Node < WithNames < M > > > ,
126+ inner : Inner < & Arc < Node < WithNames < N > > > , N :: Jet , & NoDisconnect , & WitnessName > ,
127+ ) -> Result < N :: CachedData , Self :: Error > {
128+ let new_inner = inner. map ( |node| node. cached_data ( ) ) ;
129+ self . 0 ( data. node , new_inner)
130+ }
131+ }
132+
133+ node. convert :: < InternalSharing , _ , _ > ( & mut Translator ( translatefn) )
134+ }
67135
68136/// Convert [`ConstructNode`] into [`CommitNode`] by dropping the name of witness nodes.
69137pub fn forget_names < M > ( node : & Node < WithNames < M > > ) -> Arc < Node < M > >
0 commit comments