amaranth-lang / amaranth

A modern hardware definition language and toolchain based on Python
https://amaranth-lang.org/docs/amaranth/
BSD 2-Clause "Simplified" License
1.57k stars 174 forks source link

nextpnr crash: "terminate called after throwing an instance of 'std::out_of_range'" #138

Closed nmigen-issue-migration closed 5 years ago

nmigen-issue-migration commented 5 years ago

Issue by sbourdeauducq Sunday Jul 07, 2019 at 02:16 GMT Originally opened as https://github.com/m-labs/nmigen/issues/136


I'm not sure is this is actually related to nMigen or if this is purely a nextpnr bug, but HeavyX simplesoc_ecp5 no longer works after attempting to use nmigen.build. I had to update Yosys and nextpnr to get the new I/O system to work, otherwise Yosys would complain about an unknown cell IB. Now using Yosys YosysHQ/yosys@8455d1f4ffb942c802b65e20748e54a123e08df0 and nextpnr YosysHQ/nextpnr@ff958830d1097b9bfa3c3b34094e6717.

Repro (without Nix) and error:

$ python simplesoc_ecp5.py simplesoc_ecp5.py test
terminate called after throwing an instance of 'std::out_of_range'
  what():  _Map_base::at
build_top.sh: line 4:  7557 Aborted                 nextpnr-ecp5 --quiet --log top.tim --um-45k --package CABGA381 --speed 8 --json top.json --lpf top.lpf --textcfg top.config
nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:17 GMT


I had to update Yosys and nextpnr to get the new I/O system to work, otherwise Yosys would complain about an unknown cell IB.

Yes, this is expected. Until we release 0.1, you should always run nMigen against master branch of Yosys and nextpnr. The next version of Yosys, 0.9, is the current target, and I'll make sure every patch required for functionality is merged there.

Repro (without Nix)

Did you attach the repro?

nmigen-issue-migration commented 5 years ago

Comment by sbourdeauducq Sunday Jul 07, 2019 at 02:18 GMT


https://git.m-labs.hk/M-Labs/HeavyX/src/branch/master/examples/simplesoc_ecp5.py You only need to add minerva and jtagtap from lambdaconcept in addition to the usual packages.

nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:19 GMT


Can you zip the build directory and attach it here?

nmigen-issue-migration commented 5 years ago

Comment by sbourdeauducq Sunday Jul 07, 2019 at 02:21 GMT


repro.zip

nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:24 GMT


That's a bug in nextpnr, I believe.

nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:26 GMT


See https://github.com/YosysHQ/nextpnr/issues/301.

nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:27 GMT


@sbourdeauducq Looks like Nix breaks Versioneer:

# Automatically generated by nMigen 0+unknown. Do not edit.

Can you fix that?

nmigen-issue-migration commented 5 years ago

Comment by sbourdeauducq Sunday Jul 07, 2019 at 02:30 GMT


Yeah, that's because .git is not present in the downloaded sources. It breaks in exactly the same way if you use the "Download ZIP" link on GitHub to get nmigen.

nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:33 GMT


It breaks in exactly the same way if you use the "Download ZIP" link on GitHub to get nmigen.

It does not, which you can check if you want. The reason is the gitattributes file, which causes the following block in nmigen/_version.py:

def get_keywords():
    """Get the keywords needed to look up the version information."""
    # these strings will be replaced by git during git-archive.
    # setup.py/versioneer.py will grep for the variable names, so they must
    # each be defined on a line of their own. _version.py will just call
    # get_keywords().
    git_refnames = "$Format:%d$"
    git_full = "$Format:%H$"
    git_date = "$Format:%ci$"
    keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
    return keywords

to be turned into:

def get_keywords():
    """Get the keywords needed to look up the version information."""
    # these strings will be replaced by git during git-archive.
    # setup.py/versioneer.py will grep for the variable names, so they must
    # each be defined on a line of their own. _version.py will just call
    # get_keywords().
    git_refnames = " (HEAD -> master)"
    git_full = "da1f58b7aef99912b32b65fe32cd72b61fd5dc34"
    git_date = "2019-07-07 01:03:59 +0000"
    keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
    return keywords

So nix should do the same thing then.

nmigen-issue-migration commented 5 years ago

Comment by sbourdeauducq Sunday Jul 07, 2019 at 02:43 GMT


Interesting, but even though this replacement does happen correctly in both cases, versionneer still breaks on GitHub archives downloaded and extracted manually and those in the Nix store.

nmigen-master> python
>>> import nmigen
>>> nmigen
<module 'nmigen' from '/home/sb/Downloads/nm/nmigen-master/nmigen/__init__.py'>
>>> nmigen.__version__
'0+unknown'
5x2c0kh722dncpbdlyipjxzd3f2kjj2w-source> python
>>> import nmigen
>>> nmigen
<module 'nmigen' from '/nix/store/5x2c0kh722dncpbdlyipjxzd3f2kjj2w-source/nmigen/__init__.py'>
>>> nmigen.__version__
'0+unknown'
nmigen-issue-migration commented 5 years ago

Comment by whitequark Sunday Jul 07, 2019 at 02:44 GMT


Ah, sorry, my bad. I'll take a look at it myself then.

nmigen-issue-migration commented 5 years ago

Comment by sbourdeauducq Sunday Jul 07, 2019 at 02:47 GMT


This is also affecting ARTIQ (and leaving .git around with Nix is actually annoying), and I didn't know about this gitattributes thing so I ended up bypassing versioneer.