Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sequence point coverage for debug info #3639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.AssignStmt:
c.saveSequencePoint(n)
Copy link
Member

@AnnaShaleva AnnaShaleva Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a lot of tests for it. It's easy to place these missing lines of code to every AST node handler, I don't need an issue for that. But it's not a solution. What we need is to ensure that the resulting sequence points are:

  1. Properly generated and match the expectations.
  2. There are no duplicating sequence points.
  3. Match (or at least relatively match) the corresponding C# debugger output for similar AST nodes.
  4. There are no more statements that don't have corresponding sequence points.

// Filter out type assertion with two return values: i, ok = v.(int)
if len(n.Lhs) == 2 && len(n.Rhs) == 1 && (n.Tok == token.DEFINE || n.Tok == token.ASSIGN) {
err := checkTypeAssertWithOK(n.Rhs[0])
Expand Down Expand Up @@ -753,6 +754,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.ReturnStmt:
c.saveSequencePoint(n)
l := c.newLabel()
c.setLabel(l)

Expand Down Expand Up @@ -799,6 +801,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.IfStmt:
c.saveSequencePoint(n)
c.scope.vars.newScope()
defer c.scope.vars.dropScope()

Expand Down Expand Up @@ -827,6 +830,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.SwitchStmt:
c.saveSequencePoint(n)
eqOpcode := opcode.EQUAL
if n.Tag != nil {
ast.Walk(c, n.Tag)
Expand Down Expand Up @@ -973,6 +977,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.CallExpr:
c.saveSequencePoint(n)
var (
f *funcScope
ok bool
Expand Down Expand Up @@ -1108,6 +1113,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.DeferStmt:
c.saveSequencePoint(n)
catch := c.newLabel()
finally := c.newLabel()
param := make([]byte, 8)
Expand Down Expand Up @@ -1183,6 +1189,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.IncDecStmt:
c.saveSequencePoint(n)
ast.Walk(c, n.X)
c.emitToken(n.Tok, c.typeOf(n.X))

Expand All @@ -1204,6 +1211,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.BranchStmt:
c.saveSequencePoint(n)
var label string
if n.Label != nil {
label = n.Label.Name
Expand Down Expand Up @@ -1238,6 +1246,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.BlockStmt:
c.saveSequencePoint(n)
c.scope.vars.newScope()
defer c.scope.vars.dropScope()

Expand All @@ -1248,6 +1257,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.ForStmt:
c.saveSequencePoint(n)
c.scope.vars.newScope()
defer c.scope.vars.dropScope()

Expand Down Expand Up @@ -1293,6 +1303,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil

case *ast.RangeStmt:
c.saveSequencePoint(n)
c.scope.vars.newScope()
defer c.scope.vars.dropScope()

Expand Down Expand Up @@ -1403,6 +1414,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
// For this to work properly, we only need to walk the expression
// which is not the assertion type.
case *ast.TypeAssertExpr:
c.saveSequencePoint(n)
ast.Walk(c, n.X)
if c.isCallExprSyscall(n.X) {
return nil
Expand Down
Loading