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

Support let bindings in Effect blocks #95

Merged
merged 1 commit into from
Nov 8, 2022
Merged

Support let bindings in Effect blocks #95

merged 1 commit into from
Nov 8, 2022

Conversation

jmackie
Copy link
Member

@jmackie jmackie commented Nov 7, 2022

This allows pure variable binding in Effect blocks. For example:

main = do {
    let five: Int = 5;
    return five
};

Of course the above is a bit redundant (and should probably be rewritten as part of the JS codegen 👀 ) but this is useful in less trivial cases.

It's particularly useful as we don't currently support patterns on the left-hand side of effect binds (<-, due to parsing restrictions).

So eventually this will be nice for code like:

main = do {
    env <- get_env();
    let { foo } = env;
    return foo
};

Also note that as part of this I had to add a fresh variable supply to the JavaSCript code generator, so that we can use generated variables without risking bad const assignments (i.e. Identifier 'x' has already been declared).

box expression,
box rest,
} => {
// REVIEW: could just drop the unused assignment altogether?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily want to do this because we might want to...

let _ = Debug.spy(some_value);

} => {
// REVIEW: could just drop the unused assignment altogether?
Block::ConstAssignment {
ident: Ident::from(unused_name),
Copy link
Member Author

@jmackie jmackie Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might blowup if we have something like...

let _ = 1;
let _ = 2;
let _ = 3;

In which case we could end generating dodgy const assignments, i.e.

const _ = 1;
const _ = 2;  // Identifier '_' has already been declared
const _ = 3;

@codecov
Copy link

codecov bot commented Nov 7, 2022

Codecov Report

Merging #95 (0407ccc) into main (edc8829) will increase coverage by 0.12%.
The diff coverage is 87.73%.

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
+ Coverage   73.90%   74.03%   +0.12%     
==========================================
  Files         111      111              
  Lines        8319     8406      +87     
==========================================
+ Hits         6148     6223      +75     
- Misses       2171     2183      +12     
Impacted Files Coverage Δ
crates/ditto-ast/src/expression.rs 81.63% <ø> (ø)
crates/ditto-codegen-js/src/optimize/mod.rs 95.30% <ø> (ø)
crates/ditto-fmt/src/has_comments.rs 44.74% <0.00%> (-1.63%) ⬇️
crates/ditto-codegen-js/src/convert.rs 95.33% <89.47%> (-1.11%) ⬇️
...ditto-checker/src/module/value_declarations/mod.rs 91.44% <100.00%> (+0.19%) ⬆️
crates/ditto-checker/src/typechecker/mod.rs 82.47% <100.00%> (+0.39%) ⬆️
crates/ditto-checker/src/typechecker/pre_ast.rs 100.00% <100.00%> (ø)
...ates/ditto-checker/src/typechecker/substitution.rs 78.07% <100.00%> (+0.59%) ⬆️
...ates/ditto-checker/src/typechecker/tests/effect.rs 100.00% <100.00%> (ø)
crates/ditto-cst/src/parser/tests/expression.rs 100.00% <100.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jmackie jmackie merged commit 74d872f into main Nov 8, 2022
@jmackie jmackie deleted the effect-let branch November 8, 2022 09:35
@jmackie jmackie mentioned this pull request Dec 5, 2022
5 tasks
@jmackie jmackie linked an issue Dec 5, 2022 that may be closed by this pull request
5 tasks
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.

Add let expressions
1 participant