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/incorrect variable resolution #570

Merged
merged 2 commits into from
Feb 23, 2024
Merged

Fix/incorrect variable resolution #570

merged 2 commits into from
Feb 23, 2024

Conversation

ccamel
Copy link
Member

@ccamel ccamel commented Feb 23, 2024

This PR fixes the issue with variable resolution during predicates interpretation as initially reported by @amimart.

Example:

program:

okp4d query logic ask --program "okp4_addr(Addr) :- bech32_address(-('okp4', _), Addr).

query:

okp4_addr('okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6').

result 🙀:

error(type_error(atom,okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6),bech32_address/2)

expected 😌:

true

Basically, the assertion functions (used to implement predicates) no longer verify the groundness of terms. They now only resolve terms that are essential for the assertion. For example, to confirm that a term is a pair, only the compound term is resolved, without resolving the arguments of the compound.

New test cases have been introduced to improve coverage.

Summary by CodeRabbit

  • Refactor
    • Consolidated query execution logic for improved efficiency and maintainability.
    • Adjusted argument orders in various functions for consistency and clarity.
  • New Features
    • Enhanced functionality for handling options and assertions in Prolog engine.
    • Introduced new test utilities for more robust testing.
  • Bug Fixes
    • Fixed control flow and term resolution issues by adjusting argument orders and utilizing environments effectively.
  • Tests
    • Added new test cases to validate the correctness of predicates and assertions.
  • Documentation
    • Internal documentation improvements through code comments and parameter adjustments for better readability.

@ccamel ccamel self-assigned this Feb 23, 2024
Copy link
Contributor

coderabbitai bot commented Feb 23, 2024

Walkthrough

The recent updates focus on refining the logic and structure of a Prolog interpreter within a specific project. Key changes include refactoring query execution, enhancing argument handling across various predicates, and improving error handling by utilizing the environment for term resolution. Additionally, the introduction of utility functions and adjustments in test cases reflect a commitment to code clarity and efficiency. This overhaul not only streamlines execution logic but also fortifies the system's robustness and maintainability.

Changes

Files Summary
x/logic/keeper/interpreter.go, x/logic/util/prolog.go Centralized query execution logic and improved handling of variables and environments.
x/logic/predicate/*.go, x/logic/prolog/*.go (except list.go, option.go) Swapped order of arguments in various function calls to enhance clarity and consistency.
x/logic/prolog/list.go, x/logic/prolog/option.go Adjusted condition checks and updated functions for better environment utilization and option processing.
x/logic/testutil/logic.go, .../prolog/assert_test.go Enhanced test utilities and refactored test cases for broader coverage and improved testing logic.

🐰✨
In the realm of code, where logic threads intertwine,
A rabbit hopped through, making everything align.
Swapping and refining, with a gentle touch so fine,
Now the code flows smooth, like a well-aged wine.
Celebrate the changes, for they are but a sign,
Of progress and growth, in this digital vine.
🌟🐇

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.
  • 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 from git 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.

@ccamel ccamel force-pushed the fix/variable-resolution branch from acdf4f7 to d06a731 Compare February 23, 2024 13:44
@ccamel ccamel changed the title Fix/variable resolution Fix/incorrect variable resolution Feb 23, 2024
@ccamel ccamel marked this pull request as ready for review February 23, 2024 13:47
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 9fd5264 and d06a731.
Files selected for processing (18)
  • x/logic/keeper/interpreter.go (3 hunks)
  • x/logic/predicate/address.go (2 hunks)
  • x/logic/predicate/address_test.go (1 hunks)
  • x/logic/predicate/crypto.go (2 hunks)
  • x/logic/predicate/did.go (1 hunks)
  • x/logic/predicate/did_test.go (1 hunks)
  • x/logic/predicate/file.go (1 hunks)
  • x/logic/predicate/string.go (1 hunks)
  • x/logic/predicate/uri.go (1 hunks)
  • x/logic/prolog/assert.go (3 hunks)
  • x/logic/prolog/assert_test.go (5 hunks)
  • x/logic/prolog/byte.go (1 hunks)
  • x/logic/prolog/hex.go (1 hunks)
  • x/logic/prolog/list.go (1 hunks)
  • x/logic/prolog/option.go (4 hunks)
  • x/logic/prolog/text.go (6 hunks)
  • x/logic/testutil/logic.go (1 hunks)
  • x/logic/util/prolog.go (1 hunks)
Additional comments: 27
x/logic/prolog/hex.go (1)
  • 11-11: The change in the order of arguments for the AssertAtom function call aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/prolog/list.go (1)
  • 16-16: The modification to directly use !IsList(list, env) for the list validity check simplifies the logic and enhances readability. This change is consistent with the PR's objectives to streamline the variable resolution process.
x/logic/prolog/byte.go (1)
  • 16-16: The change in the order of arguments for the AssertByte function call within the loop aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/predicate/uri.go (2)
  • 34-34: The change in the order of arguments for the AssertIsGround function call aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
  • 38-38: The change in the order of arguments for the AssertURIComponent function call aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/prolog/option.go (2)
  • 14-14: Resolving the option within the environment before processing it in the GetOption function ensures correct handling of the option data, aligning with the PR's objectives to streamline the variable resolution process.
  • 79-79: The change in the order of arguments for the AssertAtom function call within the GetOptionAsAtomWithDefault function aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/util/prolog.go (1)
  • 1-82: The prolog.go file is relevant to the PR's objectives regarding query interpretation logic. However, no specific changes are annotated for review within this file.
x/logic/predicate/address.go (3)
  • 38-38: The change in the order of arguments for the prolog.AssertPair function call within the Bech32Address function aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
  • 46-46: The change in the order of arguments for the prolog.AssertAtom function call within the Bech32Address function aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
  • 59-59: The change in the order of arguments for the prolog.AssertAtom function call within the backward converter of the Bech32Address function aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/predicate/did.go (1)
  • 90-90: The change in the order of arguments for the AssertAtom function call within the DIDComponents function aligns with the PR's objectives to standardize argument ordering across assertion functions. This adjustment improves consistency and readability.
x/logic/testutil/logic.go (1)
  • 93-123: The addition of the ShouldBeGrounded function enhances testing capabilities by providing a way to assert that a term is fully instantiated. This is crucial for ensuring the correctness of Prolog terms in tests. The implementation follows best practices for writing goconvey assertions.
x/logic/prolog/text.go (4)
  • 11-16: The adjustments in the AtomToString function, including the renaming of parameters and the order of arguments, improve consistency, readability, and maintainability. These changes align with the PR's objectives to standardize argument ordering and enhance function clarity.
  • 22-28: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [25-35]

The changes in the listTermToString function, including the adjustment of argument order and the clarification of the function signature, contribute to the PR's objectives of improving consistency and readability across the codebase.

  • 60-61: The introduction of a lambda function within the OctetListTermToString function for converting terms to runes aligns with the PR's objectives to streamline and clarify conversion logic. This change enhances readability and maintainability.
  • 76-76: The logic within the TextTermToString function for handling different types of text representations demonstrates a clear and maintainable approach to text conversion, aligning with the PR's objectives to improve code clarity and functionality.
x/logic/predicate/string.go (1)
  • 109-109: The adjustment in the order of arguments for the AssertAtom function call within the StringBytes function aligns with the PR's objectives to improve term resolution. This change is correctly implemented and should enhance the function's logic in handling term resolution more effectively.
x/logic/predicate/file.go (1)
  • 153-157: The modifications in the Open function, specifically the adjusted order of arguments in the AssertList function call and the updated usage of the IsEmptyList function, contribute to improved term resolution and error handling. These changes are well-aligned with the PR's objectives to enhance the system's reliability in predicate interpretation.
x/logic/keeper/interpreter.go (1)
  • 74-74: The refactoring of the queryInterpreter function to delegate query execution to util.QueryInterpreter is a positive change that centralizes the logic for executing queries. This improves code organization and maintainability by removing obsolete functions related to parsing variables and handling environments.
x/logic/predicate/did_test.go (1)
  • 37-41: The addition of a new test case in the TestDID function to verify the is_did_key predicate with a specific DID value is a valuable enhancement to the test suite. This test case contributes to ensuring the system's behavior is as expected under various scenarios, particularly in relation to did_components and is_did_key.
x/logic/prolog/assert.go (1)
  • 57-173: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [33-180]

The updates in the assert.go file, including the addition of an env *engine.Env parameter to various functions, significantly enhance term resolution and error handling. These changes align with the PR's objectives to refine term resolution processes, contributing to the system's reliability and accuracy in predicate interpretation.

x/logic/predicate/address_test.go (1)
  • 42-47: The addition of a new test case to TestBech32 function is a good practice for ensuring the robustness of the okp4_addr predicate handling. It's important to verify that the address used in the test ('okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6') aligns with the expected format and that the test case accurately reflects the intended behavior of the predicate. This test case enhances the coverage and helps in validating the changes made to address the issue with variable resolution during predicate interpretation.
x/logic/prolog/assert_test.go (2)
  • 197-218: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [187-212]

Refactoring the TestAreGround function to use variables (X, Y, foo, fortyTwo) instead of inline functions for terms improves the readability and maintainability of the test cases. The updated test cases cover different scenarios of term types and structures, which is crucial for ensuring the robustness of term groundness assertions. This change aligns well with the PR objectives of enhancing the system's reliability in predicate interpretation.

  • 248-315: The addition of the TestAssertIsGround function is a significant improvement, as it tests the AssertIsGround functionality with various term scenarios. This function ensures that the system correctly identifies whether terms are grounded or not, which is essential for the robustness of the predicate logic. The test cases cover a wide range of scenarios, including variables, atoms, integers, lists, and compounds, both grounded and containing variables. This comprehensive testing approach is commendable and aligns with the PR objectives to enhance the system's reliability.
x/logic/predicate/crypto.go (2)
  • 170-170: Swapping the order of arguments in the AssertAtom function call for typeAtom is a critical change that needs to be carefully reviewed. Ensure that this change aligns with the updated signature of the AssertAtom function and that it correctly asserts the type of cryptographic algorithm being used. This modification is essential for the correct functioning of the cryptographic verification predicates and should be thoroughly tested to ensure it does not introduce any regressions.
  • 214-214: Similarly, the change in the order of arguments in the AssertAtom function call for encodingAtom must be reviewed with caution. This adjustment must align with the updated function signature and ensure the correct assertion of data encoding options. It's crucial for the accurate processing of data within cryptographic functions. As with the previous change, this modification requires thorough testing to confirm its correctness and to prevent any potential issues in data handling.

@ccamel ccamel requested a review from amimart February 23, 2024 13:54
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.

Thanks! 🙏

Seems good to me

@ccamel ccamel merged commit 0dd8526 into main Feb 23, 2024
19 checks passed
@ccamel ccamel deleted the fix/variable-resolution branch February 23, 2024 16:18
@bot-anik
Copy link
Member

🎉 This PR is included in version 7.0.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