-
Notifications
You must be signed in to change notification settings - Fork 11
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
Erroneous bitcast for indefinite array allocation #10
Comments
So, here is the deal: Thorin at its core is designed to be type-safe. This means you have to track all array sizes explicitly in the type. In order to support unsafe features such as C-like arrays, we need unsafe axioms such as If I understand your use case correctly, the real solution would be to simply not use an unsafe array but a safe array at the allocation. Later on, you can cast the safe array to an unsafe one like so:
And here a little background regarding the Both things mean the same thing. The only difference is that the size computation in Finally, the LLVM backend should probably throw an exception with a reasonable error message instead of just asserting or returning Does this solve your issue? |
In my use case, I get provided with an unsafe array (_2 in the example above) for instance as an argument in a function. |
An unsafe Array only makes sense when having a pointer to it and
Note that with approach 2) and 3) you duplicate size information when doing sth like the matmul. Finally, 3) is an unsafe C-style way of doing things and is only present in Thorin in order to communicate with unsafe code and should only be used when you really have to do this. |
Allocations with a statically unknown size
T::nat
lead to<TODO>
in LLVM code.For instance, when an array of the same size as an indefinite array
«⊤∷nat; r32»
is created in Thorin,invalid LLVM code is produced by the code generation.
Using Alloc2Malloc:
Before optimizations:
After optimizations
and the corresponding LLVM code:
Without Alloc2Malloc:
After optimizations:
LLVM: (no malloc or alloc is generated)
The problem here is that
T::nat
is used as size but does not exist in LLVM.One solution for some cases might be a more extensive tracking of the sizes used in allocation.
For instance, the original allocation uses a constant size of 3 and the bitcasts of the array
are eliminated.
But this propagation does not extend to the newly generated array which should have the same size.
Comment: It is not possible to produce this error using valid impala code.
The text was updated successfully, but these errors were encountered: