Skip to content

Commit b67183b

Browse files
Use infinite-list to eliminate magic numbers
In primitive templates, we often refer to inputs by their index in the list of all inputs. This is cumbersome and error-prone, and makes maintenance a headache. GHC 9.2 is very quick on reporting an `incomplete-uni-patterns` warning, but by using a provably infinite list, we can graft an arbitrary number of binders from that list without warnings and name our indices with them. All occurences of these magic numbers that I could find have been replaced by named indices, except for where this is impossible (notably `clash-lib/prims` which contains many, many more). The `TemplateFunction`s in `clash-lib:Clash.Primitives.Intel.ClockGen` were technically incorrect. It didn't matter though: the `used` field is not actually currently used in Clash, and if the `valid` field is too optimistic, the render function (last field) will still throw an error message to the user. This different error message provides more information in several ways, but it crucially lacks the location in the user code that triggered the error, which is a significant disadvantage. The problems were these: - `used` for `altpll` was overly broad, listing all arguments. Collectively, the two `TemplateFunction`s did need all arguments, though. - `used` for `alteraPll` lists 21 inputs but the function has only 6. Most likely the up-to-16-tuple that is one of the constraints was accidentally thought to be expanded into separate constraints. - `valid` for `alteraPllTemplate` doesn't check `bbResults` for the correct shape. - The `valid`s for the `QsysTF`s don't check the parsed constraint arguments for validity. - Conversely, they do check the `name` argument and the results for validity, but these are only used by `altpllTF` and `alteraPllTF` and are also already checked there. The `used` fields were fixed. The `valid` functions have superfluous checks removed, but no checks were added. The net result is that the same error messages are emitted as before this patch.
1 parent 835bf1f commit b67183b

File tree

18 files changed

+347
-322
lines changed

18 files changed

+347
-322
lines changed

.ci/stack-8.10.7.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ extra-deps:
1717
- fakedata-1.0.2@sha256:37c93be9a81acbc9109e2c0b300a793d9c1f5ead1d34330d869d76568191f428,24593
1818
- docopt-0.7.0.7@sha256:a3d2eac54cd77d8c0b306ff96fb57be55542f143d81766aa1ae51458ad790dbe,3655
1919
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
20+
- infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383

.ci/stack-8.6.5.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ extra-deps:
2929
- regex-base-0.94.0.2@sha256:4ff4425c710cddf440dfbac6cd52310bb6b23e17902390ff71c9fc7eaafc4fcc,2643
3030
- string-interpolate-0.3.1.2@sha256:4d0987f453c66040aa8e482fe28a7d3cdc9d8df01b698bc92f42a592cfb337db,4268
3131
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
32+
- infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383

.ci/stack-8.8.4.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ extra-deps:
2424
- docopt-0.7.0.7@sha256:a3d2eac54cd77d8c0b306ff96fb57be55542f143d81766aa1ae51458ad790dbe,3655
2525
- string-interpolate-0.3.1.2@sha256:4d0987f453c66040aa8e482fe28a7d3cdc9d8df01b698bc92f42a592cfb337db,4268
2626
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
27+
- infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383

.ci/stack-9.0.2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ packages:
1414

1515
extra-deps:
1616
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
17+
- infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383

.ci/stack-9.2.4.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ extra-deps:
1616
- concurrent-supply-0.1.8@sha256:9373f4868ad28936a7b93781b214ef4afdeacf377ef4ac729583073491c9f9fb,1627
1717
- hashable-1.3.5.0@sha256:3a2beeafb220f9de706568a7e4a5b3c762cc4c9f25c94d7ef795b8c2d6a691d7,4240
1818
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
19+
- infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383

clash-cores/clash-cores.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ license: BSD-2-Clause
99
license-file: LICENSE
1010
author: QBayLogic B.V.
1111
maintainer: [email protected]
12-
copyright: Copyright © 2019, Foamspace Corp.
13-
2022, QBayLogic B.V.
12+
copyright: Copyright © 2019 , Foamspace Corp.,
13+
2022-2023, QBayLogic B.V.
1414
category: Hardware
1515
build-type: Simple
1616
extra-source-files: CHANGELOG.md
@@ -46,6 +46,7 @@ common basic-config
4646
FlexibleContexts
4747
MagicHash
4848
NoImplicitPrelude
49+
PostfixOperators
4950
ScopedTypeVariables
5051
TemplateHaskell
5152
TypeApplications
@@ -109,6 +110,7 @@ library
109110

110111
build-depends:
111112
clash-lib,
113+
infinite-list ^>= 0.1,
112114
mtl >= 2.1.1 && < 2.3,
113115
prettyprinter >= 1.2.0.1 && < 1.8,
114116
prettyprinter-interp ^>= 0.2,

0 commit comments

Comments
 (0)