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

feat(cairo_native): add synchronous sierra to native compilation flow #2771

Merged

Conversation

avi-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@avi-starkware avi-starkware force-pushed the avi/compilation-thread/blocking-native-compilation-flow branch from 1aa10c9 to 6487719 Compare December 18, 2024 17:13
Base automatically changed from avi/compilation-thread/papyrus-reader to main December 18, 2024 17:14
Copy link

github-actions bot commented Dec 18, 2024

Artifacts upload workflows:

Copy link
Collaborator

@noaov1 noaov1 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 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, @meship-starkware, and @Yoni-Starkware)


crates/blockifier/src/state/contract_class_manager.rs line 60 at r1 (raw file):

    /// The sierra-to-native compiler.
    #[cfg(feature = "cairo_native")]
    compiler: Option<Arc<dyn SierraToNativeCompiler>>,

Why is it an Arc? process_compilation_request can get a reference.
Why do the ContractClassManager has to hold it in case of a compilation thread?

Code quote:

    compiler: Option<Arc<dyn SierraToNativeCompiler>>,

crates/blockifier/src/state/contract_class_manager.rs line 104 at r1 (raw file):

            std::thread::spawn({
                let contract_caches = contract_caches.clone();
                let compiler = compiler.clone();

Why is the clone needed?

Code quote:

                let compiler = compiler.clone();

crates/blockifier/src/state/contract_class_manager.rs line 118 at r1 (raw file):

    /// Sends a compilation request. Two cases:
    /// 1. If `config.wait_on_native_compilation` is `true`, sends the request to the compilation

No?

Suggestion:

    /// 1. If `config.wait_on_native_compilation` is `false`, sends the request to the compilation

crates/blockifier/src/state/contract_class_manager.rs line 125 at r1 (raw file):

    pub fn send_compilation_request(&self, request: CompilationRequest) {
        assert!(self.config.run_cairo_native, "Native compilation is disabled.");
        self.cache_request_contracts(&request);

As discussed, can be deleted.

Code quote:

        self.cache_request_contracts(&request);

crates/blockifier/src/state/contract_class_manager.rs line 137 at r1 (raw file):

        sender.try_send(request).unwrap_or_else(|err| match err {
            TrySendError::Full((class_hash, _, _)) => {
                error!(

Can you please explain what this macro does?

Code quote:

error!(

crates/blockifier/src/state/contract_class_manager.rs line 215 at r1 (raw file):

fn process_compilation_request(
    contract_caches: ContractCaches,
    compiler: Arc<dyn SierraToNativeCompiler>,

Suggestion:

compiler: &impl SierraToNativeCompiler,

Copy link
Contributor Author

@avi-starkware avi-starkware 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, 5 unresolved discussions (waiting on @avivg-starkware, @meship-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/state/contract_class_manager.rs line 60 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Why is it an Arc? process_compilation_request can get a reference.
Why do the ContractClassManager has to hold it in case of a compilation thread?

I can lose the dyn and give a concrete type here, or use a generic T implementing the trait, But if we don't want to do that, Arc is the only way. Option<impl SierraToNativeCompiler> does not work.

Box doesn't work since we want ContractClassManager to implement Clone.

Regarding the second question, the ContractClassManager does not need to hold the compiler in that case. I removed that.


crates/blockifier/src/state/contract_class_manager.rs line 104 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Why is the clone needed?

It isn't.

Removed


crates/blockifier/src/state/contract_class_manager.rs line 118 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

No?

Done


crates/blockifier/src/state/contract_class_manager.rs line 125 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

As discussed, can be deleted.

I am doing it in the PR unifying the caches


crates/blockifier/src/state/contract_class_manager.rs line 137 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Can you please explain what this macro does?

It prints an error message to stderr using a configurable logger.


crates/blockifier/src/state/contract_class_manager.rs line 215 at r1 (raw file):

fn process_compilation_request(
    contract_caches: ContractCaches,
    compiler: Arc<dyn SierraToNativeCompiler>,

This doesn't work since we can't put the impl SierraToNativeCompile inside an Option (in the ContractClassManager struct)

@avi-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager.rs line 137 at r1 (raw file):

Previously, avi-starkware wrote…

It prints an error message to stderr using a configurable logger.

Should I write log::error!() to make it clearer?

Copy link
Collaborator

@noaov1 noaov1 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, 5 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, @meship-starkware, and @Yoni-Starkware)


crates/blockifier/src/state/contract_class_manager.rs line 60 at r1 (raw file):

Option<impl SierraToNativeCompiler> does not work.

Can you please elaborate?


crates/blockifier/src/state/contract_class_manager.rs line 137 at r1 (raw file):

Previously, avi-starkware wrote…

Should I write log::error!() to make it clearer?

Oh, I see. I prefer that, but I leave it up to you.

@avi-starkware avi-starkware force-pushed the avi/compilation-thread/blocking-native-compilation-flow branch from 6487719 to 57524a5 Compare December 23, 2024 12:34
@avi-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager.rs line 60 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Option<impl SierraToNativeCompiler> does not work.

Can you please elaborate?

I get the following error if I try to do that :

  --> crates/blockifier/src/state/contract_class_manager.rs:60:22
   |
60 |     compiler: Option<impl SierraToNativeCompiler>,
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `impl Trait` is only allowed in arguments and return types of functions and methods

@avi-starkware avi-starkware force-pushed the avi/compilation-thread/blocking-native-compilation-flow branch from 57524a5 to e309bb9 Compare December 23, 2024 12:53
@avi-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager.rs line 137 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Oh, I see. I prefer that, but I leave it up to you.

Done.

@avi-starkware avi-starkware force-pushed the avi/compilation-thread/blocking-native-compilation-flow branch from e309bb9 to 4ad2f79 Compare December 23, 2024 13:02
Copy link
Contributor

@meship-starkware meship-starkware 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: 0 of 1 files reviewed, 5 unresolved discussions (waiting on @avivg-starkware, @noaov1, and @Yoni-Starkware)

Copy link
Contributor

@meship-starkware meship-starkware 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 1 files at r2.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @avivg-starkware, @noaov1, and @Yoni-Starkware)

Copy link
Collaborator

@noaov1 noaov1 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 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @avivg-starkware and @Yoni-Starkware)

Copy link
Contributor Author

@avi-starkware avi-starkware 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 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @avivg-starkware and @Yoni-Starkware)

@avi-starkware avi-starkware merged commit b3047f8 into main Dec 24, 2024
11 checks passed
@avi-starkware avi-starkware deleted the avi/compilation-thread/blocking-native-compilation-flow branch December 24, 2024 08:12
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants