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

More codegen (control flow, if else, while) #77

Merged
merged 20 commits into from
Jan 18, 2024
Merged

More codegen (control flow, if else, while) #77

merged 20 commits into from
Jan 18, 2024

Conversation

edg-l
Copy link
Collaborator

@edg-l edg-l commented Jan 13, 2024

Adds:

  • If support
  • While support
  • Integration tests
  • Some cleanup

This adds support of if statements, which let us already be able to run the following factorial program:

mod Simple {
    fn main() -> i64 {
        return factorial(4);
    }

    fn factorial(n: i64) -> i64 {
        let zero: i64 = 0;
        if n == zero {
            return 1;
        } else {
            return n * factorial(n - 1);
        }
    }
}

Checking the result with bash exit code (needs to be a low value otherwise bash shows 0 because shell limitations)

concrete on  if_impl [$✘!?] via 🦀 v1.75.0 
❯ ./build_artifacts/factorial_if 

concrete on  if_impl [$✘!?] via 🦀 v1.75.0 
❯ echo $?
24

While is also implemented:

mod Simple {
    fn main() -> i64 {
        return my_func(4);
    }

    fn my_func(times: i64) -> i64 {
        let mut n: i64 = times;
        let mut result: i64 = 1;

        while n > 0 {
            result = result + result;
            n = n - 1;
        }

        return result;
    }
}

@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2024

Codecov Report

Attention: 133 lines in your changes are missing coverage. Please review.

Comparison is base (771662e) 14.55% compared to head (e67c308) 68.74%.

Files Patch % Lines
crates/concrete_parser/src/error.rs 0.00% 82 Missing ⚠️
crates/concrete_codegen_mlir/src/codegen.rs 92.26% 28 Missing ⚠️
crates/concrete_driver/src/lib.rs 0.00% 13 Missing ⚠️
crates/concrete_session/src/lib.rs 0.00% 6 Missing ⚠️
crates/concrete_codegen_mlir/src/context.rs 33.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #77       +/-   ##
===========================================
+ Coverage   14.55%   68.74%   +54.18%     
===========================================
  Files          27       27               
  Lines         886     1187      +301     
===========================================
+ Hits          129      816      +687     
+ Misses        757      371      -386     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@edg-l edg-l marked this pull request as ready for review January 15, 2024 11:26
@edg-l edg-l changed the title More codegen (control flow, if else) More codegen (control flow, if else, while) Jan 15, 2024
@edg-l edg-l mentioned this pull request Jan 16, 2024
@igaray igaray merged commit 4f68ec5 into main Jan 18, 2024
4 checks passed
@igaray igaray deleted the if_impl branch January 18, 2024 12:42
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.

5 participants