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
//! Definition of the hir.
//!
//! This module's contents are exported at the crate root, this is just separated for some internal
//! organization.
use pomelo_parse::ast;

use crate::arena::Idx;
use crate::identifiers::{Label, LongStrId, LongTyCon, LongVId, TyCon, TyVar, VId};
use crate::{AstId, FileArena};

/// Location where an identifier is bound.
///
/// The `Pat` variant is only used for bindings inside of the pattern in a match statement.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DefLoc {
    Dec(Idx<Dec>),
    Pat(Idx<Pat>),
    Builtin,
    Missing,
}

/// HIR declaration node.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Dec {
    pub kind: DecKind,
    pub ast_id: AstId<ast::Dec>,
}

impl Dec {
    pub fn bound_vids<A: FileArena>(&self, arena: &A) -> Vec<LongVId> {
        self.kind.bound_vids(arena)
    }

    pub fn bound_tycons<A: FileArena>(&self, arena: &A) -> Vec<LongTyCon> {
        self.kind.bound_tycons(arena)
    }

    pub fn kind(&self) -> &DecKind {
        &self.kind
    }

    pub fn missing(&self) -> bool {
        matches!(self.kind(), DecKind::Missing)
    }

    pub fn seq(&self) -> Option<&[Idx<Dec>]> {
        if let DecKind::Seq { decs } = self.kind() {
            Some(decs)
        } else {
            None
        }
    }

    pub fn val(&self) -> Option<(&[TyVar], &[ValBind])> {
        if let DecKind::Val { tyvarseq, bindings } = self.kind() {
            Some((tyvarseq, bindings))
        } else {
            None
        }
    }

    pub fn ty(&self) -> Option<&[TypBind]> {
        if let DecKind::Ty { bindings } = self.kind() {
            Some(bindings)
        } else {
            None
        }
    }

    pub fn datatype(&self) -> Option<&[DataBind]> {
        if let DecKind::Datatype { databinds } = self.kind() {
            Some(databinds)
        } else {
            None
        }
    }

    pub fn replication(&self) -> Option<(&TyCon, &(LongTyCon, DefLoc))> {
        if let DecKind::Replication { lhs, rhs } = self.kind() {
            Some((lhs, rhs))
        } else {
            None
        }
    }

    pub fn abstype(&self) -> Option<(&[DataBind], Idx<Dec>)> {
        if let DecKind::Abstype { databinds, dec } = self.kind() {
            Some((databinds, *dec))
        } else {
            None
        }
    }

    pub fn exception(&self) -> Option<&ExBind> {
        if let DecKind::Exception { exbind } = self.kind() {
            Some(exbind)
        } else {
            None
        }
    }

    pub fn local(&self) -> Option<(Idx<Dec>, Idx<Dec>)> {
        if let DecKind::Local { inner, outer } = self.kind() {
            Some((*inner, *outer))
        } else {
            None
        }
    }

    pub fn open(&self) -> Option<&[LongStrId]> {
        if let DecKind::Open { longstrids } = self.kind() {
            Some(longstrids)
        } else {
            None
        }
    }

    pub fn fixity(&self) -> Option<(&Fixity, &[(VId, DefLoc)])> {
        if let DecKind::Fixity { fixity, vids } = self.kind() {
            Some((fixity, vids))
        } else {
            None
        }
    }
}

/// Kinds of HIR declarations.
///
/// These correspond to the basic forms in Chapter 2 of the Definition, after
/// desugaring the derived forms from Appendix A.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecKind {
    Missing,
    Seq {
        decs: Box<[Idx<Dec>]>,
    },
    Val {
        tyvarseq: Box<[TyVar]>,
        bindings: Box<[ValBind]>,
    },
    Ty {
        bindings: Box<[TypBind]>,
    },
    Datatype {
        databinds: Box<[DataBind]>,
    },
    Replication {
        lhs: TyCon,
        rhs: (LongTyCon, DefLoc),
    },
    Abstype {
        databinds: Box<[DataBind]>,
        dec: Idx<Dec>,
    },
    Exception {
        exbind: ExBind,
    },
    Local {
        inner: Idx<Dec>,
        outer: Idx<Dec>,
    },
    Open {
        longstrids: Box<[LongStrId]>,
    },
    Fixity {
        fixity: Fixity,
        vids: Box<[(VId, DefLoc)]>,
    },
}

impl DecKind {
    pub fn bound_vids<A: FileArena>(&self, arena: &A) -> Vec<LongVId> {
        match self {
            DecKind::Missing
            | DecKind::Ty { .. }
            | DecKind::Replication { .. }
                // Fixity is a weird one, need to figure out how to treat it
            | DecKind::Fixity { .. } => vec![],
            DecKind::Seq { decs } => {
                let mut names = vec![];

                for d in decs.iter() {
                    let d = arena.get_dec(*d).bound_vids(arena);
                    names.extend(d);
                }

                names
            }
            DecKind::Val { bindings, .. } => bindings
                .iter()
                .flat_map(|b| b.bound_vids(arena).into_iter())
                .collect(),
            DecKind::Datatype { databinds } => databinds.iter().flat_map(|d| d.bound_vids().into_iter()).collect(),
            DecKind::Abstype { databinds, dec } => {
                let mut names = databinds
                    .iter()
                    .flat_map(|d| d.bound_vids().into_iter())
                    .collect::<Vec<_>>();
                names.extend(arena.get_dec(*dec).bound_vids(arena));
                names
            }
            DecKind::Exception { exbind } => vec![exbind.bound_vid()],
            DecKind::Local { outer, .. } => arena.get_dec(*outer).bound_vids(arena),
            DecKind::Open { .. } => todo!(),
        }
    }

    pub fn bound_tycons<A: FileArena>(&self, arena: &A) -> Vec<LongTyCon> {
        match self {
            DecKind::Missing
            | DecKind::Val {  .. }
            | DecKind::Exception { .. }
                // Fixity is a weird one, need to figure out how to treat it
            | DecKind::Fixity { .. } => vec![],
            DecKind::Seq { decs } => {
                let mut tycons = vec![];

                for d in decs.iter() {
                    let d = arena.get_dec(*d).bound_tycons(arena);
                    tycons.extend(d);
                }

                tycons
            },
            DecKind::Ty { bindings } => bindings.iter().map(TypBind::bound_tycon).collect(),
            DecKind::Datatype { databinds } => databinds.iter().map(DataBind::bound_tycon).collect(),
            DecKind::Replication { lhs, .. } => vec![LongTyCon::from(*lhs)],
            DecKind::Abstype { databinds, dec } => {
                let mut tycons = databinds
                    .iter()
                    .map(DataBind::bound_tycon)
                    .collect::<Vec<_>>();
                tycons.extend(arena.get_dec(*dec).bound_tycons(arena));
                tycons
            }
            DecKind::Local { outer, .. } => arena.get_dec(*outer).bound_tycons(arena),
            DecKind::Open { .. } => todo!(),
        }
    }
}

/// Binding of the names in a pattern to an expression.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValBind {
    pub rec: bool,
    pub pat: Idx<Pat>,
    pub expr: Idx<Expr>,
}

impl ValBind {
    pub fn bound_vids<A: FileArena>(&self, arena: &A) -> Vec<LongVId> {
        arena.get_pat(self.pat).bound_vids(arena)
    }
}

/// Binding of a type constructor.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypBind {
    pub tyvarseq: Box<[TyVar]>,
    pub tycon: TyCon,
    pub ty: Idx<Ty>,
}

impl TypBind {
    pub fn bound_tycon(&self) -> LongTyCon {
        LongTyCon::from(self.tycon)
    }
}

/// Binding of a new datatype.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataBind {
    pub tyvarseq: Box<[TyVar]>,
    pub tycon: TyCon,
    pub conbinds: Box<[ConBind]>,
}

impl DataBind {
    pub fn bound_vids(&self) -> Vec<LongVId> {
        self.conbinds.iter().map(|b| LongVId::from(b.vid)).collect()
    }

    pub fn bound_tycon(&self) -> LongTyCon {
        LongTyCon::from(self.tycon)
    }
}

/// Binding of a datatype constructor.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConBind {
    pub op: bool,
    pub vid: VId,
    pub ty: Option<Idx<Ty>>,
}

/// Binding an exception.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExBind {
    Name {
        op: bool,
        vid: VId,
        ty: Option<Idx<Ty>>,
    },
    Assignment {
        op_lhs: bool,
        lhs: VId,
        op_rhs: bool,
        rhs: (LongVId, DefLoc),
    },
}

impl ExBind {
    pub fn bound_vid(&self) -> LongVId {
        match self {
            Self::Name { vid, .. } => LongVId::from(*vid),
            Self::Assignment { lhs, .. } => LongVId::from(*lhs),
        }
    }
}

/// Type of fixity, including whether it is left- or right-associative and its operator precedence.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Fixity {
    Left(Option<u8>),
    Right(Option<u8>),
    Nonfix,
}

/// HIR expression node.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Expr {
    pub kind: ExprKind,
    pub ast_id: AstId<ast::Expr>,
}

impl Expr {
    pub fn kind(&self) -> &ExprKind {
        &self.kind
    }

    pub fn missing(&self) -> bool {
        matches!(self.kind(), ExprKind::Missing)
    }

    pub fn scon(&self) -> Option<&Scon> {
        if let ExprKind::Scon(s) = self.kind() {
            Some(s)
        } else {
            None
        }
    }

    pub fn seq(&self) -> Option<&[Idx<Expr>]> {
        if let ExprKind::Seq { exprs } = self.kind() {
            Some(exprs)
        } else {
            None
        }
    }

    pub fn vid(&self) -> Option<(bool, &(LongVId, DefLoc))> {
        if let ExprKind::VId { op, longvid } = self.kind() {
            Some((*op, longvid))
        } else {
            None
        }
    }

    pub fn record(&self) -> Option<&[ExpRow]> {
        if let ExprKind::Record { rows } = self.kind() {
            Some(rows)
        } else {
            None
        }
    }

    pub fn let_expr(&self) -> Option<(Idx<Dec>, Idx<Expr>)> {
        if let ExprKind::Let { dec, expr } = self.kind() {
            Some((*dec, *expr))
        } else {
            None
        }
    }

    pub fn application(&self) -> Option<(Idx<Expr>, Idx<Expr>)> {
        if let ExprKind::Application { expr, param } = self.kind() {
            Some((*expr, *param))
        } else {
            None
        }
    }

    #[allow(clippy::type_complexity)]
    pub fn infix(&self) -> Option<(Idx<Expr>, (VId, DefLoc), Idx<Expr>)> {
        if let ExprKind::Infix { lhs, vid, rhs } = self.kind() {
            Some((*lhs, *vid, *rhs))
        } else {
            None
        }
    }

    pub fn typed(&self) -> Option<(Idx<Expr>, Idx<Ty>)> {
        if let ExprKind::Typed { expr, ty } = self.kind() {
            Some((*expr, *ty))
        } else {
            None
        }
    }

    pub fn handle(&self) -> Option<(Idx<Expr>, &[MRule])> {
        if let ExprKind::Handle { expr, match_ } = self.kind() {
            Some((*expr, match_))
        } else {
            None
        }
    }

    pub fn raise(&self) -> Option<Idx<Expr>> {
        if let ExprKind::Raise { expr } = self.kind() {
            Some(*expr)
        } else {
            None
        }
    }

    pub fn fn_expr(&self) -> Option<&[MRule]> {
        if let ExprKind::Fn { match_ } = self.kind() {
            Some(match_)
        } else {
            None
        }
    }
}

/// Kinds of HIR expressions.
///
/// These correspond to the basic forms in Chapter 2 of the Definition, after
/// desugaring the derived forms from Appendix A.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExprKind {
    Missing,
    Scon(Scon),
    Seq {
        exprs: Box<[Idx<Expr>]>,
    },
    VId {
        op: bool,
        longvid: (LongVId, DefLoc),
    },
    Record {
        rows: Box<[ExpRow]>,
    },
    Let {
        dec: Idx<Dec>,
        expr: Idx<Expr>,
    },
    Application {
        expr: Idx<Expr>,
        param: Idx<Expr>,
    },
    Infix {
        lhs: Idx<Expr>,
        vid: (VId, DefLoc),
        rhs: Idx<Expr>,
    },
    Typed {
        expr: Idx<Expr>,
        ty: Idx<Ty>,
    },
    Handle {
        expr: Idx<Expr>,
        match_: Box<[MRule]>,
    },
    Raise {
        expr: Idx<Expr>,
    },
    Fn {
        match_: Box<[MRule]>,
    },
}

/// HIR constant (literal).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Scon {
    Missing,
    Int(i128),
    Word(u128),
    Real(FloatWrapper),
    String(String),
    Char(char),
}

/// Wrapper so we can derive `Eq` for [`Scon`].
///
/// See
/// [`FloatTypeWrapper`](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-def/src/expr.rs)
/// from `rust-analyzer`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FloatWrapper(u64);

impl FloatWrapper {
    pub fn new(value: f64) -> Self {
        Self(value.to_bits())
    }
}

impl std::fmt::Display for FloatWrapper {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", f64::from_bits(self.0))
    }
}

/// Record entry in an expression.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExpRow {
    pub label: Label,
    pub expr: Idx<Expr>,
}

/// HIR pattern node.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Pat {
    pub kind: PatKind,
    pub ast_id: AstId<ast::Pat>,
}

impl Pat {
    /// Names bound by this pattern
    pub fn bound_vids<A: FileArena>(&self, arena: &A) -> Vec<LongVId> {
        self.kind.bound_vids(arena)
    }

    pub fn kind(&self) -> &PatKind {
        &self.kind
    }

    pub fn missing(&self) -> bool {
        matches!(self.kind(), PatKind::Missing)
    }

    pub fn wildcard(&self) -> bool {
        matches!(self.kind(), PatKind::Wildcard)
    }

    pub fn scon(&self) -> Option<&Scon> {
        if let PatKind::Scon(s) = self.kind() {
            Some(s)
        } else {
            None
        }
    }

    pub fn vid(&self) -> Option<(bool, &(LongVId, Option<DefLoc>))> {
        if let PatKind::VId { op, longvid } = self.kind() {
            Some((*op, longvid))
        } else {
            None
        }
    }

    pub fn record(&self) -> Option<&[PatRow]> {
        if let PatKind::Record { rows } = self.kind() {
            Some(rows)
        } else {
            None
        }
    }

    pub fn cons(&self) -> Option<(bool, &(LongVId, DefLoc), Idx<Pat>)> {
        if let PatKind::Constructed { op, longvid, pat } = self.kind() {
            Some((*op, longvid, *pat))
        } else {
            None
        }
    }

    #[allow(clippy::type_complexity)]
    pub fn infix(&self) -> Option<(Idx<Pat>, &(VId, DefLoc), Idx<Pat>)> {
        if let PatKind::Infix { lhs, vid, rhs } = self.kind() {
            Some((*lhs, vid, *rhs))
        } else {
            None
        }
    }

    pub fn typed(&self) -> Option<(Idx<Pat>, Idx<Ty>)> {
        if let PatKind::Typed { pat, ty } = self.kind() {
            Some((*pat, *ty))
        } else {
            None
        }
    }

    #[allow(clippy::type_complexity)]
    pub fn layered(&self) -> Option<(bool, &VId, Option<Idx<Ty>>, Idx<Pat>)> {
        if let PatKind::Layered { op, vid, ty, pat } = self.kind() {
            Some((*op, vid, *ty, *pat))
        } else {
            None
        }
    }
}

/// Kinds of HIR expressions.
///
/// These correspond to the basic forms in Chapter 2 of the Definition, after
/// desugaring the derived forms from Appendix A.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PatKind {
    Missing,
    Wildcard,
    Scon(Scon),
    VId {
        op: bool,
        // Note that `longvid` can bind a new variable, or it could refer to a variant of a
        // datatype! If it's the latter, then we need to know where the variant was defined.
        longvid: (LongVId, Option<DefLoc>),
    },
    Record {
        rows: Box<[PatRow]>,
    },
    Constructed {
        op: bool,
        longvid: (LongVId, DefLoc),
        pat: Idx<Pat>,
    },
    Infix {
        lhs: Idx<Pat>,
        vid: (VId, DefLoc),
        rhs: Idx<Pat>,
    },
    Typed {
        pat: Idx<Pat>,
        ty: Idx<Ty>,
    },
    Layered {
        op: bool,
        vid: VId,
        ty: Option<Idx<Ty>>,
        pat: Idx<Pat>,
    },
}

impl PatKind {
    /// Names bound by this pattern
    pub fn bound_vids<A: FileArena>(&self, arena: &A) -> Vec<LongVId> {
        match &self {
            PatKind::Missing | PatKind::Wildcard | PatKind::Scon(_) => vec![],
            PatKind::VId {
                longvid: (name, def),
                ..
            } => match def {
                None => vec![name.clone()],
                Some(_) => vec![],
            },
            PatKind::Record { rows } => {
                let mut names = vec![];

                for r in rows.iter() {
                    if let PatRow::Pattern { pat, .. } = r {
                        names.extend(arena.get_pat(*pat).bound_vids(arena));
                    }
                }
                names
            }
            PatKind::Constructed { pat, .. } => arena.get_pat(*pat).bound_vids(arena),
            PatKind::Infix { lhs, rhs, .. } => {
                let mut lhs = arena.get_pat(*lhs).bound_vids(arena);
                let rhs = arena.get_pat(*rhs).bound_vids(arena);
                lhs.extend(rhs);
                lhs
            }
            PatKind::Typed { pat, .. } => arena.get_pat(*pat).bound_vids(arena),
            PatKind::Layered { vid, pat, .. } => {
                let mut names = vec![LongVId::from(*vid)];
                let pat_names = arena.get_pat(*pat).bound_vids(arena);
                names.extend(pat_names);
                names
            }
        }
    }
}

/// Record entry in a pattern.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PatRow {
    Wildcard,
    Pattern { label: Label, pat: Idx<Pat> },
}

/// HIR type node.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Ty {
    pub kind: TyKind,
    // None only if TyKind::Missing
    pub ast_id: AstId<ast::Ty>,
}

impl Ty {
    pub fn kind(&self) -> &TyKind {
        &self.kind
    }

    pub fn missing(&self) -> bool {
        matches!(self.kind(), TyKind::Missing)
    }

    pub fn tyvar(&self) -> Option<TyVar> {
        if let TyKind::Var(v) = self.kind() {
            Some(*v)
        } else {
            None
        }
    }

    pub fn record(&self) -> Option<&[TyRow]> {
        if let TyKind::Record { tyrows } = self.kind() {
            Some(tyrows)
        } else {
            None
        }
    }

    #[allow(clippy::type_complexity)]
    pub fn cons(&self) -> Option<(&[Idx<Ty>], &(LongTyCon, DefLoc))> {
        if let TyKind::Constructed { tyseq, longtycon } = self.kind() {
            Some((tyseq, longtycon))
        } else {
            None
        }
    }

    pub fn fn_ty(&self) -> Option<(Idx<Ty>, Idx<Ty>)> {
        if let TyKind::Function { domain, range } = self.kind() {
            Some((*domain, *range))
        } else {
            None
        }
    }
}

/// Kinds of HIR types.
///
/// These correspond to the basic forms in Chapter 2 of the Definition, after
/// desugaring the derived forms from Appendix A.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TyKind {
    Missing,
    // TODO: make a `TyVar` also refer to it's `DefLoc`?
    Var(TyVar),
    Record {
        tyrows: Box<[TyRow]>,
    },
    Constructed {
        tyseq: Box<[Idx<Ty>]>,
        longtycon: (LongTyCon, DefLoc),
    },
    Function {
        domain: Idx<Ty>,
        range: Idx<Ty>,
    },
}

/// Record entry in a type.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TyRow {
    pub label: Label,
    pub ty: Idx<Ty>,
}

/// A rule in a match statement.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MRule {
    pub pat: Idx<Pat>,
    pub expr: Idx<Expr>,
}