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

Add support overriding block id/tag/hash with a named fork binding #2475

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

kkawula
Copy link
Collaborator

@kkawula kkawula commented Sep 17, 2024

Closes #2450

Introduced changes

  • Added new fork config resolving option

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@kkawula kkawula changed the title Add mixed variant for 'fork' configuration Add support overriding block id/tag/hash with a named fork binding Sep 17, 2024
@kkawula kkawula marked this pull request as draft September 17, 2024 12:19
@kkawula kkawula marked this pull request as ready for review September 18, 2024 14:12
@kkawula kkawula requested a review from Draggu September 18, 2024 14:12
@kkawula kkawula added this pull request to the merge queue Sep 19, 2024
@cptartur cptartur removed this pull request from the merge queue due to a manual request Sep 19, 2024
Copy link
Member

@cptartur cptartur left a comment

Choose a reason for hiding this comment

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

Good work, however this is missing documentation, an entry to CHANGELOG.md and most importantly some actual tests verifying this behaves as intended in crates/forge/tests/integration/setup_fork.rs.

} else {
Err(Diagnostic {
message: $crate::utils::format_error_message(&messages),
severity: messages.into_iter().fold(Severity::Warning, |acc, x| $crate::utils::higher_severity(acc, x.severity))
Copy link
Member

Choose a reason for hiding this comment

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

Nit but I think this could just be reduce since this branch will only execute if there is at least one message in messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose that fold will be more idiomatic in this case, we do not have to think about that there always will be at least one member in the list, we can avoid doing uwrap etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Docs are blocked by #1533, page about forks is reconstructed there. I'll wait till they're done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Please rename this x to more descriptive name

}

#[macro_export]
macro_rules! branch {
Copy link
Collaborator

@ksew1 ksew1 Sep 20, 2024

Choose a reason for hiding this comment

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

I don't know why this is a macro. It would be more readable as a function.

pub fn branch(results: Vec<Result<String, Diagnostic>>) -> Result<String, Diagnostic> {
    let mut messages: Vec<Diagnostic> = Vec::new();

    for result in results {
        match result {
            Ok(val) => return Ok(val),
            Err(err) => messages.push(err),
        }
    }

    Err(Diagnostic {
        message: format_error_message(&messages),
        severity: messages.iter().fold(Severity::Warning, |acc, diagnostic| {
            higher_severity(acc, diagnostic.severity)
        }),
    })
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Macro is lazy

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see it now. At lease give a comment that this is way as it is not obvious to caller

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still can be done with function though

pub fn branch(results: Vec<Box<dyn Fn() -> Result<String, Diagnostic>>>) -> Result<String, Diagnostic> {
    let mut messages: Vec<Diagnostic> = Vec::new();

    for result in results {
        match result() {
            Ok(val) => return Ok(val),
            Err(err) => messages.push(err),
        }
    }

    Err(Diagnostic {
        message: format_error_message(&messages),
        severity: messages.iter().fold(Severity::Warning, |acc, diagnostic| {
            higher_severity(acc, diagnostic.severity)
        }),
    })
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll stay with the macro because it has better readability

Copy link
Collaborator

@ksew1 ksew1 Sep 20, 2024

Choose a reason for hiding this comment

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

No problem 😄. But I think you are mistaking verbosity for readability.

Comment on lines 261 to 262
"tag".to_string(),
"latest".to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

I'd change it to something stable. Let's use specific block number, just different that it is used to override in test.

@@ -1,30 +1,55 @@
use cairo_lang_macro::{Diagnostic, Severity};
use indoc::formatdoc;

fn higher_severity(a: Severity, b: Severity) -> Severity {
pub fn higher_severity(a: Severity, b: Severity) -> Severity {
Copy link
Member

Choose a reason for hiding this comment

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

Why was this done?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has to be changed because the macro uses this function

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.

Support overriding block id/tag/hash with a named fork binding
5 participants