Skip to content

Commit

Permalink
- reverts "- attempting to reduce branch coverage overhead under Pyth…
Browse files Browse the repository at this point in the history
…on 3.12;",

  as that didn't reduce overhead.  This reverts commit 7ce89fb.
  • Loading branch information
jaltmayerpizzorno committed Oct 26, 2023
1 parent 7ce89fb commit 1907956
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/slipcover/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ def __init__(self):
pass

def _mark_branch(self, from_line: int, to_line: int) -> List[ast.stmt]:
mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())],
ast.Tuple([ast.Constant(from_line), ast.Constant(to_line)], ast.Load()))

if sys.version_info[0:2] == (3,12):
mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())], ast.Constant(0))
for node in ast.walk(mark):
node.lineno = node.end_lineno = encode_branch(from_line, to_line)

elif sys.version_info[0:2] == (3,11):
for node in ast.walk(mark):
node.lineno = 0 # we ignore line 0, so this avoids generating extra line probes
else:
mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())],
ast.Tuple([ast.Constant(from_line), ast.Constant(to_line)], ast.Load()))

if sys.version_info[0:2] == (3,11):
for node in ast.walk(mark):
node.lineno = 0 # we ignore line 0, so this avoids generating extra line probes
else:
for node in ast.walk(mark):
node.lineno = from_line
for node in ast.walk(mark):
node.lineno = from_line

return [mark]

Expand Down
13 changes: 2 additions & 11 deletions tests/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def get_branches(code):

elif const is not None:
if inst.opname in ('STORE_NAME', 'STORE_GLOBAL') and inst.argval == br.BRANCH_NAME:
if PYTHON_VERSION >= (3,12) and br.is_branch(inst.positions.lineno):
branches.append(br.decode_branch(inst.positions.lineno))
else:
branches.append(const)
branches.append(const)

const = None

Expand All @@ -50,16 +47,10 @@ def __init__(self):
def visit_Assign(self, node: ast.Assign) -> ast.Assign:
if node.targets and isinstance(node.targets[0], ast.Name) \
and node.targets[0].id == br.BRANCH_NAME:
if PYTHON_VERSION >= (3,12) and br.is_branch(node.lineno):
branch = br.decode_branch(node.lineno)
value = ast.Tuple([ast.Constant(branch[0]), ast.Constant(branch[1])], ast.Load())
value.lineno, value.end_lineno = node.lineno, node.end_lineno
else:
value = node.value
return ast.AugAssign(
target=node.targets[0],
op=ast.Add(),
value=ast.List(elts=[value], ctx=ast.Load()),
value=ast.List(elts=[node.value], ctx=ast.Load()),
ctx=ast.Load())

return node
Expand Down

0 comments on commit 1907956

Please sign in to comment.