You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: allow arbitrary sorts in structural recursion over reflexive inductive types (#7639)
This PR changes the generated `below` and `brecOn` implementations for
reflexive inductive types to support motives in `Sort u` rather than
`Type u`.
Closes#7638
matchConstInduct xType.getAppFn (fun _ => throwError "its type is not an inductive") fun indInfo us => do
73
-
if indInfo.isReflexive && !(← hasConst (mkBInductionOnName indInfo.name)) && !(← isInductivePredicate indInfo.name) then
74
-
throwError "its type {indInfo.name} is a reflexive inductive, but {mkBInductionOnName indInfo.name} does not exist and it is not an inductive predicate"
73
+
let indArgs : Array Expr := xType.getAppArgs
74
+
let indParams : Array Expr := indArgs[0:indInfo.numParams]
75
+
let indIndices : Array Expr := indArgs[indInfo.numParams:]
76
+
if !indIndices.all Expr.isFVar then
77
+
throwError "its type {indInfo.name} is an inductive family and indices are not variables{indentExpr xType}"
78
+
elseif !indIndices.allDiff then
79
+
throwError "its type {indInfo.name} is an inductive family and indices are not pairwise distinct{indentExpr xType}"
75
80
else
76
-
let indArgs : Array Expr := xType.getAppArgs
77
-
let indParams : Array Expr := indArgs[0:indInfo.numParams]
78
-
let indIndices : Array Expr := indArgs[indInfo.numParams:]
79
-
if !indIndices.all Expr.isFVar then
80
-
throwError "its type {indInfo.name} is an inductive family and indices are not variables{indentExpr xType}"
81
-
elseif !indIndices.allDiff then
82
-
throwError "its type {indInfo.name} is an inductive family and indices are not pairwise distinct{indentExpr xType}"
83
-
else
84
-
let ys := fixedParamPerm.pickVarying xs
85
-
match (← hasBadIndexDep? ys indIndices) with
86
-
| some (index, y) =>
87
-
throwError "its type {indInfo.name} is an inductive family{indentExpr xType}\nand index{indentExpr index}\ndepends on the non index{indentExpr y}"
81
+
let ys := fixedParamPerm.pickVarying xs
82
+
match (← hasBadIndexDep? ys indIndices) with
83
+
| some (index, y) =>
84
+
throwError "its type {indInfo.name} is an inductive family{indentExpr xType}\nand index{indentExpr index}\ndepends on the non index{indentExpr y}"
85
+
| none =>
86
+
match (← hasBadParamDep? ys indParams) with
87
+
| some (indParam, y) =>
88
+
throwError "its type is an inductive datatype{indentExpr xType}\nand the datatype parameter{indentExpr indParam}\ndepends on the function parameter{indentExpr y}\nwhich is not fixed."
88
89
| none =>
89
-
match (← hasBadParamDep? ys indParams) with
90
-
| some (indParam, y) =>
91
-
throwError "its type is an inductive datatype{indentExpr xType}\nand the datatype parameter{indentExpr indParam}\ndepends on the function parameter{indentExpr y}\nwhich is not fixed."
92
-
| none =>
93
-
let indAll := indInfo.all.toArray
94
-
let .some indIdx := indAll.idxOf? indInfo.name | panic! "{indInfo.name} not in {indInfo.all}"
95
-
let indicesPos := indIndices.map fun index => match xs.idxOf? index with | some i => i | none => unreachable!
96
-
let indGroupInst := {
97
-
IndGroupInfo.ofInductiveVal indInfo with
98
-
levels := us
99
-
params := indParams }
100
-
return { fnName := fnName
101
-
fixedParamPerm := fixedParamPerm
102
-
recArgPos := i
103
-
indicesPos := indicesPos
104
-
indGroupInst := indGroupInst
105
-
indIdx := indIdx }
106
-
else
107
-
throwError "the index #{i+1} exceeds {xs.size}, the number of parameters"
90
+
let indAll := indInfo.all.toArray
91
+
let .some indIdx := indAll.idxOf? indInfo.name | panic! "{indInfo.name} not in {indInfo.all}"
92
+
let indicesPos := indIndices.map fun index => match xs.idxOf? index with | some i => i | none => unreachable!
93
+
let indGroupInst := {
94
+
IndGroupInfo.ofInductiveVal indInfo with
95
+
levels := us
96
+
params := indParams }
97
+
return { fnName := fnName
98
+
fixedParamPerm := fixedParamPerm
99
+
recArgPos := i
100
+
indicesPos := indicesPos
101
+
indGroupInst := indGroupInst
102
+
indIdx := indIdx }
103
+
else
104
+
throwError "the index #{i+1} exceeds {xs.size}, the number of parameters"
108
105
109
106
/--
110
107
Collects the `RecArgInfos` for one function, and returns a report for why the others were not
0 commit comments