Skip to content

Commit cdb9123

Browse files
committed
Namespace
1 parent d9296c0 commit cdb9123

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/Lean/Meta/Constructions/NoConfusion.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import Lean.Meta.CompletionName
1010
import Lean.Meta.Constructions.NoConfusionLinear
1111

1212

13-
register_builtin_option linearNoConfusionType : Bool := {
13+
register_builtin_option backwards.linearNoConfusionType : Bool := {
1414
defValue := true
15-
descr := "use the linear-size construction for the no-confusion-tyep for inductive types"
15+
descr := "use the linear-size construction for the `noConfusionType` declaration of an inductive type, else use for the no-confusion-tyep for inductive types"
1616
}
1717

1818
namespace Lean
@@ -29,15 +29,15 @@ def mkNoConfusionCore (declName : Name) : MetaM Unit := do
2929
unless recInfo.levelParams.length > indVal.levelParams.length do return
3030

3131
let useLinear ←
32-
if linearNoConfusionType.get (← getOptions) then
33-
linearNoConfusionDeps.allM (hasConst · (skipRealize := true))
32+
if backwards.linearNoConfusionType.get (← getOptions) then
33+
NoConfusionLinear.deps.allM (hasConst · (skipRealize := true))
3434
else
3535
pure false
3636

3737
if useLinear then
38-
mkWithCtorType declName
39-
mkWithCtor declName
40-
mkNoConfusionTypeLinear declName
38+
NoConfusionLinear.mkWithCtorType declName
39+
NoConfusionLinear.mkWithCtor declName
40+
NoConfusionLinear.mkNoConfusionTypeLinear declName
4141
else
4242
let name := Name.mkStr declName "noConfusionType"
4343
let decl ← ofExceptKernelException (mkNoConfusionTypeCoreImp (← getEnv) declName)

src/Lean/Meta/Constructions/NoConfusionLinear.lean

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ This module is written in a rather manual style, constructing the `Expr` directl
3333
read with the expected output to the side.
3434
-/
3535

36-
namespace Lean
36+
namespace Lean.NoConfusionLinear
3737

3838
open Meta
3939

4040
/--
4141
List of constants that the linear `noConfusionType` construction depends on.
4242
-/
43-
def linearNoConfusionDeps : Array Lean.Name :=
44-
#[ ``Nat.lt, ``cond, ``OfNat.ofNat, ``instOfNatNat, ``Nat, ``PUnit, ``Eq, ``Not, ``dite,
45-
``Nat.decEq, ``Nat.blt ]
43+
def deps : Array Lean.Name :=
44+
#[ ``Nat.lt, ``cond, ``Nat, ``PUnit, ``Eq, ``Not, ``dite, ``Nat.decEq, ``Nat.blt ]
4645

4746
def mkNatLookupTable (n : Expr) (es : Array Expr) (default : Expr) : MetaM Expr := do
4847
let type ← inferType default
@@ -54,12 +53,21 @@ def mkNatLookupTable (n : Expr) (es : Array Expr) (default : Expr) : MetaM Expr
5453
let mid := (start + stop) / 2
5554
let low ← go start mid
5655
let high ← go mid stop
57-
return mkApp4 (mkConst ``cond [u]) type (mkApp2 (mkConst ``Nat.blt) n (mkNatLit mid)) low high
56+
return mkApp4 (mkConst ``cond [u]) type (mkApp2 (mkConst ``Nat.blt) n (mkRawNatLit mid)) low high
5857
if h : es.size = 0 then
5958
pure default
6059
else
6160
go 0 es.size
6261

62+
def mkWithCtorTypeName (indName : Name) : Name :=
63+
Name.str indName "noConfusionType" |>.str "withCtorType"
64+
65+
def mkWithCtorName (indName : Name) : Name :=
66+
Name.str indName "noConfusionType" |>.str "withCtor"
67+
68+
def mkNoConfusionTypeName (indName : Name) : Name :=
69+
Name.str indName "noConfusionType"
70+
6371
def mkWithCtorType (indName : Name) : MetaM Unit := do
6472
let ConstantInfo.inductInfo info ← getConstInfo indName | unreachable!
6573
let casesOnName := mkCasesOnName indName
@@ -81,7 +89,7 @@ def mkWithCtorType (indName : Name) : MetaM Unit := do
8189
let e ← mkNatLookupTable ctorIdx es default
8290
mkLambdaFVars ((xs.push P).push ctorIdx) e
8391

84-
let declName := Name.str indName "noConfusionType" |>.str "withCtorType"
92+
let declName := mkWithCtorTypeName indName
8593
addAndCompile (.defnDecl (← mkDefinitionValInferrringUnsafe
8694
(name := declName)
8795
(levelParams := casesOnInfo.levelParams)
@@ -95,7 +103,7 @@ def mkWithCtorType (indName : Name) : MetaM Unit := do
95103

96104
def mkWithCtor (indName : Name) : MetaM Unit := do
97105
let ConstantInfo.inductInfo info ← getConstInfo indName | unreachable!
98-
let withCtorTypeName := Name.str indName "noConfusionType" |>.str "withCtorType"
106+
let withCtorTypeName := mkWithCtorTypeName indName
99107
let casesOnName := mkCasesOnName indName
100108
let casesOnInfo ← getConstVal casesOnName
101109
let v::us := casesOnInfo.levelParams.map mkLevelParam | panic! "unexpected universe levels on `casesOn`"
@@ -123,7 +131,7 @@ def mkWithCtor (indName : Name) : MetaM Unit := do
123131
let ctor := mkAppN (mkConst ctorName us) xs
124132
let ctorType ← inferType ctor
125133
forallTelescope ctorType fun zs _ => do
126-
let heq := mkApp3 (mkConst ``Eq [1]) (mkConst ``Nat) ctorIdx (mkNatLit i)
134+
let heq := mkApp3 (mkConst ``Eq [1]) (mkConst ``Nat) ctorIdx (mkRawNatLit i)
127135
let «then» ← withLocalDeclD `h heq fun h => do
128136
let e ← mkEqNDRec (motive := withCtorTypeNameApp) k h
129137
let e := mkApp e (mkConst ``PUnit.unit [indLevel])
@@ -133,13 +141,13 @@ def mkWithCtor (indName : Name) : MetaM Unit := do
133141
let «else» ← withLocalDeclD `h (mkNot heq) fun h =>
134142
mkLambdaFVars #[h] k'
135143
let alt := mkApp5 (mkConst ``dite [v.succ])
136-
P heq (mkApp2 (mkConst ``Nat.decEq) ctorIdx (mkNatLit i))
144+
P heq (mkApp2 (mkConst ``Nat.decEq) ctorIdx (mkRawNatLit i))
137145
«then» «else»
138146
mkLambdaFVars zs alt
139147
let e := mkAppN e alts
140148
mkLambdaFVars (xs ++ #[P, ctorIdx, k, k'] ++ ys ++ #[x]) e
141149

142-
let declName := Name.str indName "noConfusionType" |>.str "withCtor"
150+
let declName := mkWithCtorName indName
143151
-- not compiled to avoid old code generator bug #1774
144152
addDecl (.defnDecl (← mkDefinitionValInferrringUnsafe
145153
(name := declName)
@@ -153,7 +161,7 @@ def mkWithCtor (indName : Name) : MetaM Unit := do
153161
setReducibleAttribute declName
154162

155163
def mkNoConfusionTypeLinear (indName : Name) : MetaM Unit := do
156-
let declName := .str indName "noConfusionType"
164+
let declName := mkNoConfusionTypeName indName
157165
let ConstantInfo.inductInfo info ← getConstInfo indName | unreachable!
158166
let casesOnName := mkCasesOnName indName
159167
let casesOnInfo ← getConstVal casesOnName
@@ -179,10 +187,10 @@ def mkNoConfusionTypeLinear (indName : Name) : MetaM Unit := do
179187
let alts' ← alts.mapIdxM fun i alt => do
180188
let altType ← inferType alt
181189
forallTelescope altType fun zs1 _ => do
182-
let alt := mkConst (Name.str declName "withCtor") (v :: us)
190+
let alt := mkConst (mkWithCtorName indName) (v :: us)
183191
let alt := mkAppN alt xs
184192
let alt := mkApp alt PType
185-
let alt := mkApp alt (mkNatLit i)
193+
let alt := mkApp alt (mkRawNatLit i)
186194
let k ← forallTelescopeReducing (← inferType alt).bindingDomain! fun zs2 _ => do
187195
let eqs ← (Array.zip zs1 zs2[1:]).filterMapM fun (z1,z2) => do
188196
if (← isProof z1) then
@@ -214,3 +222,5 @@ def mkNoConfusionTypeLinear (indName : Name) : MetaM Unit := do
214222
modifyEnv fun env => addToCompletionBlackList env declName
215223
modifyEnv fun env => addProtected env declName
216224
setReducibleAttribute declName
225+
226+
end Lean.NoConfusionLinear

0 commit comments

Comments
 (0)