StanfordLegion / regent-lang.org

Regent website
Apache License 2.0
1 stars 3 forks source link

Metaprogramming field spaces #6

Open LonelyCat124 opened 3 years ago

LonelyCat124 commented 3 years ago

At the moment the website suggests that

Field spaces with input-dependent sets of fields

should be possible.

However, since fspaces are created in lua code (as opposed to terra or Regent code) I'm unclear how this is done, or if this can be done at all how I was expecting.

From looking in the test suite, it is clear that this can be done for metaprogramming types pretty straightforwardly using:

function make_fs (type)

and using type inside the field space to determine the types.

What I'm trying to work out though is a little more complex. I have a "mapper" list, and an old field space, e.g.

fspace part{

  test1 : int,
  test2 : double
}
mapper = {}
mapper["f1"] = "test1"
mapper["f2"] = "test2"

What I'm trying to do is create a function that will create a field space from the mapper, such that each key of the mapper will be present in the new field space with the type of the corresponding field from the part field space, i.e. a field space:

fspace metaprogrammed_space{
  f1 : int,
  f2 : double
}

Pulling the required names and types is pretty straightforward, but I'm not sure how to then "insert" them into the generated field space. The best idea I have so far is to create an empty field space, and then modify the fieldspace.fields before returning the field space, but I'm not sure if that would work and it also feels likely to create bugs.

Is this something thats intended to be doable? If so could an example be added into the documentation?

LonelyCat124 commented 3 years ago

Ok, so I randomly was looking for something else (using a terralib map inside a generated task, which should be ok) and came across code just using a terralib struct as a field space - if that works I assume that is how creating metaprogrammed field spaces should be done?

elliottslaughter commented 3 years ago

Yes, Regent is compatible with Terra structs. The main limitation is you can't do things like parameterized fspaces this way (i.e. a field space that contains either regions or pointers into regions).

And yes, Terra structs currently have the best support if you need variable numbers of fields. If you just want to make the field names metaprogrammed, you can do that with fspaces and escapes.