feat(frontends/lean/frontend_elaborator): use is_convertible to minimize number of coercions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
777582380f
commit
baf99779dc
3 changed files with 15 additions and 1 deletions
|
@ -172,6 +172,14 @@ class frontend_elaborator::imp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_convertible(expr const & from, expr const & to) {
|
||||||
|
try {
|
||||||
|
return m_ref.m_type_checker.is_convertible(from, to);
|
||||||
|
} catch (exception &) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Make sure f_t is a Pi, if it is not, then return none_expr()
|
\brief Make sure f_t is a Pi, if it is not, then return none_expr()
|
||||||
*/
|
*/
|
||||||
|
@ -363,7 +371,7 @@ class frontend_elaborator::imp {
|
||||||
new_a = add_coercion_mvar_app(coercions, new_a, *new_a_t, ctx, a);
|
new_a = add_coercion_mvar_app(coercions, new_a, *new_a_t, ctx, a);
|
||||||
} else {
|
} else {
|
||||||
expr expected = abst_domain(*f_t);
|
expr expected = abst_domain(*f_t);
|
||||||
if (expected != *new_a_t) {
|
if (!is_convertible(*new_a_t, expected)) {
|
||||||
optional<expr> c = find_coercion(coercions, expected);
|
optional<expr> c = find_coercion(coercions, expected);
|
||||||
if (c) {
|
if (c) {
|
||||||
new_a = mk_app(*c, new_a); // apply coercion
|
new_a = mk_app(*c, new_a); // apply coercion
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
SetOption pp::implicit true
|
SetOption pp::implicit true
|
||||||
|
SetOption pp::coercion true
|
||||||
|
SetOption pp::notation false
|
||||||
Variable vector (A : Type) (sz : Nat) : Type
|
Variable vector (A : Type) (sz : Nat) : Type
|
||||||
Variable read {A : Type} {sz : Nat} (v : vector A sz) (i : Nat) (H : i < sz) : A
|
Variable read {A : Type} {sz : Nat} (v : vector A sz) (i : Nat) (H : i < sz) : A
|
||||||
Variable V1 : vector Int 10
|
Variable V1 : vector Int 10
|
||||||
Definition D := read V1 1 (by trivial_tac)
|
Definition D := read V1 1 (by trivial_tac)
|
||||||
|
Show Environment 1
|
||||||
Variable b : Bool
|
Variable b : Bool
|
||||||
Definition a := b
|
Definition a := b
|
||||||
Theorem T : b => a := (by (** imp_tac() .. normalize_tac() .. assumption_tac() **))
|
Theorem T : b => a := (by (** imp_tac() .. normalize_tac() .. assumption_tac() **))
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
Set: pp::colors
|
Set: pp::colors
|
||||||
Set: pp::unicode
|
Set: pp::unicode
|
||||||
Set: lean::pp::implicit
|
Set: lean::pp::implicit
|
||||||
|
Set: lean::pp::coercion
|
||||||
|
Set: lean::pp::notation
|
||||||
Assumed: vector
|
Assumed: vector
|
||||||
Assumed: read
|
Assumed: read
|
||||||
Assumed: V1
|
Assumed: V1
|
||||||
Defined: D
|
Defined: D
|
||||||
|
Definition D : ℤ := @read ℤ 10 V1 1 Trivial
|
||||||
Assumed: b
|
Assumed: b
|
||||||
Defined: a
|
Defined: a
|
||||||
Proved: T
|
Proved: T
|
||||||
|
|
Loading…
Reference in a new issue