Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: afece150016e
Choose a base ref
...
head repository: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6fd7cbad0d6c
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Feb 1, 2020

  1. hdl.dsl: don't allow inheriting from Module.

    `Module` is an object with a lot of complex and sometimes fragile
    behavior that overrides Python attribute accessors and so on.
    To prevent user designs from breaking when it is changed, it is not
    supposed to be inherited from (unlike in Migen), but rather returned
    from the elaborate() method. This commit makes sure it will not be
    inherited from by accident (most likely by users familiar with
    Migen).
    
    Fixes #286.
    whitequark committed Feb 1, 2020
    Copy the full SHA
    6fd7cba View commit details
Showing with 12 additions and 0 deletions.
  1. +5 −0 nmigen/hdl/dsl.py
  2. +7 −0 nmigen/test/test_hdl_dsl.py
5 changes: 5 additions & 0 deletions nmigen/hdl/dsl.py
Original file line number Diff line number Diff line change
@@ -148,6 +148,11 @@ def ongoing(self, name):


class Module(_ModuleBuilderRoot, Elaboratable):
@classmethod
def __init_subclass__(cls):
raise SyntaxError("Instead of inheriting from `Module`, inherit from `Elaboratable` "
"and return a `Module` from the `elaborate(self, platform)` method")

def __init__(self):
_ModuleBuilderRoot.__init__(self, self, depth=0)
self.submodules = _ModuleBuilderSubmodules(self)
7 changes: 7 additions & 0 deletions nmigen/test/test_hdl_dsl.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,13 @@ def setUp(self):
self.c3 = Signal()
self.w1 = Signal(4)

def test_cant_inherit(self):
with self.assertRaises(SyntaxError,
msg="Instead of inheriting from `Module`, inherit from `Elaboratable` and "
"return a `Module` from the `elaborate(self, platform)` method"):
class ORGate(Module):
pass

def test_d_comb(self):
m = Module()
m.d.comb += self.c1.eq(1)