makes DrNim compile again (#17584)
This commit is contained in:
parent
af2a7e8cbc
commit
5ecbe67371
2 changed files with 19 additions and 13 deletions
|
|
@ -393,8 +393,9 @@ proc registerModule*(g: ModuleGraph; m: PSym) =
|
||||||
proc registerModuleById*(g: ModuleGraph; m: FileIndex) =
|
proc registerModuleById*(g: ModuleGraph; m: FileIndex) =
|
||||||
registerModule(g, g.packed[int m].module)
|
registerModule(g, g.packed[int m].module)
|
||||||
|
|
||||||
proc initOperators(g: ModuleGraph): Operators =
|
proc initOperators*(g: ModuleGraph): Operators =
|
||||||
# These are safe for IC.
|
# These are safe for IC.
|
||||||
|
# Public because it's used by DrNim.
|
||||||
result.opLe = createMagic(g, "<=", mLeI)
|
result.opLe = createMagic(g, "<=", mLeI)
|
||||||
result.opLt = createMagic(g, "<", mLtI)
|
result.opLt = createMagic(g, "<", mLtI)
|
||||||
result.opAnd = createMagic(g, "and", mAnd)
|
result.opAnd = createMagic(g, "and", mAnd)
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ type
|
||||||
DrnimContext = ref object
|
DrnimContext = ref object
|
||||||
z3: Z3_context
|
z3: Z3_context
|
||||||
graph: ModuleGraph
|
graph: ModuleGraph
|
||||||
|
idgen: IdGenerator
|
||||||
facts: seq[(PNode, VersionScope)]
|
facts: seq[(PNode, VersionScope)]
|
||||||
varVersions: seq[int] # this maps variable IDs to their current version.
|
varVersions: seq[int] # this maps variable IDs to their current version.
|
||||||
varSyms: seq[PSym] # mirrors 'varVersions'
|
varSyms: seq[PSym] # mirrors 'varVersions'
|
||||||
|
|
@ -80,6 +81,7 @@ type
|
||||||
|
|
||||||
DrCon = object
|
DrCon = object
|
||||||
graph: ModuleGraph
|
graph: ModuleGraph
|
||||||
|
idgen: IdGenerator
|
||||||
mapping: Table[string, Z3_ast]
|
mapping: Table[string, Z3_ast]
|
||||||
canonParameterNames: bool
|
canonParameterNames: bool
|
||||||
assumeUniqueness: bool
|
assumeUniqueness: bool
|
||||||
|
|
@ -301,12 +303,12 @@ proc nodeToZ3(c: var DrCon; n: PNode; scope: VersionScope; vars: var seq[PNode])
|
||||||
|
|
||||||
proc nodeToDomain(c: var DrCon; n, q: PNode; opAnd: PSym): PNode =
|
proc nodeToDomain(c: var DrCon; n, q: PNode; opAnd: PSym): PNode =
|
||||||
assert n.kind == nkInfix
|
assert n.kind == nkInfix
|
||||||
let opLe = createMagic(c.graph, "<=", mLeI)
|
let opLe = createMagic(c.graph, c.idgen, "<=", mLeI)
|
||||||
case $n[0]
|
case $n[0]
|
||||||
of "..":
|
of "..":
|
||||||
result = buildCall(opAnd, buildCall(opLe, n[1], q), buildCall(opLe, q, n[2]))
|
result = buildCall(opAnd, buildCall(opLe, n[1], q), buildCall(opLe, q, n[2]))
|
||||||
of "..<":
|
of "..<":
|
||||||
let opLt = createMagic(c.graph, "<", mLtI)
|
let opLt = createMagic(c.graph, c.idgen, "<", mLtI)
|
||||||
result = buildCall(opAnd, buildCall(opLe, n[1], q), buildCall(opLt, q, n[2]))
|
result = buildCall(opAnd, buildCall(opLe, n[1], q), buildCall(opLt, q, n[2]))
|
||||||
else:
|
else:
|
||||||
notImplemented(n)
|
notImplemented(n)
|
||||||
|
|
@ -315,7 +317,7 @@ template quantorToZ3(fn) {.dirty.} =
|
||||||
template ctx: untyped = c.up.z3
|
template ctx: untyped = c.up.z3
|
||||||
|
|
||||||
var bound = newSeq[Z3_app](n.len-2)
|
var bound = newSeq[Z3_app](n.len-2)
|
||||||
let opAnd = createMagic(c.graph, "and", mAnd)
|
let opAnd = createMagic(c.graph, c.idgen, "and", mAnd)
|
||||||
var known: PNode
|
var known: PNode
|
||||||
for i in 1..n.len-2:
|
for i in 1..n.len-2:
|
||||||
let it = n[i]
|
let it = n[i]
|
||||||
|
|
@ -333,7 +335,7 @@ template quantorToZ3(fn) {.dirty.} =
|
||||||
|
|
||||||
var dummy: seq[PNode]
|
var dummy: seq[PNode]
|
||||||
assert known != nil
|
assert known != nil
|
||||||
let x = nodeToZ3(c, buildCall(createMagic(c.graph, "->", mImplies),
|
let x = nodeToZ3(c, buildCall(createMagic(c.graph, c.idgen, "->", mImplies),
|
||||||
known, n[^1]), scope, dummy)
|
known, n[^1]), scope, dummy)
|
||||||
result = fn(ctx, 0, bound.len.cuint, addr(bound[0]), 0, nil, x)
|
result = fn(ctx, 0, bound.len.cuint, addr(bound[0]), 0, nil, x)
|
||||||
|
|
||||||
|
|
@ -395,8 +397,8 @@ proc nodeToZ3(c: var DrCon; n: PNode; scope: VersionScope; vars: var seq[PNode])
|
||||||
else:
|
else:
|
||||||
notImplemented(n)
|
notImplemented(n)
|
||||||
of mHigh:
|
of mHigh:
|
||||||
let addOpr = createMagic(c.graph, "+", mAddI)
|
let addOpr = createMagic(c.graph, c.idgen, "+", mAddI)
|
||||||
let lenOpr = createMagic(c.graph, "len", mLengthOpenArray)
|
let lenOpr = createMagic(c.graph, c.idgen, "len", mLengthOpenArray)
|
||||||
let asLenExpr = addOpr.buildCall(lenOpr.buildCall(n[1]), nkIntLit.newIntNode(-1))
|
let asLenExpr = addOpr.buildCall(lenOpr.buildCall(n[1]), nkIntLit.newIntNode(-1))
|
||||||
result = rec asLenExpr
|
result = rec asLenExpr
|
||||||
of mLow:
|
of mLow:
|
||||||
|
|
@ -577,8 +579,8 @@ proc addRangeInfo(c: var DrCon, n: PNode; scope: VersionScope, res: var seq[Z3_a
|
||||||
res.add nodeToZ3(c, translateEnsures(ensures, n), scope, dummy)
|
res.add nodeToZ3(c, translateEnsures(ensures, n), scope, dummy)
|
||||||
return
|
return
|
||||||
|
|
||||||
let x = newTree(nkInfix, newSymNode createMagic(c.graph, "<=", cmpOp), lowBound, n)
|
let x = newTree(nkInfix, newSymNode createMagic(c.graph, c.idgen, "<=", cmpOp), lowBound, n)
|
||||||
let y = newTree(nkInfix, newSymNode createMagic(c.graph, "<=", cmpOp), n, highBound)
|
let y = newTree(nkInfix, newSymNode createMagic(c.graph, c.idgen, "<=", cmpOp), n, highBound)
|
||||||
|
|
||||||
var dummy: seq[PNode]
|
var dummy: seq[PNode]
|
||||||
res.add nodeToZ3(c, x, scope, dummy)
|
res.add nodeToZ3(c, x, scope, dummy)
|
||||||
|
|
@ -677,6 +679,7 @@ proc proofEngine(ctx: DrnimContext; assumptions: seq[(PNode, VersionScope)];
|
||||||
toProve: (PNode, VersionScope)): (bool, string) =
|
toProve: (PNode, VersionScope)): (bool, string) =
|
||||||
var c: DrCon
|
var c: DrCon
|
||||||
c.graph = ctx.graph
|
c.graph = ctx.graph
|
||||||
|
c.idgen = ctx.idgen
|
||||||
c.assumeUniqueness = assumeUniqueness
|
c.assumeUniqueness = assumeUniqueness
|
||||||
c.up = ctx
|
c.up = ctx
|
||||||
result = proofEngineAux(c, assumptions, toProve)
|
result = proofEngineAux(c, assumptions, toProve)
|
||||||
|
|
@ -738,10 +741,11 @@ proc compatibleProps(graph: ModuleGraph; formal, actual: PType): bool {.nimcall.
|
||||||
|
|
||||||
var c: DrCon
|
var c: DrCon
|
||||||
c.graph = graph
|
c.graph = graph
|
||||||
|
c.idgen = graph.idgen
|
||||||
c.canonParameterNames = true
|
c.canonParameterNames = true
|
||||||
try:
|
try:
|
||||||
c.up = DrnimContext(z3: setupZ3(), o: initOperators(graph), graph: graph, owner: nil,
|
c.up = DrnimContext(z3: setupZ3(), o: initOperators(graph), graph: graph, owner: nil,
|
||||||
opImplies: createMagic(graph, "->", mImplies))
|
opImplies: createMagic(graph, c.idgen, "->", mImplies))
|
||||||
template zero: untyped = VersionScope(0)
|
template zero: untyped = VersionScope(0)
|
||||||
if not frequires.isEmpty:
|
if not frequires.isEmpty:
|
||||||
result = not arequires.isEmpty and proofEngineAux(c, @[(frequires, zero)], (arequires, zero))[0]
|
result = not arequires.isEmpty and proofEngineAux(c, @[(frequires, zero)], (arequires, zero))[0]
|
||||||
|
|
@ -847,7 +851,7 @@ proc checkLe(c: DrnimContext, a, b: PNode) =
|
||||||
of tyChar, tyUInt..tyUInt64: cmpOp = mLeU
|
of tyChar, tyUInt..tyUInt64: cmpOp = mLeU
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
let cmp = newTree(nkInfix, newSymNode createMagic(c.graph, "<=", cmpOp), a, b)
|
let cmp = newTree(nkInfix, newSymNode createMagic(c.graph, c.idgen, "<=", cmpOp), a, b)
|
||||||
cmp.info = a.info
|
cmp.info = a.info
|
||||||
discard prove(c, cmp)
|
discard prove(c, cmp)
|
||||||
|
|
||||||
|
|
@ -1026,7 +1030,7 @@ proc traverseAsgn(c: DrnimContext; n: PNode) =
|
||||||
proc replaceByOldParams(fact, le: PNode): PNode =
|
proc replaceByOldParams(fact, le: PNode): PNode =
|
||||||
if guards.sameTree(fact, le):
|
if guards.sameTree(fact, le):
|
||||||
result = newNodeIT(nkCall, fact.info, fact.typ)
|
result = newNodeIT(nkCall, fact.info, fact.typ)
|
||||||
result.add newSymNode createMagic(c.graph, "old", mOld)
|
result.add newSymNode createMagic(c.graph, c.idgen, "old", mOld)
|
||||||
result.add fact
|
result.add fact
|
||||||
else:
|
else:
|
||||||
result = shallowCopy(fact)
|
result = shallowCopy(fact)
|
||||||
|
|
@ -1176,8 +1180,9 @@ proc strongSemCheck(graph: ModuleGraph; owner: PSym; n: PNode) =
|
||||||
c.z3 = setupZ3()
|
c.z3 = setupZ3()
|
||||||
c.o = initOperators(graph)
|
c.o = initOperators(graph)
|
||||||
c.graph = graph
|
c.graph = graph
|
||||||
|
c.idgen = graph.idgen
|
||||||
c.owner = owner
|
c.owner = owner
|
||||||
c.opImplies = createMagic(c.graph, "->", mImplies)
|
c.opImplies = createMagic(c.graph, c.idgen, "->", mImplies)
|
||||||
try:
|
try:
|
||||||
traverse(c, n)
|
traverse(c, n)
|
||||||
ensuresCheck(c, owner)
|
ensuresCheck(c, owner)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue