summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semfold.nim3
-rw-r--r--compiler/trees.nim12
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index b83641706..9a0c856dc 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -437,6 +437,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
      mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym, mSpawn,
      mParallel, mPlugin:
     discard
+  of mEqProc:
+    result = newIntNodeT(ord(
+        exprStructuralEquivalent(a, b, strictSymEquality=true)), n)
   else: internalError(a.info, "evalOp(" & $m & ')')
 
 proc getConstIfExpr(c: PSym, n: PNode): PNode =
diff --git a/compiler/trees.nim b/compiler/trees.nim
index 2c631af99..659df334b 100644
--- a/compiler/trees.nim
+++ b/compiler/trees.nim
@@ -36,15 +36,18 @@ proc cyclicTree*(n: PNode): bool =
   var s = newNodeI(nkEmpty, n.info)
   result = cyclicTreeAux(n, s)
 
-proc exprStructuralEquivalent*(a, b: PNode): bool =
+proc exprStructuralEquivalent*(a, b: PNode; strictSymEquality=false): bool =
   result = false
   if a == b:
     result = true
   elif (a != nil) and (b != nil) and (a.kind == b.kind):
     case a.kind
     of nkSym:
-      # don't go nuts here: same symbol as string is enough:
-      result = a.sym.name.id == b.sym.name.id
+      if strictSymEquality:
+        result = a.sym == b.sym
+      else:
+        # don't go nuts here: same symbol as string is enough:
+        result = a.sym.name.id == b.sym.name.id
     of nkIdent: result = a.ident.id == b.ident.id
     of nkCharLit..nkInt64Lit: result = a.intVal == b.intVal
     of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal
@@ -53,7 +56,8 @@ proc exprStructuralEquivalent*(a, b: PNode): bool =
     else:
       if sonsLen(a) == sonsLen(b):
         for i in countup(0, sonsLen(a) - 1):
-          if not exprStructuralEquivalent(a.sons[i], b.sons[i]): return
+          if not exprStructuralEquivalent(a.sons[i], b.sons[i],
+                                          strictSymEquality): return
         result = true
 
 proc sameTree*(a, b: PNode): bool =
>
c4e143d6 ^
ce2e604e ^

a17f9186 ^


af023b32 ^
555d95c1 ^
a17f9186 ^











1f7e3c05 ^
08cf048f ^
a17f9186 ^




66abe7c1 ^






6808ff7d ^
a17f9186 ^

6808ff7d ^

af023b32 ^
1f7e3c05 ^
af023b32 ^


66abe7c1 ^
6808ff7d ^
66abe7c1 ^









6808ff7d ^
a17f9186 ^
6808ff7d ^
af023b32 ^
a2a20225 ^
87196c34 ^
af023b32 ^


87196c34 ^
af023b32 ^






6808ff7d ^
a17f9186 ^
6808ff7d ^

9cfd925a ^
1ead3562 ^
15f79a66 ^
6808ff7d ^
15f79a66 ^




acc4792d ^
87196c34 ^
a2a20225 ^





87196c34 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120