Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/non bound substitution variables #605

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

ccamel
Copy link
Member

@ccamel ccamel commented Mar 20, 2024

Prevent non-bound substitution variables to be returned. These kind of variables are converted into string terms with a prefix of _ followed by a number, such as _88. The numeric part is unpredictable and may vary across different nodes of the chain, compromising determinism — a situation that is problematic, as you know.

For instance:

% program
father(bob, X) :- true.

% query with singleton variables: [X]
father(B, X).

Before:

answer:
  has_more: false
  results:
  - error: ""
    substitutions:
    - expression: bob
      variable: B
    - expression: _42
      variable: X
  variables:
  - B
  - X

After:

answer:
  has_more: false
  results:
  - error: ""
    substitutions:
    - expression: bob
      variable: B
  variables:
  - B
  - X

The expression value for X has been removed.

Summary by CodeRabbit

  • New Features
    • Enhanced the app's capability to handle complex expressions more effectively.
  • Tests
    • Added a new test case to ensure the reliability of querying functionalities.
  • Refactor
    • Improved the internal logic for scanning and evaluating expressions, leading to more accurate results.

@ccamel ccamel self-assigned this Mar 20, 2024
Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Walkthrough

The recent update introduces a new test case in the TestGRPCAsk function to ensure the robustness of query handling with specific programs and expected answers. It also brings enhancements to the handling of expressions in the logic utility, particularly through the introduction of the scanExpression function for scanning expressions and isBound to check variable bindings. These improvements are complemented by adjustments in the envsToResults function to integrate these changes seamlessly.

Changes

Files Change Summaries
.../grpc_query_ask_test.go Added a new test case in TestGRPCAsk for testing queries with specific programs and expectations.
.../util/prolog.go Introduced scanExpression, added isBound, and adjusted envsToResults for enhanced functionality.

🐇✨

In the realm of code, where logic trees grow,
A rabbit hopped in, with updates in tow.
"Let's scan," it said, "and bind with care,
For expressions and queries have tales to share."
With a leap and a twirl, it danced away,
Leaving behind code, brighter than day.
🌟📚🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
    • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 113bd38 and f327463.
Files selected for processing (2)
  • x/logic/keeper/grpc_query_ask_test.go (1 hunks)
  • x/logic/util/prolog.go (1 hunks)
Additional comments: 5
x/logic/util/prolog.go (4)
  • 76-78: Skipping non-bound variables in envsToResults function is a crucial step towards ensuring determinism by excluding unbound variables from the results. This change directly addresses the issue described in the PR objectives.
  • 81-83: The error handling in scanExpression call within envsToResults is correctly implemented. By returning early in case of an error, it ensures that the error is propagated up and handled appropriately, maintaining the robustness of the system.
  • 92-104: The scanExpression function is well-implemented, with clear error handling and a straightforward return of the Substitution type. This function encapsulates the logic for scanning expressions and extracting the necessary information, contributing to the modularity and maintainability of the code.
  • 106-111: The isBound function provides a concise and effective way to check if a parsed variable is bound in the given environment. This utility function enhances code readability and reuse, aligning with best practices for code modularity.
x/logic/keeper/grpc_query_ask_test.go (1)
  • 195-204: Adding a new test case to verify the handling of non-bound substitution variables is a good practice. It ensures that the changes made to the system's logic are correctly implemented and that the system behaves as expected in scenarios involving non-bound variables. This test case contributes to the overall robustness and reliability of the system.

@ccamel ccamel requested a review from amimart March 20, 2024 18:32
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Yes perfect! Important one thanks 🙏

@ccamel ccamel merged commit 5084fd4 into main Mar 21, 2024
19 checks passed
@ccamel ccamel deleted the fix/non-bound-substitution-variables branch March 21, 2024 14:37
@bot-anik
Copy link
Member

bot-anik commented Apr 2, 2024

🎉 This PR is included in version 7.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants