lcompilers / lc

C++ compiler
MIT License
26 stars 7 forks source link

Add support for `mdspan` #111

Closed czgdp1807 closed 5 months ago

czgdp1807 commented 5 months ago

So as can be seen in the test we need to add support for the following things in the ASR,

ListToArray cast - This will simply represent, std::vector::data call. Inside LLVM backend it will be implemented simply as taking the data pointer from list struct to data pointer of array (shallow copy as those are the semantics followed by mdspan as well). In C backend it will be simply transformed to a pointer assignment from list struct to array's data pointer (if the user doesn't want to use any array library) or if someone chooses to use mdspan then will be transformed to original source code.

Rest everything can be managed with the existing ASR features.

https://github.com/lcompilers/lc/issues/14

cc: @certik

czgdp1807 commented 5 months ago

I will continue this work on Monday.

certik commented 5 months ago

Yes, one way to solve this is to introduce a list to array cast, which we need for LPython as well. By assigning to mdspan, we copy the data. The C++ code above does not copy data, but does a "view". We would need to ensure that the original data is not use elsewhere, similarly like we (will) do for LPython.