Skip to content

Match PETSc object leaks on the syntax tree, not on source text - #249

Merged
boriskaus merged 2 commits into
JuliaParallel:mainfrom
filoferra:audit-ast
Sep 9, 2026
Merged

Match PETSc object leaks on the syntax tree, not on source text#249
boriskaus merged 2 commits into
JuliaParallel:mainfrom
filoferra:audit-ast

Conversation

@filoferra

Copy link
Copy Markdown
Contributor

audit_petsc_file paired object creations with destroy calls by running seven near-identical regexes over each source line. That approach had four defects, all of which the fixture in test/fixtures/leaky.jl now covers:

  • each regex block ended in continue, so only one event per line was recorded; v = VecCreateSeq(...); VecDestroy(petsclib, v) counted the creation and missed the release
  • only whole-line comments were skipped, so # destroy!(dm) and a destroy mentioned inside a string literal both counted as releases
  • only bare and PETSc.-qualified destroy were recognised, so LibPETSc.VecDestroy read as a leak
  • DMPlex objects were not tracked at all, and the high-level Mat/Vec factories (MatSeqAIJ, MatSeqDense, VecSeq, ...) were missed because their names carry no Create or Duplicate marker

Walking the parsed AST collapses the seven blocks into one traversal over two name sets. Destroy calls now record every plain name in the argument list, since the object is the first argument high-level (destroy!(v)) and the second low-level (VecDestroy(petsclib, v)).

Note: audit_petsc_file returns a NamedTuple of created, destroyed, finalized and leaked rather than nothing, so the behaviour can be asserted. It still prints the same report; pass verbose = false to suppress it. Nothing in the repo consumed the old return value.

audit_petsc_file paired object creations with destroy calls by running seven near-identical regexes over each source line.
That approach had four defects, all of which the fixture in test/fixtures/leaky.jl now covers:

- each regex block ended in `continue`, so only one event per line was recorded; `v = VecCreateSeq(...); VecDestroy(petsclib, v)` counted the creation and missed the release
- only whole-line comments were skipped, so `# destroy!(dm)` and a destroy mentioned inside a string literal both counted as releases
- only bare and PETSc.-qualified `destroy` were recognised, so LibPETSc.VecDestroy read as a leak
- DMPlex objects were not tracked at all, and the high-level Mat/Vec factories (MatSeqAIJ, MatSeqDense, VecSeq, ...) were missed because their names carry no Create or Duplicate marker

Walking the parsed AST collapses the seven blocks into one traversal over two name sets. Destroy calls now record every plain name in the argument list, since the object is the first argument high-level (destroy!(v)) and the second low-level (VecDestroy(petsclib, v)).

audit_petsc_file returns a NamedTuple of created, destroyed, finalized and leaked instead of nothing, so the behaviour can be asserted; pass verbose = false to suppress the printed report. Nothing tested this file before.
@boriskaus

Copy link
Copy Markdown
Collaborator

@filoferra can you check the conflicts?

@boriskaus
boriskaus merged commit da814fd into JuliaParallel:main Sep 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants