Function verification should be complete, no tests yet
[bigint-presentation-code.git] / register_allocator / src / error.rs
1 use crate::{
2 index::{BlockIdx, DisplayOptionIdx, InstIdx, SSAValIdx},
3 loc::{BaseTy, Ty},
4 };
5 use thiserror::Error;
6
7 #[derive(Debug, Error)]
8 pub enum Error {
9 #[error("can't create a vector of an only-scalar type: {base_ty:?}")]
10 TriedToCreateVectorOfOnlyScalarType { base_ty: BaseTy },
11 #[error("reg_len out of range")]
12 RegLenOutOfRange,
13 #[error("invalid reg_len")]
14 InvalidRegLen,
15 #[error("start not in valid range")]
16 StartNotInValidRange,
17 #[error("BaseTy mismatch")]
18 BaseTyMismatch,
19 #[error("invalid sub-Loc: offset and/or reg_len out of range")]
20 InvalidSubLocOutOfRange,
21 #[error("Ty mismatch: expected {expected_ty:?} got {ty:?}")]
22 TyMismatch {
23 ty: Option<Ty>,
24 expected_ty: Option<Ty>,
25 },
26 #[error("function doesn't have entry block")]
27 MissingEntryBlock,
28 #[error("instruction index is too big")]
29 InstIdxTooBig,
30 #[error("block has invalid start {start}, expected {expected_start}")]
31 BlockHasInvalidStart {
32 start: InstIdx,
33 expected_start: InstIdx,
34 },
35 #[error("block {block} doesn't contain any instructions")]
36 BlockIsEmpty { block: BlockIdx },
37 #[error("entry block must not have any block parameters")]
38 EntryBlockCantHaveParams,
39 #[error("entry block must not have any predecessors")]
40 EntryBlockCantHavePreds,
41 #[error("block end is out of range: {end}")]
42 BlockEndOutOfRange { end: InstIdx },
43 #[error("block's last instruction must be a block terminator: {term_idx}")]
44 BlocksLastInstMustBeTerm { term_idx: InstIdx },
45 #[error(
46 "block terminator instructions are only allowed as a block's last \
47 instruction: {inst_idx}"
48 )]
49 TermInstOnlyAllowedAtBlockEnd { inst_idx: InstIdx },
50 #[error("instruction not in a block: {inst}")]
51 InstHasNoBlock { inst: InstIdx },
52 #[error("operand index {operand_idx} out of range for {inst}")]
53 OperandIndexOutOfRange { inst: InstIdx, operand_idx: usize },
54 #[error("duplicate copy destination operand: operand index {operand_idx} for {inst}")]
55 DupCopyDestOperand { inst: InstIdx, operand_idx: usize },
56 #[error("SSA value index {idx} out of range")]
57 SSAValIdxOutOfRange { idx: SSAValIdx },
58 #[error("instruction index {idx} out of range")]
59 InstIdxOutOfRange { idx: InstIdx },
60 #[error("block index {idx} out of range")]
61 BlockIdxOutOfRange { idx: BlockIdx },
62 #[error("copy instruction's source type doesn't match source operands")]
63 CopySrcTyMismatch { inst: InstIdx },
64 #[error("copy instruction's destination type doesn't match destination operands")]
65 CopyDestTyMismatch { inst: InstIdx },
66 #[error(
67 "operand index {operand_idx} for {inst} is missing from SSA value \
68 {ssa_val_idx}'s uses"
69 )]
70 MissingOperandUse {
71 ssa_val_idx: SSAValIdx,
72 inst: InstIdx,
73 operand_idx: usize,
74 },
75 #[error(
76 "operand index {operand_idx} for {inst} has kind `Def` but isn't \
77 SSA value {ssa_val_idx}'s definition"
78 )]
79 OperandDefIsNotSSAValDef {
80 ssa_val_idx: SSAValIdx,
81 inst: InstIdx,
82 operand_idx: usize,
83 },
84 #[error(
85 "SSA value {ssa_val_idx}'s definition isn't the corresponding \
86 operand's SSA Value: operand index {operand_idx} for {inst}"
87 )]
88 SSAValDefIsNotOperandsSSAVal {
89 ssa_val_idx: SSAValIdx,
90 inst: InstIdx,
91 operand_idx: usize,
92 },
93 #[error(
94 "SSA value {ssa_val_idx}'s type can't be used with the constraint on \
95 operand index {operand_idx} for {inst}"
96 )]
97 ConstraintTyMismatch {
98 ssa_val_idx: SSAValIdx,
99 inst: InstIdx,
100 operand_idx: usize,
101 },
102 #[error(
103 "fixed location constraint on operand index {operand_idx} for \
104 {inst} conflicts with clobbers"
105 )]
106 FixedLocConflictsWithClobbers { inst: InstIdx, operand_idx: usize },
107 #[error("operand kind must be def")]
108 OperandKindMustBeDef,
109 #[error(
110 "reuse target operand (index {reuse_target_operand_idx}) for \
111 {inst} must have kind `Use`"
112 )]
113 ReuseTargetOperandMustBeUse {
114 inst: InstIdx,
115 reuse_target_operand_idx: usize,
116 },
117 #[error(
118 "source block {src_block} missing from branch {branch_inst}'s \
119 target block {tgt_block}'s predecessors"
120 )]
121 SrcBlockMissingFromBranchTgtBlocksPreds {
122 src_block: BlockIdx,
123 branch_inst: InstIdx,
124 tgt_block: BlockIdx,
125 },
126 #[error(
127 "branch {inst}'s parameter (index {param_idx}) for successor {succ} \
128 is missing from SSA value {ssa_val_idx}'s uses"
129 )]
130 MissingBranchSuccParamUse {
131 ssa_val_idx: SSAValIdx,
132 inst: InstIdx,
133 succ: BlockIdx,
134 param_idx: usize,
135 },
136 #[error(
137 "the number of parameters ({branch_param_count}) for branch {inst}'s \
138 successor {succ} doesn't match the number of parameters \
139 ({block_param_count}) declared in that block"
140 )]
141 BranchSuccParamCountMismatch {
142 inst: InstIdx,
143 succ: BlockIdx,
144 block_param_count: usize,
145 branch_param_count: usize,
146 },
147 #[error(
148 "the type {branch_param_ty:?} of parameter {param_idx} for branch \
149 {inst}'s successor {succ} doesn't match the type {block_param_ty:?} \
150 declared in that block"
151 )]
152 BranchSuccParamTyMismatch {
153 inst: InstIdx,
154 succ: BlockIdx,
155 param_idx: usize,
156 block_param_ty: Ty,
157 branch_param_ty: Ty,
158 },
159 #[error(
160 "block {block}'s parameter {param_idx} doesn't match SSA value \
161 {ssa_val_idx}'s definition"
162 )]
163 MismatchedBlockParamDef {
164 ssa_val_idx: SSAValIdx,
165 block: BlockIdx,
166 param_idx: usize,
167 },
168 #[error(
169 "predecessor {src_block} of target block {tgt_block} is missing from \
170 that predecessor block's terminating branch {branch_inst}'s targets"
171 )]
172 PredMissingFromPredsTermBranchsTargets {
173 src_block: BlockIdx,
174 branch_inst: InstIdx,
175 tgt_block: BlockIdx,
176 },
177 #[error("block parameter index {param_idx} is out of range for block {block}")]
178 BlockParamIdxOutOfRange { block: BlockIdx, param_idx: usize },
179 #[error(
180 "SSA value {ssa_val_idx}'s use isn't the corresponding \
181 operand's SSA Value: operand index {operand_idx} for {inst}"
182 )]
183 SSAValUseIsNotOperandsSSAVal {
184 ssa_val_idx: SSAValIdx,
185 inst: InstIdx,
186 operand_idx: usize,
187 },
188 #[error(
189 "SSA value {ssa_val_idx} is use as a branch instruction {inst}'s \
190 block parameter, but that instruction isn't a branch instruction"
191 )]
192 SSAValUseIsNotBranch {
193 ssa_val_idx: SSAValIdx,
194 inst: InstIdx,
195 },
196 #[error("expected instruction {inst} to be a `BlockTerm` instruction")]
197 InstIsNotBlockTerm { inst: InstIdx },
198 #[error("target block {tgt_block} not found in branch instruction {branch_inst}")]
199 BranchTargetNotFound {
200 branch_inst: InstIdx,
201 tgt_block: BlockIdx,
202 },
203 #[error(
204 "branch instruction {branch_inst}'s block parameter index {param_idx} \
205 is out of range for target block {tgt_block}"
206 )]
207 BranchTargetParamIdxOutOfRange {
208 branch_inst: InstIdx,
209 tgt_block: BlockIdx,
210 param_idx: usize,
211 },
212 #[error(
213 "SSA value {ssa_val_idx}'s use isn't the corresponding \
214 branch {branch_inst}'s target block parameter's SSA Value for \
215 target block {tgt_block}'s parameter index {param_idx}"
216 )]
217 MismatchedBranchTargetBlockParamUse {
218 ssa_val_idx: SSAValIdx,
219 branch_inst: InstIdx,
220 tgt_block: BlockIdx,
221 param_idx: usize,
222 },
223 #[error(
224 "block {block_idx} has incorrect immediate dominator: expected \
225 {} found {}",
226 .expected.display_option_idx(),
227 .found.display_option_idx(),
228 )]
229 IncorrectImmediateDominator {
230 block_idx: BlockIdx,
231 found: Option<BlockIdx>,
232 expected: Option<BlockIdx>,
233 },
234 }
235
236 pub type Result<T, E = Error> = std::result::Result<T, E>;