-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add functional updates #879
Conversation
9a4b0ff
to
564a23c
Compare
ebba28c
to
ffac9c9
Compare
Is this still WIP? Looks like only the formatter is grumbling? |
Yes, I still need to work on sort checking but hoping to have this done soon. |
b40814d
to
5bfa567
Compare
@nilehmann, do you want to wait until I have spreads added or do you want to take a look at this now? |
8f94777
to
8b35e2c
Compare
@vrindisbacher I'll take a look now |
b4d735e
to
18f6a6c
Compare
99e627f
to
42b0eda
Compare
13bd9af
to
3cfee1f
Compare
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.
Ok cool, this looks great.
I left some stylistic suggestions, but it looks good to go. There are also some clippy warnings.
} | ||
|
||
#[derive(Debug)] | ||
pub enum ConstructorArgs { |
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'd use singular
pub enum ConstructorArgs { | |
pub enum ConstructorArg { |
crates/flux-middle/src/rty/mod.rs
Outdated
let mut map = FxIndexMap::default(); | ||
let folded = self.0.sorts.fold_with(&mut SortSubst::new(args)); | ||
std::iter::zip(folded.iter(), self.0.field_names.iter()).for_each(|(sort, field_name)| { | ||
map.insert(*field_name, sort.clone()); | ||
}); | ||
map |
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.
The following reads better in my opinion (or some variation of it)
let mut map = FxIndexMap::default(); | |
let folded = self.0.sorts.fold_with(&mut SortSubst::new(args)); | |
std::iter::zip(folded.iter(), self.0.field_names.iter()).for_each(|(sort, field_name)| { | |
map.insert(*field_name, sort.clone()); | |
}); | |
map | |
std::iter::zip(&self.0.field_names, &self.0.sorts.fold_with(&mut SortSubst::new(args))) | |
.map(|(name, sort)| (*name, sort.clone())) | |
.collect() |
crates/flux-desugar/src/desugar.rs
Outdated
let spread = if spreads.len() == 0 { | ||
None | ||
} else if spreads.len() == 1 { | ||
let s = spreads[0]; | ||
let spread = fhir::Spread { | ||
expr: self.desugar_expr(&s.expr)?, | ||
span: s.span, | ||
fhir_id: self.next_fhir_id(), | ||
}; | ||
Some(self.genv().alloc(spread)) | ||
} else { | ||
// Multiple spreads found - emit and error | ||
return Err(self.emit_err(errors::MultipleSpreadsInConstructor::new( | ||
spreads[1].span, | ||
spreads[0].span, | ||
))); | ||
}; |
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.
maybe
let spread = if spreads.len() == 0 { | |
None | |
} else if spreads.len() == 1 { | |
let s = spreads[0]; | |
let spread = fhir::Spread { | |
expr: self.desugar_expr(&s.expr)?, | |
span: s.span, | |
fhir_id: self.next_fhir_id(), | |
}; | |
Some(self.genv().alloc(spread)) | |
} else { | |
// Multiple spreads found - emit and error | |
return Err(self.emit_err(errors::MultipleSpreadsInConstructor::new( | |
spreads[1].span, | |
spreads[0].span, | |
))); | |
}; | |
let spread = match &spreads[..] { | |
[] => None. | |
[s] => { | |
let spread = fhir::Spread { | |
expr: self.desugar_expr(&s.expr)?, | |
span: s.span, | |
fhir_id: self.next_fhir_id(), | |
}; | |
Some(self.genv().alloc(spread)) | |
} | |
[s1, s2, ..] => { | |
// Multiple spreads found - emit and error | |
return Err(self.emit_err(errors::MultipleSpreadsInConstructor::new( | |
s1.span, | |
s2.span, | |
))); | |
} | |
}; |
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.
Oh cool I didn't know you could do that actually
spread: &Option<&fhir::Spread>, | ||
) -> QueryResult<List<rty::Expr>> { | ||
let struct_adt = self.genv.adt_sort_def_of(struct_def_id)?; | ||
let sort_by_field = FxIndexSet::from_iter(struct_adt.field_names()); |
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.
We could make struct_adt.field_names()
return an &FxIndexSet<Symbol>
. and even more, we can make the field field_names
in AdtSortDefData
an FxIndexSet<Symbol>
instead of a Vec<Symbol>
.
Also,
let sort_by_field = FxIndexSet::from_iter(struct_adt.field_names()); | |
let field_names = FxIndexSet::from_iter(struct_adt.field_names()); |
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.
Or maybe we can invert this, map exprs
by name, and iterate over the field names. Something like
let spread = spread
.map(|spread| self.conv_expr(env, &spread.expr))
.transpose()?;
let field_exprs_by_name: FxIndexMap<Symbol, &fhir::FieldExpr> =
exprs.iter().map(|e| (e.ident.name, e)).collect();
for (idx, field_name) in struct_adt.field_names().enumerate() {
if let Some(field_expr) = field_exprs_by_name.get(field_name) {
assns.push(self.conv_expr(env, &field_expr.expr)?);
} else if Some(spread) = spread {
let proj = rty::FieldProj::Adt { def_id: struct_def_id, field: idx as u32 };
assns.push(rty::Expr::field_proj(spread, proj));
}
}
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 like that one.
Yay! This is awesome thanks @vivien!
- Ranjit.
…On Wed, Nov 20, 2024 at 11:02 AM Vivien Rindisbacher < ***@***.***> wrote:
Merged #879
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/pull/879__;!!Mih3wA!A3eniGZ5MxQfgXrxvsdmA-x-9tu8fBTx5PWMFS3fHy2fIIM7L7ysFB1sDlnV2MO1hX0JB63AapeDoy0NJ6I72nBA$>
into main.
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/pull/879*event-15371611228__;Iw!!Mih3wA!A3eniGZ5MxQfgXrxvsdmA-x-9tu8fBTx5PWMFS3fHy2fIIM7L7ysFB1sDlnV2MO1hX0JB63AapeDoy0NJ3zlbFKN$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OHI4HJYRHNMUHDLRYD2BTMERAVCNFSM6AAAAABRMHNYNKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJVGM3TCNRRGEZDEOA__;!!Mih3wA!A3eniGZ5MxQfgXrxvsdmA-x-9tu8fBTx5PWMFS3fHy2fIIM7L7ysFB1sDlnV2MO1hX0JB63AapeDoy0NJ2YKl-14$>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
closes (#870)