@@ -26,10 +26,6 @@ partial def isPropOrTypeFuncType(t: Expr): Bool :=
2626partial def exprToWithCost (expr: Expr)(prevCost: Option Expr): MetaM Expr := do
2727 let type ← inferType expr
2828 logInfo m! "Working: { expr} with type { type} "
29- if type.isType then
30- return expr
31- if type.isProp then
32- return expr
3329
3430 let withPrevCost(expr: Expr): MetaM Expr := do
3531 match prevCost with
@@ -81,7 +77,13 @@ partial def exprToWithCost(expr: Expr)(prevCost: Option Expr): MetaM Expr := do
8177 bi)
8278 withPrevCost newExpr
8379 | proj typeName idx struct =>
84- return expr
80+ let newStruct ← exprToWithCost struct none
81+ let newStructType ← inferType newStruct
82+ logInfo m! "newStruct={ newStruct} newStructType={ newStructType} "
83+ if isWithCostType newStructType then
84+ throwError m! "TODO"
85+ else
86+ return expr
8587 | app f a =>
8688 let newF ← exprToWithCost f none
8789 let newA ← exprToWithCost a none
@@ -100,18 +102,18 @@ partial def exprToWithCost(expr: Expr)(prevCost: Option Expr): MetaM Expr := do
100102 -- 最内层的调用
101103 let genApply(f: Expr)(a: Expr): Expr :=
102104 let app := Expr.app f a
103- if isPropOrTypeFuncType newAType then
105+ if isPropOrTypeFuncType newAType ∨ isPropOrTypeFuncType retType then
104106 app
105107 else
106108 if isWithCostType retType then
107- -- 带类型调用 ,增加消耗 ret.addCost 1
109+ -- 返回值带Cost ,增加消耗 ret.addCost 1
108110 let retValueType := getValueType retType
109111 let addCost := Expr.const `Algorithm.WithCost.addCost []
110112 let addCost := Expr.app addCost retValueType
111113 let addCost := Expr.app addCost app
112114 Expr.app addCost (Expr.lit (.natVal 1 ))
113115 else
114- -- 不带类型调用 ,构造消耗 {cost:= 1, val:= ret}
116+ -- 返回值不带Cost ,构造消耗 {cost:= 1, val:= ret}
115117 let mkCost := Expr.const `Algorithm.WithCost.mk []
116118 let mkCost := Expr.app mkCost retType
117119 let mkCost := Expr.app mkCost (Expr.lit (.natVal 1 ))
@@ -153,7 +155,10 @@ partial def exprToWithCost(expr: Expr)(prevCost: Option Expr): MetaM Expr := do
153155 else
154156 -- 直接调用
155157 return genApply1 newF newA
156-
158+ | forallE binderName binderType body binderInfo =>
159+ let binderType ← exprToWithCost binderType none
160+ let binderBody ← exprToWithCost body none
161+ return .forallE binderName binderType binderBody binderInfo
157162 | _ =>
158163 throwError m! "不支持的表达式类型:{ expr} "
159164
0 commit comments