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 compiler flag to disable inlining #5911

Merged
merged 10 commits into from
Jul 2, 2024

Conversation

javra
Copy link
Contributor

@javra javra commented Jun 28, 2024

For the discussion see the issue. Adds fields disable_inlining to CompilerConfig, RootDatabaseBuilder and OptimizationConfig. I don't know if there is any slicker way of adding the option.

This change is Reviewable

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 6 of 8 files at r1, all commit messages.
Reviewable status: 6 of 8 files reviewed, 1 unresolved discussion (waiting on @javra)


crates/cairo-lang-lowering/src/inline/mod.rs line 68 at r1 (raw file):

    )?;

    Ok(match config {

Move the query out of the match.
Ok(if db.optconfig().disable..() { matches!(config, Always(_)) } else .....

@mkaput mkaput linked an issue Jun 28, 2024 that may be closed by this pull request
2 tasks
Copy link
Member

@mkaput mkaput 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: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)


crates/bin/cairo-compile/src/main.rs line 27 at r1 (raw file):

    /// Disables inlining functions
    #[arg(short, long, default_value_t = false)]
    disable_inlining: bool,

I don't feel this is a good representation of the property here:

  1. It's negated.
  2. I feel true/false may not be enough cases.

What do you think about using an enum here and in CompilerConfig? Say

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
enum IniliningStrategy {
    #[default]
    Default,
    Avoid, // Future case I can imagine, allow inline(always) but forbid others.
    Forbid
}

Copy link
Member

@mkaput mkaput 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: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)


crates/bin/cairo-compile/src/main.rs line 27 at r1 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I don't feel this is a good representation of the property here:

  1. It's negated.
  2. I feel true/false may not be enough cases.

What do you think about using an enum here and in CompilerConfig? Say

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
enum IniliningStrategy {
    #[default]
    Default,
    Avoid, // Future case I can imagine, allow inline(always) but forbid others.
    Forbid
}

Oh, just noticed there's InliningConfiguration enum already in the codebase -- reuse it

@javra
Copy link
Contributor Author

javra commented Jun 28, 2024

Reviewable status: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)

crates/bin/cairo-compile/src/main.rs line 27 at r1 (raw file):

    /// Disables inlining functions
    #[arg(short, long, default_value_t = false)]
    disable_inlining: bool,

I don't feel this is a good representation of the property here:

1. It's negated.

2. I feel `true`/`false` may not be enough cases.

What do you think about using an enum here and in CompilerConfig? Say

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
enum IniliningStrategy {
    #[default]
    Default,
    Avoid, // Future case I can imagine, allow inline(always) but forbid others.
    Forbid
}

Sounds good, like I said in the other discussions, I'd love an option that overrides even the local inline(always) annotations.

@javra
Copy link
Contributor Author

javra commented Jun 28, 2024

Oh, just noticed there's InliningConfiguration enum already in the codebase -- reuse it

Do the same four options in InlineConfiguration make sense as global options as well though? How to reconcile the local vs the global ones then? 🤔

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

@javra please use Reviewable in this repository for responding to comments, you can find the button in PR description :)

Reviewable status: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)

Copy link
Member

@mkaput mkaput 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: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)


crates/bin/cairo-compile/src/main.rs line 27 at r1 (raw file):

Previously, javra (Jakob von Raumer) wrote…

Sounds good, like I said in the other discussions, I'd love an option that overrides even the local inline(always) annotations.

Ah you're right, it's not exactly representing what we're conveying here. So my first comment applies then

Copy link
Contributor Author

@javra javra 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: 0 of 12 files reviewed, 3 unresolved discussions (waiting on @mkaput and @orizi)


crates/cairo-lang-lowering/src/utils.rs line 14 at r2 (raw file):

/// Options for the `inlining` arguments
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
pub enum InliningStrategy {

I put the enum in cairo-lang-lowering::utils, maybe cairo-lang-utils might be the better choice?

Copy link
Member

@mkaput mkaput 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: 0 of 12 files reviewed, 2 unresolved discussions (waiting on @javra and @orizi)


crates/cairo-lang-lowering/src/utils.rs line 14 at r2 (raw file):

Previously, javra (Jakob von Raumer) wrote…

I put the enum in cairo-lang-lowering::utils, maybe cairo-lang-utils might be the better choice?

I think lowering is the good place, but using clap in lib-crates is not.

It'd be best IMO to:

  1. copy-paste this enum just with clap::ValueEnum to cairo-compile
  2. add there the following:
impl From<crate::InliningStrategy> for cairo_lang_lowering::InliningStrategy {
...
}

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 5 of 12 files at r2, all commit messages.
Reviewable status: 5 of 12 files reviewed, 4 unresolved discussions (waiting on @javra and @mkaput)


crates/cairo-lang-lowering/Cargo.toml line 19 at r3 (raw file):

cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "~2.6.4" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.6.4" }
clap.workspace = true

this shouldn't be a dependency of the lowering.


crates/cairo-lang-lowering/src/utils.rs line 14 at r2 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I think lowering is the good place, but using clap in lib-crates is not.

It'd be best IMO to:

  1. copy-paste this enum just with clap::ValueEnum to cairo-compile
  2. add there the following:
impl From<crate::InliningStrategy> for cairo_lang_lowering::InliningStrategy {
...
}

good suggestion.


crates/cairo-lang-lowering/src/utils.rs line 19 at r3 (raw file):

    /// Inline only in the case of a `inline(always)` annotation
    Avoid,
    /// Never inline

as discussed - this would cause the compiler to crash - so remove this as an option.

you can (in another PR) remove all inline(always) from the corelib (aside from 2 probably, and switch them with a simple inline.

Copy link
Contributor Author

@javra javra 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: 5 of 12 files reviewed, 4 unresolved discussions (waiting on @mkaput and @orizi)


crates/cairo-lang-lowering/src/utils.rs line 14 at r2 (raw file):

Previously, orizi wrote…

good suggestion.

Ah yes, that's a good solution 👍


crates/cairo-lang-lowering/src/utils.rs line 19 at r3 (raw file):

Previously, orizi wrote…

as discussed - this would cause the compiler to crash - so remove this as an option.

you can (in another PR) remove all inline(always) from the corelib (aside from 2 probably, and switch them with a simple inline.

Thanks, can you point me towards which ones are the 2 I won't be able to remove?


crates/cairo-lang-lowering/src/inline/mod.rs line 68 at r1 (raw file):

Previously, orizi wrote…

Move the query out of the match.
Ok(if db.optconfig().disable..() { matches!(config, Always(_)) } else .....

Done.

Copy link
Contributor Author

@javra javra 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: 3 of 12 files reviewed, 3 unresolved discussions (waiting on @mkaput and @orizi)


crates/cairo-lang-lowering/Cargo.toml line 19 at r3 (raw file):

Previously, orizi wrote…

this shouldn't be a dependency of the lowering.

Done.

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 4 of 12 files at r2, 4 of 5 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @javra)


crates/cairo-lang-lowering/src/utils.rs line 19 at r3 (raw file):

Previously, javra (Jakob von Raumer) wrote…

Thanks, can you point me towards which ones are the 2 I won't be able to remove?

IIRC - basically only Option::unwrap - but not for this PR in any case.

Copy link
Contributor Author

@javra javra 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-lowering/src/utils.rs line 19 at r3 (raw file):

Previously, orizi wrote…

IIRC - basically only Option::unwrap - but not for this PR in any case.

Done.

@piotmag769 piotmag769 requested a review from orizi July 1, 2024 08:21
Copy link
Collaborator

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

Just making sure - you don't need this flag for tests compilation, do you?

Reviewed 7 of 12 files at r2, 4 of 5 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (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:

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

Copy link
Contributor Author

@javra javra left a comment

Choose a reason for hiding this comment

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

@piotmag769 Correct

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

@javra javra requested a review from mkaput July 1, 2024 09:12
Copy link
Collaborator

@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 @mkaput)

Copy link
Member

@mkaput mkaput 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 12 files at r2, 4 of 5 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @javra)


crates/bin/cairo-compile/src/main.rs line 18 at r5 (raw file):

    /// Inline only in the case of a `inline(always)` annotation
    Avoid,
}

nitpick

Suggestion:

/// Options for the `inlining` arguments.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
pub enum InliningStrategy {
    /// Do not override inlining strategy.
    #[default]
    Default,
    /// Inline only in the case of a `inline(always)` annotation.
    Avoid,
}

crates/bin/cairo-compile/src/main.rs line 44 at r5 (raw file):

    #[arg(short, long, default_value_t = false)]
    replace_ids: bool,
    /// Overrides inlining behavior

Suggestion:

    /// Overrides inlining behavior.

Copy link
Contributor Author

@javra javra 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: 10 of 12 files reviewed, 2 unresolved discussions (waiting on @mkaput, @orizi, and @piotmag769)


crates/bin/cairo-compile/src/main.rs line 18 at r5 (raw file):

Previously, mkaput (Marek Kaput) wrote…

nitpick

Done.


crates/bin/cairo-compile/src/main.rs line 44 at r5 (raw file):

    #[arg(short, long, default_value_t = false)]
    replace_ids: bool,
    /// Overrides inlining behavior

Done.

@javra javra requested a review from mkaput July 1, 2024 13:02
Copy link
Member

@mkaput mkaput 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 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @javra)

Copy link
Contributor Author

@javra javra 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 12 files at r2, 2 of 5 files at r4, 2 of 2 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @javra)

@javra javra force-pushed the feat/disable_inlining branch from d39f651 to 68756de Compare July 1, 2024 13:40
Copy link
Member

@mkaput mkaput 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 r7, 1 of 1 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @javra)

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 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @javra)

Copy link
Member

@mkaput mkaput 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 r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @javra)

@mkaput mkaput added this pull request to the merge queue Jul 2, 2024
Merged via the queue into starkware-libs:main with commit 43cf361 Jul 2, 2024
44 checks passed
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.

feat: Add a compiler flag to turn off inlining
4 participants