Skip to content

feat : implement watchers#21

Merged
FreeYourSoul merged 6 commits intomainfrom
feat/implement_watchers
Jul 21, 2025
Merged

feat : implement watchers#21
FreeYourSoul merged 6 commits intomainfrom
feat/implement_watchers

Conversation

@FreeYourSoul
Copy link
Owner

@FreeYourSoul FreeYourSoul commented Jul 18, 2025

Summary by CodeRabbit

  • New Features

    • Added CNF files encoding the 8-queens and pigeonhole problems for SAT solver demonstrations or testing.
    • Introduced a new test case for clause watcher functionality.
  • Bug Fixes

    • Resolved ambiguity in CLI options by assigning the short flag -l exclusively to the log file option.
  • Documentation

    • Corrected the filename in the CNF documentation for consistency.
    • Added a URL link to a CNF benchmark repository in the documentation.
  • Style

    • Standardized naming conventions for types and classes to use PascalCase throughout the codebase.
  • Chores

    • Changed the default CLI log level from "debug" to "info" for less verbose logging by default.
    • Updated test configurations: enabled compiler tests and disabled agent tests.

@coderabbitai
Copy link

coderabbitai bot commented Jul 18, 2025

"""

Walkthrough

The changes standardize naming conventions across the SAT solver codebase, renaming types and members to use PascalCase (e.g., model to Model, clause_watcher to Clause_Watcher, metadata to Metadata). A new CNF file for the 8-queens problem and a new test case were added. Minor CMake and CLI adjustments were made.

Changes

File(s) Change Summary
fabko/compiler/CMakeLists.txt, CMakeLists.txt Updated source references and target sources; added test source to interface library; modified conditional test inclusion.
fabko/compiler/backend/Metadata.hh Renamed class metadata to Metadata.
fabko/compiler/backend/sat/solver.cpp, solver.hh, solver_context.hh, solver_impl.cpp Renamed types/members to PascalCase (modelModel, clause_watcherClause_Watcher, metadataMetadata); revised constructor signatures; updated watcher logic; removed unused members; changed logging behavior; updated CNF parsing types.
fabko/cli_base.hh Changed default CLI log level from debug to info.
fabko/fabko.cpp Fixed CLI short option flag overlap for --log-level and --log-file.
docs/cnf/8-queens-problem.cnf Added new CNF file encoding the 8-queens problem.
docs/cnf/pigeon-hole.cnf Added new CNF file encoding the pigeonhole principle problem.
docs/cnf/README.md Corrected link text to "4-queens-problem.cnf" and added a benchmark URL.
tests/compiler/soa/watcher_testcase.cpp Added new test case verifying Clause_Watcher behavior with various clause and variable assignments.
tests/CMakeLists.txt Enabled test target for compiler watcher test; disabled test target for agent.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Model
    participant Solver
    participant Context

    User->>CLI: Provide CNF file (e.g., 8-queens-problem.cnf)
    CLI->>Model: Parse CNF into Model
    CLI->>Solver: Instantiate Solver with Model
    Solver->>Context: Create Solver_Context with Model
    Solver->>Solver: Solve SAT problem
    Solver-->>CLI: Return result
    CLI-->>User: Output SAT/UNSAT or solution
Loading

Estimated code review effort

3 (~45 minutes)

Possibly related PRs

  • Sat Reimplementation #18: Introduces a comprehensive SAT solver reimplementation with similar renaming of types and architectural changes, closely related to the current updates.

Poem

🐇
Names now shine with Pascal grace,
Models, Watchers, take their place.
Queens on boards in CNF rows,
A watcher test with checks that grow.
CLI flags now clear, concise—
This rabbit finds the code quite nice!
🥕✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd69b7a and 353fb7b.

📒 Files selected for processing (3)
  • fabko/compiler/backend/sat/solver.cpp (5 hunks)
  • fabko/compiler/backend/sat/solver.hh (4 hunks)
  • tests/compiler/soa/watcher_testcase.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/compiler/soa/watcher_testcase.cpp
  • fabko/compiler/backend/sat/solver.cpp
  • fabko/compiler/backend/sat/solver.hh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff74359 and 09b15fb.

📒 Files selected for processing (6)
  • fabko/compiler/CMakeLists.txt (1 hunks)
  • fabko/compiler/backend/Metadata.hh (1 hunks)
  • fabko/compiler/backend/sat/solver.cpp (3 hunks)
  • fabko/compiler/backend/sat/solver.hh (5 hunks)
  • fabko/compiler/backend/sat/solver_context.cpp (4 hunks)
  • fabko/compiler/backend/sat/solver_context.hh (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
fabko/compiler/backend/sat/solver.cpp (1)
fabko/compiler/backend/sat/solver.hh (1)
  • solver (200-200)
🪛 GitHub Actions: CI Linux Build
fabko/compiler/backend/sat/solver_context.cpp

[error] 1-1: Compilation failed due to errors in 'solver.hh' included in this file. Lambda capture of 'vs' missing and incorrect std::ranges::views::filter usage.

fabko/compiler/backend/sat/solver.cpp

[error] 1-1: Compilation failed due to errors in 'solver.hh' included in this file. See errors about lambda capture and std::ranges::views::filter usage.

fabko/compiler/backend/sat/solver.hh

[error] 114-116: Compilation error: Lambda function does not capture 'vs' variable used inside. Also, invalid use of std::ranges::views::filter with incorrect arguments and brace-enclosed initializer list conversion failure to std::array. Errors occur around lines 114-116.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (19)
fabko/compiler/backend/Metadata.hh (1)

29-29: LGTM! Naming convention improvement.

The class name change from metadata to Metadata follows standard C++ naming conventions where class names use PascalCase.

fabko/compiler/CMakeLists.txt (1)

7-7: LGTM! Build configuration updated correctly.

The filename change from metadata.hh to Metadata.hh correctly reflects the capitalization change of the header file.

fabko/compiler/backend/sat/solver_context.cpp (4)

284-284: LGTM! Type name updated correctly.

The change from clause_watcher to Clause_Watcher maintains consistency with the PascalCase naming convention.


316-316: LGTM! Function signature updated correctly.

The parameter type change from model to Model aligns with the naming standardization across the codebase.


372-372: LGTM! Constructor parameter updated correctly.

The parameter type change from model to Model maintains consistency with the updated type definitions.


380-380: Fix compilation errors in solver.hh

The call to std::ranges::views::filter inside the Clause_Watcher constructor neither captures vs nor supplies a valid index, causing the build to fail.

• File: fabko/compiler/backend/sat/solver.hh
Location: inside the Clause_Watcher(const Vars_Soa& vs, const Clause& clause) initializer
Issues:

  • The inner lambda uses vs but is declared [], so it cannot see vs.
  • The expression vs[] is invalid—it needs an index (e.g. lit.second).

Suggested fix (replace the filter call with a properly captured and indexed version):

     // Before:
-    std::ranges::views::filter(clause, [](const auto& lit) {
-        return get<soa_literal>(vs[]) == lit;
-    });
+    // After:
+    auto matching = clause.get_literals()
+        | std::views::filter([&vs](const auto& lit_pair) {
+            return get<soa_literal>(vs[lit_pair.second]) == lit_pair.first;
+        });

• Ensure the lambda capture list includes vs (e.g. [&vs] or [&]) and index into vs with the correct element.
• Adapt the rest of the watcher logic to use matching (or inline the corrected filter) as needed.

Likely an incorrect or invalid review comment.

fabko/compiler/backend/sat/solver.cpp (4)

27-27: LGTM! Forward declaration updated correctly.

The parameter type change from model to Model in the forward declaration maintains consistency with the updated type definitions.


38-38: LGTM! Function return type updated correctly.

The return type change from model to Model aligns with the naming standardization across the codebase.


98-98: LGTM! Return statement updated correctly.

The return statement correctly constructs and returns a Model instance using the updated type name.


101-101: LGTM! Constructor parameter updated correctly.

The constructor parameter type change from model to Model maintains consistency with the declaration in solver.hh (line 200) and the updated type definitions.

fabko/compiler/backend/sat/solver_context.hh (5)

21-21: LGTM! Include path updated correctly.

The include path change from "metadata.hh" to "Metadata.hh" correctly reflects the header file capitalization change.


32-32: LGTM! Forward declarations updated correctly.

The forward declaration changes from clause_watcher to Clause_Watcher and model to Model maintain consistency with the PascalCase naming convention.

Also applies to: 34-34


48-49: LGTM! Type aliases updated correctly.

The type alias updates to use Metadata and Clause_Watcher maintain consistency with the renamed types throughout the codebase.


74-74: LGTM! Nested struct names updated correctly.

The nested struct name changes from configuration to Configuration and statistics to Statistics align with the PascalCase naming convention for types.

Also applies to: 90-90


100-100: LGTM! Type usage updated correctly.

The type usage updates to Model, Configuration, and Statistics maintain consistency with the renamed types and follow proper C++ naming conventions.

Also applies to: 102-103, 116-116

fabko/compiler/backend/sat/solver.hh (4)

86-86: LGTM!

The renaming from metadata to Metadata is consistent with the standardization of type names to PascalCase.


156-163: LGTM!

The renaming from model to Model and the updated type reference Solver_Context::Configuration are consistent with the PascalCase standardization.


174-174: LGTM!

All Model type references have been correctly updated to maintain consistency with the PascalCase naming convention.

Also applies to: 200-200, 206-206


99-121: All type migrations verified—no issues detected.

  • No lowercase clause_watcher, model, or metadata remain anywhere in the CPP/H files.
  • The new watchers_ field only appears in fabko/compiler/backend/sat/solver.hh (definition and constructor) and isn’t accessed elsewhere.
  • All #include entries correctly reference Metadata.hh.

No further changes required.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/compiler/soa/watcher_testcase.cpp (1)

15-15: Empty test case needs implementation.

The test case is currently empty, which serves as a good placeholder for the watcher functionality mentioned in the PR objectives. However, to provide value, this test should include actual test logic for the watcher implementation.

Consider implementing test cases that cover:

  • Watcher creation and initialization
  • Watcher state transitions
  • Edge cases and error conditions
  • Integration with the SAT solver backend

Would you like me to help generate some initial test scaffolding based on the watcher functionality requirements?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da8b60f and 9accadc.

📒 Files selected for processing (4)
  • fabko/compiler/CMakeLists.txt (1 hunks)
  • fabko/compiler/backend/sat/solver.cpp (3 hunks)
  • fabko/compiler/backend/sat/solver_impl.cpp (3 hunks)
  • tests/compiler/soa/watcher_testcase.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • fabko/compiler/CMakeLists.txt
  • fabko/compiler/backend/sat/solver.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (5)
tests/compiler/soa/watcher_testcase.cpp (2)

1-12: LGTM! Comprehensive dual licensing header.

The licensing header is well-structured and provides clear dual licensing options (AGPL or commercial subscription). The contact information and attribution are properly included.


13-13: Good practice using Catch2 test framework.

The include for Catch2 is appropriate for the test infrastructure.

fabko/compiler/backend/sat/solver_impl.cpp (3)

284-284: LGTM: Type name updated consistently with PascalCase convention.

The change from clause_watcher to Clause_Watcher aligns with the standardization to PascalCase naming convention mentioned in the PR objectives.


316-316: All solve_sat callers updated to use Model

The signature change from const model& to const Model& has been applied consistently. Calls in fabko/compiler/backend/sat/solver.cpp and solver_impl.cpp now pass a Model instance, and there are no remaining function calls using the old lowercase model type.


293-293: Change Verified: Debug Level Is Appropriate for Internal Solver Event

The search shows that user-facing messages in the CLI use log_info/log_warn (e.g., “solution found” and “no solution found”), while internal SAT solver steps consistently use log_debug. Keeping “no unassigned variable found” at DEBUG level aligns with our existing logging strategy and reduces noise in production logs.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/cnf/README.md (2)

3-3: Convert bare URL to markdown link for lint-compliance

markdownlint flags the naked URL; wrap it in standard link syntax for readability and to satisfy MD034.

-https://www.cs.ubc.ca/~hoos/SATLIB/benchm.html : link to benchmarks to be downloaded.
+[SATLIB benchmarks](https://www.cs.ubc.ca/~hoos/SATLIB/benchm.html) – repository of additional CNF benchmarks.

5-5: Polish sentence for clarity

“Those are CNF files …” sounds awkward. Prefer “These CNF files …” to refer to items that follow.

-Those are CNF files representing problems that must be runnable from the CLI.
+These CNF files represent problems that are runnable from the CLI.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9accadc and bd69b7a.

📒 Files selected for processing (8)
  • CMakeLists.txt (2 hunks)
  • docs/cnf/README.md (2 hunks)
  • docs/cnf/pigeon-hole.cnf (1 hunks)
  • fabko/compiler/backend/sat/solver.cpp (5 hunks)
  • fabko/compiler/backend/sat/solver.hh (4 hunks)
  • fabko/compiler/backend/sat/solver_impl.cpp (8 hunks)
  • tests/CMakeLists.txt (1 hunks)
  • tests/compiler/soa/watcher_testcase.cpp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/cnf/pigeon-hole.cnf
🚧 Files skipped from review as they are similar to previous changes (4)
  • CMakeLists.txt
  • fabko/compiler/backend/sat/solver_impl.cpp
  • fabko/compiler/backend/sat/solver.cpp
  • fabko/compiler/backend/sat/solver.hh
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/cnf/README.md

3-3: Bare URL used

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (9)
tests/CMakeLists.txt (2)

10-22: LGTM: Properly disabled test_agent target

The commenting out of the test_agent target is clean and preserves the configuration for potential future re-enabling.


25-36: LGTM: Properly enabled test_compiler target with watcher tests

The test_compiler target configuration is correct and appropriately links the watcher test case. The C++26 standard requirement aligns with modern C++ features likely used in the watcher implementation.

tests/compiler/soa/watcher_testcase.cpp (6)

1-17: LGTM: Proper license header and includes

The dual licensing header is comprehensive and the includes are appropriate for the test functionality.


18-38: LGTM: Comprehensive test for fully assigned variables

This test correctly verifies that when all variables in a clause are assigned, the watcher should be empty (size 0). This is the expected behavior for the two-literal watching optimization.


40-58: LGTM: Well-structured test for single unassigned variable

The test properly verifies that with one unassigned variable, the watcher tracks exactly that variable. The assertions check both size and the specific watched variable offset.


60-80: LGTM: Good coverage for two unassigned variables

This test validates the two-literal watching behavior when exactly two variables are unassigned, confirming both variables are watched.


82-102: Verify the two-watcher limit behavior is intentional

This test shows that even when three variables are unassigned, only two are watched (variables at offsets var_id1 and var_id2, but not var_id3). This appears to implement the standard two-literal watching optimization used in DPLL-based SAT solvers.

Please confirm this is the intended behavior for your watcher implementation.


104-117: LGTM: Edge case coverage for single-element clauses

This test properly handles the edge case of unit clauses (single literal), ensuring the watcher correctly tracks the single unassigned variable.

docs/cnf/README.md (1)

83-83: Filename pluralisation fix looks good

Updating the link to 4-queens-problem.cnf matches the actual file name and prevents 404s. 👍

@FreeYourSoul FreeYourSoul merged commit dda0cc3 into main Jul 21, 2025
1 of 2 checks passed
@FreeYourSoul FreeYourSoul deleted the feat/implement_watchers branch July 21, 2025 16:27
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