Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 38 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
# Use clang-tidy 22. Keep checks focused on correctness and useful modernization.
Checks: >-
-*,
clang-analyzer-core.*,
bugprone-assert-side-effect,
bugprone-dangling-handle,
bugprone-inaccurate-erase,
bugprone-integer-division,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-sizeof-expression,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-memset-usage,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
modernize-deprecated-headers,
modernize-use-nullptr,
modernize-use-override,
performance-avoid-endl,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param
readability-identifier-naming
WarningsAsErrors: '*'
HeaderFilterRegex: '(gecode|test|examples|tools)/'
ExcludeHeaderFilterRegex: 'gecode/third-party/|gecode/flatzinc/(parser\.tab\.(cpp|hpp)|lexer\.yy\.cpp)$'
FormatStyle: file

CheckOptions:
# Explicit discards document intentional ownership handoffs.
bugprone-unused-return-value.AllowCastToVoid: true
readability-identifier-naming.FunctionCase: lower_case
readability-identifier-naming.MethodCase: lower_case
readability-identifier-naming.VariableCase: lower_case
readability-identifier-naming.MemberCase: lower_case
readability-identifier-naming.ParameterCase: lower_case
readability-identifier-naming.EnumConstantCase: UPPER_CASE
readability-identifier-naming.ConstantCase: lower_case
# Constants and functions standing for constant values, such as
# ME_INT_VAL, ES_SUBSUMED, and INT_VAR_SIZE_MIN, may use UPPER_CASE.
readability-identifier-naming.ConstantIgnoredRegexp: '^(_?[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_|[A-Z][A-Z0-9_]*)$'
readability-identifier-naming.FunctionIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[A-Z][A-Z0-9_]*)$'
readability-identifier-naming.MethodIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[A-Z][A-Z0-9_]*)$'
readability-identifier-naming.VariableIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$'
readability-identifier-naming.MemberIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$'
readability-identifier-naming.ParameterIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$'
readability-identifier-naming.EnumConstantIgnoredRegexp: '^[A-Z][A-Z0-9_]*_$'
# New scoped enums name their constants in PascalCase, as EndReason::Limit;
# scoped enums converted from plain enums keep UPPER_CASE.
readability-identifier-naming.ScopedEnumConstantCase: UPPER_CASE
readability-identifier-naming.ScopedEnumConstantIgnoredRegexp: '^([A-Z][a-zA-Z0-9]*|[A-Z][A-Z0-9_]*_)$'
13 changes: 5 additions & 8 deletions .github/ci/generated-source-freshness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ vis_files=(

# Copy generator inputs with their source-relative paths. Generated outputs stay
# isolated until --update explicitly copies them back to the source tree.
# The copy goes through an archive file: in a pipe, bsdtar may stop reading
# at the end-of-archive marker before the writer has written its final
# padding, which fails the writer with a write error.
tar -C "$repo_root" -cf "$workspace/source.tar" \
.clang-format misc/genvarimp.py "${vis_files[@]}" \
gecode/flatzinc/parser.yxx gecode/flatzinc/lexer.lxx
tar -C "$source_copy" -xf "$workspace/source.tar"
rm -f -- "$workspace/source.tar"
for input in .clang-format misc/genvarimp.py "${vis_files[@]}" \
gecode/flatzinc/parser.yxx gecode/flatzinc/lexer.lxx; do
mkdir -p "$source_copy/$(dirname "$input")"
cp "$repo_root/$input" "$source_copy/$input"
done
mkdir -p "$source_copy/gecode/kernel"

normalize_generated_whitespace() {
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,56 @@ jobs:
shell: bash
run: uv run misc/tidy.py --check

check-extended:
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0

- name: Install uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39
with:
enable-cache: false

- name: Install LLVM 22 and check dependencies
shell: bash
run: |
curl --fail --location --retry 3 https://apt.llvm.org/llvm-snapshot.gpg.key -o "$RUNNER_TEMP/llvm.asc"
sudo install -m 644 "$RUNNER_TEMP/llvm.asc" /usr/share/keyrings/llvm.asc
echo 'deb [signed-by=/usr/share/keyrings/llvm.asc] https://apt.llvm.org/noble/ llvm-toolchain-noble-22 main' | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-22 clang-format-22 clang-tidy-22 clang-tools-22 \
ninja-build bison flex graphviz libgmp-dev libmpfr-dev \
qt6-base-dev qt6-base-dev-tools libgl1-mesa-dev

- name: Install Doxygen 1.18.0
shell: bash
run: |
archive="$RUNNER_TEMP/doxygen-1.18.0.linux.bin.tar.gz"
curl --fail --location --retry 3 https://www.doxygen.nl/files/doxygen-1.18.0.linux.bin.tar.gz -o "$archive"
printf '%s %s\n' 14fa81bdc34171edb5f1f02b1d60e74802f0439b77fa44e592565d517d72df90 "$archive" | sha256sum --check
mkdir -p "$RUNNER_TEMP/doxygen"
tar -xzf "$archive" -C "$RUNNER_TEMP/doxygen" --strip-components=1
doxygen_bin="$(find "$RUNNER_TEMP/doxygen" -type f -name doxygen -print -quit)"
"$doxygen_bin" --version
dirname "$doxygen_bin" >> "$GITHUB_PATH"

- name: Configure full Debug checks
shell: bash
run: >
cmake -S . -B build/check-extended -G Ninja
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_C_COMPILER=clang-22 -DCMAKE_CXX_COMPILER=clang++-22
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DGECODE_ENABLE_EXPERIMENTAL=ON -DGECODE_ENABLE_CBS=ON
-DGECODE_ENABLE_AUDIT=ON -DGECODE_ENABLE_FAULT_INJECTION=ON
-DGECODE_ENABLE_QT=ON -DGECODE_ENABLE_GIST=ON -DGECODE_ENABLE_MPFR=ON
-DGECODE_ENABLE_EXAMPLES=ON -DGECODE_REGENERATE_VARIMP=ON

- name: Run all checks
shell: bash
run: uv run misc/check.py all --build-dir build/check-extended --jobs 4

build-cmake-unix:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,12 @@ endif()

if(GECODE_ENABLE_EXAMPLES)
add_subdirectory(examples)
if(GECODE_BUILD_GIST_TARGET)
add_subdirectory(gecode/gist/standalone-example)
endif()
if(GECODE_ENABLE_FLATZINC AND GECODE_HAS_QT_RUNTIME AND GECODE_BUILD_SHARED)
add_subdirectory(gecode/flatzinc/exampleplugin)
endif()
endif()

# ---------------------------------------------------------------------------
Expand Down
40 changes: 40 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ Rank: minor
Define the GECODE_FREELIST32_SIZE_MAX and GECODE_FREELIST64_SIZE_MAX build
options as numbers in config.hpp. A quoted value broke compilation.

[ENTRY]
Module: other
What: performance
Rank: minor
[DESCRIPTION]
Move owned branching and open-variable-list callbacks through constructors
instead of copying them repeatedly. Avoid copying read-only argument arrays
in examples, reserve worker-control thread storage, and buffer multi-line
output while flushing complete solutions, progress, and protocol messages.
[MORE]
Expand clang-tidy checks for hidden copies, container operations, missed moves,
stream flushing, and correctness errors.

[ENTRY]
Module: other
What: change
Rank: major
[DESCRIPTION]
Rename the strict-less relation constants IRT_LE, FRT_LE, and SRT_LE to
IRT_LT, FRT_LT, and SRT_LT. Remove the old spellings without compatibility
aliases to avoid confusion with less-or-equal. Relation values and semantics
are unchanged; the less-or-equal constants retain the _LQ suffix.

[ENTRY]
Module: other
What: change
Rank: major
[DESCRIPTION]
Require C++23 and adopt four-space indentation and a 120-column limit with
clang-format 22.
Functions, variables, and members use snake_case; types retain PascalCase.
Constants and functions that stand for constant values, such as ME_INT_VAL,
ES_SUBSUMED, and INT_VAR_SIZE_MIN, retain UPPER_CASE. Public API names
change, including no_overlap, bin_packing, and modification_event_delta.
Update downstream source code before recompiling.
[MORE]
Add formatting, clang-tidy, and extended repository check commands. Extended
checks include generated sources, CTest suites, installed-package consumers,
and documentation. EditorConfig replaces per-file indentation headers.

[ENTRY]
Module: other
What: removed
Expand Down
86 changes: 71 additions & 15 deletions docs/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ defaults. Keep upstream third-party files in their original style.
C++ uses four-space indentation and a 120-column limit. Braces stay on the
opening line, compact nested namespaces remain indented, and pointer and
reference markers bind to the type. Function definitions retain a separate
return-type line. Include order and comment wrapping are preserved, including
copyright notices and Doxygen text.
return-type line. Include order and comment wrapping are preserved. Comment
indentation follows the surrounding code, including copyright notices and
Doxygen text.

Four spaces distinguish nested control flow. The 120-column limit leaves room
for namespace-qualified calls, templates, and generated scheduling expressions.
Expand All @@ -35,18 +36,40 @@ The generated FlatZinc parser and lexer retain Bison and Flex formatting;
their upstream scaffolding is excluded from clang-format. Regenerate these
files from `.yxx` and `.lxx` inputs rather than editing the output by hand.

## Naming migration

The naming migration is pending a decision on which identifier categories
change, including types and namespaces. Names should separate words with
underscores and describe their purpose. A casing check cannot identify word
boundaries in existing names such as `dfsengine` and `modeventdelta`; those
need explicit review.

Changing every category requires resolving collisions before applying fixes.
For example, `Int` cannot become the keyword `int`, and the `DFS` class
template cannot take the existing `dfs` function's name. Review those choices
alongside the public API, generated code, and documentation.
## Naming

Functions, variables, and members use `snake_case`. Types retain `PascalCase`;
enum constants and macros retain `UPPER_CASE`. The constants of a new scoped
enum use `PascalCase`, as in `EndReason::Limit`. Existing private-member leading
or trailing underscores are accepted when the name itself is snake_case.

Constants may use `UPPER_CASE`, and so may functions that stand for constant
values. Modification events and propagation conditions (`ME_INT_VAL`,
`PC_INT_DOM`), propagator status helpers (`ES_SUBSUMED`, `ES_FIX_PARTIAL`),
and branching selectors (`INT_VAR_SIZE_MIN()`, `INT_VAL_MIN()`) belong to the
same vocabulary as the enum constants they appear with, such as `ES_FIX` and
`IRT_EQ`, and keep their spelling.
Names should separate words and describe their purpose. A casing check cannot
identify word boundaries in names such as `dfsengine` and `modeventdelta`;
those require explicit review.

Representative API changes include:

| Previous spelling | Current spelling |
|---|---|
| `IRT_LE`, `FRT_LE`, `SRT_LE` | `IRT_LT`, `FRT_LT`, `SRT_LT` |
| `nooverlap(...)` | `no_overlap(...)` |
| `binpacking(...)` | `bin_packing(...)` |
| `modeventdelta(...)` | `modification_event_delta(...)` |
| `dfsengine(...)` | `make_dfs_engine(...)` |
| `clearall(value)` | `fill_bits(value)` |
| `arg2intvarargs(...)` | `arg_to_int_var_args(...)` |

Strict-less relation constants use `_LT`; `_LQ` continues to mean less-or-equal.
The former `_LE` names have no compatibility aliases.

Qt overrides and other external interfaces retain the spellings their APIs
require. Parser tokens and protocol strings remain unchanged.

## Checking changes

Expand All @@ -66,9 +89,42 @@ Lint requires a Ninja or Makefiles compilation database configured with
`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`; it checks compiled sources and their
maintained headers. The command reports sources outside that build so optional
modules cannot silently disappear from the coverage report.
Bison/Flex grammar syntax is reviewed manually; clang-tidy checks the owned C++
action ranges in their generated translation units.

The extended command also checks the changelog and generated-source freshness,
builds the configured targets, runs the standard test suite, and runs CTest.
builds the configured targets, runs CTest integrity and enabled fault suites,
installs into `check-install` under the build directory, and builds, tests, and lints the
allocator and public-test-component package consumers. It also builds the
documentation (Doxygen 1.18.0 or newer). The full `check-standard` and
`check-sweep` suites remain separate targets: the standard suite alone contains
over 54,000 cases and defaults to five iterations per case.
Besides LLVM 22, the extended check requires uv, Bison 3.8.2, Flex 2.6.4, Ninja,
and Doxygen 1.18.0 or newer. Configure with `BUILD_TESTING`, `GECODE_INSTALL`,
`GECODE_ENABLE_ALLOCATOR`, search, integer variables, minimodel, and driver
enabled. Lint always analyzes assertions by undefining `NDEBUG`, regardless of
the selected build type. Ordinary compilation and runtime tests retain the
configured build settings.
Enable optional and experimental modules in the build when checking them;
platform-specific code also needs its corresponding CI toolchain. Normal
builds use checked-in generated sources and do not require LLVM tools.

Performance checks cover hidden loop copies, associative-container lookup,
vector growth, string operations, and missed moves as well as unnecessary
copies. Use `'\n'` inside a formatted record. Flush explicitly when publishing
a solution, progress update, protocol response, or complete diagnostic; a
printer should not flush each row of a multi-line solution.
The unused-return-value check accepts explicit `(void)` discards for reviewed
operations such as ownership handoff after successful engine construction.

`performance-unnecessary-value-param` is reserved for manual performance audits.
Its suggestions mix Gecode's small, intentionally copied variable/view handles
with ownership-sensitive callbacks and argument arrays. Review actual copy
cost and lifetime requirements before changing those public signatures.

Other performance checks need focused review: `performance-enum-size` changes
layouts and ABI, and `performance-no-int-to-ptr` conflicts with deliberate
pointer tagging. Review `noexcept` guarantees, destructor triviality, and math
promotion against allocation-failure handling and interval-rounding semantics
before adopting those checks. Never add `noexcept` to a potentially throwing
operation just to satisfy a diagnostic.
14 changes: 7 additions & 7 deletions examples/all-interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AllInterval : public Script {
distinct(*this, d, opt.ipl());

// Break mirror symmetry
rel(*this, x[0], IRT_LE, x[1]);
rel(*this, x[0], IRT_LT, x[1]);
// Break symmetry of dual solution
rel(*this, d[0], IRT_GR, d[n - 2]);

Expand All @@ -91,18 +91,18 @@ class AllInterval : public Script {
d.update(*this, s.d);
}
/// Copy during cloning
virtual Space*
copy(void) {
Space*
copy(void) override {
return new AllInterval(*this);
}
/// Print solution
virtual void
print(std::ostream& os) const {
void
print(std::ostream& os) const override {
const int n = x.size();
os << "\tx[" << n << "] = {";
for (int i = 0; i < n - 1; i++)
os << x[i] << "(" << d[i] << "),";
os << x[n - 1] << "}" << std::endl;
os << x[n - 1] << "}" << '\n';
}
};

Expand All @@ -117,7 +117,7 @@ main(int argc, char* argv[]) {
opt.ipl(IPL_BND);
opt.parse(argc, argv);
if (opt.size() < 2) {
std::cerr << "size must be at least 2!" << std::endl;
std::cerr << "size must be at least 2!" << '\n';
return -1;
}
Script::run<AllInterval, DFS, SizeOptions>(opt);
Expand Down
12 changes: 6 additions & 6 deletions examples/alpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ class Alpha : public Script {
le.update(*this, s.le);
}
/// Copy during cloning
virtual Space*
copy(void) {
Space*
copy(void) override {
return new Alpha(*this);
}
/// Print solution
virtual void
print(std::ostream& os) const {
void
print(std::ostream& os) const override {
os << "\t";
for (int i = 0; i < n; i++) {
os << ((char)(i + 'a')) << '=' << le[i] << ((i < n - 1) ? ", " : "\n");
if ((i + 1) % 8 == 0)
os << std::endl << "\t";
os << '\n' << "\t";
}
os << std::endl;
os << '\n';
}
};

Expand Down
Loading
Loading