refactor(library/converter): expose is_opaque predicate in the converter interface
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
8aa217ea76
commit
e366aadad0
2 changed files with 32 additions and 26 deletions
|
@ -13,6 +13,35 @@ Author: Leonardo de Moura
|
||||||
#include "kernel/type_checker.h"
|
#include "kernel/type_checker.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
|
/**
|
||||||
|
\brief Predicate for deciding whether \c d is an opaque definition or not.
|
||||||
|
|
||||||
|
Here is the basic idea:
|
||||||
|
|
||||||
|
1) Each definition has an opaque flag. This flag cannot be modified after a definition is added to the environment.
|
||||||
|
The opaque flag affects the convertability check. The idea is to minimize the number of delta-reduction steps.
|
||||||
|
We also believe it increases the modularity of Lean developments by minimizing the dependency on how things are defined.
|
||||||
|
We should view non-opaque definitions as "inline definitions" used in programming languages such as C++.
|
||||||
|
|
||||||
|
2) Whenever type checking an expression, the user can provide an additional set of definition names (m_extra_opaque) that
|
||||||
|
should be considered opaque. Note that, if \c t type checks when using an extra_opaque set S, then t also type checks
|
||||||
|
(modulo resource constraints) with the empty set. Again, the purpose of extra_opaque is to mimimize the number
|
||||||
|
of delta-reduction steps.
|
||||||
|
|
||||||
|
3) To be able to prove theorems about an opaque definition, we treat an opaque definition D in a module M as
|
||||||
|
transparent when we are type checking another definition/theorem D' also in M. This rule only applies if
|
||||||
|
D is not a theorem, nor D is in the set m_extra_opaque. To implement this feature, this class has a field
|
||||||
|
m_module_idx that is not none when this rule should be applied.
|
||||||
|
*/
|
||||||
|
bool is_opaque(declaration const & d, name_set const & extra_opaque, optional<module_idx> const & mod_idx) {
|
||||||
|
lean_assert(d.is_definition());
|
||||||
|
if (d.is_theorem()) return true; // theorems are always opaque
|
||||||
|
if (extra_opaque.contains(d.get_name())) return true; // extra_opaque set overrides opaque flag
|
||||||
|
if (!d.is_opaque()) return false; // d is a transparent definition
|
||||||
|
if (mod_idx && d.get_module_idx() == *mod_idx) return false; // the opaque definitions in mod_idx are considered transparent
|
||||||
|
return true; // d is opaque
|
||||||
|
}
|
||||||
|
|
||||||
static no_delayed_justification g_no_delayed_jst;
|
static no_delayed_justification g_no_delayed_jst;
|
||||||
bool converter::is_def_eq(expr const & t, expr const & s, type_checker & c) {
|
bool converter::is_def_eq(expr const & t, expr const & s, type_checker & c) {
|
||||||
return is_def_eq(t, s, c, g_no_delayed_jst);
|
return is_def_eq(t, s, c, g_no_delayed_jst);
|
||||||
|
@ -138,33 +167,8 @@ struct default_converter : public converter {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
\brief Predicate for deciding whether \c d is an opaque definition or not.
|
|
||||||
|
|
||||||
Here is the basic idea:
|
|
||||||
|
|
||||||
1) Each definition has an opaque flag. This flag cannot be modified after a definition is added to the environment.
|
|
||||||
The opaque flag affects the convertability check. The idea is to minimize the number of delta-reduction steps.
|
|
||||||
We also believe it increases the modularity of Lean developments by minimizing the dependency on how things are defined.
|
|
||||||
We should view non-opaque definitions as "inline definitions" used in programming languages such as C++.
|
|
||||||
|
|
||||||
2) Whenever type checking an expression, the user can provide an additional set of definition names (m_extra_opaque) that
|
|
||||||
should be considered opaque. Note that, if \c t type checks when using an extra_opaque set S, then t also type checks
|
|
||||||
(modulo resource constraints) with the empty set. Again, the purpose of extra_opaque is to mimimize the number
|
|
||||||
of delta-reduction steps.
|
|
||||||
|
|
||||||
3) To be able to prove theorems about an opaque definition, we treat an opaque definition D in a module M as
|
|
||||||
transparent when we are type checking another definition/theorem D' also in M. This rule only applies if
|
|
||||||
D is not a theorem, nor D is in the set m_extra_opaque. To implement this feature, this class has a field
|
|
||||||
m_module_idx that is not none when this rule should be applied.
|
|
||||||
*/
|
|
||||||
bool is_opaque(declaration const & d) const {
|
bool is_opaque(declaration const & d) const {
|
||||||
lean_assert(d.is_definition());
|
return ::lean::is_opaque(d, m_extra_opaque, m_module_idx);
|
||||||
if (d.is_theorem()) return true; // theorems are always opaque
|
|
||||||
if (m_extra_opaque.contains(d.get_name())) return true; // extra_opaque set overrides opaque flag
|
|
||||||
if (!d.is_opaque()) return false; // d is a transparent definition
|
|
||||||
if (m_module_idx && d.get_module_idx() == *m_module_idx) return false; // the opaque definitions in module_idx are considered transparent
|
|
||||||
return true; // d is opaque
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Expand \c e if it is non-opaque constant with weight >= w */
|
/** \brief Expand \c e if it is non-opaque constant with weight >= w */
|
||||||
|
|
|
@ -30,4 +30,6 @@ std::unique_ptr<converter> mk_default_converter(environment const & env,
|
||||||
name_set const & extra_opaque = name_set());
|
name_set const & extra_opaque = name_set());
|
||||||
std::unique_ptr<converter> mk_default_converter(environment const & env, bool unfold_opaque_main,
|
std::unique_ptr<converter> mk_default_converter(environment const & env, bool unfold_opaque_main,
|
||||||
bool memoize = true, name_set const & extra_opaque = name_set());
|
bool memoize = true, name_set const & extra_opaque = name_set());
|
||||||
|
|
||||||
|
bool is_opaque(declaration const & d, name_set const & extra_opaque, optional<module_idx> const & mod_idx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue