-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Lower collections extension #1720
Conversation
26d8498
to
e6f8e1a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1720 +/- ##
==========================================
- Coverage 86.38% 86.35% -0.03%
==========================================
Files 166 167 +1
Lines 30063 30361 +298
Branches 26975 27273 +298
==========================================
+ Hits 25969 26219 +250
- Misses 2558 2559 +1
- Partials 1536 1583 +47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Looks great! Some nits, see what you think. I understand execution tests would be hard, could you add an issue for those?
@@ -59,6 +59,11 @@ impl ListValue { | |||
pub fn custom_type(&self) -> CustomType { | |||
list_custom_type(self.1.clone()) | |||
} | |||
|
|||
/// Returns the values contained inside the `[ListValue]`. | |||
pub fn get_contents(&self) -> &Vec<Value> { |
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 is more idomatic returning &[Value]
. Not too bothered.
/// delegates everything to those default implementations. | ||
pub trait CollectionsCodegen: Clone { | ||
/// Return the llvm type of [hugr_core::std_extensions::collections::LIST_TYPENAME]. | ||
fn list_type<'c>(&self, session: &TypingSession<'c, '_>) -> BasicTypeEnum<'c> { |
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.
fn list_type<'c>(&self, session: &TypingSession<'c, '_>) -> BasicTypeEnum<'c> { | |
fn list_type<'c>(&self, session: TypingSession<'c, '_>) -> BasicTypeEnum<'c> { |
} | ||
|
||
/// Helper function to compute the signature of runtime functions. | ||
fn rt_func_sig<'c>( |
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 don't like these bools, I would prefer something like pub enum CollectionRuntimeFunc { ... }
. If you do keep the bools please elaborate in the comment what they mean.
], | ||
false, | ||
); | ||
let func = ctx.get_extern_func("__rt__list__new", func_ty)?; |
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 understand that this is not the worst. Users with a different function name could reimplement this. I would much prefer self.runtime_func_name(CollectionsRuntimeFunc::new)
though.
} | ||
} | ||
|
||
fn build_option<'c, H: HugrView>( |
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 would be better as a free function in crate::emit::func
, there are many other places that would like it.
Ok(option) | ||
} | ||
|
||
fn build_ok_or_else<'c, H: HugrView>( |
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.
as for build_option
where | ||
Self: 'a, | ||
{ | ||
add_collections_extensions(builder, self.0) |
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.
My current thinking is that the free add_collections_extension
is unnecessary, we should just put it's implementation here. What do you think?
_ => { | ||
return Err(anyhow!("Collections: invalid type args for list op")); |
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.
_ => { | |
return Err(anyhow!("Collections: invalid type args for list op")); | |
args => bail!("Collections: invalid type args for list op: {args:?}")); |
I added the runtime function enum and removed most of the functions in Also created issue #1722 for execution tests |
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.
Awesome, thank you Mark.
}; | ||
|
||
/// Runtime functions that implement operations on lists. | ||
#[derive(Clone, Copy, Debug, PartialEq, Hash)] |
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.
#[derive(Clone, Copy, Debug, PartialEq, Hash)] | |
#[derive(Clone, Copy, Debug, PartialEq, Hash)] | |
#[non_exhaustive] |
would mean adding enums isn't a breaking change
Closes #1701 and fixes #1645.
Note that destructors and ref-counting hooks are still missing. These will follow in a future PR once they are available in hugr-llvm.