Skip to content

Commit c6a1e00

Browse files
author
bors-servo
authored
Auto merge of #633 - fitzgen:stylo-stuff, r=emilio
Finish fixing blacklisting + template analysis This is a follow up to c8a206a, and the support for blacklisting in the named template parameter usage analysis. This ensures that ever item we ever call `constrain` on has an entry in `used` for the set of template parameters it uses. Additionally, it adds extra assertions to enforce the invariant. We cannot completely avoid analyzing blacklisted items because we want to consider all of a blacklisted template's parameters as used. This is why we ensure that blacklisted items have a used template parameter set rather than ensuring that blacklisted items never end up in the worklist. This fixes the panic I saw in servo/servo#16392, but there are still issues leftover in the resulting bindings that I am tracking down. r? @emilio
2 parents 76cc088 + 568b011 commit c6a1e00

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

src/ir/named.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,14 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
322322

323323
for item in whitelisted_items.iter().cloned() {
324324
dependencies.entry(item).or_insert(vec![]);
325-
used.insert(item, Some(ItemSet::new()));
325+
used.entry(item).or_insert(Some(ItemSet::new()));
326326

327327
{
328328
// We reverse our natural IR graph edges to find dependencies
329329
// between nodes.
330330
item.trace(ctx, &mut |sub_item, _| {
331+
used.entry(sub_item).or_insert(Some(ItemSet::new()));
332+
331333
// We won't be generating code for items that aren't
332334
// whitelisted, so don't bother keeping track of their
333335
// template parameters. But isn't whitelisting the
@@ -353,12 +355,17 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
353355
&TypeKind::TemplateInstantiation(ref inst) => {
354356
let decl = ctx.resolve_type(inst.template_definition());
355357
let args = inst.template_arguments();
358+
356359
// Although template definitions should always have
357360
// template parameters, there is a single exception:
358361
// opaque templates. Hence the unwrap_or.
359362
let params = decl.self_template_params(ctx)
360363
.unwrap_or(vec![]);
364+
361365
for (arg, param) in args.iter().zip(params.iter()) {
366+
used.entry(*arg).or_insert(Some(ItemSet::new()));
367+
used.entry(*param).or_insert(Some(ItemSet::new()));
368+
362369
dependencies.entry(*arg)
363370
.or_insert(vec![])
364371
.push(*param);
@@ -368,6 +375,28 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
368375
});
369376
}
370377

378+
if cfg!(feature = "testing_only_extra_assertions") {
379+
// Invariant: The `used` map has an entry for every whitelisted
380+
// item, as well as all explicitly blacklisted items that are
381+
// reachable from whitelisted items.
382+
//
383+
// (This is so that every item we call `constrain` on is guaranteed
384+
// to have a set of template parameters, and we can allow
385+
// blacklisted templates to use all of their parameters).
386+
for item in whitelisted_items.iter() {
387+
extra_assert!(used.contains_key(item));
388+
item.trace(ctx, &mut |sub_item, _| {
389+
extra_assert!(used.contains_key(&sub_item));
390+
}, &())
391+
}
392+
393+
// Invariant: the `dependencies` map has an entry for every
394+
// whitelisted item.
395+
for item in whitelisted_items.iter() {
396+
extra_assert!(dependencies.contains_key(item));
397+
}
398+
}
399+
371400
UsedTemplateParameters {
372401
ctx: ctx,
373402
used: used,

src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ impl Builder {
235235
if !self.options.whitelist_recursively {
236236
output_vector.push("--no-recursive-whitelist".into());
237237
}
238-
238+
239239
if self.options.objc_extern_crate {
240240
output_vector.push("--objc-extern-crate".into());
241241
}
242-
242+
243243
if self.options.builtins {
244244
output_vector.push("--builtins".into());
245245
}
@@ -249,15 +249,6 @@ impl Builder {
249249
output_vector.push(prefix.clone());
250250
}
251251

252-
self.options
253-
.clang_args
254-
.iter()
255-
.map(|item| {
256-
output_vector.push("--clang-args".into());
257-
output_vector.push(item.trim_left_matches("^").trim_right_matches("$").into());
258-
})
259-
.count();
260-
261252
if let Some(ref dummy) = self.options.dummy_uses {
262253
output_vector.push("--dummy-uses".into());
263254
output_vector.push(dummy.clone());
@@ -316,7 +307,7 @@ impl Builder {
316307
if self.options.codegen_config.destructors {
317308
options.push("destructors".into());
318309
}
319-
310+
320311
output_vector.push(options.join(","));
321312

322313
if !self.options.codegen_config.methods {
@@ -410,6 +401,18 @@ impl Builder {
410401
})
411402
.count();
412403

404+
if !self.options.clang_args.is_empty() {
405+
output_vector.push("--".into());
406+
self.options
407+
.clang_args
408+
.iter()
409+
.cloned()
410+
.map(|item| {
411+
output_vector.push(item);
412+
})
413+
.count();
414+
}
415+
413416
output_vector
414417
}
415418

@@ -1243,7 +1246,7 @@ fn commandline_flag_unit_test_function() {
12431246

12441247
assert!(test_cases.iter().all(|ref x| command_line_flags.contains(x)) );
12451248

1246-
//Test 2
1249+
//Test 2
12471250
let bindings = ::builder().header("input_header")
12481251
.whitelisted_type("Distinct_Type")
12491252
.whitelisted_function("safe_function");

0 commit comments

Comments
 (0)