@@ -3,10 +3,12 @@ package cmd
33import (
44 "fmt"
55 "os"
6+ "slices"
67 "sort"
78
89 "github.com/consensys/gnark-crypto/ecc/bls12-377/fr"
910 "github.com/consensys/go-corset/pkg/trace"
11+ "github.com/consensys/go-corset/pkg/util/collection/set"
1012 "github.com/consensys/go-corset/pkg/util/field"
1113 "github.com/spf13/cobra"
1214)
@@ -28,10 +30,20 @@ var traceDiffCmd = &cobra.Command{
2830 // Read trace files
2931 tracefile1 := ReadTraceFile (filename1 )
3032 tracefile2 := ReadTraceFile (filename2 )
33+ // Extract column names
34+ trace1cols := extractColumnNames (tracefile1 .Columns )
35+ trace2cols := extractColumnNames (tracefile2 .Columns )
3136 // Sanity check
32- if len (tracefile1 .Columns ) != len (tracefile2 .Columns ) {
33- fmt .Printf ("differing number of columns (%d v %d)" , len (tracefile1 .Columns ), len (tracefile2 .Columns ))
34- os .Exit (2 )
37+ if ! slices .Equal (trace1cols , trace2cols ) {
38+ var common set.SortedSet [string ]
39+ //
40+ common .InsertSorted (& trace1cols )
41+ common .Intersect (& trace2cols )
42+ //
43+ reportExtraColumns (filename1 , trace1cols , common )
44+ reportExtraColumns (filename2 , trace2cols , common )
45+ tracefile1 .Columns = filterCommonColumns (tracefile1 .Columns , common )
46+ tracefile2 .Columns = filterCommonColumns (tracefile2 .Columns , common )
3547 }
3648 //
3749 errors := parallelDiff (tracefile1 .Columns , tracefile2 .Columns )
@@ -42,6 +54,36 @@ var traceDiffCmd = &cobra.Command{
4254 },
4355}
4456
57+ func extractColumnNames (columns []trace.RawColumn ) set.SortedSet [string ] {
58+ var names set.SortedSet [string ]
59+ //
60+ for _ , c := range columns {
61+ names .Insert (c .QualifiedName ())
62+ }
63+ //
64+ return names
65+ }
66+
67+ func reportExtraColumns (name string , columns []string , common set.SortedSet [string ]) {
68+ for _ , c := range columns {
69+ if ! common .Contains (c ) {
70+ fmt .Printf ("column %s only in trace %s\n " , c , name )
71+ }
72+ }
73+ }
74+
75+ func filterCommonColumns (columns []trace.RawColumn , common set.SortedSet [string ]) []trace.RawColumn {
76+ var ncolumns []trace.RawColumn
77+ //
78+ for _ , c := range columns {
79+ if common .Contains (c .QualifiedName ()) {
80+ ncolumns = append (ncolumns , c )
81+ }
82+ }
83+ //
84+ return ncolumns
85+ }
86+
4587func parallelDiff (columns1 []trace.RawColumn , columns2 []trace.RawColumn ) []error {
4688 errors := make ([]error , 0 )
4789 ncols := len (columns1 )
0 commit comments