Skip to content

Commit 3233c65

Browse files
committed
deploy: 54f159f
1 parent 72b39ac commit 3233c65

File tree

7 files changed

+451
-7
lines changed

7 files changed

+451
-7
lines changed

pr-10/compiler-user-guide/developing-hardware/limitations.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
339339

340340
<nav class="nav-wrapper" aria-label="Page navigation">
341341
<!-- Mobile navigation buttons -->
342-
<a rel="prev" href="../developing-hardware/primitives.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
342+
<a rel="prev" href="../developing-hardware/troubleshooting.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
343343
<i class="fa fa-angle-left"></i>
344344
</a>
345345

@@ -353,7 +353,7 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
353353
</div>
354354

355355
<nav class="nav-wide-wrapper" aria-label="Page navigation">
356-
<a rel="prev" href="../developing-hardware/primitives.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
356+
<a rel="prev" href="../developing-hardware/troubleshooting.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
357357
<i class="fa fa-angle-left"></i>
358358
</a>
359359

pr-10/compiler-user-guide/developing-hardware/primitives.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
545545
<i class="fa fa-angle-left"></i>
546546
</a>
547547

548-
<a rel="next prefetch" href="../developing-hardware/limitations.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
548+
<a rel="next prefetch" href="../developing-hardware/troubleshooting.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
549549
<i class="fa fa-angle-right"></i>
550550
</a>
551551

@@ -559,7 +559,7 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
559559
<i class="fa fa-angle-left"></i>
560560
</a>
561561

562-
<a rel="next prefetch" href="../developing-hardware/limitations.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
562+
<a rel="next prefetch" href="../developing-hardware/troubleshooting.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
563563
<i class="fa fa-angle-right"></i>
564564
</a>
565565
</nav>
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en" class="light sidebar-visible" dir="ltr">
3+
<head>
4+
<!-- Book generated using mdBook -->
5+
<meta charset="UTF-8">
6+
<title>Troubleshooting - Clash Compiler User Guide</title>
7+
8+
9+
<!-- Custom HTML head -->
10+
11+
<meta name="description" content="">
12+
<meta name="viewport" content="width=device-width, initial-scale=1">
13+
<meta name="theme-color" content="#ffffff">
14+
15+
<link rel="icon" href="../favicon.svg">
16+
<link rel="shortcut icon" href="../favicon.png">
17+
<link rel="stylesheet" href="../css/variables.css">
18+
<link rel="stylesheet" href="../css/general.css">
19+
<link rel="stylesheet" href="../css/chrome.css">
20+
<link rel="stylesheet" href="../css/print.css" media="print">
21+
22+
<!-- Fonts -->
23+
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
24+
<link rel="stylesheet" href="../fonts/fonts.css">
25+
26+
<!-- Highlight.js Stylesheets -->
27+
<link rel="stylesheet" id="highlight-css" href="../highlight.css">
28+
<link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css">
29+
<link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css">
30+
31+
<!-- Custom theme stylesheets -->
32+
33+
34+
<!-- Provide site root and default themes to javascript -->
35+
<script>
36+
const path_to_root = "../";
37+
const default_light_theme = "light";
38+
const default_dark_theme = "navy";
39+
</script>
40+
<!-- Start loading toc.js asap -->
41+
<script src="../toc.js"></script>
42+
</head>
43+
<body>
44+
<div id="mdbook-help-container">
45+
<div id="mdbook-help-popup">
46+
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
47+
<div>
48+
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
49+
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
50+
<p>Press <kbd>?</kbd> to show this help</p>
51+
<p>Press <kbd>Esc</kbd> to hide this help</p>
52+
</div>
53+
</div>
54+
</div>
55+
<div id="body-container">
56+
<!-- Work around some values being stored in localStorage wrapped in quotes -->
57+
<script>
58+
try {
59+
let theme = localStorage.getItem('mdbook-theme');
60+
let sidebar = localStorage.getItem('mdbook-sidebar');
61+
62+
if (theme.startsWith('"') && theme.endsWith('"')) {
63+
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
64+
}
65+
66+
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
67+
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
68+
}
69+
} catch (e) { }
70+
</script>
71+
72+
<!-- Set the theme before any content is loaded, prevents flash -->
73+
<script>
74+
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
75+
let theme;
76+
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
77+
if (theme === null || theme === undefined) { theme = default_theme; }
78+
const html = document.documentElement;
79+
html.classList.remove('light')
80+
html.classList.add(theme);
81+
html.classList.add("js");
82+
</script>
83+
84+
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
85+
86+
<!-- Hide / unhide sidebar before it is displayed -->
87+
<script>
88+
let sidebar = null;
89+
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
90+
if (document.body.clientWidth >= 1080) {
91+
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
92+
sidebar = sidebar || 'visible';
93+
} else {
94+
sidebar = 'hidden';
95+
}
96+
sidebar_toggle.checked = sidebar === 'visible';
97+
html.classList.remove('sidebar-visible');
98+
html.classList.add("sidebar-" + sidebar);
99+
</script>
100+
101+
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
102+
<!-- populated by js -->
103+
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
104+
<noscript>
105+
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
106+
</noscript>
107+
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
108+
<div class="sidebar-resize-indicator"></div>
109+
</div>
110+
</nav>
111+
112+
<div id="page-wrapper" class="page-wrapper">
113+
114+
<div class="page">
115+
<div id="menu-bar-hover-placeholder"></div>
116+
<div id="menu-bar" class="menu-bar sticky">
117+
<div class="left-buttons">
118+
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
119+
<i class="fa fa-bars"></i>
120+
</label>
121+
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
122+
<i class="fa fa-paint-brush"></i>
123+
</button>
124+
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
125+
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
126+
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
127+
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
128+
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
129+
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
130+
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
131+
</ul>
132+
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
133+
<i class="fa fa-search"></i>
134+
</button>
135+
</div>
136+
137+
<h1 class="menu-title">Clash Compiler User Guide</h1>
138+
139+
<div class="right-buttons">
140+
<a href="../print.html" title="Print this book" aria-label="Print this book">
141+
<i id="print-button" class="fa fa-print"></i>
142+
</a>
143+
144+
</div>
145+
</div>
146+
147+
<div id="search-wrapper" class="hidden">
148+
<form id="searchbar-outer" class="searchbar-outer">
149+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
150+
</form>
151+
<div id="searchresults-outer" class="searchresults-outer hidden">
152+
<div id="searchresults-header" class="searchresults-header"></div>
153+
<ul id="searchresults">
154+
</ul>
155+
</div>
156+
</div>
157+
158+
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
159+
<script>
160+
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
161+
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
162+
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
163+
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
164+
});
165+
</script>
166+
167+
<div id="content" class="content">
168+
<main>
169+
<h1 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h1>
170+
<p>A list of often encountered errors and their solutions:</p>
171+
<ul>
172+
<li>
173+
<p><strong>Type error: Couldn't match expected type <code>Signal dom (a,b)</code> with actual type <code>(Signal dom a, Signal dom b)</code></strong>:</p>
174+
<p>Signals of product types and product types of signals are <strong>isomorphic</strong> due to synchronisity principle, but are not (structurally) equal.
175+
Tuples are a product type. Use the <code>bundle</code> function to convert from a product type to the signal type.
176+
So if your code which gives the error looks like:</p>
177+
<pre><code class="language-haskell">... = f a b (c,d)
178+
</code></pre>
179+
<p>add the <code>bundle</code> function like so:</p>
180+
<pre><code class="language-haskell">... = f a b (bundle (c,d))
181+
</code></pre>
182+
<p>Product types supported by <code>bundle</code> are:</p>
183+
<ul>
184+
<li>All tuples up to and including 62-tuples (GHC limit)</li>
185+
<li>The <code>Vec</code>tor type</li>
186+
</ul>
187+
</li>
188+
<li>
189+
<p><strong>Type error: Couldn't match expected type <code>(Signal dom a, Signal dom b)</code> with actual type <code>Signal dom (a,b)</code></strong>:</p>
190+
<p>Product types of signals and signals of product types are <strong>isomorphic</strong> due to synchronicity principle, but are not (structurally) equal.
191+
Tuples are a product type. Use the <code>unbundle</code> function to convert from a signal type to the product type.
192+
So if your code which gives the error looks like:</p>
193+
<pre><code class="language-haskell">(c,d) = f a b
194+
</code></pre>
195+
<p>add the <code>unbundle</code> function like so:</p>
196+
<pre><code class="language-haskell">(c,d) = unbundle (f a b)
197+
</code></pre>
198+
<p>Product types supported by <code>unbundle</code> are:</p>
199+
<ul>
200+
<li>All tuples up to and including 62-tuples (GHC limit)</li>
201+
<li>The <code>Vec</code>tor type</li>
202+
</ul>
203+
</li>
204+
<li>
205+
<p><strong>Clash.Netlist(..): Not in normal form: &lt;REASON&gt;: &lt;EXPR&gt;</strong>:</p>
206+
<p>A function could not be transformed into the expected normal form.
207+
This usually means one of the following:</p>
208+
<ul>
209+
<li>The <code>topEntity</code> has higher-order arguments, or a higher-order result.</li>
210+
<li>You are using types which cannot be represented in hardware.</li>
211+
</ul>
212+
<p>The solution for all the above listed reasons is quite simple: remove them.
213+
That is, make sure that the <code>topEntity</code> is completely monomorphic and first-order.
214+
Also remove any variables and constants/literals that have a non-representable type; see <a href="limitations.html">Limitations of Clash</a> to find out which types are not representable.</p>
215+
</li>
216+
<li>
217+
<p><strong>Clash.Normalize(..): Clash can only normalize monomorphic functions, but this is polymorphic</strong>:</p>
218+
<p>If this happens for a <code>topEntity</code> or something with a <code>Synthesize</code> annotation, add a monomorphic type signature.
219+
Non topEntites should be type-specialized by clash automatically, if not please report this as a bug.
220+
But adding a monomorphic type signature should still help (when possible).</p>
221+
</li>
222+
<li>
223+
<p><strong>Clash.Normalize(..): Expr belonging to bndr: &lt;FUNCTION&gt; remains recursive after normalization</strong>:</p>
224+
<ul>
225+
<li>
226+
<p>If you actually wrote a recursive function, rewrite it to a non-recursive one using e.g. one of the higher-order functions in <code>Clash.Sized.Vector</code></p>
227+
</li>
228+
<li>
229+
<p>You defined a recursively defined value, but left it polymorphic:</p>
230+
</li>
231+
</ul>
232+
<pre><code class="language-haskell">topEntity x y = acc
233+
where
234+
acc = register 3 (acc + x * y)
235+
</code></pre>
236+
<p>The above function, works for any number-like type.
237+
This means that <code>acc</code> is a recursively defined <strong>polymorphic</strong> value.
238+
Adding a monomorphic type annotation makes the error go away:</p>
239+
<pre><code class="language-haskell">topEntity
240+
:: SystemClockResetEnable
241+
=&gt; Signal System (Signed 8)
242+
-&gt; Signal System (Signed 8)
243+
-&gt; Signal System (Signed 8)
244+
topEntity x y = acc
245+
where
246+
acc = register 3 (acc + x * y)
247+
</code></pre>
248+
</li>
249+
<li>
250+
<p><strong>Clash.Normalize.Transformations(..): InlineNonRep: &lt;FUNCTION&gt; already inlined 100 times in:&lt;FUNCTION&gt;, &lt;TYPE&gt;</strong>:</p>
251+
<p>You left the <code>topEntity</code> function polymorphic or higher-order: use <code>:i topEntity</code> to check if the type is indeed polymorphic or higher-order.
252+
If it is, add a monomorphic type signature, and/or supply higher-order arguments.</p>
253+
</li>
254+
<li>
255+
<p><strong>&lt;*** Exception: &lt;&lt;loop&gt;&gt; or "blinking cursor"</strong></p>
256+
<p>You are using value-recursion, but one of the <code>Vec</code>tor functions that you are using is too <em>strict</em> in one of the recursive arguments. For example:</p>
257+
<pre><code class="language-haskell">-- Bubble sort for 1 iteration
258+
sortV xs = map fst sorted :&lt; (snd (last sorted))
259+
where
260+
lefts = head xs :&gt; map snd (init sorted)
261+
rights = tail xs
262+
sorted = zipWith compareSwapL lefts rights
263+
264+
-- Compare and swap
265+
compareSwapL a b = if a &lt; b then (a,b) else (b,a)
266+
</code></pre>
267+
<p>Will not terminate because <code>zipWith</code> is too strict in its second argument.</p>
268+
<p>In this case, adding <code>lazyV</code> on <code>zipWith</code>s second argument:</p>
269+
<pre><code class="language-haskell">sortVL xs = map fst sorted :&lt; (snd (last sorted))
270+
where
271+
lefts = head xs :&gt; map snd (init sorted)
272+
rights = tail xs
273+
sorted = zipWith compareSwapL (lazyV lefts) rights
274+
</code></pre>
275+
<p>Results in a successful computation:</p>
276+
<pre><code>clashi&gt; sortVL (4 :&gt; 1 :&gt; 2 :&gt; 3 :&gt; Nil)
277+
1 :&gt; 2 :&gt; 3 :&gt; 4 :&gt; Nil
278+
</code></pre>
279+
</li>
280+
</ul>
281+
282+
</main>
283+
284+
<nav class="nav-wrapper" aria-label="Page navigation">
285+
<!-- Mobile navigation buttons -->
286+
<a rel="prev" href="../developing-hardware/primitives.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
287+
<i class="fa fa-angle-left"></i>
288+
</a>
289+
290+
<a rel="next prefetch" href="../developing-hardware/limitations.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
291+
<i class="fa fa-angle-right"></i>
292+
</a>
293+
294+
<div style="clear: both"></div>
295+
</nav>
296+
</div>
297+
</div>
298+
299+
<nav class="nav-wide-wrapper" aria-label="Page navigation">
300+
<a rel="prev" href="../developing-hardware/primitives.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
301+
<i class="fa fa-angle-left"></i>
302+
</a>
303+
304+
<a rel="next prefetch" href="../developing-hardware/limitations.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
305+
<i class="fa fa-angle-right"></i>
306+
</a>
307+
</nav>
308+
309+
</div>
310+
311+
312+
313+
314+
<script>
315+
window.playground_copyable = true;
316+
</script>
317+
318+
319+
<script src="../elasticlunr.min.js"></script>
320+
<script src="../mark.min.js"></script>
321+
<script src="../searcher.js"></script>
322+
323+
<script src="../clipboard.min.js"></script>
324+
<script src="../highlight.js"></script>
325+
<script src="../book.js"></script>
326+
327+
<!-- Custom JS scripts -->
328+
329+
330+
</div>
331+
</body>
332+
</html>

0 commit comments

Comments
 (0)