diff --git a/compiler/ast/trees.nim b/compiler/ast/trees.nim index c0e770e26e3a4..fc643ec6b0610 100644 --- a/compiler/ast/trees.nim +++ b/compiler/ast/trees.nim @@ -72,30 +72,33 @@ template structEquiv*( if not self(a[i], b[i]): return false result = true -proc exprStructuralEquivalentLaxSym(a, b: PNode): bool = - structEquiv(exprStructuralEquivalentLaxSym, +proc exprStructuralEquivalent*(a, b: PNode): bool = + structEquiv(exprStructuralEquivalent, relaxKindCheck = false, # don't go nuts here: same symbol as string is enough: symCheck = a.sym.name.id == b.sym.name.id, floatCheck = sameFloatIgnoreNan(a.floatVal, b.floatVal), - commentCheck = a.comment == b.comment, + commentCheck = true, typeCheck = true ) -proc exprStructuralEquivalentStrictSym(a, b: PNode): bool = +proc exprStructuralEquivalentStrictSym*(a, b: PNode): bool = structEquiv(exprStructuralEquivalentStrictSym, relaxKindCheck = false, symCheck = a.sym == b.sym, floatCheck = sameFloatIgnoreNan(a.floatVal, b.floatVal), - commentCheck = a.comment == b.comment, + commentCheck = true, typeCheck = true ) -proc exprStructuralEquivalent*(a, b: PNode; strictSymEquality=false): bool = - if strictSymEquality: - exprStructuralEquivalentStrictSym(a, b) - else: - exprStructuralEquivalentLaxSym(a, b) +proc exprStructuralEquivalentStrictSymAndComm*(a, b: PNode): bool = + structEquiv(exprStructuralEquivalentStrictSymAndComm, + relaxKindCheck = false, + symCheck = a.sym == b.sym, + floatCheck = sameFloatIgnoreNan(a.floatVal, b.floatVal), + commentCheck = a.comment == b.comment, + typeCheck = true + ) proc getMagic*(op: PNode): TMagic = if op == nil: return mNone diff --git a/compiler/ic/replayer.nim b/compiler/ic/replayer.nim index 94ef7d6ee2609..2b9b4976ff8eb 100644 --- a/compiler/ic/replayer.nim +++ b/compiler/ic/replayer.nim @@ -101,7 +101,7 @@ proc replayStateChanges*(module: PSym; g: ModuleGraph) = else: block search: for existing in g.cacheSeqs[destKey]: - if exprStructuralEquivalent(existing, val, strictSymEquality = true): + if exprStructuralEquivalentStrictSymAndComm(existing, val): # comment equality DOES matter here break search g.cacheSeqs[destKey].add val diff --git a/compiler/sem/semfold.nim b/compiler/sem/semfold.nim index 78196c7d369bb..7936b6120f68d 100644 --- a/compiler/sem/semfold.nim +++ b/compiler/sem/semfold.nim @@ -379,7 +379,7 @@ proc evalOp*(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): result.typ = n.typ of mEqProc: result = newIntNodeT(toInt128(ord( - exprStructuralEquivalent(a, b, strictSymEquality=true))), n, idgen, g) + exprStructuralEquivalentStrictSym(a, b))), n, idgen, g) # comment equality doesn't matter here (getConstExpr doesn't return AST with comments) else: discard diff --git a/compiler/vm/vm.nim b/compiler/vm/vm.nim index 4f1d28f94cc8c..4a908ff883fb7 100644 --- a/compiler/vm/vm.nim +++ b/compiler/vm/vm.nim @@ -1550,8 +1550,7 @@ proc rawExecute(c: var TCtx, t: var VmThread, pc: var int): YieldReason = of opcEqNimNode: decodeBC(rkInt) regs[ra].intVal = - ord(exprStructuralEquivalent(regs[rb].nimNode, regs[rc].nimNode, - strictSymEquality=true)) + ord(exprStructuralEquivalentStrictSymAndComm(regs[rb].nimNode, regs[rc].nimNode)) # comment equality DOES matter here of opcSameNodeType: decodeBC(rkInt) @@ -2835,7 +2834,7 @@ proc rawExecute(c: var TCtx, t: var VmThread, pc: var int): YieldReason = else: block search: for existing in g.cacheSeqs[destKey]: - if exprStructuralEquivalent(existing, val, strictSymEquality=true): + if exprStructuralEquivalentStrictSymAndComm(existing, val): # comment equality DOES matter here break search g.cacheSeqs[destKey].add val