llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.69k stars 302 forks source link

[FIRRTL] SFC requires a unique name for everything #1537

Open youngar opened 3 years ago

youngar commented 3 years ago

SFC doesn't just disallow name shadowing, it doesn't allow any two things to have the same name:

circuit foo :
  module foo :
    input p: UInt<1>

    when p:
      wire x: UInt<1>
    when p:
      wire x: UInt<1>

SFC produces an error for this:

 firrtl-1.5-SNAPSHOT -i ./test-names.fir -o test-names
Exception in thread "main" firrtl.passes.CheckHighFormLike$NotUniqueException: : [module foo] Reference x does not have a unique name

MFC has no problem with this code.

mmaloney-sf commented 1 year ago

@youngar pointed me to this.

SFC is acting in accordance with the spec. MFC is actually the one not complying here:

As mention in Section 14, circuit component declarations in a module must be unique within the module’s flat namespace; this means that shadowing a component in an enclosing scope with a component of the same name inside a conditional statement is not allowed.

(FIRRTL Spec version v2.3.0)

Ignore the commentary after the semicolon. The first part of the snippet clearly states that the module's namespace is flat. Nested scopes in FIRRTL only affect where references to circuit components are permitted. This is notably different from how scopes work in most programming languages.

This issue has been open for over a year, so it could be that the spec actually changed during this time. I tried to look back, but the spec repo was reorganized back in March of 2022 and I didn't try to look back beyond the history of the spec.md file.