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
|
use crate::ast::*;
use crate::checker_state::{CheckerError, CheckerState, ElementValue};
use tracing::{debug, instrument};
impl Programme {
pub fn check(&self) -> Result<(), CheckerError> {
let mut state = CheckerState::default();
state.check(self)
}
}
impl CheckerState {
#[instrument(skip(self, prog), level = "debug")]
pub fn check(&mut self, prog: &Programme) -> Result<(), CheckerError> {
let Programme(decls) = prog;
for decl in decls {
debug!(%self, %decl);
match decl {
Decl::Set { name, set } => {
let set = self.check_set(set)?;
self.add_set(name, set)
}
Decl::Element { name, element, set } => {
let set = self.check_set(set)?;
let element = self.check_element(element.clone().into(), &set)?;
if matches!(element, ElementValue::Hypothetical(_)) {
panic!(
"invariant violation: from concrete values at the top level we returned a hypothetical value"
);
}
self.add_element(name.clone(), element, set)
}
Decl::Signature { .. } => {
return Err(CheckerError::Unimplemented("signatures".to_string()));
}
Decl::Instance { .. } => {
return Err(CheckerError::Unimplemented("instances".to_string()));
}
}?;
}
debug!(%self);
Ok(())
}
}
|