Skip to content

Gecode 7: scoped enums and descriptive constant names - #293

Open
zayenz wants to merge 2 commits into
feature/breaking-7-09-bug-fixesfrom
feature/breaking-7-10-scoped-enums
Open

zayenz wants to merge 2 commits into
feature/breaking-7-09-bug-fixesfrom
feature/breaking-7-10-scoped-enums

Conversation

@zayenz

@zayenz zayenz commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Unscoped enums leak their enumerators into the enclosing namespace and convert implicitly to int, hiding type mismatches and accidental integer arithmetic. This PR converts the remaining unscoped enums across the public and test headers to enum class and replaces heavily abbreviated constant names with descriptive ones.

Scoped enums

The remaining unscoped enums across Gecode's modules and test component become enum class, keeping their underlying values and order unchanged. To keep migrations manageable, using enum at each enclosing scope preserves existing spellings such as IRT_EQ, Gecode::SS_FAILED, and IntVarBranch::SEL_RND; in class templates, where using enum cannot name a dependent type, static constexpr aliases provide the same names.

What stops compiling is implicit conversion to int, arithmetic or bit shifts (such as 1 << RM_EQV), array indexing, streaming, and comparing across different enums. Call sites now convert explicitly with std::to_underlying or static_cast. Because installed headers use std::to_underlying, downstream projects need C++23 even if they do not consume Gecode through CMake.

IntPropLevel is the one enum that supports bitwise operations. It gets an unsigned int underlying type (matching the bit-fields in IntPropLevels), gains operator|, operator&, and operator|=, and drops IPL_BITS_ in favor of an internal constant. Testing a bit now requires an explicit comparison such as (ipl & IPL_BASIC) != IPL_DEF. ev_t is also renamed to Int::Cumulatives::EventType.

Descriptive constant names

Following the IRT_LE -> IRT_LT rename in #286, abbreviated enum constants are given descriptive names without compatibility aliases. Examples include RestartMode (RM_* -> RESTART_*, removing the prefix collision with ReifyMode), ReifyMode::RM_PMI -> RM_RIMP, TaskType (TT_FIXP/TT_FIXS/TT_FIXE -> TT_FIXED_PROCESSING/TT_FIXED_START/TT_FIXED_END), SetRelType (SRT_DISJ/SRT_CMPL -> SRT_DISJOINT/SRT_COMPLEMENT), and SetOpType (SOT_DUNION/SOT_INTER -> SOT_DISJOINT_UNION/SOT_INTERSECTION). Underlying values, printed output, and CLI option strings do not change; docs/code-style.md and changelog.in list every rename.

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
  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 ← this PR
  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
    • Public enums are now scoped, preventing implicit conversion to integers or mixing between enum types. Code relying on integer operations or comparisons may need explicit conversions.
    • Several public constant names have changed, including restart, task, set-operation, set-relation, reification, and search values. Previous spellings are not retained as compatibility aliases.
    • IntPropLevel now supports bitwise operators, has an unsigned underlying type, and no longer includes IPL_BITS_.
  • Compatibility
    • Consumers using installed headers outside exported CMake targets need C++23 support.
  • Documentation
    • Updated guidance on enum usage and constant naming.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Changes: Scoped enum API and rules

Layer / File(s) Summary
Enum declarations and API rules
changelog.in, docs/code-style.md, gecode/*.hh, gecode/*/*.hh, test/float.hh, test/int.hh, test/test.hh
Enums become scoped. Selected enumerators receive descriptive names, with using enum or static aliases exposing values in their surrounding scopes. IntPropLevel gains bitwise operators and an unsigned underlying type. The changelog and style guide describe these changes and explicit conversions.
Enum-dependent implementation and API integration
gecode/driver/*, gecode/flatzinc*, gecode/float/*, gecode/int/*, gecode/kernel/*, gecode/search/*, gecode/set/*, gecode/support/*
Runtime code uses renamed enumerators and converts scoped enum values when integer representations are required. Reverse-implication handling is updated across integer, float, and set constraints.
Examples and test updates
examples/sudoku-advanced.cpp, test/*
Examples and tests use the renamed enumerators and updated enum types. Compile-time checks cover enum conversion and the IntPropLevel underlying type.

Possibly related PRs

  • Gecode/gecode#284: Establishes the C++23 baseline that this pull request’s use of std::to_underlying relies on.

Change: Refactor

Merge Risk: Minimal · previous review ad493

This change converts enums to scoped enums and renames abbreviated constants without compatibility aliases. Downstream code must update spellings and use explicit conversions, and installed headers now require C++23. These changes are documented in the changelog and style guide. No concrete defect was identified in the supplied summaries.

Architecture risk: Low · up to ad493

The change affects 5 systems.

Changed systems: gecode, test, changelog.in, docs, examples

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — gecode (service) was modified; 98 changed files map to changed impact.
  • observed — test (service) was modified; 39 changed files map to changed impact.
  • observed — changelog.in (service) was modified; 1 changed file maps to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in changelog.in: Adds the 7.0.0 major-change changelog entry listing descriptive replacements for abbreviated public, test, and internal constants. It states that old spellings have no compatibility aliases and that values, semantics, and command-line option values are unchanged.
  • observed — Modified behavior in changelog.in: Adds a major-change entry documenting 68 enums becoming scoped enums, the scoped-alias approach used to preserve existing spellings, and the affected enum groups. It specifies the loss of implicit integer conversion and cross-enum mixing, the operations that require explicit conversion, and the C++23 requirement for consumers outside exported CMake targets.
  • observed — Modified behavior in changelog.in: Adds a major-change entry specifying IntPropLevel as an enum class with underlying type unsigned int, adding bitwise OR, AND, and OR-assignment operators, documenting the explicit comparison needed for bit tests, and removing IPL_BITS_.
  • observed — Modified behavior in examples/sudoku-advanced.cpp: SudokuInt::same replaces both SOT_DUNION relations with SOT_DISJOINT_UNION relations.
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: 175c3d75-24cf-4dec-9314-b2070bc2e20a
Commits

Reviewing files that changed from the base of the PR and between 3cccac2 and ad493a9.

Files selected for processing: 1

  • docs/code-style.md

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

@zayenz
zayenz added this pull request to stack #295 November 25, 2026 20:41
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch 2 times, most recently from af14521 to db832f6 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-10-scoped-enums branch 3 times, most recently from 0b13cd6 to 33ebd87 Compare November 26, 2026 06:13
@zayenz
zayenz marked this pull request as ready for review November 26, 2026 06:14
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from 33ebd87 to 39570b7 Compare November 26, 2026 10:18
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from 39570b7 to dff6484 Compare November 26, 2026 12:27
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from dff6484 to 3cccac2 Compare November 26, 2026 16:24
@zayenz zayenz closed this Nov 26, 2026
@zayenz zayenz reopened this Nov 26, 2026
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from 3cccac2 to ad493a9 Compare November 26, 2026 19:14
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from ad493a9 to ae7dd0e Compare November 26, 2026 19:44
68 enums become enum class. using enum keeps existing spellings such as IRT_EQ and IntVarBranch::SEL_RND compiling; class templates use static constexpr aliases instead, since using enum cannot name a dependent type. Enumerator values and order do not change.

IntPropLevel is the only enum with operators and has an unsigned underlying type, because IntPropLevels stores levels in bit-fields. IPL_BITS_ is replaced by a private constant computed from the levels, and ev_t becomes EventType.

Other conversions are now explicit, and installed headers need C++23.

Zdev-Change-Id: Zbe6acb9cfd1f8806879c5c1a6bd306c2cf58f61134417b2e83c6ee379d2bce5f
Apply the approved constant renames with no compatibility aliases, following the IRT_LE to IRT_LT rename. RestartMode's RM_ constants become RESTART_, because ReifyMode shares that prefix, and truncated names such as SRT_DISJ and SOT_DUNION are spelled out. docs/code-style.md and the changelog list each rename.

Enumerator values, printed strings, and option values do not change.

Zdev-Change-Id: Z43bb475ac60ed9ff06a641cb09f52d90383860f01757f28f113e8f472c039503
@zayenz
zayenz force-pushed the feature/breaking-7-10-scoped-enums branch from ae7dd0e to 3f561f1 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