@@ -23,24 +23,28 @@ typedef struct {
2323static void search_op_for_free_variables (Context * visitor , NodeClass class , String op_name , const Node * node ) {
2424 assert (node );
2525 switch (node -> tag ) {
26- case Param_TAG : {
27- Nodes params = get_abstraction_params (visitor -> current_scope -> node -> node );
28- for (size_t i = 0 ; i < params .count ; i ++ ) {
29- if (params .nodes [i ] == node )
30- return ;
26+ case Let_TAG : {
27+ Nodes variables = node -> payload .let .variables ;
28+ for (size_t j = 0 ; j < variables .count ; j ++ ) {
29+ const Node * var = variables .nodes [j ];
30+ bool r = insert_set_get_result (const Node * , visitor -> current_scope -> bound_set , var );
31+ assert (r );
3132 }
32- insert_set_get_result (const Node * , visitor -> current_scope -> free_set , node );
3333 break ;
3434 }
35- case Variablez_TAG : {
36- insert_set_get_result (const Node * , visitor -> current_scope -> free_set , node );
37- break ;
35+ case Variablez_TAG :
36+ case Param_TAG : {
37+ const Node * * found = find_key_dict (const Node * , visitor -> current_scope -> bound_set , node );
38+ if (!found )
39+ insert_set_get_result (const Node * , visitor -> current_scope -> free_set , node );
40+ return ;
3841 }
3942 case Function_TAG :
4043 case Case_TAG :
4144 case BasicBlock_TAG : assert (false);
42- default : visit_node_operands ( & visitor -> visitor , IGNORE_ABSTRACTIONS_MASK , node ); break ;
45+ default : break ;
4346 }
47+ visit_node_operands (& visitor -> visitor , IGNORE_ABSTRACTIONS_MASK | NcVariable , node );
4448}
4549
4650static CFNodeVariables * create_node_variables (CFNode * cfnode ) {
@@ -57,11 +61,7 @@ static CFNodeVariables* visit_domtree(Context* ctx, CFNode* cfnode, int depth, C
5761 ctx = & new_context ;
5862
5963 ctx -> current_scope = create_node_variables (cfnode );
60- if (parent ) {
61- ctx -> current_scope -> bound_set = clone_dict (parent -> bound_set );
62- } else {
63- ctx -> current_scope -> bound_set = new_set (const Node * , (HashFn ) hash_node , (CmpFn ) compare_node );
64- }
64+ ctx -> current_scope -> bound_set = new_set (const Node * , (HashFn ) hash_node , (CmpFn ) compare_node );
6565 insert_dict (CFNode * , CFNodeVariables * , ctx -> map , cfnode , ctx -> current_scope );
6666 const Node * abs = cfnode -> node ;
6767
@@ -85,15 +85,21 @@ static CFNodeVariables* visit_domtree(Context* ctx, CFNode* cfnode, int depth, C
8585 size_t j = 0 ;
8686 const Node * free_var ;
8787 while (dict_iter (child_variables -> free_set , & j , & free_var , NULL )) {
88- for (size_t k = 0 ; k < params .count ; k ++ ) {
89- if (params .nodes [k ] == free_var )
90- goto next ;
91- }
92- insert_set_get_result (const Node * , ctx -> current_scope -> free_set , free_var );
88+ const Node * * found = find_key_dict (const Node * , ctx -> current_scope -> bound_set , free_var );
89+ if (!found )
90+ insert_set_get_result (const Node * , ctx -> current_scope -> free_set , free_var );
9391 next :;
9492 }
9593 }
9694
95+ if (parent ) {
96+ size_t j = 0 ;
97+ const Node * bound ;
98+ while (dict_iter (parent -> bound_set , & j , & bound , NULL )) {
99+ insert_set_get_result (const Node * , ctx -> current_scope -> bound_set , bound );
100+ }
101+ }
102+
97103 /*String abs_name = get_abstraction_name_unsafe(abs);
98104 for (int i = 0; i < depth; i++)
99105 debugvv_print(" ");
0 commit comments