[sv-bc] Ballot issue 10 / Mantis 2664 - compilation unit declarations are imported?

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Mon Apr 27 2009 - 08:46:37 PDT
This issue uses the following example:

    integer r;

    module top;
      integer s = r; // ‘r’ is imported in the module
      integer r; // error, declaration
    endmodule

The question is essentially whether compilation unit items
are implicitly imported into a referencing scope.

I do not think that compilation unit items are implicitly
imported; they are visible due to lexical scoping.

In 3.12.1 we have:

     When an identifier is referenced within a scope:
         First, the nested scope is searched (see 23.9) (including nested
         module declarations), including any identifiers made available
         through package import declarations.

         Next, the portion of the compilation-unit scope defined prior to
         the reference is searched (including any identifiers made
         available through package import declarations).


And in 26.3:
     The search algorithm shall be repeated for each outer lexical
     scope until an identifier is found that matches the reference or
     there are no more outer lexical scopes, the compilation unit scope
     being the final scope searched.

Both of these quite clearly consider the compilation unit as a
lexical scope to be searched, not as a set of potentially visible
identifiers.  Note in particular that the second paragraph from
3.12.1 quoted above is clear that declarations imported into
the compilation unit are visible in the same manner as a normal
lexical search.  This would be at odds with an "import" view of
compilation items unless the LRM stated that such items were
implicitly "exported" from $unit.


So although 3.12.1 comments that "Thus, the compilation-unit scope is
similar to an implicitly defined anonymous package.", I think that
is related to the kinds of items and is related to being able to
share across modules without hierarchical references.  I do not
think that statement is meant to imply "import like" behavior
for referenced identifiers.

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 Mon Apr 27 09:02:46 2009

This archive was generated by hypermail 2.1.8 : Mon Apr 27 2009 - 09:03:47 PDT