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

Constant-folding on intermediate language #46

Open
6 tasks
Sword-Smith opened this issue Sep 27, 2023 · 0 comments
Open
6 tasks

Constant-folding on intermediate language #46

Sword-Smith opened this issue Sep 27, 2023 · 0 comments

Comments

@Sword-Smith
Copy link
Contributor

Constant folding in the intermediate language should reduce expressions such as BFieldElement::new(100) * BFieldElement::new(100) to BFieldElement::new(10_000).

The compiler will parse and graft let a: BFieldElement = BFieldElement::new(100) * BFieldElement::new(100); to this intermediate expression:

Let(
            LetStmt {
                var_name: "a",
                mutable: false,
                data_type: BFE,
                expr: Binop(
                    Lit(
                        BFE(
                            BFieldElement(
                                429496729500,
                            ),
                        ),
                    ),
                    Mul,
                    Lit(
                        BFE(
                            BFieldElement(
                                429496729500,
                            ),
                        ),
                    ),
                    KnownType(
                        BFE,
                    ),
                ),
            },
        ),

After the constant folding the BinOp of type Mul should be removed and only one BFE element should remain.

Constant folding on the intermediate language should be handled for these data types:

  • bool, simplifying e.g. !!a to a
  • BFieldElement (internally called BFE)
  • XFieldElement (internally called XFE)
  • u32 simplifying e.g. 14u32 + 15u32 to 29u32
  • u64
  • u128
@Sword-Smith Sword-Smith changed the title Constant folding on intermediate language Constant-folding on intermediate language Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant