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

Migrated the compiler to per-crate plugin queries #6843

Open
wants to merge 1 commit into
base: spr/main/ffce04df
Choose a base branch
from

Conversation

integraledelebesgue
Copy link
Collaborator

@integraledelebesgue integraledelebesgue commented Dec 6, 2024

@reviewable-StarkWare
Copy link

This change is Reviewable

@integraledelebesgue integraledelebesgue force-pushed the spr/main/f0989263 branch 2 times, most recently from f500b20 to 2ff4cac Compare December 6, 2024 13:04
@integraledelebesgue integraledelebesgue changed the base branch from spr/main/d4abac73 to main December 9, 2024 21:24
@integraledelebesgue integraledelebesgue changed the title Migrated compiler to per-crate plugin queries Introduced per-crate plugin queries to the compiler Dec 9, 2024
@integraledelebesgue integraledelebesgue changed the base branch from main to spr/main/ffce04df December 9, 2024 21:24
@integraledelebesgue integraledelebesgue force-pushed the spr/main/f0989263 branch 2 times, most recently from 6c8700c to eb2d318 Compare December 9, 2024 21:37
@integraledelebesgue integraledelebesgue requested review from piotmag769 and removed request for wawel37 December 9, 2024 21:48
Copy link
Collaborator Author

@integraledelebesgue integraledelebesgue 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 65 files reviewed, 1 unresolved discussion (waiting on @mkaput, @orizi, and @piotmag769)


a discussion (no related file):
I have two problems here which I am work on now:

  1. Fallback from "override" to "default" input (e.g. DefsGroup::default_macro_plugins and DefsGroup::override_crate_macro_plugins) is tricky to implement due to the way the input getters are implemented in Salsa: they panic. Sadly, I cannot catch the panic without constraining the DefsGroup (and, consequently, all its subtraits) to UnwindSafe.
  2. Tests related to circuits break because the compiler's input has Tuple<...> types instead of (...) structural types.

However, the rest of the stack is ready to be reviewed.

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 58 of 64 files at r3, all commit messages.
Reviewable status: 58 of 65 files reviewed, 1 unresolved discussion (waiting on @integraledelebesgue, @orizi, and @piotmag769)


a discussion (no related file):

Previously, integraledelebesgue (Jan Smółka) wrote…

I have two problems here which I am work on now:

  1. Fallback from "override" to "default" input (e.g. DefsGroup::default_macro_plugins and DefsGroup::override_crate_macro_plugins) is tricky to implement due to the way the input getters are implemented in Salsa: they panic. Sadly, I cannot catch the panic without constraining the DefsGroup (and, consequently, all its subtraits) to UnwindSafe.
  2. Tests related to circuits break because the compiler's input has Tuple<...> types instead of (...) structural types.

However, the rest of the stack is ready to be reviewed.

Ad 1. I believe that's the reason file_overrides in FilesGroup are implemented as two queries: one, the parameterless input, keeps an HashMap of FileId -> override and the other query meant for broad use does the lookup and returns Option

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 65 files at r1, 6 of 64 files at r3.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @integraledelebesgue, @orizi, and @piotmag769)


crates/cairo-lang-semantic/src/types.rs line 187 at r3 (raw file):

    /// containing it.
    pub fn is_phantom(&self, db: &dyn SemanticGroup) -> bool {
        let Some(module_file_id) = self.module_file_id(db) else {

I think this generalization of module_file_id for any TypeId is misleading a bit, and not really that useful outside this context. See my other comment down this file for an explanation of how I believe this should work.


crates/cairo-lang-semantic/src/types.rs line 205 at r3 (raw file):

                    .iter()
                    .any(|attr| id.has_attr(db, attr).unwrap_or_default()),
            },

I think this is the place where you should actually look for the crate and its declared phantom type attrs. Here, you know a concrete item that we're interested in, so we can always reliably ask for its crate.

Code quote:

            TypeLongId::Concrete(id) => match id {
                ConcreteTypeId::Struct(id) => phantom_type_attributes
                    .iter()
                    .any(|attr| id.has_attr(db, attr).unwrap_or_default()),
                ConcreteTypeId::Enum(id) => phantom_type_attributes
                    .iter()
                    .any(|attr| id.has_attr(db, attr).unwrap_or_default()),
                ConcreteTypeId::Extern(id) => phantom_type_attributes
                    .iter()
                    .any(|attr| id.has_attr(db, attr).unwrap_or_default()),
            },

crates/cairo-lang-semantic/src/types.rs line 208 at r3 (raw file):

            TypeLongId::Tuple(inner) => inner.iter().any(|ty| ty.is_phantom(db)),
            TypeLongId::FixedSizeArray { type_id, .. } => type_id.is_phantom(db),
            TypeLongId::Snapshot(_)

This is an example where generalized module_file_id might not be a good idea: we don't need it for snapshots, yet your code attempted to look for something.

Copy link
Collaborator

@Draggu Draggu 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: all files reviewed, 4 unresolved discussions (waiting on @integraledelebesgue, @orizi, and @piotmag769)

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 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @integraledelebesgue, @orizi, and @piotmag769)

@integraledelebesgue integraledelebesgue force-pushed the spr/main/f0989263 branch 2 times, most recently from 39e8dc8 to d60d143 Compare December 11, 2024 11:56
Copy link
Collaborator Author

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


crates/cairo-lang-semantic/src/types.rs line 205 at r3 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I think this is the place where you should actually look for the crate and its declared phantom type attrs. Here, you know a concrete item that we're interested in, so we can always reliably ask for its crate.

Done, as you said :)

Copy link
Collaborator Author

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


a discussion (no related file):

Previously, mkaput (Marek Kaput) wrote…

Ad 1. I believe that's the reason file_overrides in FilesGroup are implemented as two queries: one, the parameterless input, keeps an HashMap of FileId -> override and the other query meant for broad use does the lookup and returns Option

Update: 2 has been fixed, now I work on 1

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

@integraledelebesgue integraledelebesgue force-pushed the spr/main/f0989263 branch 2 times, most recently from 5c20a2b to e797670 Compare December 13, 2024 07:13
@integraledelebesgue integraledelebesgue changed the title Introduced per-crate plugin queries to the compiler Migrated the compiler to per-crate plugin queries Dec 13, 2024
@integraledelebesgue integraledelebesgue force-pushed the spr/main/f0989263 branch 2 times, most recently from 1c41148 to b02b437 Compare December 13, 2024 08:17
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 9 of 9 files at r6, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @integraledelebesgue, @orizi, and @piotmag769)


crates/cairo-lang-compiler/src/db.rs line 57 at r6 (raw file):

        init_lowering_group(&mut res, inlining_strategy);
        init_defs_group(&mut res);
        init_semantic_group(&mut res);

this should be changed in the PR introducing these fns

Copy link
Collaborator Author

@integraledelebesgue integraledelebesgue 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 @mkaput, @orizi, and @piotmag769)


crates/cairo-lang-compiler/src/db.rs line 57 at r6 (raw file):

Previously, mkaput (Marek Kaput) wrote…

this should be changed in the PR introducing these fns

I know it might not be very review-friendly, but this PR, in general, introduces all the new logic I prepared in the preceding ones. Thus I decided to use these functions here too

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:

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


crates/cairo-lang-compiler/src/db.rs line 57 at r6 (raw file):

Previously, integraledelebesgue (Jan Smółka) wrote…

I know it might not be very review-friendly, but this PR, in general, introduces all the new logic I prepared in the preceding ones. Thus I decided to use these functions here too

mind that #6840 is potentially broken without changes from this PR, that's what I'm mostly nitpicking about. but yeah, this is nitpicking on my side.

unlocking

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 6 of 6 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi and @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.

:lgtm:

Reviewed 52 of 64 files at r3, 4 of 8 files at r5, 3 of 9 files at r6, 6 of 6 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @piotmag769)

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:

Really good job (reviewed everything as full diff of the 3 PRs, everything seems fine)

Reviewed 52 of 64 files at r3, 5 of 8 files at r5, 3 of 9 files at r6, 6 of 6 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @integraledelebesgue)

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.

6 participants