예제 #1
0
 level collect(level const & l) {
     return replace(l, [&](level const & l) {
             if (is_meta(l)) {
                 name const & id = meta_id(l);
                 if (auto r = m_univ_meta_to_param.find(id)) {
                     return some_level(*r);
                 } else {
                     name n      = m_prefix.append_after(m_next_idx);
                     m_next_idx++;
                     level new_r = mk_param_univ(n);
                     m_univ_meta_to_param.insert(id, new_r);
                     m_univ_meta_to_param_inv.insert(n, l);
                     m_level_params.push_back(n);
                     return some_level(new_r);
                 }
             } else if (is_param(l)) {
                 name const & id = param_id(l);
                 if (!m_found_univ_params.contains(id)) {
                     m_found_univ_params.insert(id);
                     m_level_params.push_back(id);
                 }
             }
             return none_level();
         });
 }
예제 #2
0
 expr collect(expr const & e) {
     return replace(e, [&](expr const & e, unsigned) {
             if (is_metavar(e)) {
                 name const & id = mlocal_name(e);
                 if (auto r = m_meta_to_param.find(id)) {
                     return some_expr(*r);
                 } else {
                     expr type  = m_ctx.infer(e);
                     expr x     = m_ctx.push_local("_x", type);
                     m_meta_to_param.insert(id, x);
                     m_meta_to_param_inv.insert(mlocal_name(x), e);
                     m_params.push_back(x);
                     return some_expr(x);
                 }
             } else if (is_local(e)) {
                 name const & id = mlocal_name(e);
                 if (!m_found_local.contains(id)) {
                     m_found_local.insert(id);
                     m_params.push_back(e);
                 }
             } else if (is_sort(e)) {
                 return some_expr(update_sort(e, collect(sort_level(e))));
             } else if (is_constant(e)) {
                 return some_expr(update_constant(e, collect(const_levels(e))));
             }
             return none_expr();
         });
 }
예제 #3
0
 void get_constructor_info(name const & n, buffer<bool> & rel_fields) {
     if (auto r = m_constructor_info.find(n)) {
         to_buffer(*r, rel_fields);
     } else {
         get_constructor_relevant_fields(env(), n, rel_fields);
         m_constructor_info.insert(n, to_list(rel_fields));
     }
 }
예제 #4
0
// Return a new ls s.t. there is no conflict between the names in ls and globals.
// Store the mapping between old and new names in param_name_map.
static level_param_names sanitize_level_params(level_param_names const & ls, name_set const & globals,
                                               name_map<name> & param_name_map) {
    buffer<name> new_params;
    for (name const & n : ls) {
        if (globals.contains(n)) {
            unsigned i = 1;
            name new_n = n.append_after(i);
            while (globals.contains(new_n)) {
                i++;
                name new_n = n.append_after(i);
            }
            param_name_map.insert(n, new_n);
            new_params.push_back(new_n);
        } else {
            new_params.push_back(n);
        }
    }
    if (param_name_map.empty())
        return ls;
    return to_list(new_params.begin(), new_params.end());
}