Skip to content

Make ParticleSystem construction trim-safe - #183

Merged
lmiq merged 2 commits into
mainfrom
trim-safe-particlesystem
Oct 19, 2026
Merged

lmiq merged 2 commits into
mainfrom
trim-safe-particlesystem

Conversation

@lmiq

@lmiq lmiq commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Removes the non-inferable code in the ParticleSystem constructors that blocks compiling packages that use CellListMap with juliac --trim=safe. Found while compiling Packmol.jl to a standalone executable. None of the changes break existing code.

Changes

  • ParticleSystemPositions.updated is now a concrete Base.RefValue{Bool} instead of the abstract Ref{Bool}. Every updated[] read and write was a dynamic call (CellLists.jl, NonPeriodicCells.jl).
  • The constructor no longer reassigns output. That variable is captured by the comprehension that builds the threaded outputs, so it was boxed (Core.Box). With reset = false, _reset_all_output! returns output unchanged, so the assignment did nothing.
  • New get_dim method for SVector coordinates. It takes the dimension from the coordinate type, so Val(DIM) is a compile-time constant even when the unit cell is a Vector/Matrix. The unit cell size is still checked at runtime.
  • New feature: output_name now also accepts a Val, e.g. output_name = Val(:forces). The defaults are now Vals, so constructing without output_name is fully inferable. Passing a Symbol works exactly as before, through a dynamic call. InPlaceNeighborList now passes Val(:nb) internally.

Changelog and docs

  • CHANGELOG.md: under 0.10.6-DEV, a FEATURE entry for output_name = Val(...) and an ENHANCEMENT entry for type-stable construction.
  • Docs: new "Type-stable construction" section in ParticleSystem/options.md (when the constructor is inferable, with a runnable example, and why it matters for juliac --trim), linked from the paragraph in single_set_simple.md that introduces output_name. That paragraph's broken sentence ("the output value from the system.output field") is fixed too.
  • The docs build succeeds locally. The only warning is the existing large-output one on examples.md.

Testing

  • New test item, "ParticleSystem constructor type stability": checks @inferred on the keyword constructor (one and two position sets; unitcell as Vector, Matrix, SVector, and nothing), that Symbol names still work, and that a dimension mismatch still throws.
  • The full test suite passes locally (Julia 1.12).
  • Trim check: I built Packmol.jl with juliac --trim=safe. Verifier errors raised inside CellListMap's own source dropped from 32 (v0.10.5) to 0. The remaining ones are on the Packmol side.

🤖 Generated with Claude Code

lmiq and others added 2 commits October 15, 2026 21:39
Remove the sources of non-inferable code in the ParticleSystem constructors
that prevent compiling code using CellListMap with `juliac --trim=safe`:

- `ParticleSystemPositions.updated` is now a concrete `Base.RefValue{Bool}`
  instead of the abstract `Ref{Bool}`.
- The constructor no longer reassigns `output`, which was captured by the
  comprehension creating the threaded outputs (boxed variable). The
  reassignment was a no-op with `reset = false`.
- `get_dim` returns the dimension from the coordinate type when coordinates
  are vectors of `SVector`s, so the dimension is a compile-time constant even
  when the unit cell is given as a dynamic array (unitcell size still checked).
- `output_name` accepts a `Val` in addition to a `Symbol`; defaults are now
  `Val`s, so the default construction path is fully inferable. Passing a
  `Symbol` still works as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document `output_name = Val(...)` as a new feature and add a
"Type-stable construction" section to the options page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.53%. Comparing base (e9c7540) to head (64eb4d1).

Files with missing lines Patch % Lines
src/internals/auxiliary_functions.jl 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
- Coverage   98.65%   98.53%   -0.12%     
==========================================
  Files          21       21              
  Lines        1632     1640       +8     
==========================================
+ Hits         1610     1616       +6     
- Misses         22       24       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lmiq
lmiq merged commit 4daab0c into main Oct 19, 2026
18 of 20 checks passed
@lmiq
lmiq deleted the trim-safe-particlesystem branch October 19, 2026 11:54
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.

1 participant