Skip to content

Gecode 7: pass large parameters by const reference - #288

Open
zayenz wants to merge 6 commits into
feature/breaking-7-04-empty-arraysfrom
feature/breaking-7-05-value-params
Open

zayenz wants to merge 6 commits into
feature/breaking-7-04-empty-arraysfrom
feature/breaking-7-05-value-params

Conversation

@zayenz

@zayenz zayenz commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Several Gecode APIs took owned handles, argument arrays, callbacks, and FloatVal by value even when they only read them, paying for reference-count updates or allocations on every call. This PR enables performance-unnecessary-value-param and updates the codebase to match.

The parameter rule added to docs/code-style.md splits types into two groups:

  • Shallow handles stay passed by value (listed in the check's AllowedTypes): Home, groups, Pos, Reify, variables (IntVar, etc.), variable arrays, ViewArray, open lists, and views. Copying one copies a few pointers or ids with no allocation or reference count.
  • Reference-counted and owning types (SharedHandle subclasses such as IntSet, TupleSet, DFA, Rnd, Action, and CHB, SharedArray, *Args, REG, strings, and callbacks) along with FloatVal (two doubles, not a handle) are now taken by const& when only read, or taken by value and moved with std::move when stored.

Most of the diff is mechanical, split into commits by area to keep review manageable:

  • Branch configuration handles, moving brancher filter and print callbacks into SharedData storage so they are moved rather than copied.
  • CBS hooks, shared posting data, execution callbacks, open lists, and tracing.
  • FlatZinc, Gist, search, tests, and examples.
  • FloatVal, in its own commit.

The last commit enables performance-unnecessary-value-param in .clang-tidy and documents the rule in docs/code-style.md.

Stack

Merge in this order. #242, #282, #283, #241, #284, and #285 are merged. #286 targets main, and each later PR builds on the one before it so its diff shows only its own commits. The first four PRs are standalone search and random-number changes; #284 through #274 are the Gecode 7 changes split out of what used to be a single branch.

  1. Rank solutions with Space::compare in best-solution search #242 Rank solutions with Space::compare (merged)
  2. Rename the meta-search hooks to hub and spoke #282 Rename the meta-search hooks to hub and spoke (merged)
  3. Give meta search hub and spoke contexts and report why search ended #283 Hub and spoke contexts and end reasons (merged)
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators (merged)
  5. Gecode 7: CMake-only C++23 build baseline #284 Gecode 7: build baseline (merged)
  6. Gecode 7: format the sources with LLVM 22 #285 Gecode 7: reformat (merged)
  7. Gecode 7: normalized API names, LT constants and Clang checks #286 Gecode 7: API names, LT constants, checks
  8. Gecode 7: post nothing for empty arrays #287 Gecode 7: empty arrays
  9. Gecode 7: pass large parameters by const reference #288 Gecode 7: const& parameters ← this PR
  10. Gecode 7: state and assert the heap size contract #289 Gecode 7: heap contract
  11. Gecode 7: trivially copyable handles and defaulted special members #290 Gecode 7: modern classes
  12. Gecode 7: native float interval instead of Boost #291 Gecode 7: native float interval
  13. Gecode 7: bug fixes and Doxygen warnings #292 Gecode 7: bug fixes and Doxygen
  14. Gecode 7: scoped enums and descriptive constant names #293 Gecode 7: scoped enums
  15. Gecode 7: clang-tidy sweep #274 Gecode 7: clang-tidy sweep
  16. Add down_cast and a typed Space::clone #294 down_cast and a typed Space::clone

Summary by CodeRabbit

  • API Changes
    • Gecode 7.0.0 updates parameter signatures across branching, assignment, floating-point constraints, tracing, and other APIs. Calls generally compile unchanged, but overrides of `solution-distribution or domain-size-sum methods must now use const-reference parameters.
    • Functions that retain by-value arguments now require those types to be movable.
  • Performance
    • Callback and other retained values are moved into place where supported, while shallow handles continue to be passed by value.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1af61cb9-aa10-42b8-856b-413163c038dd
Commits

Reviewing files that changed from the base of the PR and between 3300f02 and 52dad66.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Changes: Parameter and ownership updates

Layer / File(s) Summary
Parameter-passing rules and examples
.clang-tidy, changelog.in, docs/code-style.md, examples/*
The clang-tidy configuration enables performance-unnecessary-value-param and lists allowed shallow-handle types. The style guide and changelog document const-reference and move conventions. Two examples change parameters to const references.
Kernel storage and callback ownership
gecode/kernel/branch/*, gecode/kernel/data/shared-data.hpp, gecode/kernel/propagator/wait.hpp, gecode/kernel/trace/*, gecode/*/exec.cpp, test/array.cpp, test/instance.cpp, test/int/min-distance.cpp, test/search.cpp, test/test.cpp
Kernel branch objects, wait propagators, and trace recorders move callbacks into storage or forwarding calls. SharedData adds a constrained move-taking constructor and retains its copy-taking constructor. Related callbacks and retained values are moved in other execution and test paths. A test checks SharedData construction with copyable, non-movable data.
Integer, Boolean, and FlatZinc branching
gecode/int.hh, gecode/int/branch/*, gecode/int/ldsb*, gecode/flatzinc/branch*, gecode/flatzinc/flatzinc.cpp, test/branch/int.cpp, test/int/open-var-list.cpp, test/ldsb.cpp, test/nogoods.cpp
Integer and Boolean branching declarations and implementations use const references for strategy objects. Branching and LDSB forwarding paths move filters and print callbacks. FlatZinc selectors and related tests use the updated parameter conventions.
Float branching APIs and forwarding
gecode/float.hh, gecode/float/branch*
Float branching and assignment strategies use const-reference parameters where applicable. Posting and forwarding paths move filters and print callbacks.
Float constraints, views, and expressions
gecode/float.hh, gecode/float/*, gecode/minimodel.hh, gecode/minimodel/float-*, test/float*, test/search.cpp
Float constraint, view, expression, test, relaxation, and tracing parameters change to const references where applicable. The shown constraint and comparison logic remains unchanged.
Integer constraints, sequences, and tracing
gecode/int.hh, gecode/int/count*, gecode/int/distinct*, gecode/int/element.cpp, gecode/int/extensional*, gecode/int/sequence*, gecode/int/relax.cpp, gecode/int/trace.cpp, test/int/extensional.cpp
Integer counting, distinct, element, extensional, and sequence APIs use const references for read-only parameters. Integer and Boolean relaxation and tracing declarations also use const references.
Set branching, weights, and LDSB
gecode/set.hh, gecode/set/*
Set branching strategies and shared arrays use const references. Branching and LDSB paths move callbacks. Relaxation and tracing parameters use const references.
FlatZinc, Gist, and minimodel integrations
gecode/flatzinc/blackbox-propagator.cpp, gecode/flatzinc/parser*, gecode/gist*, gecode/minimodel*, gecode/search/cpprofiler/tracer.cpp, test/flatzinc.cpp, test/int/gcc.cpp, test/test.cpp, .github/ci/*gist-consumer-smoke.sh
FlatZinc parser and black-box paths, Gist names, minimodel inputs, and profiler names update parameter passing or ownership transfer. Related test helpers use the updated conventions.

Possibly related PRs

  • Gecode/gecode#291: It changes FloatVal and Float::ScaleView type properties related to the value-parameter rule enabled here.

Change: Refactor

Merge Risk: Low · previous review 3300f

This change switches many Gecode API parameters to const references or move semantics. It is documented in the changelog as an ABI change, so downstream code needs to be recompiled, and custom propagator overrides must be updated. No concrete defect was found in the reviewed changes.

Security architecture risk: Low · up to 3300f

The main risk is binary compatibility, not expanded access. If a build from this revision replaces the previous shared libraries without a new ABI version, applications built against the old signatures can fail to load or resolve symbols. The break is documented for the unreleased Gecode 7, and the updated consumer checks target the new signatures.

Retained concerns

  • Low · architecture · inferred: The head changes public binary signatures but retains the base shared-library ABI version. If this build is distributed as a replacement, the loader can select it for an older consumer even though changed symbols no longer match. The unreleased Gecode 7 heading documents the intended break but does not isolate intermediate builds or make a library-only rollback compatible.
Security review details

Trust Boundaries and Controls

  • observed — In the inspected open-list path, the PR forwards the same caller-supplied filter and printer to the existing brancher policies. It retains the posting guard and selector validation rather than adding an alternate route around either check.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 0ad59182-9f5d-4b7b-a699-36046653f2dd
Commits

Reviewing files that changed from the base of the PR and between 99fcd12 and 3300f02.

Files selected for processing: 2

  • docs/code-style.md
  • gecode/kernel/branch/tiebreak.hpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch from a615343 to 79999e4 Compare November 25, 2026 19:47
@zayenz
zayenz added this pull request to stack #295 November 25, 2026 20:41
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch from 79999e4 to d0c8ee2 Compare November 25, 2026 21:54
@zayenz
zayenz removed this pull request from stack #295 November 25, 2026 21:55
@zayenz
zayenz added this pull request to stack #296 November 25, 2026 21:55
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch from d0c8ee2 to 0290101 Compare November 26, 2026 06:05
@zayenz
zayenz marked this pull request as ready for review November 26, 2026 06:06
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch 2 times, most recently from ebf4677 to 7855336 Compare November 26, 2026 06:13
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch 2 times, most recently from ddb2042 to 99fcd12 Compare November 26, 2026 16:24
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch from 99fcd12 to 3300f02 Compare November 26, 2026 19:14
Zdev-Change-Id: Zcab7b04117e00a1fae0ceb57e7f08b8ef521927647e15241606b165f7a4eb00e
Zdev-Change-Id: Z757c255838d9ab5582918cb98071b2660dbb370a68149ff589c16d34f4410986
…and tracing

Zdev-Change-Id: Zf998dffd1006fff50b23b42adcc1fc221887df0830b7a06397c01341484cce7d
The Qt consumer smokes take the string of Comparator::compare by const
reference to match.

Zdev-Change-Id: Za9107647ee8a830efc792dd21dd7b38a4435f208b81cc6f685607cf606421094
Zdev-Change-Id: Z9c9aa854f95a78c2fbb7e6930e3b50733187129e78720bdcdb1a830d578321ad
… rule

Zdev-Change-Id: Z866642b8abb6de44b9e3b3ba31eea59a5ee562ec86fa93292ba9ce73ab1d698a
@zayenz
zayenz force-pushed the feature/breaking-7-05-value-params branch from 3300f02 to 52dad66 Compare November 26, 2026 19:48

This branch has not been deployed

No deployments
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