Skip to content

Commit 946335b

Browse files
author
bors-servo
authored
Auto merge of #621 - fitzgen:template-analysis-diagnostics, r=emilio
Provide better diagnostics for assertions in the template analysis This replaces various `unwrap` calls with `expect` calls that have better diagnostic messages if/when they fail. Doing this as part of the investigation into why the analysis is failing when producing bindings for stylo. r? @emilio
2 parents d112bc8 + 1e2a78f commit 946335b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/ir/named.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,13 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
377377
// on other hash map entries. We *must* put it back into the hash map at
378378
// the end of this method. This allows us to side-step HashMap's lack of
379379
// an analog to slice::split_at_mut.
380-
let mut used_by_this_id =
381-
self.used.get_mut(&id).unwrap().take().unwrap();
380+
let mut used_by_this_id = self.used
381+
.get_mut(&id)
382+
.expect("Should have a set of used template params for every item \
383+
id")
384+
.take()
385+
.expect("Should maintain the invariant that all used template param \
386+
sets are `Some` upon entry of `constrain`");
382387

383388
let original_len = used_by_this_id.len();
384389

@@ -415,27 +420,31 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
415420
// Otherwise, add the union of each of its referent item's template
416421
// parameter usage.
417422
_ => {
418-
item.trace(self.ctx,
419-
&mut |sub_id, edge_kind| {
423+
item.trace(self.ctx, &mut |sub_id, edge_kind| {
420424
if sub_id == id || !Self::consider_edge(edge_kind) {
421425
return;
422426
}
423427

424428
let used_by_sub_id = self.used[&sub_id]
425429
.as_ref()
426-
.unwrap()
430+
.expect("Because sub_id != id, and all used template \
431+
param sets other than id's are `Some`, \
432+
sub_id's used template param set should be \
433+
`Some`")
427434
.iter()
428435
.cloned();
429436
used_by_this_id.extend(used_by_sub_id);
430-
},
431-
&());
437+
}, &());
432438
}
433439
}
434440

435441
let new_len = used_by_this_id.len();
436-
assert!(new_len >= original_len);
442+
assert!(new_len >= original_len,
443+
"This is the property that ensures this function is monotone -- \
444+
if it doesn't hold, the analysis might never terminate!");
437445

438446
// Put the set back in the hash map and restore our invariant.
447+
debug_assert!(self.used[&id].is_none());
439448
self.used.insert(id, Some(used_by_this_id));
440449
debug_assert!(self.used.values().all(|v| v.is_some()));
441450

0 commit comments

Comments
 (0)