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 statements->functions map to SierraDebugInfo #5325

Merged
merged 10 commits into from
Mar 27, 2024
Merged

Add statements->functions map to SierraDebugInfo #5325

merged 10 commits into from
Mar 27, 2024

Conversation

piotmag769
Copy link
Collaborator

@piotmag769 piotmag769 commented Mar 25, 2024

Follow up to #5306

This change is Reviewable

@piotmag769 piotmag769 marked this pull request as draft March 25, 2024 14:36
@piotmag769 piotmag769 marked this pull request as ready for review March 25, 2024 15:46
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 22 files at r1, all commit messages.
Reviewable status: 1 of 22 files reviewed, 1 unresolved discussion (waiting on @piotmag769)


crates/cairo-lang-sierra/src/debug_info.rs line 40 at r1 (raw file):

    pub annotations: Annotations,

    pub statements_functions: Option<StatementsFunctions>,

how difficult would it be to just insert into the annotations structure?
this would add no dependencies here.

Code quote:

    pub statements_functions: Option<StatementsFunctions>,

@piotmag769 piotmag769 requested a review from orizi March 25, 2024 18:32
Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 23 files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-sierra/src/debug_info.rs line 40 at r1 (raw file):

Previously, orizi wrote…

how difficult would it be to just insert into the annotations structure?
this would add no dependencies here.

Done

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 22 files at r1, 16 of 16 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 12 of 12 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-compiler/src/lib.rs line 38 at r3 (raw file):

    /// Adds mappings used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler)
    /// to debug info annotations.
    pub add_cairo_profiler_annotations: bool,

Decided to make it configurable so it doesn't slow down the compiler


crates/cairo-lang-starknet/src/test_utils.rs line 85 at r3 (raw file):

            allowed_libfuncs_list_name: Some(BUILTIN_ALL_LIBFUNCS_LIST.to_string()),
            diagnostics_reporter,
            add_cairo_profiler_annotations: true,

Here for testing purposes

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra/src/debug_info.rs line 83 at r3 (raw file):

        } else {
            Default::default()
        };

add all of this externally - not here.

Code quote:

/// The mapping from sierra statement index to fully qualified Cairo path of the Cairo function
/// (if obtainable) which caused the statement to be generated.
///  Should be created using [`StatementsLocation::extract_statements_functions`].
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct StatementsFunctions {
    pub statements_to_functions_map: HashMap<StatementIdx, Option<String>>,
}

impl DebugInfo {
    /// Extracts the existing debug info from a program.
    pub fn extract(program: &Program, statements_functions: Option<StatementsFunctions>) -> Self {
        let annotations = if let Some(sf) = statements_functions {
            let mapping = serde_json::to_value(sf.statements_to_functions_map).unwrap();
            OrderedHashMap::from([(
                "github.com/software-mansion/cairo-profiler".to_string(),
                serde_json::Value::from_iter([("statements_functions", mapping)]),
            )])
        } else {
            Default::default()
        };

crates/cairo-lang-sierra-generator/src/program_generator.rs line 336 at r3 (raw file):

    db: &dyn SierraGenGroup,
    requested_crate_ids: Vec<CrateId>,
    add_cairo_profiler_annotations: bool,

probably - since this is not directly profiler related

Suggestion:

    add_location_annotations: bool,

crates/cairo-lang-sierra-generator/src/statements_locations.rs line 152 at r3 (raw file):

    }

    pub fn extract_statements_functions(&self, db: &dyn DefsGroup) -> StatementsFunctions {

doc.


crates/cairo-lang-starknet/src/test_utils.rs line 85 at r3 (raw file):

Previously, piotmag769 (Piotr Magiera) wrote…

Here for testing purposes

make it false - as i don't want this data for the starknet tests.
you should do a specific test for it somewhere else.

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra/src/debug_info.rs line 83 at r3 (raw file):

Previously, orizi wrote…

add all of this externally - not here.

You mean in the other function? Done.


crates/cairo-lang-sierra-generator/src/program_generator.rs line 336 at r3 (raw file):

Previously, orizi wrote…

probably - since this is not directly profiler related

Done.


crates/cairo-lang-sierra-generator/src/statements_locations.rs line 152 at r3 (raw file):

Previously, orizi wrote…

doc.

Done.


crates/cairo-lang-starknet/src/test_utils.rs line 85 at r3 (raw file):

Previously, orizi wrote…

make it false - as i don't want this data for the starknet tests.
you should do a specific test for it somewhere else.

Done.

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 22 of 22 files at r4, 14 of 14 files at r5, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @orizi)

@piotmag769 piotmag769 requested a review from orizi March 26, 2024 10:58
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 12 files at r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra/src/debug_info.rs line 83 at r3 (raw file):

Previously, piotmag769 (Piotr Magiera) wrote…

You mean in the other function? Done.

this shouldn't be in this crate at all.
move this to the place where it is actually added.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra/src/debug_info.rs line 83 at r3 (raw file):

Previously, orizi wrote…

this shouldn't be in this crate at all.
move this to the place where it is actually added.

or a completely different crate.
i expect to see no changes in the sierra crate.

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 10 files at r6, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra/src/debug_info.rs line 83 at r3 (raw file):

Previously, orizi wrote…

or a completely different crate.
i expect to see no changes in the sierra crate.

Created a different crate, done.

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 11 of 11 files at r7, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @orizi)

@piotmag769 piotmag769 requested a review from orizi March 26, 2024 12:59
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 22 files at r4, 13 of 14 files at r5, 1 of 10 files at r6, 3 of 11 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

        program,
        debug_info: SierraProgramDebugInfo { statements_locations, statements_functions },
    }))

can't you call this externally?
you already have the db and the extra results.

Code quote:

    let statements_locations = StatementsLocations::from_locations_vec(&statements_locations);
    let statements_functions = if add_location_annotations {
        Some(statements_locations.extract_statements_functions(db.upcast()))
    } else {
        None
    };

    Ok(Arc::new(SierraProgramWithDebug {
        program,
        debug_info: SierraProgramDebugInfo { statements_locations, statements_functions },
    }))

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r8, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

Previously, orizi wrote…

can't you call this externally?
you already have the db and the extra results.

Done

@piotmag769 piotmag769 requested a review from orizi March 26, 2024 14:12
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

Previously, piotmag769 (Piotr Magiera) wrote…

Done

You can remove it (and the bool) from here completely.

just call extract_statement_functions directly on the output if required.

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r9, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

Previously, orizi wrote…

You can remove it (and the bool) from here completely.

just call extract_statement_functions directly on the output if required.

Misunderstood you, done.

@piotmag769 piotmag769 requested a review from orizi March 26, 2024 15:37
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 6 files at r9, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

Previously, piotmag769 (Piotr Magiera) wrote…

Misunderstood you, done.

remove it completely.
pub statements_functions: Option<StatementsFunctions>,
is not needed as part of the structure at all IIUC.
you can just have the db available, and extract statements_functions from statements_functions and strait into annotations.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @piotmag769)


crates/cairo-lang-sierra-generator/src/function_generator_test_data/generics line 14 at r9 (raw file):

foo

//! > module_code

revert

@piotmag769 piotmag769 requested a review from orizi March 26, 2024 18:08
Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 28 of 37 files reviewed, 2 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra-generator/src/program_generator.rs line 291 at r7 (raw file):

Previously, orizi wrote…

remove it completely.
pub statements_functions: Option<StatementsFunctions>,
is not needed as part of the structure at all IIUC.
you can just have the db available, and extract statements_functions from statements_functions and strait into annotations.

Forgot it is not necessary here as it is not the debug info that is used in VersionedProgram


crates/cairo-lang-sierra-generator/src/function_generator_test_data/generics line 14 at r9 (raw file):

Previously, orizi wrote…

revert

This was actually generated by running CAIRO_FIX_TESTS=1 cargo test

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 9 files at r10, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 5 of 9 files at r10, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @piotmag769)


crates/cairo-lang-sierra-generator/src/statements_functions.rs line 23 at r10 (raw file):

            serde_json::Value::from_iter([("statements_functions", mapping)]),
        )])
    }

make the function add instead - in case there are other annotations.

Code quote:

impl From<StatementsFunctions> for Annotations {
    fn from(value: StatementsFunctions) -> Self {
        let mapping = serde_json::to_value(value.statements_to_functions_map).unwrap();
        OrderedHashMap::from([(
            "github.com/software-mansion/cairo-profiler".to_string(),
            serde_json::Value::from_iter([("statements_functions", mapping)]),
        )])
    }

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-sierra-generator/src/statements_functions.rs line 23 at r10 (raw file):

Previously, orizi wrote…

make the function add instead - in case there are other annotations.

The adding is done in ContractClass::new, this one is a cast

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 11 files at r7, 1 of 6 files at r9, 1 of 9 files at r10.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @piotmag769)

Copy link
Collaborator Author

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @piotmag769)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r11, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @piotmag769)

@orizi orizi enabled auto-merge March 27, 2024 10:26
@orizi orizi added this pull request to the merge queue Mar 27, 2024
Merged via the queue into starkware-libs:main with commit babbb5a Mar 27, 2024
43 checks passed
@piotmag769 piotmag769 deleted the add-debug-info-field branch March 27, 2024 10:44
shramee pushed a commit to shramee/cairo that referenced this pull request Sep 17, 2024
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.

2 participants