AnyDSL / thorin

The Higher-Order Intermediate Representation

Home Page:https://anydsl.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing functionality for sizeof

madmann91 opened this issue · comments

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.

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.

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.

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