No longer destroy the list of free variables.

It so happens that this list will tell us which variables
need to be captured.
This commit is contained in:
Danila Fedorin 2020-05-30 23:29:36 -07:00
parent feeee2039b
commit dec6d834f5
2 changed files with 3 additions and 4 deletions

View File

@ -114,15 +114,13 @@ void definition_group::find_free(type_mgr& mgr, type_env_ptr& env, std::set<std:
for(auto& def_pair : defs_defn) {
def_pair.second->find_free(mgr, env);
std::set<std::string> local_dependencies;
for(auto& free_var : def_pair.second->free_variables) {
if(defs_defn.find(free_var) == defs_defn.end()) {
into.insert(free_var);
} else {
local_dependencies.insert(free_var);
def_pair.second->nearby_variables.insert(free_var);
}
}
std::swap(def_pair.second->free_variables, local_dependencies);
}
}
@ -140,7 +138,7 @@ void definition_group::typecheck(type_mgr& mgr) {
def_defn.second->find_free(mgr, env);
dependency_graph.add_function(def_defn.second->name);
for(auto& dependency : def_defn.second->free_variables) {
for(auto& dependency : def_defn.second->nearby_variables) {
if(defs_defn.find(dependency) == defs_defn.end())
throw 0;
dependency_graph.add_edge(def_defn.second->name, dependency);

View File

@ -30,6 +30,7 @@ struct definition_defn {
type_env_ptr env;
type_env_ptr var_env;
std::set<std::string> free_variables;
std::set<std::string> nearby_variables;
type_ptr full_type;
type_ptr return_type;