Skip to content

Commit

Permalink
only use recorded liveness version info during slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed Apr 17, 2021
1 parent 07da04f commit 247dafe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 1 addition & 7 deletions nbsafety/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,8 @@ def _get_cell_dependencies(
dependencies.add(cell_num)

# Retrieve cell numbers for the dependent symbols
cell = self.cell_content_by_counter[cell_num]
live_symbols = self._check_cell_and_resolve_symbols(cell)['live']
dep_cell_nums = set(
dep_symbol.defined_cell_num for dep_symbol in live_symbols
)
# Add dynamic and static dependencies
dep_cell_nums = dep_cell_nums | cell_num_to_dynamic_deps[cell_num]
dep_cell_nums = dep_cell_nums | cell_num_to_static_deps[cell_num]
dep_cell_nums = cell_num_to_dynamic_deps[cell_num] | cell_num_to_static_deps[cell_num]
logger.info("dynamic cell deps for %d: %s", cell_num,
cell_num_to_dynamic_deps[cell_num])
logger.info("static cell deps for %d: %s", cell_num,
Expand Down
20 changes: 19 additions & 1 deletion test/test_dynamic_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def test_imports():
assert deps == {1, 2, 3}, 'got %s' % deps


@skipif_known_failing
def test_handle_stale():
run_cell('a = 1')
run_cell('b = 2 * a')
Expand Down Expand Up @@ -120,3 +119,22 @@ def test_version_used_when_live():
run_cell('logging.info(x + y)')
deps = set(nbs().get_cell_dependencies(4).keys())
assert deps == {1, 2, 3, 4}, 'got %s' % deps


def test_no_definitely_spurious_cells():
run_cell('x = 0')
run_cell("""
if True:
y = 7
else:
# even though this branch is not taken,
# liveness-based usage should detect the
# version of `x` used at the time it was
# live, meaning cell 1 should get included
# in the slice
logging.info(x)
""")
run_cell('x = 5')
run_cell('logging.info(y)')
deps = set(nbs().get_cell_dependencies(4).keys())
assert deps == {1, 2, 4}, 'got %s' % deps

0 comments on commit 247dafe

Please sign in to comment.