perf: reorder DiscrTree.Key constructors (#10110)

this PR reorders the `DiscrTree.Key` constructors to match the order
given in the manually written `DiscrTree.Key.ctorIdx`. This allows us to
use the auto-generated one, and moreover lets this code benefit from
special compiler support for `.ctorIdx`, once that lands.
This commit is contained in:
Joachim Breitner 2025-08-25 18:13:43 +02:00 committed by GitHub
parent 2107f45991
commit 13e8cb5a3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 18 deletions

View file

@ -215,7 +215,7 @@ jobs:
path: pack/*
- name: Lean stats
run: |
build/stage1/bin/lean --stats src/Lean.lean -Dexperimental.module=true
build/$TARGET_STAGE/bin/lean --stats src/Lean.lean -Dexperimental.module=true
if: ${{ !matrix.cross }}
- name: Test
id: test

View file

@ -53,24 +53,12 @@ namespace Lean.Meta.DiscrTree
2- Distinguish partial applications `f a`, `f a b`, and `f a b c`.
-/
/--
An ordering for the key that puts `star` and `other` first. Differs from the auto-generated `ctorIdx`.
-/
private def Key.ctorIdx' : Key → Nat
| .star => 0
| .other => 1
| .lit .. => 2
| .fvar .. => 3
| .const .. => 4
| .arrow => 5
| .proj .. => 6
def Key.lt : Key → Key → Bool
| .lit v₁, .lit v₂ => v₁ < v₂
| .fvar n₁ a₁, .fvar n₂ a₂ => Name.quickLt n₁.name n₂.name || (n₁ == n₂ && a₁ < a₂)
| .const n₁ a₁, .const n₂ a₂ => Name.quickLt n₁ n₂ || (n₁ == n₂ && a₁ < a₂)
| .proj s₁ i₁ a₁, .proj s₂ i₂ a₂ => Name.quickLt s₁ s₂ || (s₁ == s₂ && i₁ < i₂) || (s₁ == s₂ && i₁ == i₂ && a₁ < a₂)
| k₁, k₂ => k₁.ctorIdx' < k₂.ctorIdx'
| k₁, k₂ => k₁.ctorIdx < k₂.ctorIdx
instance : LT Key := ⟨fun a b => Key.lt a b⟩
instance (a b : Key) : Decidable (a < b) := inferInstanceAs (Decidable (Key.lt a b))

View file

@ -20,11 +20,11 @@ namespace DiscrTree
Discrimination tree key. See `DiscrTree`
-/
inductive Key where
| const : Name → Nat → Key
| fvar : FVarId → Nat → Key
| lit : Literal → Key
| star : Key
| other : Key
| lit : Literal → Key
| fvar : FVarId → Nat → Key
| const : Name → Nat → Key
| arrow : Key
| proj : Name → Nat → Nat → Key
deriving Inhabited, BEq, Repr

View file

@ -1,5 +1,7 @@
#include "util/options.h"
// please update stage0
namespace lean {
options get_default_options() {
options opts;
@ -11,7 +13,7 @@ options get_default_options() {
opts = opts.update({"debug", "terminalTacticsAsSorry"}, false);
// switch to `true` for ABI-breaking changes affecting meta code;
// see also next option!
opts = opts.update({"interpreter", "prefer_native"}, false);
opts = opts.update({"interpreter", "prefer_native"}, true);
// switch to `false` when enabling `prefer_native` should also affect use
// of built-in parsers in quotations; this is usually the case, but setting
// both to `true` may be necessary for handling non-builtin parsers with