StanfordLegion / legion

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

Regent type mismatch error sometimes reports matching types #491

Open TWarszawski opened 5 years ago

TWarszawski commented 5 years ago

Sometimes the Regent compiler gives type mismatch errors where it reports two identical types. The example program below results in the error message: "type mismatch in assignment: expected region(ispace(int1d), int32) but got region(ispace(int1d), int32)". I've had several questions about similar examples from students during cs315b, and also since the class ended from those continuing to work with Regent. I believe one of those examples was due to a struct or field space being both imported and defined. I think that it could help alleviate confusion to give a more informative error message.

import "regent"
local c = regentlib.c
struct AStruct {
  ptr : region(ispace(int1d), int32),
}
task test(x : AStruct)
  x.ptr = region(ispace(int1d,100), int32)
end
elliottslaughter commented 5 years ago

If you run with the flag -fdebug 1 you should see an error message like:

expected region#1(ispace#1(int1d), int32) but got region#2(ispace#2(int1d), int32)

Regions are not really always equal, and in general assignment to regions is not expected to work (it wouldn't be safe even if the index and field spaces match). In this particular case, since we're talking about a region relation, you can make this program type check by doing:

import "regent"

struct AStruct {
  r : region(ispace(int1d), int32),
}

task test(x : AStruct)
  x = AStruct { r = region(ispace(int1d,100), int32) }
end

But this wouldn't work for e.g. a region local variable r. Basically, there are cases were we're allowed to do special matching of regions (task calls, packing structs), but aside from that regions should always be considered to be incompatible with each other. Therefore, we could add logic to print the #1 and #2, but it wouldn't tell you why these particular regions weren't allowed to match. (E.g. in the original code the error was in the kind of statement used to assign the region, not in the regions themselves being incompatible per se.) So I'm not sure there are any easy changes that would really be that big of an improvement.

If you have any suggestions for how to improve the error messages, let me know.

manopapad commented 5 years ago

How about adding an extra note to region incompatibility error messages, that covers the common case? Something like "Note that a reference to a region cannot be overriden/reseated". You could even do this only in cases where the two incompatible region types have the same index and field space.

elliottslaughter commented 4 years ago

This will be addressed in part when #583 merges, though there are still some issues blocking that merge.