[sv-ec] Mantis 888 - problem introduced with "foreach" and "type"

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Tue Aug 28 2007 - 13:42:54 PDT
In Mantis 888 we relaxed the rules regarding "foreach" arrays
to permit more general forms than just "array_identifier".  Part
of the intent there was to allow selects and package references
and also hierarchical references.

I think that allowing general hierarchical references introduces
a subtle but quite nasty problem.

Here is a case that I think is legal with the 888 change and that
ends up with a circular type definition:

   module top;
      a a();
      b b();
   endmodule

   module a;
      initial begin : a1
          foreach ( b.b1.b2.arr[i] ) begin : a2
              int arr[type(i)];
          end
      end
   endmodule

   module b;
      initial begin : b1
          foreach ( a.a1.a2.arr[i] ) begin : b2
              int arr[type(i)];
          end
      end
   endmodule


The "type" operator was carefully constrained to only work
on local types so that such problems could not occur.
However in this context, the type of "i" is effectively a
hierarchical type reference, leading to the possibility
of having circular references.

I don't think this can be problem in other uses of "i", but
in the context of "type" it appears to be.  The easiest
fix would be to state that the "type" operator shall
not be legal for use with a foreach loop variable.  That
is a pretty big stick though, since that wouldn't allow
one to define temporaries with a loop where the type
would be guaranteed to match the foreach loop variable
type.

I don't have a strong opinion yet as to a good solution.
It is obviously quite useful to allow the general forms
of "foreach" but that interacts quite poorly with the
type operator on the loop variables.

I am a bit worried about whether there are any other latent
cases in which we could run into something similar.  Particularly
in the assertions context where untyped formals exist, I suspect
that one might be able to construct something similar.  I don't
know enough about that off the top of my head to try to
write such an example, but someone else might want to give
that some thought.

Gord.
-- 
--------------------------------------------------------------------
Gordon Vreugdenhil                                503-685-0808
Model Technology (Mentor Graphics)                gordonv@model.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Aug 28 13:43:11 2007

This archive was generated by hypermail 2.1.8 : Tue Aug 28 2007 - 13:43:48 PDT