• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vcfxb / wright-lang / 16310058828

16 Jul 2025 04:01AM UTC coverage: 75.352% (-0.4%) from 75.708%
16310058828

push

github

vcfxb
tweak gh actions to skip checking LLVM version

963 of 1278 relevant lines covered (75.35%)

34.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.9
/wright/src/ast/ty.rs
1
//! AST models for type signatures in wright source.
2

3
use crate::{ast::path::Path, source_tracking::fragment::Fragment};
4

5
/// A type signature in source code.
6
#[derive(Debug)]
7
#[allow(missing_docs)]
8
pub enum Type {
9
    Atomic(AtomicTy),
10
    Reference(ReferenceTy),
11
    Constrained(ConstrainedTy),
12
}
13

14
impl Type {
15
    /// Get the matching source for this type signature in source code.
16
    pub fn matching_source(&self) -> &Fragment {
6✔
17
        match self {
6✔
18
            Type::Atomic(atomic_ty) => &atomic_ty.matching_source,
4✔
19
            Type::Reference(reference_ty) => &reference_ty.matching_source,
2✔
20
            Type::Constrained(constrained_ty) => &constrained_ty.matching_source,
×
21
        }
22
    }
6✔
23

24
    /// Attempt to "downcast" this to an atomic type signature if it is one.
25
    pub fn downcast_primitive(&self) -> Option<&AtomicTy> {
3✔
26
        match self {
3✔
27
            Type::Atomic(atomic) => Some(atomic),
3✔
28
            _ => None,
×
29
        }
30
    }
3✔
31

32
    /// Attempt to "downcast" this to a reference type signature if it is one.
33
    pub fn downcast_reference(&self) -> Option<&ReferenceTy> {
2✔
34
        match self {
2✔
35
            Type::Reference(reference) => Some(reference),
2✔
36
            _ => None,
×
37
        }
38
    }
2✔
39

40
    /// Attempt to "downcast" this to a constrained type signature if it is one.
41
    pub fn downcast_constrained_ty(&self) -> Option<&ConstrainedTy> {
×
42
        match self {
×
43
            Type::Constrained(constrained) => Some(constrained),
×
44
            _ => None,
×
45
        }
46
    }
×
47
}
48

49
/// The atomic types of wright -- primitive numeric types, boolean, char, etc.
50
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
51
#[allow(missing_docs)]
52
pub enum AtomicTyVariant {
53
    Bool,
54
    U8,
55
    I8,
56
    U16,
57
    I16,
58
    U32,
59
    I32,
60
    U64,
61
    I64,
62
    F32,
63
    F64,
64
    Char,
65
}
66

67
/// An atomic type signature in wright source code.
68
#[derive(Debug)]
69
#[allow(missing_docs)]
70
pub struct AtomicTy {
71
    pub variant: AtomicTyVariant,
72
    pub matching_source: Fragment,
73
}
74

75
/// Source code for a reference type signature, such as `@u64`.
76
#[derive(Debug)]
77
pub struct ReferenceTy {
78
    /// The source code of the target type.
79
    pub target_ty: Box<Type>,
80
    /// The fragment of the whole reference.
81
    pub matching_source: Fragment,
82
}
83

84
/// A type with a given set of constraints.
85
/// 
86
/// Constraints in wright are functions that the compiler can verify are strictly [pure]
87
/// (which is informally defined here, and a point of further work eventually).
88
/// 
89
/// A constrained type declaration lists a base type and then one or more "strictly pure"
90
/// functions that have a signature exactly matching T -> bool (where T is the constrained type).
91
/// 
92
/// An example of this could be 
93
/// ```text
94
/// pure func is_even(i: u8) -> bool {
95
///     i % 2 == 0
96
/// }
97
/// 
98
/// type EvenU8 = u8 constrain is_even;
99
/// ```
100
/// 
101
/// The wright compiler can then optimize agressively around these constraints later on (I hope).
102
#[derive(Debug)]
103
pub struct ConstrainedTy {
104
    /// The entire type signature from the beginning of the base type 
105
    /// to the end of the last constraining item.
106
    pub matching_source: Fragment,
107

108
    /// The type being constrained. 
109
    pub base_ty: Box<Type>,
110

111
    /// The functions constraining it.
112
    pub constraining_items: Vec<Path>,    
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc