refactor(library/projection): move is_constructor_app to util
This commit is contained in:
parent
1043cc8b48
commit
39446a7215
3 changed files with 34 additions and 30 deletions
|
@ -66,36 +66,6 @@ static void projection_info_reader(deserializer & d, module_idx, shared_environm
|
|||
});
|
||||
}
|
||||
|
||||
/** \brief If \c e is a constructor application, then return the name of the constructor.
|
||||
Otherwise, return none.
|
||||
*/
|
||||
optional<name> is_constructor_app(environment const & env, expr const & e) {
|
||||
expr const & fn = get_app_fn(e);
|
||||
if (is_constant(fn))
|
||||
if (auto I = inductive::is_intro_rule(env, const_name(fn)))
|
||||
return optional<name>(const_name(fn));
|
||||
return optional<name>();
|
||||
}
|
||||
|
||||
/** \brief If \c e is a constructor application, or a definition that wraps a
|
||||
constructor application, then return the name of the constructor.
|
||||
Otherwise, return none.
|
||||
*/
|
||||
optional<name> is_constructor_app_ext(environment const & env, expr const & e) {
|
||||
if (auto r = is_constructor_app(env, e))
|
||||
return r;
|
||||
expr const & f = get_app_fn(e);
|
||||
if (!is_constant(f))
|
||||
return optional<name>();
|
||||
auto decl = env.find(const_name(f));
|
||||
if (!decl || !decl->is_definition() || decl->is_opaque())
|
||||
return optional<name>();
|
||||
expr const * it = &decl->get_value();
|
||||
while (is_lambda(*it))
|
||||
it = &binding_body(*it);
|
||||
return is_constructor_app_ext(env, *it);
|
||||
}
|
||||
|
||||
static name * g_projection_macro_name = nullptr;
|
||||
static std::string * g_projection_opcode = nullptr;
|
||||
|
||||
|
|
|
@ -169,6 +169,29 @@ void get_intro_rule_names(environment const & env, name const & n, buffer<name>
|
|||
}
|
||||
}
|
||||
|
||||
optional<name> is_constructor_app(environment const & env, expr const & e) {
|
||||
expr const & fn = get_app_fn(e);
|
||||
if (is_constant(fn))
|
||||
if (auto I = inductive::is_intro_rule(env, const_name(fn)))
|
||||
return optional<name>(const_name(fn));
|
||||
return optional<name>();
|
||||
}
|
||||
|
||||
optional<name> is_constructor_app_ext(environment const & env, expr const & e) {
|
||||
if (auto r = is_constructor_app(env, e))
|
||||
return r;
|
||||
expr const & f = get_app_fn(e);
|
||||
if (!is_constant(f))
|
||||
return optional<name>();
|
||||
auto decl = env.find(const_name(f));
|
||||
if (!decl || !decl->is_definition() || decl->is_opaque())
|
||||
return optional<name>();
|
||||
expr const * it = &decl->get_value();
|
||||
while (is_lambda(*it))
|
||||
it = &binding_body(*it);
|
||||
return is_constructor_app_ext(env, *it);
|
||||
}
|
||||
|
||||
expr instantiate_univ_param (expr const & e, name const & p, level const & l) {
|
||||
return instantiate_univ_params(e, to_list(p), to_list(l));
|
||||
}
|
||||
|
|
|
@ -59,6 +59,17 @@ bool is_inductive_predicate(environment const & env, name const & n);
|
|||
*/
|
||||
void get_intro_rule_names(environment const & env, name const & n, buffer<name> & result);
|
||||
|
||||
/** \brief If \c e is a constructor application, then return the name of the constructor.
|
||||
Otherwise, return none.
|
||||
*/
|
||||
optional<name> is_constructor_app(environment const & env, expr const & e);
|
||||
|
||||
/** \brief If \c e is a constructor application, or a definition that wraps a
|
||||
constructor application, then return the name of the constructor.
|
||||
Otherwise, return none.
|
||||
*/
|
||||
optional<name> is_constructor_app_ext(environment const & env, expr const & e);
|
||||
|
||||
/** \brief "Consume" Pi-type \c type. This procedure creates local constants based on the domain of \c type
|
||||
and store them in telescope. If \c binfo is provided, then the local constants are annoted with the given
|
||||
binder_info, otherwise the procedure uses the one attached in the domain.
|
||||
|
|
Loading…
Reference in a new issue