Skip to content

Commit 3fd78af

Browse files
[aslspec] addressing review comments
1 parent d7a8d1f commit 3fd78af

File tree

3 files changed

+538
-503
lines changed

3 files changed

+538
-503
lines changed

asllib/aslspec/error.ml

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
open AST
2+
3+
let spec_error msg = raise (SpecError msg)
4+
5+
let bad_layout term layout ~consistent_layout =
6+
spec_error
7+
@@ Format.asprintf
8+
"layout %a is inconsistent with %a. Here's a consistent layout: %a"
9+
PP.pp_layout layout PP.pp_type_term term PP.pp_layout consistent_layout
10+
11+
let undefined_reference id context =
12+
spec_error @@ Format.asprintf "Undefined reference to '%s' in %s" id context
13+
14+
let undefined_element id =
15+
spec_error @@ Format.asprintf "Encountered undefined element: %s" id
16+
17+
let duplicate_definition id =
18+
spec_error @@ Format.asprintf "Duplicate definition of '%s'" id
19+
20+
let unmatched_variables_in_template template unmatched_vars =
21+
spec_error
22+
@@ Format.asprintf
23+
"The prose template '%s' contains the following unmatched variables: %s"
24+
template
25+
(String.concat ", " unmatched_vars)
26+
27+
let not_type_name_error relation_name term =
28+
spec_error
29+
@@ Format.asprintf
30+
"In relation '%s', output type term '%a' is not a type name or a set of \
31+
constants. All relation output types, except for the first one, must \
32+
be type names or a set of constants."
33+
relation_name PP.pp_type_term term
34+
35+
let missing_short_circuit_attribute relation_name term type_name =
36+
spec_error
37+
@@ Format.asprintf
38+
"In relation '%s', output type term '%a' references type '%s' which \
39+
does not have a short-circuit macro defined. All relation output \
40+
types, except for the first one, must reference types with \
41+
short-circuit macros."
42+
relation_name PP.pp_type_term term type_name
43+
44+
let invalid_application_of_symbol_in_expr name expr =
45+
spec_error
46+
@@ Format.asprintf "Invalid application of symbol '%s' to expression %a" name
47+
PP.pp_expr expr
48+
49+
let type_subsumption_failure sub super =
50+
spec_error
51+
@@ Format.asprintf "Unable to determine that `%a` is subsumed by `%a`"
52+
PP.pp_type_term sub PP.pp_type_term super
53+
54+
let argument_subsumption_failure sub super ~context_expr =
55+
spec_error
56+
@@ Format.asprintf "Unable to determine that `%a` is subsumed by `%a` in %a"
57+
PP.pp_type_term sub PP.pp_type_term super PP.pp_expr context_expr
58+
59+
let non_constant_used_as_constant_set id =
60+
spec_error
61+
@@ Format.asprintf
62+
"%s is used as a constant even though it is not defined as one" id
63+
64+
let tuple_instantiation_length_failure term args label def_components =
65+
spec_error
66+
@@ Format.asprintf
67+
"The type term `%a` cannot be instantiated since it has %i type terms \
68+
and `%s` requires %i type terms"
69+
PP.pp_type_term term (List.length args) label
70+
(List.length def_components)
71+
72+
let tuple_instantiation_failure_not_labelled_tuple term label =
73+
spec_error
74+
@@ Format.asprintf
75+
"The type term `%a` cannot be instantiated since '%s' is not a labelled \
76+
tuple type"
77+
PP.pp_type_term term label
78+
79+
let record_instantiation_failure_different_fields term def_term =
80+
spec_error
81+
@@ Format.asprintf
82+
"The type term `%a` cannot be instantiated since its list of fields is \
83+
different to those of %a"
84+
PP.pp_type_term term PP.pp_type_term def_term
85+
86+
let record_instantiation_failure_not_labelled_record term label =
87+
spec_error
88+
@@ Format.asprintf
89+
"The type term `%a` cannot be instantiated since '%s' is not a labelled \
90+
record type"
91+
PP.pp_type_term term label
92+
93+
let instantiation_failure_not_a_type term label =
94+
spec_error
95+
@@ Format.asprintf
96+
"The type term `%a` cannot be instantiated since '%s' is not a type"
97+
PP.pp_type_term term label
98+
99+
let empty_rule relation_name =
100+
spec_error
101+
@@ Format.asprintf "The rule for relation '%s' is empty." relation_name
102+
103+
let missing_relation_argument_name relation_name =
104+
spec_error
105+
@@ Format.asprintf
106+
"All arguments in the relation '%s' must have names, since it specifies \
107+
a rule."
108+
relation_name
109+
110+
let multiple_output_judgments relation_name rule_name_opt =
111+
let pp_name_opt fmt = function
112+
| Some name -> Format.fprintf fmt ": %s" name
113+
| None -> ()
114+
in
115+
spec_error
116+
@@ Format.asprintf
117+
"All but the last judgment in the rule for relation %s must be \
118+
non-output judgments%a"
119+
relation_name pp_name_opt rule_name_opt
120+
121+
let missing_output_judgment relation_name expanded_rule_name_opt =
122+
spec_error
123+
@@ Format.asprintf
124+
"The rule for relation %s does not end with an output judgment in case \
125+
%s"
126+
relation_name
127+
(Option.value ~default:"top-level" expanded_rule_name_opt)
128+
129+
let illegal_lhs_application expr =
130+
spec_error
131+
@@ Format.asprintf
132+
"The left-hand side of an application must be a relation, type variant, \
133+
or operator, but found expression %a"
134+
PP.pp_expr expr
135+
136+
let invalid_number_of_arguments rel_name expr ~expected ~actual =
137+
spec_error
138+
@@ Format.asprintf
139+
"The application of relation '%s' in expression %a has an invalid \
140+
number of arguments: expected %d but found %d"
141+
rel_name PP.pp_expr expr expected actual
142+
143+
let invalid_number_of_components label expr ~expected ~actual =
144+
spec_error
145+
@@ Format.asprintf
146+
"The application of tuple label '%s' in expression %a has an invalid \
147+
number of args: expected %d but found %d"
148+
label PP.pp_expr expr expected actual
149+
150+
let invalid_record_field_names expr expr_field_names record_type_field_names =
151+
spec_error
152+
@@ Format.asprintf
153+
"The record expression %a has invalid field names: expected %s but \
154+
found %s"
155+
PP.pp_expr expr
156+
(String.concat ", " expr_field_names)
157+
(String.concat ", " record_type_field_names)
158+
159+
let non_field id expr =
160+
spec_error
161+
@@ Format.asprintf
162+
"The non-field identifier '%s' is used in expression %a as a field" id
163+
PP.pp_expr expr
164+
165+
let undefined_variable_in_rule ~context_expr id =
166+
spec_error
167+
@@ Format.asprintf "The variable %s is used in %a before it is defined" id
168+
PP.pp_expr context_expr
169+
170+
let redefined_variable_in_rule ~context_expr id =
171+
spec_error
172+
@@ Format.asprintf
173+
"The variable %s is defined twice, the second time is in %a" id
174+
PP.pp_expr context_expr
175+
176+
let undefined_field_in_record ~context_expr base_type field_id =
177+
spec_error
178+
@@ Format.asprintf "The field '%s' is not defined in the record type %a in %a"
179+
field_id PP.pp_type_term base_type PP.pp_expr context_expr
180+
181+
let invalid_list_index_type index_type ~context_expr =
182+
spec_error
183+
@@ Format.asprintf
184+
"The index type %a in %a is not a subtype of the natural numbers type \
185+
(N)"
186+
PP.pp_type_term index_type PP.pp_expr context_expr
187+
188+
let invalid_list_base_type base_type ~context_expr =
189+
spec_error
190+
@@ Format.asprintf "The type %a in %a is not a list type" PP.pp_type_term
191+
base_type PP.pp_expr context_expr
192+
193+
let invalid_number_of_arguments_for_map ~expected ~actual ~context_expr =
194+
spec_error
195+
@@ Format.asprintf
196+
"The map application in %a has an invalid number of arguments: expected \
197+
%d but found %d"
198+
PP.pp_expr context_expr expected actual
199+
200+
let invalid_argument_type ~arg_expr ~actual_type ~formal_type ~context_expr =
201+
spec_error
202+
@@ Format.asprintf
203+
"The argument or field expression %a has type %a but expected to have a \
204+
subtype of %a in %a"
205+
PP.pp_expr arg_expr PP.pp_type_term actual_type PP.pp_type_term
206+
formal_type PP.pp_expr context_expr
207+
208+
let invalid_map_lhs_type lhs_type ~context_expr:expr =
209+
spec_error
210+
@@ Format.asprintf
211+
"The map application in %a has an invalid left-hand side type: expected \
212+
a function type but found %a"
213+
PP.pp_expr expr PP.pp_type_term lhs_type
214+
215+
let invalid_labelled_type label ~context_expr =
216+
spec_error
217+
@@ Format.asprintf
218+
"The label '%s' does not correspond to a labelled record or tuple in %a"
219+
label PP.pp_expr context_expr
220+
221+
let type_instantiation_length_failure formal_type arg_type ~expected_length
222+
~actual_length =
223+
spec_error
224+
@@ Format.asprintf
225+
"The type term `%a` cannot be instantiated with `%a` since they have \
226+
different numbers of arguments/fields: expected %d but found %d"
227+
PP.pp_type_term formal_type PP.pp_type_term arg_type expected_length
228+
actual_length
229+
230+
let type_operator_instantiation_failure ~relation_name formal_type arg_type =
231+
spec_error
232+
@@ Format.asprintf
233+
"The type term `%a` cannot be instantiated with `%a` for operator `%s` \
234+
since they have incompatible type operators"
235+
PP.pp_type_term formal_type PP.pp_type_term arg_type relation_name
236+
237+
let uninstantiated_parameter_in_relation param relation_name ~context_expr =
238+
spec_error
239+
@@ Format.asprintf
240+
"The type parameter '%s' of relation '%s' could not be instantiated in \
241+
%a"
242+
param relation_name PP.pp_expr context_expr
243+
244+
let parameter_type_unification_failure ~relation_name parameter_name term1 term2
245+
=
246+
spec_error
247+
@@ Format.asprintf
248+
"Could not unify types %a and %a for parameter '%s' of relation '%s'"
249+
PP.pp_type_term term1 PP.pp_type_term term2 parameter_name relation_name
250+
251+
let only_single_output_relations_supported name ~context_expr =
252+
spec_error
253+
@@ Format.asprintf
254+
"Only single output relations are supported outside of transition \
255+
judgment: %s in %a"
256+
name PP.pp_expr context_expr
257+
258+
let only_relation_transitions_supported ~context_expr =
259+
spec_error
260+
@@ Format.asprintf
261+
"Only relation applications are supported on the left-hand side of \
262+
transitions in %a"
263+
PP.pp_expr context_expr
264+
265+
let no_matching_output_type rhs ~context_expr =
266+
spec_error
267+
@@ Format.asprintf "No matching output type found for expression %a in %a"
268+
PP.pp_expr rhs PP.pp_expr context_expr
269+
270+
let ambiguous_output_type rhs candidates ~context_expr =
271+
spec_error
272+
@@ Format.asprintf
273+
"Ambiguous output type for expression %a in %a. Possible candidates: %a"
274+
PP.pp_expr rhs PP.pp_expr context_expr
275+
(PP.pp_sep_list ~sep:", " PP.pp_type_term)
276+
candidates
277+
278+
let invalid_indexed_body_type body_type ~context_expr =
279+
spec_error
280+
@@ Format.asprintf "The body type %a in %a is not the Boolean type"
281+
PP.pp_type_term body_type PP.pp_expr context_expr
282+
283+
let cannot_apply_type_to_expr expr target_type =
284+
spec_error
285+
@@ Format.asprintf "Cannot apply type %a to expression %a" PP.pp_type_term
286+
target_type PP.pp_expr expr
287+
288+
let judgment_not_boolean inferred_judgment_type judgment_expr =
289+
spec_error
290+
@@ Format.asprintf
291+
"The type inferred for the judgment `%a` is %a, which is not Boolean"
292+
PP.pp_expr judgment_expr PP.pp_type_term inferred_judgment_type
293+
294+
let output_type_mismatch output_judgment_type output_types output_expr =
295+
spec_error
296+
@@ Format.asprintf
297+
"The type %a inferred for the output judgment `%a` does not match any \
298+
of the output types %a"
299+
PP.pp_type_term output_judgment_type PP.pp_expr output_expr
300+
(PP.pp_sep_list ~sep:" | " PP.pp_type_term)
301+
output_types

0 commit comments

Comments
 (0)