Skip to content

Commit

Permalink
fix CI issues for Nim 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosborn committed Aug 6, 2023
1 parent 828e35a commit bc25510
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
26 changes: 18 additions & 8 deletions src/algorithms/dilution.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ type
case kind*: DilutionKind
of dkEvenOdd: eo*: range[0..1]
of dkCorners3D: c3d*: range[0..7]
template high(dk: DilutionKind): int =
case dk
of dkEvenOdd: 1
of dkCorners3D: 7
template newDilution(dk: DilutionKind, i: int): Dilution =
case dk
of dkEvenOdd: Dilution(kind: dkEvenOdd, eo: i)
of dkCorners3D: Dilution(kind: dkCorners3D, c3d: i)
proc `$`*(x: Dilution): string =
case x.kind
of dkEvenOdd: "EvenOdd " & $x.eo
of dkCorners3D: "Corners3D " & $x.c3d

template sitesI(l: Layout, d: Dilution): untyped =
template sitesI(l: Layout, d: Dilution): auto =
case d.kind
of dkEvenOdd:
# Assuming even-odd layout
Expand All @@ -37,13 +45,15 @@ iterator sites*(l: Layout, d: Dilution): int = l.sitesI d
iterator sites*(f: Field, d: Dilution): int = f.l.sitesI d

iterator dilution*(dl:DilutionKind): Dilution =
case dl
of dkEvenOdd:
yield Dilution(kind:dkEvenOdd, eo:0)
yield Dilution(kind:dkEvenOdd, eo:1)
of dkCorners3D:
for i in 0..7:
yield Dilution(kind:dkCorners3D, c3d:i)
#case dl
#of dkEvenOdd:
# for i in 0..1:
# yield Dilution(kind:dkEvenOdd, eo:i)
#of dkCorners3D:
# for i in 0..7:
# yield Dilution(kind:dkCorners3D, c3d:i)
for i in 0..high(dl):
yield newDilution(dl, i)

proc parseDilution*(dl:string): DilutionKind =
case dl
Expand Down
12 changes: 10 additions & 2 deletions src/base/metaUtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ proc replaceNonDeclSym(b,s,r: NimNode, extra:NimNodeKind = nnkEmpty): NimNode =
case n.kind:
of nnkSym:
if n.eqIdent ss: checkSym n
of nnkIdent:
if n.eqIdent ss: checkSym n
of nnkIdentDefs, nnkConstDef:
for i in 0..<n.len-2:
if n[i].eqIdent ss: declSyms.add n[i]
Expand Down Expand Up @@ -447,9 +449,10 @@ proc inlineProcsY(call: NimNode, procImpl: NimNode): NimNode =
(sym,typ) = getParam(fp, i)
t = genSym(nskLet, $sym)
c = genSym(nskConst, $sym)
template letX(x,y: untyped): untyped =
#echo "sym: ", sym.repr, " typ: ", typ.repr, " typ.kind: ", typ.kind
template letX(x,y: untyped) =
let x = y
template constX(x,y: untyped): untyped =
template constX(x,y: untyped) =
const x = y
# let p = if call[i].kind in {nnkHiddenAddr,nnkHiddenDeref}: call[i][0] else: call[i]
let p = call[i]
Expand All @@ -473,6 +476,11 @@ proc inlineProcsY(call: NimNode, procImpl: NimNode): NimNode =
elif typ.kind == nnkVarTy:
pre.add getAst(letX(t, newNimNode(nnkAddr,p).add p))
body = body.replaceNonDeclSym(sym, newNimNode(nnkDerefExpr,p).add(t), nnkHiddenDeref)
elif typ.kind == nnkSym and typ.repr == "typedesc":
#echo "repl: ", $sym, " -> ", $p
#echo body.lisprepr
body = body.replaceNonDeclSym(sym, p)
#echo body.repr
else:
pre.add getAst(letX(t, p))
body = body.replaceNonDeclSym(sym, t)
Expand Down
47 changes: 39 additions & 8 deletions src/field/fieldET.nim
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ proc `$`*(x:Field):string =
if i<l.nSites-1: result.add "\n"

template indexField(x:Shifted, y:int):untyped = 0
proc applyOp1(x,y:NimNode; op:string):auto =
proc applyOp1x(x,y:NimNode; op:string):auto =
let o = ident(op)
result = quote do:
let tx = `x`
Expand All @@ -459,6 +459,19 @@ proc applyOp1(x,y:NimNode; op:string):auto =
#mixin isMatrix
#echoAll isMatrix(`x`[e])
`o`(tx[e], ty)
template applyOp1Impl(x,y,o:untyped) =
let tx = `x`
let ty = `y`
#echoImm `x`[0] is VMconcept1
#echoImm t isnot VMconcept2
for e in tx:
mixin `o`
#mixin isMatrix
#echoAll isMatrix(`x`[e])
`o`(tx[e], ty)
proc applyOp1(x,y:NimNode; op:string):auto =
let o = ident(op)
result = getAst(applyOp1Impl(x,y,o))

#[
var exprInstInfo {.compiletime.}: type(instantiationInfo())
Expand All @@ -477,7 +490,7 @@ macro debugExpr(body: typed): untyped =
]#

#proc applyOp2(x,y:NimNode; ty:typedesc; op:string):auto =
proc applyOp2(x,y:NimNode; ty:NimNode; op:string):auto =
proc applyOp2(x,y:NimNode; op:string):auto =
#echo ty.getType.treeRepr
#echo ty.getType.getImpl.treeRepr
let o = ident(op)
Expand All @@ -498,11 +511,29 @@ proc applyOp2(x,y:NimNode; ty:NimNode; op:string):auto =
`o`(xx[e], indexField(yy, e))
staticTraceEnd: `o Field2`
#echo result.treerepr
template makeOps(op,f,fM,s: untyped): untyped {.dirty.} =
macro f*(x:Subsetted; y:notSomeField2):auto = applyOp1(x,y,s)
macro f*(x:Subsetted; y:SomeField2):auto = applyOp2(x,y,int.getType,s)
macro fM*(x:Field; y:notSomeField; ty:typedesc):auto = applyOp1(x,y,s)
macro fM*(x:Field; y:SomeField; ty:typedesc):auto = applyOp2(x,y,ty,s)
#macro id(op:static string):auto =
# result = newIdentNode(op)
#macro id(op:string):auto =
# result = newIdentNode(op.strVal)
#template makeOps2(o,f,fM: untyped) {.dirty.} =
# proc f*(x:Subsetted; y:notSomeField2) =
# for e in x:
# mixin o
# o(tx[e], ty)
template makeOps(op,f,fM,s: untyped) {.dirty.} =
#makeOps2(id(s),f,fM)
#macro f*(x:Subsetted; y:notSomeField2):auto = applyOp1(x,y,s)
proc f*(x:Subsetted; y:notSomeField2) =
for e in x:
mixin f
f(x[e], y)
macro f*(x:Subsetted; y:SomeField2):auto = applyOp2(x,y,s)
#macro fM*(x:Field; y:notSomeField; ty:typedesc):auto = applyOp1(x,y,s)
proc fM*(x:Field; y:notSomeField) =
for e in x:
mixin f
f(x[e], y)
macro fM*(x:Field; y:SomeField):auto = applyOp2(x,y,s)
template f*(x:Field; y:auto):untyped =
#when declaredInScope(subsetObject):
when declared(subsetObject):
Expand All @@ -514,7 +545,7 @@ template makeOps(op,f,fM,s: untyped): untyped {.dirty.} =
else:
#fM(x, y, y.type)
staticTraceBegin: `f FieldAuto`
fM(x, y, int)
fM(x, y)
staticTraceEnd: `f FieldAuto`
when profileEqns:
template op*(x:Field; y:auto):untyped =
Expand Down
12 changes: 8 additions & 4 deletions tests/base/tmasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ var

suite "test random source and masked assignment":
test "random z4 source norm2":
var n = 0.0
threads:
eta.z4 r
var n = eta.norm2
var n2 = eta.norm2
threadMaster:
check(n ~ float(3*lat[0]*lat[1]*lat[2]*lat[3]))
n = n2
check(n ~ float(3*lat[0]*lat[1]*lat[2]*lat[3]))

test "dilution and masked assignment":
for t in 0..<nt:
for dl in dilution(dilute_type):
var n = 0.0
threads:
tmps := 0
threadBarrier()
Expand All @@ -43,8 +46,9 @@ suite "test random source and masked assignment":
# tmps{i}[c].re := eta{i}[c].re
# tmps{i}[c].im := eta{i}[c].im
threadBarrier()
var n = tmps.norm2
var n2 = tmps.norm2
threadMaster:
check(n ~ float(3*lat[0]*lat[1]*lat[2])/2)
n = n2
check(n ~ float(3*lat[0]*lat[1]*lat[2])/2)

qexFinalize()

0 comments on commit bc25510

Please sign in to comment.