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

Implement a macro checking experimental_features during building project config #1040

Open
tomek0123456789 opened this issue Jan 8, 2024 · 0 comments

Comments

@tomek0123456789
Copy link
Contributor

tomek0123456789 commented Jan 8, 2024

Problem

I have an idea how to ensure in compile-time that the list of experiments is exhaustive:
Write a macro (macro_rules!), which usage would look like this:

experimental_features!(ExperimentalFeatues, [negative_impls,something_else,etc])

which would expand to something like this:

// Struct name is the first argument to the macro.
struct ExperimentalFeatures(HashSet<SmolStr>);

impl ExperimentalFeatures {
    fn new_checked(values: HashSet<SmolStr>, package: PackageId, ui: &Ui) -> Self {
        for feature in &values {
             match feature {
                 "negative_impls" => {},
                 "something_else" => {},
                 "etc" => {},
                 _ => ui.warn(&format!("{package}: unknown experimental feature: {feature}"))
             }
        }
        Self(values)
    }

    fn to_compiler_features(&self) -> cairo_lang_filesystem::db::ExperimentalFeaturesConfig {
        // Rust compiler will check exhaustiveness here
        cairo_lang_filesystem::db::ExperimentalFeaturesConfig {
            negative_impls: self.0.contains("negative_impls"),
        }
    }
}

Do it here (compiler config) and here (snforge-test-collector)

Additionally, add checking for fields that are not in ExperimentalFeaturesConfig and raise warnings for those not in the struct (probably before parsing it into Manifest, here). Add a test checking that, too.


Search in code by phrase TODO (#1040)

Originally discussed here.

Proposed Solution

No response

Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

1 participant