-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
929 lines (878 loc) · 50.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="Sam Derbyshire, Well-Typed">
<title>GHC’s renamer</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/dist/reset.css">
<link rel="stylesheet" href="reveal.js/dist/reveal.css">
<style>
.reveal .sourceCode { /* see #7635 */
overflow: visible;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="reveal.js/dist/theme/welltyped_theme.css" id="theme">
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="title-slide">
<h1 class="title">GHC’s renamer</h1>
<p class="subtitle">GHC Contributors’ Workshop</p>
<p class="author">Sam Derbyshire, Well-Typed</p>
<p class="date">June 7th, 2023</p>
</section>
<section class="slide level2">
<!--
Compile the HTML slides with Pandoc:
pandoc -t revealjs -s -o index.html renamer.md -V revealjs-url=reveal.js -V theme=welltyped_theme -V controlsTutorial=false -V controlsLayout=edges -V slideNumber='c/t' -V transition=slide
Custom theme in reveal.js/dist/themes/welltyped_theme.css
-->
<p align="center">
<img src=GHC_passes_renamer.svg height="500px" />
</p>
</section>
<section id="plan" class="slide level2">
<h2>Plan</h2>
<ul>
<li>First part: survey of the renamer and how information about
identifiers flows through the compiler pipeline.</li>
<li>Second part: getting our hands dirty, fixing a bug in the renamer
(interaction of <code>COMPLETE</code> sets of pattern synonyms and
<code>do</code> notation).</li>
</ul>
<p class="indicator">
⭲
</p>
</section>
<section id="what-does-the-renamer-do" class="slide level2">
<h2>What does the renamer do?</h2>
<ol type="I">
<li class="fragment" data-fragment-index="1">
Gives all names unique identifiers.
<ul>
<li>
Resolve namespacing (type constructor vs variable, module qualification,
record fields).
</li>
<li>
Handle shadowing.
</li>
</ul>
</li>
<li class="fragment" data-fragment-index="2">
Usage & dependency analysis.
<ul>
<li>
Redundant/unused imports, unused declarations, …
</li>
<li>
Dependency analysis: determines order of typechecking.
</li>
<p class="indicator">
⭲
</p>
</ul>
</li>
</ol>
</section>
<section id="names" class="slide level2">
<h2>Names</h2>
<p>There are many ways that GHC can refer to an identifier depending on
how much it knows about it.</p>
<div class="element: fragment">
<ul>
<li><code>OccName</code></li>
</ul>
</div>
<div class="element: fragment">
<ul>
<li><code>Name</code></li>
</ul>
</div>
<div class="element: fragment">
<ul>
<li><code>RdrName</code></li>
</ul>
</div>
<div class="element: fragment">
<ul>
<li><code>GlobalRdrElt</code></li>
</ul>
</div>
<div class="element: fragment">
<ul>
<li><code>Var</code>, <code>TyVar</code>, <code>Id</code>
<p class="indicator">
⭲
</p></li>
</ul>
</div>
</section>
<section id="occname-occurrences-with-a-namespace" class="slide level2">
<h2><code>OccName</code>: occurrences with a <code>NameSpace</code></h2>
<div class="element: fragment">
<div class="sourceCode" id="cb1"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">OccName</span> <span class="ot">=</span> <span class="dt">OccName</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> {<span class="ot"> occNameSpace ::</span> <span class="dt">NameSpace</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> occNameFS ::</span> <span class="dt">FastString</span> }</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">NameSpace</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">VarName</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">FldName</span> {<span class="ot"> fldParent ::</span> <span class="dt">FastString</span> }</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">DataName</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">TvName</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">TcClsName</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="kw">newtype</span> <span class="dt">OccEnv</span> a <span class="ot">=</span> <span class="dt">MkOccEnv</span> (<span class="dt">FastStringEnv</span> (<span class="dt">UniqFM</span> <span class="dt">NameSpace</span> a))</span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="name-unique-identifiers" class="slide level2">
<h2><code>Name</code>: unique identifiers</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb2"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">Name</span> <span class="ot">=</span> <span class="dt">Name</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> {<span class="ot"> n_sort ::</span> <span class="dt">NameSort</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> n_occ ::</span> <span class="dt">OccName</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> n_uniq ::</span> <span class="dt">Unique</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> n_loc ::</span> <span class="dt">SrcSpan</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">NameSort</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">External</span> <span class="dt">Module</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">WiredIn</span> <span class="dt">Module</span> <span class="dt">TyThing</span> <span class="dt">BuiltInSyntax</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">Internal</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">System</span></span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="rdrname-umbrella-datatype" class="slide level2">
<h2><code>RdrName</code>: umbrella datatype</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb3"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">RdrName</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">Unqual</span> <span class="dt">OccName</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">Qual</span> <span class="dt">ModuleName</span> <span class="dt">OccName</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">Orig</span> <span class="dt">Module</span> <span class="dt">OccName</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">Exact</span> <span class="dt">Name</span></span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="var-and-id-variables" class="slide level2">
<h2><code>Var</code> and <code>Id</code>: variables</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb4"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">Var</span> <span class="co">-- slightly abridged</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">TyVar</span> {<span class="ot"> varName ::</span> <span class="dt">Name</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> varType ::</span> <span class="dt">Kind</span> }</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">TcTyVar</span> {<span class="ot"> varName ::</span> <span class="dt">Name</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> varType ::</span> <span class="dt">Kind</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> tc_tv_details ::</span> <span class="dt">TcTyVarDetails</span> }</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">Id</span> {<span class="ot"> varName ::</span> <span class="dt">Name</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> varType ::</span> <span class="dt">Type</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> varMult ::</span> <span class="dt">Mult</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> idScope ::</span> <span class="dt">IdScope</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> id_details ::</span> <span class="dt">IdDetails</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> id_info ::</span> <span class="dt">IdInfo</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">IdScope</span> <span class="ot">=</span> <span class="dt">GlobalId</span> <span class="op">|</span> <span class="dt">LocalId</span> <span class="dt">ExportFlag</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">ExportFlag</span> <span class="ot">=</span> <span class="dt">NotExported</span> <span class="op">|</span> <span class="dt">Exported</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">IdDetails</span> <span class="ot">=</span> <span class="dt">VanillaId</span> <span class="op">|</span> <span class="dt">RecSelId</span> {} <span class="op">|</span> <span class="dt">PrimOpId</span> {} <span class="op">|</span> <span class="dt">CoVarId</span> {} <span class="op">|</span> <span class="op">...</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">TyVar</span> <span class="ot">=</span> <span class="dt">Var</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">Id</span> <span class="ot">=</span> <span class="dt">Var</span></span></code></pre></div>
</div>
</section>
<section id="information-about-names-tything-and-greinfo"
class="slide level2">
<h2>Information about <code>Name</code>s: <code>TyThing</code> and
<code>GREInfo</code></h2>
<div class="element: fragment">
<div class="sourceCode" id="cb5"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">TyThing</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">AnId</span> <span class="dt">Id</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">AConLike</span> <span class="dt">ConLike</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">ATyCon</span> <span class="dt">TyCon</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">ACoAxiom</span> (<span class="dt">CoAxiom</span> <span class="dt">Branched</span>)</span></code></pre></div>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb6"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">GREInfo</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">Vanilla</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">IAmTyCon</span> (<span class="dt">TyConFlavour</span> <span class="dt">Name</span>)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">IAmConLike</span> <span class="dt">ConInfo</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">IAmRecField</span> <span class="dt">RecFieldInfo</span></span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="globalrdrelt-and-the-globalrdrenv" class="slide level2">
<h2><code>GlobalRdrElt</code> and the <code>GlobalRdrEnv</code></h2>
<p>The renamer primarily deals with <code>GlobalRdrElt</code>, which
consists of a <code>Name</code>, information about how it’s in scope in
the renamer, and additional information that the renamer might need to
know.</p>
<div class="element: fragment">
<div class="sourceCode" id="cb7"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">GlobalRdrElt</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">GRE</span> {<span class="ot"> gre_name ::</span> <span class="dt">Name</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> gre_par ::</span> <span class="dt">Parent</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> gre_lcl ::</span> <span class="dt">Bool</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> gre_imp ::</span> <span class="dt">Bag</span> <span class="dt">ImportSpec</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> ,<span class="ot"> gre_info ::</span> <span class="dt">GREInfo</span> }</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">GlobalRdrEnv</span> <span class="ot">=</span> <span class="dt">OccEnv</span> [<span class="dt">GlobalRdrElt</span>]</span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="the-tcrn-monad" class="slide level2">
<h2>The <code>TcRn</code> monad</h2>
<p>Renaming and typechecking happens in a shared monad, <code>TcM</code>
(also called <code>TcRn</code> or <code>RnM</code>).</p>
<div class="element: fragment" data-fragment-index="1">
<div class="sourceCode" id="cb8"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">TcRnIf</span> a b <span class="ot">=</span> <span class="dt">IOEnv</span> (<span class="dt">Env</span> a b)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">TcRn</span> <span class="ot">=</span> <span class="dt">TcRnIf</span> <span class="dt">TcGblEnv</span> <span class="dt">TcLclEnv</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">TcM</span> <span class="ot">=</span> <span class="dt">TcRn</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">RnM</span> <span class="ot">=</span> <span class="dt">TcRn</span></span></code></pre></div>
</div>
<div class="element: fragment" data-fragment-index="2">
<p>This is <code>ReaderT</code> over <code>IO</code>, with access
to:</p>
<ul>
<li><code>HscEnv</code> <i class="fragment" data-fragment-index="3"> –
per-module options (e.g. flags passed to GHC) and environment</i><br />
<i class="fragment" data-fragment-index="4">e.g. <code>UnitEnv</code>,
currently loaded modules;</i></li>
<li><code>TcGblEnv</code> <i class="fragment" data-fragment-index="5"> –
generated during typechecking and passed on</i><br />
<i class="fragment" data-fragment-index="6">e.g. <code>TypeEnv</code>,
<code>InstEnv</code>, <code>GlobalRdrEnv</code>;</i></li>
<li><code>TcLclEnv</code> <i class="fragment" data-fragment-index="7"> –
changes as we move inside expressions</i><br />
<i class="fragment" data-fragment-index="8">e.g. <code>SrcSpan</code>,
<code>TcLevel</code>, <code>LocalRdrEnv</code>.
<p class="indicator">
⭲
</p>
</i></li>
</ul>
</div>
</section>
<section id="example-renaming-a-record-field-update"
class="slide level2">
<h2>Example: renaming a record field update</h2>
<div class="element: fragment">
<p>Start by looking at <code>rnExpr (RecordUpd {..})</code>:</p>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb9"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>rnExpr (<span class="dt">RecordUpd</span> { rupd_expr <span class="ot">=</span> <span class="dt">L</span> l expr, rupd_flds <span class="ot">=</span> rbinds })</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> setSrcSpanA l <span class="op">$</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> rbinds <span class="kw">of</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">RegularRecUpdFields</span> { recUpdFields <span class="ot">=</span> flds } <span class="ot">-></span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">do</span> { (e, fv_e) <span class="ot"><-</span> rnExpr expr</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a> ; (parents, flds, fv_flds) <span class="ot"><-</span> rnHsRecUpdFields flds</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a> ; <span class="op">...</span> }</span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a> <span class="co">-- ...</span></span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="looking-up-fields" class="slide level2">
<h2>Looking up fields</h2>
<p>After handling duplicates, <code>rnHsRecUpdFields</code> starts by
calling <code>lookupRecUpdFields</code> to look up each field
individually.</p>
<div class="element: fragment">
<div class="sourceCode" id="cb10"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ot">lookupRecUpdFields ::</span> <span class="dt">NE.NonEmpty</span> (<span class="dt">LHsRecUpdField</span> <span class="dt">GhcPs</span> <span class="dt">GhcPs</span>)</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">-></span> <span class="dt">RnM</span> (<span class="dt">NE.NonEmpty</span> (<span class="dt">HsRecUpdParent</span> <span class="dt">GhcRn</span>))</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>lookupRecUpdFields flds</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="kw">do</span> { gre_env <span class="ot"><-</span> getGlobalRdrEnv</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> ; fld1_gres <span class="op">NE.:|</span> other_flds_gres <span class="ot"><-</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mapM</span> (lookupFieldGREs gre_env <span class="op">.</span> getFieldUpdLbl) flds</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> ; <span class="co">-- ...</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> }</span></code></pre></div>
</div>
<div class="element: fragment">
<p>We retrieve <code>GlobalRdrElt</code>s for each record field.<br />
These have <code>GREInfo</code>s which specify which constructors have
that field.<br />
We can use that to disambiguate.</p>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="disambiguating-using-constructors" class="slide level2">
<h2>Disambiguating using constructors</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb11"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">S</span> <span class="ot">=</span> <span class="dt">MkS1</span> { x,<span class="ot"> y ::</span> <span class="dt">Float</span> } <span class="op">|</span> <span class="dt">MkS2</span> { x, y,<span class="ot"> z ::</span> <span class="dt">Float</span> }</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">T</span> <span class="ot">=</span> <span class="dt">MkT1</span> {<span class="ot"> x ::</span> <span class="dt">Word</span> } <span class="op">|</span> <span class="dt">MkT2</span> {<span class="ot"> y ::</span> <span class="dt">Int</span> }</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>foo r <span class="ot">=</span> r { x <span class="ot">=</span> <span class="dv">3</span>, y <span class="ot">=</span> <span class="dv">4</span> }</span></code></pre></div>
</div>
<div class="element: fragment">
<p>Lookup:
<code>[(x, [MkS1, MkS2, MkT1]), (y, [MkS1, MkS2, MkT2])]</code>.</p>
</div>
<div class="element: fragment">
<p>Intersect all the possible data constructors:
<code>[MkS1, MkS2]</code>.</p>
</div>
<div class="element: fragment">
<p>Take parents (removing duplicates): <code>[S]</code>.</p>
</div>
<div class="element: fragment">
<p>There is a single parent: the record update is unambiguous!</p>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="flow-through-the-compiler-trees-that-grow"
class="slide level2">
<h2>Flow through the compiler & trees that grow</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb12"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">family</span> <span class="dt">IdP</span> p</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="dt">LIdP</span> p <span class="ot">=</span> <span class="dt">XRec</span> p (<span class="dt">IdP</span> p)</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">family</span> <span class="dt">XRec</span> p a</span></code></pre></div>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb13"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">instance</span> <span class="dt">IdP</span> (<span class="dt">GhcPass</span> p) <span class="ot">=</span> <span class="dt">IdGhcP</span> p</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">family</span> <span class="dt">IdGhcP</span> pass <span class="kw">where</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">IdGhcP</span> <span class="dt">'Parsed</span> <span class="ot">=</span> <span class="dt">RdrName</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">IdGhcP</span> <span class="dt">'Renamed</span> <span class="ot">=</span> <span class="dt">Name</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">IdGhcP</span> <span class="dt">'Typechecked</span> <span class="ot">=</span> <span class="dt">Id</span></span></code></pre></div>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb14"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">instance</span> <span class="dt">XRec</span> (<span class="dt">GhcPass</span> p) a <span class="ot">=</span> <span class="dt">GenLocated</span> (<span class="dt">Anno</span> a) a</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">GenLocated</span> l e <span class="ot">=</span> <span class="dt">L</span> l e</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">instance</span> <span class="dt">Anno</span> <span class="dt">RdrName</span> <span class="ot">=</span> <span class="dt">SrcSpanAnnN</span> <span class="co">-- SrcSpan, but with</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">instance</span> <span class="dt">Anno</span> <span class="dt">Name</span> <span class="ot">=</span> <span class="dt">SrcSpanAnnN</span> <span class="co">-- some extra stuff</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> <span class="kw">instance</span> <span class="dt">Anno</span> <span class="dt">Id</span> <span class="ot">=</span> <span class="dt">SrcSpanAnnN</span> <span class="co">-- for exact-print</span></span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="lexing" class="slide level2">
<h2>Lexing</h2>
<p>We start off by lexing. See <code>GHC.Parser.Lexer.x</code>:</p>
<div class="element: fragment">
<div class="sourceCode" id="cb15"><pre
class="sourceCode ocaml"><code class="sourceCode ocaml"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>@varid = $small $idchar* -- variable identifiers</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>@conid = $large $idchar* -- constructor identifiers</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>@varsym = ($symbol # \:) $symbol* -- variable (operator) symbol</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a>@consym = \: $symbol* -- constructor (operator) symbol</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a>$small = [a-z \_]</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>$large = [A-Z]</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a>$symbol = [\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~\:]</span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a>$idchar = [$small $large $digit \']</span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="parsing" class="slide level2">
<h2>Parsing</h2>
<p>Then parsing, in <code>GHC.Parser.y</code>.</p>
<ul>
<li class="fragment">
Parse occurrences into <code>RdrName</code>.
<ul>
<li class="fragment">
Use <code>mkQual</code>/<code>mkUnqual</code> depending on
qualification.
</li>
<li class="fragment">
Resolve <code>NameSpace</code> using context (e.g. whether we are
parsing a term or a type).
</li>
</ul>
</li>
<li class="fragment">
Fix up after the fact when necessary.
</li>
</ul>
<div class="element: fragment">
<p>Example: parsing a type constructor.</p>
<div class="sourceCode" id="cb16"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="ot">tyconsym ::</span> { <span class="dt">RdrName</span> } <span class="co">-- (actually LocatedN RdrName)</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="op">:</span> <span class="dt">CONSYM</span> { mkUnqual tcClsName (getCONSYM <span class="op">$</span><span class="dv">1</span>) }</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">VARSYM</span> { mkUnqual tcClsName (getVARSYM <span class="op">$</span><span class="dv">1</span>) }</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="ch">':'</span> { consDataCon_RDR }</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="ch">'-'</span> { mkUnqual tcClsName (fsLit <span class="st">"-"</span>) }</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="ch">'.'</span> { mkUnqual tcClsName (fsLit <span class="st">"."</span>) }</span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="quick-example-of-fixing-up" class="slide level2">
<h2>Quick example of fixing up</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb17"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">D</span> a b c d <span class="ot">=</span> <span class="dt">Q</span> a <span class="ot">=></span> b <span class="op">:+:</span> c <span class="op">:*:</span> d</span></code></pre></div>
</div>
<div class="element: fragment">
<p>Parse this as a type first. Then, after properly associating using
the fixities, we find that <code>:+:</code> should be namespaced as a
data constructor, and the others remain type constructors.</p>
</div>
<div class="element: fragment">
We also need to resolve ambiguities between expression and patterns. See
Note [Ambiguous syntactic categories] in
<code>GHC.Parser.PostProcess</code>.
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="the-renamer-typechecker-pipeline" class="slide level2">
<h2>The renamer & typechecker pipeline</h2>
<div class="element: fragment">
<p>The main entry point is
<code>GHC.Tc.Module.tcRnModuleTcRnM</code>.</p>
</div>
<ol type="I">
<li class="fragment">
Rename the import list in <code>tcRnImports</code>.
</li>
<li class="fragment">
Rename and typecheck local declarations and the export list in
<code>tcRnSrcDecls</code>.
<ol type="i">
<li class="fragment">
Rename local declarations in <code>rnTopSrcDecls</code>.
</li>
<li class="fragment">
Typecheck these declarations in <code>tcTopSrcDecls</code>.
</li>
<li class="fragment">
Rename the exports in <code>rnExportList</code>. This allows us to
assemble a final <code>TcGblEnv</code> which contains everything
provided by the module.
</li>
</ol>
</li>
<li class="fragment">
<p>Assemble the final typechecked module, to be passed onto the next
stage of the compiler pipeline. Everything is extracted from the
<code>TcGblEnv</code>.</p>
<p class="indicator">
⭲
</p>
</li>
</ol>
</section>
<section id="renaming-imports" class="slide level2">
<h2>Renaming imports</h2>
<p>Entry point: <code>GHC.Rename.Names.rnImportDecl</code>.</p>
<ol type="I">
<li class="fragment">
Load the module we’re importing; this will load its interface file from
disk, or directly load the information if it’s available in memory.
</li>
<li class="fragment">
Figure out what we are importing, in <code>filterImports</code>.
<ul>
<li class="fragment">
For a blanket import, import everything.
</li>
<li class="fragment">
For an explicit import list, accumulate everything that is mentioned.
<p class="fragment">
<code>import M( A(x, ..), B(..) )</code>
</p>
</li>
<li class="fragment">
<code>import M hiding ( .. )</code>
<p class="fragment">
Works the same, except now we filter out instead.
</p>
</li>
</ul>
</li>
<li class="fragment">
<p>Add all the imported identifiers to the <code>GlobalRdrEnv</code>. We
will look up in this environment when renaming the body of the
module.</p>
<p class="indicator">
⭲
</p>
</li>
</ol>
</section>
<section id="renaming-local-definitions" class="slide level2">
<h2>Renaming local definitions</h2>
<div class="element: fragment" data-fragment-index="1">
<p>The main entry point to renaming local declarations is
<code>GHC.Rename.Module.rnSrcDecls</code>. Control flow:</p>
</div>
<ol type="I">
<li class="fragment" data-fragment-index="3">
Generate new <code>Name</code>s for all binders.
<span class="fragment fade-out" data-fragment-index="11">
<ol type="a">
<li class="fragment" data-fragment-index="4">
“Non-value” binders <code>getLocalNonValBinders</code>.
<ol type="i">
<li class="fragment" data-fragment-index="5">
Type synonyms, type families, data declarations, data families, class
declarations.
</li>
<li class="fragment" data-fragment-index="6">
Data family instances and class instances, including associated types
and methods.
</li>
<li class="fragment" data-fragment-index="7">
Foreign imports.
</li>
</ol>
</li>
<li class="fragment" data-fragment-index="8">
Pattern synonyms <code>extendPatSynEnv</code>.
</li>
<li class="fragment" data-fragment-index="9">
Generate new <code>Name</code>s and rename the LHS of top-level value
bindings (<code>rnTopBindsLHS</code>).
<p class="indicator">
⤞
</p>
</li>
</ol>
</span>
</li>
<li class="fragment" data-fragment-index="11">
Rename declaration bodies.
<ol type="a">
<li class="fragment" data-fragment-index="12">
Type declarations <code>rnTyClDecls</code>.
<ol type="i">
<li class="fragment" data-fragment-index="13">
Type synonyms, type families, data declarations, data families, class
declarations.
</li>
<li class="fragment" data-fragment-index="14">
Standalone kind signatures.
</li>
<li class="fragment" data-fragment-index="15">
Type family instances, data family instances, class instances.
</li>
<li class="fragment" data-fragment-index="16">
Role annotations.
</li>
</ol>
</li>
<li class="fragment" data-fragment-index="17">
Top-level value bindings <code>rnValBindsRHS</code>.
</li>
<li class="fragment" data-fragment-index="18">
Everything else: <code>RULES</code>, foreign import/exports, default
declarations…
<p class="indicator">
⭲
</p>
</li>
</ol>
</li>
</ol>
</section>
<section id="dependency-analysis-of-type-declarations"
class="slide level2">
<h2>Dependency analysis of type declarations</h2>
<div class="element: fragment">
<p><code>rnTyClDecls</code> - renames all types/classes defined in the
module - uses this information to compute dependency groups
(strongly-connected components).</p>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb18"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="ot">rnTyClDecls ::</span> [<span class="dt">TyClGroup</span> <span class="dt">GhcPs</span>] <span class="ot">-></span> <span class="dt">RnM</span> ([<span class="dt">TyClGroup</span> <span class="dt">GhcRn</span>], <span class="dt">FreeVars</span>)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>rnTyClDecls tycl_ds <span class="ot">=</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">do</span> { tycls_w_fvs <span class="ot"><-</span> <span class="fu">mapM</span> rnTyClDecl (tyClGroupTyClDecls tycl_ds)</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> ; kisigs_w_fvs <span class="ot"><-</span> rnStandaloneKindSigs (tyClGroupKindSigs tycl_ds)</span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> ; instds_w_fvs <span class="ot"><-</span> <span class="fu">mapM</span> rnSrcInstDecl (tyClGroupInstDecls tycl_ds)</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> ; <span class="kw">let</span> tycl_sccs <span class="ot">=</span> depAnalTyClDecls kisig_fv_env tycls_w_fvs</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a> ; <span class="op">..</span> }</span></code></pre></div>
</div>
<div class="element: fragment">
<p>See Note [Dependency analysis of type, class, and instance decls] in
<code>GHC.Rename.Module</code>.</p>
</div>
<p><br/></p>
<div class="element: fragment">
This approach is known to have shortcomings, as it doesn’t properly
account for type instances when kind-checking.
<p class="indicator">
⭲
</p>
<p>See <a
href="https://gitlab.haskell.org/ghc/ghc/-/wikis/Type-&-Class-Dependency-Analysis">wiki
page: Type-&-Class-Dependency-Analysis</a>.</p>
</div>
</section>
<section id="dependency-analysis-of-value-declarations"
class="slide level2">
<h2>Dependency analysis of value declarations</h2>
<div class="element: fragment">
<div class="sourceCode" id="cb19"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">HsBindLR</span> idL idR</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="dt">FunBind</span> {<span class="op">..</span>} <span class="co">-- used for function/variable bindings</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">PatBind</span> {<span class="op">..</span>} <span class="co">-- (pattern is never a simple variable)</span></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">VarBind</span> {<span class="op">..</span>} <span class="co">-- (introduced by the typechecker)</span></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">PatSynBind</span> {<span class="op">..</span>}</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> <span class="op">|</span> <span class="dt">XHsBindsLR</span> <span class="op">!</span>(<span class="dt">XXHsBindsLR</span> idL idR) <span class="co">-- (introduced by the typechecker)</span></span></code></pre></div>
</div>
<div class="element: fragment">
<p><code>rnValBindsRHS</code> - renames all value bindings - performs
dependency analysis</p>
</div>
<div class="element: fragment">
<div class="sourceCode" id="cb20"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>rnValBindsRHS ctxt (<span class="dt">ValBinds</span> _ mbinds sigs)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="ot">=</span> <span class="kw">do</span> { (sigs', sig_fvs) <span class="ot"><-</span> renameSigs ctxt sigs</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> ; binds_w_dus <span class="ot"><-</span> mapBagM (rnLBind (mkScopedTvFn sigs')) mbinds</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> ; <span class="kw">let</span> <span class="op">!</span>(anal_binds, anal_dus) <span class="ot">=</span> depAnalBinds binds_w_dus</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> ; <span class="op">...</span> }</span></code></pre></div>
<p class="indicator">
⭲
</p>
</div>
</section>
<section id="topics-not-covered" class="slide level2">
<h2>Topics not covered</h2>
<div class="element: fragment">
<ul>
<li>Template Haskell</li>
</ul>
</div>
<div class="element: fragment">
<ul>
<li>Backpack</li>
</ul>
</div>
</section>
<section id="section" class="slide level2">
<h2></h2>
<p>Slides available online: <a
href="https://sheaf.github.io/ghc-renamer">sheaf.github.io/ghc-renamer</a>.</p>
</section>
</div>
</div>
<script src="reveal.js/dist/reveal.js"></script>
<!-- reveal.js plugins -->
<script src="reveal.js/plugin/notes/notes.js"></script>
<script src="reveal.js/plugin/search/search.js"></script>
<script src="reveal.js/plugin/zoom/zoom.js"></script>
<script>
// Full list of configuration options available at:
// https://revealjs.com/config/
Reveal.initialize({
// Display controls in the bottom right corner
controls: true,
// Help the user learn the controls by providing hints, for example by
// bouncing the down arrow when they first encounter a vertical slide
controlsTutorial: false,
// Determines where controls appear, "edges" or "bottom-right"
controlsLayout: 'edges',
// Visibility rule for backwards navigation arrows; "faded", "hidden"
// or "visible"
controlsBackArrows: 'faded',
// Display a presentation progress bar
progress: true,
// Display the page number of the current slide
slideNumber: false,
// 'all', 'print', or 'speaker'
showSlideNumber: 'all',
// Add the current slide number to the URL hash so that reloading the
// page/copying the URL will return you to the same slide
hash: true,
// Start with 1 for the hash rather than 0
hashOneBasedIndex: false,
// Flags if we should monitor the hash and change slides accordingly
respondToHashChanges: true,
// Push each slide change to the browser history
history: false,
// Enable keyboard shortcuts for navigation
keyboard: true,
// Enable the slide overview mode
overview: true,
// Disables the default reveal.js slide layout (scaling and centering)
// so that you can use custom CSS layout
disableLayout: false,
// Vertical centering of slides
center: true,
// Enables touch navigation on devices with touch input
touch: true,
// Loop the presentation
loop: false,
// Change the presentation direction to be RTL
rtl: false,
// see https://revealjs.com/vertical-slides/#navigation-mode
navigationMode: 'default',
// Randomizes the order of slides each time the presentation loads
shuffle: false,
// Turns fragments on and off globally
fragments: true,
// Flags whether to include the current fragment in the URL,
// so that reloading brings you to the same fragment position
fragmentInURL: true,
// Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen
embedded: false,
// Flags if we should show a help overlay when the questionmark
// key is pressed
help: true,
// Flags if it should be possible to pause the presentation (blackout)
pause: true,
// Flags if speaker notes should be visible to all viewers
showNotes: false,
// Global override for autoplaying embedded media (null/true/false)
autoPlayMedia: null,
// Global override for preloading lazy-loaded iframes (null/true/false)
preloadIframes: null,
// Number of milliseconds between automatically proceeding to the
// next slide, disabled when set to 0, this value can be overwritten
// by using a data-autoslide attribute on your slides
autoSlide: 0,
// Stop auto-sliding after user input
autoSlideStoppable: true,
// Use this method for navigation when auto-sliding
autoSlideMethod: null,
// Specify the average time in seconds that you think you will spend
// presenting each slide. This is used to show a pacing timer in the
// speaker view
defaultTiming: null,
// Enable slide navigation via mouse wheel
mouseWheel: false,
// The display mode that will be used to show slides
display: 'block',
// Hide cursor if inactive
hideInactiveCursor: true,
// Time before the cursor is hidden (in ms)
hideCursorTime: 5000,
// Opens links in an iframe preview overlay
previewLinks: false,
// Transition style (none/fade/slide/convex/concave/zoom)
transition: 'slide',
// Transition speed (default/fast/slow)
transitionSpeed: 'default',
// Transition style for full page slide backgrounds
// (none/fade/slide/convex/concave/zoom)
backgroundTransition: 'fade',
// Number of slides away from the current that are visible
viewDistance: 3,
// Number of slides away from the current that are visible on mobile
// devices. It is advisable to set this to a lower number than
// viewDistance in order to save resources.
mobileViewDistance: 2,
// reveal.js plugins
plugins: [
RevealNotes,
RevealSearch,
RevealZoom
]
});
</script>
</body>
</html>