AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
150 stars 15 forks source link

Missing functionality for sizeof #57

Closed madmann91 closed 7 years ago

madmann91 commented 7 years ago

The sizeof PrimOp has no argument, one type argument (the type for which we want to get the size), and one return type (i32). This is annoying, because the import transformation requires the vrebuild function to be of the form:

const Def* SizeOf ::vrebuild(World& to, Defs, const Type* t)

Here, t is the return type (i.e. i32), and we cannot rebuild size_of->of() by calling vrebuild on its type, because it is private.

The correct fix for this is to add a Type2Type argument to vrebuild for PrimOps as well. This is a bit of a change though, and I would like to get your approval first.

Note: This fixes the SEGFAULT issue in Stincilla for the infer branch. The last remaining issue will be the reserve_shared test.

madmann91 commented 7 years ago

Another option is just to hack it and write:

const Def* SizeOf ::vrebuild(World& to, Defs,     const Type* t) const { return to.size_of(of()->rebuild(to, {} /* Monomorphic only */), loc(), name); }

But we will not support polymorphic types then, nor arrays (and this is used in the bilateral_grid code of Stincilla).

An even worse hack makes it possible to use arrays:

const Def* SizeOf ::vrebuild(World& to, Defs, const Type* t) const { Type2Type t2t; return to.size_of(import(to, t2t, of()), loc(), name); }

By making the import variant on types extern.

leissa commented 7 years ago

How about giving size_of a dummy argument? just to track the type. So the constructor for size_of would be:

world.size_of(world.bottom(whatever))

Then, rebuild would work.

madmann91 commented 7 years ago

That's probably a better option. Let's do that. I then drop the of_ member of SizeOf.

madmann91 commented 7 years ago

Fixed in 8fb2180f62ad60cf61f67d75348166885ec2b635.