From 95bb2f66d34b40163c84c9c2893da50bd989e02f Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 1 Jul 2020 13:08:59 -0400 Subject: Fix unchecked type in ManipulateNames (#1726) Fix a bug where a type check would always yield true. This caused a bug where allow/block-list annotations would be incorrectly applied to all subtypes of ManipulateNames. The tests are updated to check that this now works. Signed-off-by: Schuyler Eldridge Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>--- .../scala/firrtl/transforms/ManipulateNames.scala | 37 ++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/transforms/ManipulateNames.scala b/src/main/scala/firrtl/transforms/ManipulateNames.scala index 956b39e6..c55dab57 100644 --- a/src/main/scala/firrtl/transforms/ManipulateNames.scala +++ b/src/main/scala/firrtl/transforms/ManipulateNames.scala @@ -432,14 +432,24 @@ abstract class ManipulateNames[A <: ManipulateNames[_] : ClassTag] extends Trans def execute(state: CircuitState): CircuitState = { val block = state.annotations.collect { - case ManipulateNamesBlocklistAnnotation(targetSeq, _: Dependency[A]) => targetSeq + case ManipulateNamesBlocklistAnnotation(targetSeq, t) => t.getObject match { + case _: A => targetSeq + case _ => Nil + } }.flatten.flatten.toSet - val allow = state.annotations.collect { - case ManipulateNamesAllowlistAnnotation(targetSeq, _: Dependency[A]) => targetSeq - } match { - case Nil => (a: Target) => true - case a => a.flatten.flatten.toSet + val allow = { + val allowx = state.annotations.collect { + case ManipulateNamesAllowlistAnnotation(targetSeq, t) => t.getObject match { + case _: A => targetSeq + case _ => Nil + } + }.flatten.flatten + + allowx match { + case Nil => (a: Target) => true + case a => a.toSet + } } val renames = RenameMap() @@ -447,11 +457,18 @@ abstract class ManipulateNames[A <: ManipulateNames[_] : ClassTag] extends Trans val annotationsx = state.annotations.flatMap { /* Consume blocklist annotations */ - case ManipulateNamesBlocklistAnnotation(_, _: Dependency[A]) => None - /* Convert allowlist annotations to result annotations */ - case ManipulateNamesAllowlistAnnotation(a, t: Dependency[A]) => (a, a.map(_.map(renames(_)).flatten)) match { - case (a, b) => Some(ManipulateNamesAllowlistResultAnnotation(b, t, a)) + case foo@ ManipulateNamesBlocklistAnnotation(_, t) => t.getObject match { + case _: A => None + case _ => Some(foo) } + /* Convert allowlist annotations to result annotations */ + case foo@ ManipulateNamesAllowlistAnnotation(a, t) => + t.getObject match { + case _: A => (a, a.map(_.map(renames(_)).flatten)) match { + case (a, b) => Some(ManipulateNamesAllowlistResultAnnotation(b, t, a)) + } + case _ => Some(foo) + } case a => Some(a) } -- cgit v1.2.3