forked from Consensys/gnark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lighter stack trace by default for circuits, more verbose when …
…-tags=debug provided
- Loading branch information
Showing
9 changed files
with
112 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package debug | ||
|
||
import ( | ||
"path/filepath" | ||
"runtime" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var light = true | ||
|
||
func Stack() string { | ||
var sbb strings.Builder | ||
WriteStack(&sbb) | ||
return sbb.String() | ||
} | ||
|
||
func WriteStack(sbb *strings.Builder) { | ||
// derived from: https://golang.org/pkg/runtime/#example_Frames | ||
// we stop when func name == Define as it is where the gnark circuit code should start | ||
|
||
// Ask runtime.Callers for up to 10 pcs | ||
pc := make([]uintptr, 10) | ||
n := runtime.Callers(3, pc) | ||
if n == 0 { | ||
// No pcs available. Stop now. | ||
// This can happen if the first argument to runtime.Callers is large. | ||
return | ||
} | ||
pc = pc[:n] // pass only valid pcs to runtime.CallersFrames | ||
frames := runtime.CallersFrames(pc) | ||
// Loop to get frames. | ||
// A fixed number of pcs can expand to an indefinite number of Frames. | ||
for { | ||
frame, more := frames.Next() | ||
fe := strings.Split(frame.Function, "/") | ||
function := fe[len(fe)-1] | ||
file := frame.File | ||
|
||
if light { | ||
if strings.Contains(function, "runtime.gopanic") { | ||
continue | ||
} | ||
if strings.Contains(function, "frontend.(*constraintSystem)") { | ||
continue | ||
} | ||
if strings.Contains(frame.File, "test/engine.go") { | ||
continue | ||
} | ||
if strings.Contains(frame.File, "gnark/frontend") { | ||
continue | ||
} | ||
file = filepath.Base(file) | ||
} | ||
|
||
sbb.WriteString(function) | ||
sbb.WriteByte('\n') | ||
sbb.WriteByte('\t') | ||
sbb.WriteString(file) | ||
sbb.WriteByte(':') | ||
sbb.WriteString(strconv.Itoa(frame.Line)) | ||
sbb.WriteByte('\n') | ||
if !more { | ||
break | ||
} | ||
if strings.HasSuffix(function, "Define") { | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build debug | ||
// +build debug | ||
|
||
package debug | ||
|
||
func init() { | ||
light = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters