Checks every constant in `env` for groundedness and returns a map of all ungrounded names. First collects immediately ungrounded constants in parallel, then propagates ungroundedness transitively through `in_refs` (the reverse reference graph).
( env: &Env, in_refs: &RefMap, )
| 43 | /// First collects immediately ungrounded constants in parallel, then propagates |
| 44 | /// ungroundedness transitively through `in_refs` (the reverse reference graph). |
| 45 | pub fn ground_consts( |
| 46 | env: &Env, |
| 47 | in_refs: &RefMap, |
| 48 | ) -> FxHashMap<Name, GroundError> { |
| 49 | // Collect immediate ungrounded constants. |
| 50 | let names: Vec<&Name> = env.keys().collect(); |
| 51 | let ungrounded: FxHashMap<_, _> = names |
| 52 | .into_par_iter() |
| 53 | .filter_map(|name| { |
| 54 | let constant = env.get(name)?; |
| 55 | match ground_const_check(&constant, env) { |
| 56 | Err(err) => Some((name.clone(), err)), |
| 57 | Ok(()) => None, |
| 58 | } |
| 59 | }) |
| 60 | .collect(); |
| 61 | proliferate_ungrounded(ungrounded, in_refs) |
| 62 | } |
| 63 | |
| 64 | /// Per-constant groundedness check, for callers that already hold a |
| 65 | /// decoded constant and check as part of a wider pass. |
| 66 | pub fn ground_const_check( |
| 67 | constant: &ConstantInfo, |
| 68 | env: &Env, |
| 69 | ) -> Result<(), GroundError> { |
| 70 | let univs = const_univs(constant); |
| 71 | let mut stt = GroundState::default(); |
| 72 | ground_const(constant, env, univs, 0, &mut stt) |
| 73 | } |
| 74 | |
| 75 | /// Spread ungroundedness from the immediately-ungrounded set through |
| 76 | /// the reverse-reference graph: anything referencing an ungrounded |
| 77 | /// constant is itself ungrounded. |
| 78 | pub fn proliferate_ungrounded( |
| 79 | mut ungrounded: FxHashMap<Name, GroundError>, |
| 80 | in_refs: &RefMap, |
| 81 | ) -> FxHashMap<Name, GroundError> { |
| 82 | let mut stack: Vec<_> = ungrounded.keys().cloned().collect(); |
no test coverage detected