-
-
Notifications
You must be signed in to change notification settings - Fork 309
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
Type annotations for suffixed sugar #6868
Conversation
3a329ba
to
c337853
Compare
@kdziamura -- I've added to the zulip discussion seeking clarification on the intended design. I think the current behaviour is correct as it restricts the use of statements to If a user would like to ignore the output they can be explicit and use a Does this explanation help with your original problem? |
It makes sense. I'll change ignoreResult = \task ->
Task.await (Task.result task) \{} ->
Task.ok {}
# 3. drop destructuring because input and output are the same. it's incorrect
ignoreResult = \task ->
Task.result task this step hides the intention of returning |
76a16b5
to
cb172c5
Compare
@lukewilliamboswell I updated the fix. Now it works as expected and generates a type error: ignoreResult = \task ->
Task.result! task
Task.ok {}
|
cb172c5
to
3bcaeae
Compare
Pull request was converted to draft
d0155ea
to
a76f987
Compare
a76f987
to
f9fad17
Compare
f9fad17
to
8baec48
Compare
a03cdb1
to
a06574e
Compare
// _ = stmt_expr! | ||
|
||
let region = stmt_expr.region; | ||
let new_pat = arena.alloc(Loc::at(region, Pattern::Underscore("#!stmt"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these patterns ever conflict with each other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. At least not with the current design. The underscore pattern is not an identifier and it has no unique name restriction
crates/compiler/can/src/suffixed.rs
Outdated
/// Suffixed sub expression | ||
/// e.g. x = first! (second! 42) | ||
/// In this example, the second unwrap (after unwrapping the top level `first!`) will produce | ||
/// `UnwrappedSubExpr<{ sub_arg: second 42, sub_pat: #!a0, sub_new: #!a0 }>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit. We change the unique prefix above, so these comments are now not quite right.
Otherwise these comments are a helpful addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I updated the other comments, seems to miss this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 3b50a83
@@ -60,19 +70,17 @@ fn init_unwrapped_err<'a>( | |||
// Provide an intermediate answer expression and pattern when unwrapping a | |||
// (sub) expression. | |||
// e.g. `x = foo (bar!)` unwraps to `x = Task.await (bar) \#!a0 -> foo #!a0` | |||
let answer_ident = arena.alloc(next_unique_suffixed_ident()); | |||
let ident = arena.alloc(format!("{}_arg", next_unique_suffixed_ident())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we add the _arg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clearer purpose of the variable. The value comes from the argument
crates/compiler/can/src/suffixed.rs
Outdated
Defs(arena.alloc(defs), new_var), | ||
)) | ||
} | ||
_ => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it clearer if this is None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 3b50a83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, and I've done some testing also.
The only thing I'm unsure of is the #!stmt
's and if they should also have unique identifiers/numbers with them?
Also we are switching in comments between the new and old syntax. Might be helpful to do a find-all and replace the old versions.
80c99c1
to
3b50a83
Compare
3b50a83
to
7aa31a1
Compare
let new_ident = match loc_pat.value { | ||
Pattern::Underscore("#!stmt") => format!("{}_stmt", new_ident), | ||
Pattern::Identifier { ident } | ||
if ident.starts_with('#') && ident.ends_with("_stmt") => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little fishy; why do we need to do string parsing/matching like this? This is mildly concerning since it introduces a very subtle dependency, where someone changing a string that shouldn't matter, can accidentally have broader consequences in the future.
Is there a way to get this same information without trying to parse identifier strings like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Need to change the existing enum structure or introduce another one. I just didn't want to have too many changes in this pr to keep it simple. I can refactor it as a follow-up
use roc_types::types::AnnotationSource::*; | ||
|
||
let is_suffixed = match &name.value { | ||
Pattern::Identifier(symbol) => symbol.as_str(alloc.interns).starts_with("#!"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here - is there a way that we can get the info we need here, without inspecting a string like this?
Probably due to roc-lang/roc#6868
From Zulip thread
In this implementation, type annotations are propagated this way:
Annotated assignments:
Statements: