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

Adds break expressions #62

Merged
merged 3 commits into from
Nov 23, 2019
Merged

Adds break expressions #62

merged 3 commits into from
Nov 23, 2019

Conversation

baszalmstra
Copy link
Collaborator

@baszalmstra baszalmstra commented Nov 23, 2019

This PR adds the break expression to Mun. It allows breaking from loops and enables loops to have return types different from never.

The following code should work properly.

fn fibonacci(n:int):int {
    let a = 0;
    let b = 1;
    let i = 1;
    loop {
        if i > n {
            break a;
        }
        let sum = a + b;
        a = b;
        b = sum;
        i += 1;
    }
}

Here the loop should get the int type instead of the never type due to the break a statement.

  • Implement parsing of break expressions.
  • Implement proper type inferencing and diagnostics
    • Do not allow break expression outside loops
    • Multiple break expressions must have the same type
  • Implement code generation for the break statement

Depends on #60

@baszalmstra baszalmstra self-assigned this Nov 23, 2019
@baszalmstra
Copy link
Collaborator Author

Break expression

@codecov
Copy link

codecov bot commented Nov 23, 2019

Codecov Report

Merging #62 into master will increase coverage by 0.25%.
The diff coverage is 85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #62      +/-   ##
==========================================
+ Coverage   71.08%   71.34%   +0.25%     
==========================================
  Files         106      106              
  Lines        6928     7073     +145     
==========================================
+ Hits         4925     5046     +121     
- Misses       2003     2027      +24
Impacted Files Coverage Δ
crates/mun_syntax/src/parsing/token_set.rs 68.18% <ø> (ø) ⬆️
crates/mun_codegen/src/ir/body.rs 85.5% <100%> (+1.3%) ⬆️
crates/mun_syntax/src/syntax_kind/generated.rs 79.34% <100%> (+0.11%) ⬆️
crates/mun_runtime/src/test.rs 95.76% <100%> (+0.26%) ⬆️
crates/mun_syntax/src/tests/parser.rs 98.14% <100%> (+0.1%) ⬆️
crates/mun_hir/src/ty/tests.rs 95.91% <100%> (+0.12%) ⬆️
crates/mun_codegen/src/test.rs 100% <100%> (ø) ⬆️
crates/mun_hir/src/diagnostics.rs 16.21% <20%> (+0.27%) ⬆️
crates/mun_syntax/src/ast/generated.rs 56.17% <66.66%> (+0.3%) ⬆️
crates/mun_hir/src/expr.rs 76.05% <90%> (+0.33%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 867948c...048a362. Read the comment docs.

@baszalmstra baszalmstra force-pushed the break branch 2 times, most recently from 6ac5d7a to efc52b2 Compare November 23, 2019 15:12
@baszalmstra baszalmstra changed the title WIP: Break expressions Adds break expressions Nov 23, 2019
@baszalmstra baszalmstra marked this pull request as ready for review November 23, 2019 15:13
@baszalmstra baszalmstra requested a review from Wodann November 23, 2019 15:13
@baszalmstra baszalmstra merged commit 103c621 into mun-lang:master Nov 23, 2019
@baszalmstra baszalmstra deleted the break branch November 23, 2019 18:40
@Wodann Wodann added this to the Mun v0.2 milestone May 14, 2020
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.

2 participants