-
Notifications
You must be signed in to change notification settings - Fork 229
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
Improve different traits #16
Comments
I definitely agree that there should be shared methods across traits and possibly enums, but the tricky part is figuring out to what degree. For example, a method might be applicable to all types represented by a BasicValue/Enum but not all types represented by AnyValue/Enum. There's a lot of work involved in figuring out the differences of what method should apply to which trait. And because this API is still in flux, I've been avoiding figuring that out until it settles down a bit more. The traits can actually be returned and rust provides us with two ways of doing so: either a heap allocation via |
Most of your concerns are fair, indeed. Another problem is that many values can have different types; for example, a |
I think it makes sense to provide an |
Now that I'm mostly done with the Kaleidoscope example, I think I'm gonna get into this. To me, a single struct should exist with the Furthermore, I guess it could lead to something (not extremely useful, yet possible) like In the end, having to switch from a value to another via |
The thing is that LLVM IR is very strongly typed, but the C API is far less so. With Inkwell, I want to leverage that same strongly type interface from rust (or as close to it as possible). I definitely recognize it's not super ergonomic at the moment, and I would like to improve that. The as_ and into_ methods are merely for convenience when you know the type with 100% certainty, the enum should really ideally be matched against. A real compiler should be storing values as BasicValueEnums, since they are the abstractions so that you don't have to cast from different types. It's true |
Indeed, I didn't know the type system was that important, I believe you're right in being more restrictive. Maybe generics could be used? For example, Update: I spent some time thinking everything over, and the best I could come up with is very similar to what's already in place: different structs for
|
I think your idea for I think it would make sense to have a trait (name not final) That said, I wanted to keep this to the second iteration, and just focus on getting the foundation working for the first version. * I oversimplified the signature a bit by excluding the FloatValue subtypes, as those would need to be accounted for as well, but should still be do able. |
By "keep this to the second iteration", do you mean wait till the 0.1.0 milestone is reached? If so, I'll work on it first, since I think this whole thing should be wrapped up as quickly as possible.* * I think this should be done quickly because these changes will introduce pretty big refactorings, which may impact a previously-written documentation, or some other things. |
Yes, that is what I mean. I'd much rather focus on core functionality such as implementing all (or almost all) llvm methods, multi version compatibility, and documentation before working on further ergonomic and type safety improvements for 0.1.0. Especially since the former will help determine what improvements need to be made. It's true that some documentation might need to change, but I think the majority of it will be relocating existing methods (along with their docs), so I don't think documentation will be drastically affected (but I could be wrong). We'll probably just have to swap out some identifiers in the docs( |
|
Many traits actually exist, notably for values and types, but aren't used to their full potential.
Methods on traits
Most values declare the
get_name
andset_name
methods, and implement if the exact same way. Yet, they all implement it individually. Using a single method bound to a trait may avoid code duplication.Unsized trait
It is currently impossible to return
BasicValue
from a function, because it is unsized. Yet, all values that implementBasicValue
have the exact same size. It would be nice to have a type which represents all built-in values, whilst having a known size.Private types
The
Value
struct would be perfect for the above tasks, but it is currently private. Making it public and adding facilities, such asinto_float_value
, would be extremely useful; however, it would also be unsafe.The text was updated successfully, but these errors were encountered: