lean4-htt/library/init/lean/parser/move.lean
Leonardo de Moura c9e4c89d9c chore(library/init/meta): remove mk_dec_eq_instance
The tactic mk_dec_eq_instance constructs a function using the brec_on
recursor. The compiler generates horrible code for this kind of
definition. It creates a closure for each recursive call.
Moreover, `brec_on` accumulates all intermediate results.

To generate efficient code, we need to generate a collection of
recursive equations, and then invoke the equation compiler.

cc @kha
2018-04-27 16:13:10 -07:00

51 lines
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich
-/
prelude
import init.data
-- non-meta instance
instance : decidable_eq name :=
sorry -- TODO(Leo): define instance after we implement new `decidable` type class
universes u v w
namespace name
@[simp] protected def quick_lt : name → name → Prop
| anonymous anonymous := false
| anonymous _ := true
| (mk_numeral v n) (mk_numeral v' n') := v < v' v = v' ∧ n.quick_lt n'
| (mk_numeral _ _) (mk_string _ _) := true
| (mk_string s n) (mk_string s' n') := s < s' s = s' ∧ n.quick_lt n'
| _ _ := false
instance decidable_rel_quick_lt : decidable_rel name.quick_lt :=
begin
intros n n',
induction n generalizing n',
case anonymous {
by_cases n' = anonymous; simp *; apply_instance
},
all_goals { cases n'; {
tactic.unfreeze_local_instances, -- use recursive instance
simp; apply_instance } }
end
protected def has_lt_quick : has_lt name := ⟨name.quick_lt⟩
end name
namespace option
variables {α : Type u} (r : αα → Prop)
@[simp] protected def lt : option α → option α → Prop
| none (some x) := true
| (some x) (some y) := r x y
| _ _ := false
instance decidable_rel_lt [decidable_rel r] : decidable_rel (option.lt r) :=
by intros a b; cases a; cases b; simp; apply_instance
protected def has_lt [has_lt α] : has_lt (option α) := ⟨option.lt (<)⟩
end option