fn from_info(info: VarInfo) -> PolarResult<Self> {
        let counter = info.counter;

        // group the variables into equivalence classes.
        let mut variables = partition_equivs(info.cycles)
            .into_iter()
            .map(|c| (counter.next(), c))
            .collect::<HashMap<_, _>>();

        let fields = info.field_relationships;
        let mut assign_id = |item| get_var_id(&mut variables, item, &counter);

        let uncycles = info
            .uncycles
            .into_iter()
            .fold(HashMap::new(), |map, (a, b)| {
                let (a, b) = (assign_id(a), assign_id(b));
                hash_map_set_add(hash_map_set_add(map, a, b), b, a)
            });

        // now convert the remaining VarInfo fields into equivalent Vars fields.
        let in_relationships = info
            .in_relationships
            .into_iter()
            .map(|(lhs, rhs)| (assign_id(lhs), assign_id(rhs)))
            .collect::<HashSet<_>>();

        // I think a var can only have one value since we make sure there's a var for the dot lookup,
        // and if they had aliases they'd be collapsed by now, so it should be an error
        // if foo.name = "steve" and foo.name = "gabe".
        let eq_values = info
            .eq_values
            .into_iter()
            .map(|(var, val)| (assign_id(var), val))
            .collect::<HashMap<_, _>>();

        let types = info
            .types
            .into_iter()
            .map(|(var, typ)| (assign_id(var), typ))
            .collect::<HashMap<_, _>>();

        let contained_values = info
            .contained_values
            .into_iter()
            .fold(HashMap::new(), |map, (val, var)| {
                hash_map_set_add(map, assign_id(var), val)
            });

        let field_relationships = fields.into_iter().fold(HashMap::new(), |map, (p, f, c)| {
            hash_map_set_add(map, assign_id(p), (f, assign_id(c)))
        });

        seek_var_id(&variables, &sym!("_this")).map_or_else(
            || invalid_state("No `_this` variable"),
            |this_id| {
                Ok(Vars {
                    variables,
                    uncycles,
                    field_relationships,
                    in_relationships,
                    eq_values,
                    contained_values,
                    types,
                    this_id,
                })
            },
        )
    }
/// Collapses the var info that we obtained from walking the expressions.
/// Track equivalence classes of variables and assign each one an id.
Collapses the var info that we obtained from walking the expressions.
Track equivalence classes of variables and assign each one an id.
Collapses the var info that we obtained from walking the expressions . Track equivalence classes of variables and assign each one an id .
fn from_info(info: VarInfo) -> PolarResult<Self> {
        let counter = info.counter;
        // group the variables into equivalence classes.
        let mut variables = partition_equivs(info.cycles)
            .into_iter()
            .map(|c| (counter.next(), c))
            .collect::<HashMap<_, _>>();
        let fields = info.field_relationships;
        let mut assign_id = |item| get_var_id(&mut variables, item, &counter);
        let uncycles = info
            .uncycles
            .into_iter()
            .fold(HashMap::new(), |map, (a, b)| {
                let (a, b) = (assign_id(a), assign_id(b));
                hash_map_set_add(hash_map_set_add(map, a, b), b, a)
            });
        // now convert the remaining VarInfo fields into equivalent Vars fields.
        let in_relationships = info
            .in_relationships
            .into_iter()
            .map(|(lhs, rhs)| (assign_id(lhs), assign_id(rhs)))
            .collect::<HashSet<_>>();
        // I think a var can only have one value since we make sure there's a var for the dot lookup,
        // and if they had aliases they'd be collapsed by now, so it should be an error
        // if foo.name = "steve" and foo.name = "gabe".
        let eq_values = info
            .eq_values
            .into_iter()
            .map(|(var, val)| (assign_id(var), val))
            .collect::<HashMap<_, _>>();
        let types = info
            .types
            .into_iter()
            .map(|(var, typ)| (assign_id(var), typ))
            .collect::<HashMap<_, _>>();
        let contained_values = info
            .contained_values
            .into_iter()
            .fold(HashMap::new(), |map, (val, var)| {
                hash_map_set_add(map, assign_id(var), val)
            });
        let field_relationships = fields.into_iter().fold(HashMap::new(), |map, (p, f, c)| {
            hash_map_set_add(map, assign_id(p), (f, assign_id(c)))
        });
        seek_var_id(&variables, &sym!("_this")).map_or_else(
            || invalid_state("No `_this` variable"),
            |this_id| {
                Ok(Vars {
                    variables,
                    uncycles,
                    field_relationships,
                    in_relationships,
                    eq_values,
                    contained_values,
                    types,
                    this_id,
                })
            },
        )
    }
fn from_info ( info : VarInfo ) -> PolarResult < Self > { let counter = info . counter ; // group the variables into equivalence classes. let mut variables = partition_equivs ( info . cycles ) . into_iter ( ) . map ( | c | ( counter . next ( ) , c ) ) . collect :: < HashMap < _ , _ > > ( ) ; let fields = info . field_relationships ; let mut assign_id = | item | get_var_id ( & mut variables , item , & counter ) ; let uncycles = info . uncycles . into_iter ( ) . fold ( HashMap :: new ( ) , | map , ( a , b ) | { let ( a , b ) = ( assign_id ( a ) , assign_id ( b ) ) ; hash_map_set_add ( hash_map_set_add ( map , a , b ) , b , a ) } ) ; // now convert the remaining VarInfo fields into equivalent Vars fields. let in_relationships = info . in_relationships . into_iter ( ) . map ( | ( lhs , rhs ) | ( assign_id ( lhs ) , assign_id ( rhs ) ) ) . collect :: < HashSet < _ > > ( ) ; // I think a var can only have one value since we make sure there's a var for the dot lookup, // and if they had aliases they'd be collapsed by now, so it should be an error // if foo.name = "steve" and foo.name = "gabe". let eq_values = info . eq_values . into_iter ( ) . map ( | ( var , val ) | ( assign_id ( var ) , val ) ) . collect :: < HashMap < _ , _ > > ( ) ; let types = info . types . into_iter ( ) . map ( | ( var , typ ) | ( assign_id ( var ) , typ ) ) . collect :: < HashMap < _ , _ > > ( ) ; let contained_values = info . contained_values . into_iter ( ) . fold ( HashMap :: new ( ) , | map , ( val , var ) | { hash_map_set_add ( map , assign_id ( var ) , val ) } ) ; let field_relationships = fields . into_iter ( ) . fold ( HashMap :: new ( ) , | map , ( p , f , c ) | { hash_map_set_add ( map , assign_id ( p ) , ( f , assign_id ( c ) ) ) } ) ; seek_var_id ( & variables , & sym ! ( " " ) ) . map_or_else ( | | invalid_state ( " " ) , | this_id | { Ok ( Vars { variables , uncycles , field_relationships , in_relationships , eq_values , contained_values , types , this_id , } ) } , ) }
Collapses the var info that we obtained from walking the expressions.
Collapses the var info that we obtained from walking the expressions .
info
VarInfo
info
VarInfo