StanfordLegion / legion

The Legion Parallel Programming System
https://legion.stanford.edu
Apache License 2.0
657 stars 146 forks source link

Regent: bugs in list code #1669

Open elliottslaughter opened 3 months ago

elliottslaughter commented 3 months ago

Rupanshu found a couple of bugs in the list code (not surprising, since this has never really been tested).

Some programs:

import "regent"

task reader(r: regentlib.list(region(ispace(int1d), int)))
where reads(r) do end

task main()
  var r = region(ispace(int1d, 20), int)
  fill(r, 0)

  var p = partition(equal, r, ispace(int1d, 5))
  var ps = list_slice_partition(p, list_range(0, 5))
  reader(ps) -- works

  var s = p[0]
  var q = partition(equal, s, ispace(int1d, 2))
  var qs = list_slice_partition(q, list_range(0, 2))
  reader(qs) -- does not work
end

regentlib.start(main)

And:

import "regent"

task reader(r: regentlib.list(region(ispace(int1d), int)))
where reads(r) do
  return r[0][0]
end

task main()
  var r = region(ispace(int1d, 20), int)
  for i in r do r[i] = 2 * i end

  var p = partition(equal, r, ispace(int1d, 5))
  var ps = list_slice_partition(p, list_range(0, 5))
  reader(ps)
end

regentlib.start(main)

I have part of a tentative patch in my local copy, putting it here for posterity:

diff --git a/language/src/regent/type_check.t b/language/src/regent/type_check.t
index 3d9a44272..95e3afe20 100644
--- a/language/src/regent/type_check.t
+++ b/language/src/regent/type_check.t
@@ -2360,13 +2360,9 @@ function type_check.expr_list_slice_partition(cx, node)
     std.region(
       std.ispace(partition_type:parent_region():ispace().index_type),
       partition_type:parent_region():fspace()),
-    partition_type, 1)
-  -- FIXME: The privileges for these region aren't necessarily exactly
-  -- one level up.
+    partition_type, nil, partition_type:parent_region())

-  std.copy_privileges(cx, partition_type:parent_region(), expr_type)
-  -- FIXME: Copy constraints.
-  cx:intern_region(expr_type)
+  std.add_constraint(cx, expr_type, partition_type:parent_region(), std.subregion, false)

   return ast.typed.expr.ListSlicePartition {
     partition = partition,