Implementation for #355#697
Conversation
| #[derive(thiserror::Error, Debug)] | ||
| #[error("The variant `AnyTypeEnum::{}` cannot be used with `{}()`!", self.variant, self.function)] | ||
| pub struct InvalidVariant { | ||
| // TODO: Shorten lifetime? |
There was a problem hiding this comment.
(Wasn't sure how else to display the variant and function name; If there's a better way let me know)
There was a problem hiding this comment.
You should add a lifetime generic, that's more flexible.
There was a problem hiding this comment.
I'll get on this once I'm home
There was a problem hiding this comment.
Oh, wait, what is this? Is this an error message? Why is it implemented with strings? This could very well be an enum.
There was a problem hiding this comment.
Also, this error type would clash with inkwell's internal error types. It would make working with errors unwieldy if users have to switch between incompatible error types.
There was a problem hiding this comment.
Oh, wait, what is this? Is this an error message? Why is it implemented with strings? This could very well be an enum.
Yeah admittedly I was probably a bit too tired for implementing this yesterday. I'll try to fix it up now
There was a problem hiding this comment.
Now uses enumeration variant, but if there's a different way to implement the error type then lmk
There was a problem hiding this comment.
The error type I was referring to is in src/error.rs
There was a problem hiding this comment.
Sorry, I typed the last comment on my phone and didn't feel like being detailed.
It would be a good idea to add your new error type to the main error in src/error.rs.
Line 21 in 39f778f
You can add a new error variant to it that implements #[from] for your error type. This will enable users to use the ? operator on your error type and it will be recognized by inkwell's top-level error type.
There was a problem hiding this comment.
As per the other comments I have below: this is causing issues related to lifetimes; need to find the best way to fix
|
Another follow-up: should any other methods have wrappers implemented? should other |
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| #[error("This variant of `AnyTypeEnum` cannot be used with `{self:?}()`!")] | ||
| pub enum InvalidVariant { |
There was a problem hiding this comment.
I think each variant should have the AnyTypeEnum inside like a tuple. And move the error macro to individual variants. So you'd have something like:
#[error("The fn_type method cannot be called by the {0} variant")]
FnType(AnyTypeEnum<'ctx>),which would produce a really nice and explanatory error message
There was a problem hiding this comment.
Sounds good to me, I'll implement when I'm free
|
Oopsy I broke it |
|
Actually, forget regular compile errors, I'm getting ICEs when I try to run tests 😭 |
|
If you're getting an ICE on stable, you should definitely open a rust bug is one doesn't already exist. Sorry this seemingly small change has been so painful lol |
|
Haha it's fine. I run nightly for everything (My projects use nightly features, so it's easier to make it the default than to try and fix some weird config issues I was having) & the bug was just about incremental cache,
Although I'm sorry if this has been a pain, normally A more on-topic note: |
|
Hmm. That's a tough one. What I think is that it's not necessary to include the original value within the error variant. I don't think there's any precedent for doing that. Otherwise, perhaps we could just exclude it from the crate-level error type and just expect users to handle the error themselves. I don't know if this is a case where someone would want to retry something using the |
|
Omitting the original value would fix lifetime issues, but it also means people would have to do more tracing of which value was being passed on their end. I personally would've opted for using |
|
Can you really not make a fn_type for a function type? |
|
Another option would be to add a variant_name method to the type, which returns a static str, and then just do: #[derive(Error)]
#[error("An invalid method was called by variant {0}")]
struct InvalidVariant(&'static str);
impl From<AnyTypeEnum<'_>> for InvalidVariant {
fn from(ate) -> Self {
InvalidVariant(ate.variant_name())
}
}This nice thing about this approach is that we could eventually use it for other types like BasicTypeEnum as well. Although this lacks method info.. |
|
I think it would be better to just have a |
Counter-intuitively, a function type in LLVM does not appear to be a "type" similar to the rest (to my understanding). From what I know, it isn't a closure or lambda or function pointer type... |
|
|
I just don't think that a string is the right call. If there's only a limited number of values that it could be, it would be better off as an enum. |
|
I won't take sides on which would be the better implementation, but if we do use enums I'd suggest marking them as |
|
You almost gave me a heart attack, I thought anyhow had become a dependency in inkwell. Lol |
|
Hahahah no, I use it in my project (and I know other people like to use it (I think?)), and given the fact it (and most other |
|
Not that there's anything wrong with |
|
Sorry to have made this and then left it alone a while, it's currently midyear exam time for me. In just over a week or two I should be free to try and patch this up fully, although I could definitely work on fixes for the error type when I have some gaps in my schedule |
|
I wouldn't worry about it, Dan takes his time. |



Description
Implementation for the
AnyTypeEnum::fn_typeandAnyTypeEnum::array_typefunctions as described in #335Related Issue
#335
How This Has Been Tested
Works on my machine (Ubuntu 26.10,
raptorlake).There (probably) can't really be any issues with this breaking stuff.
Checklist