diff --git a/ffi/README.md b/ffi/README.md index f3e779d8e..496e68878 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -245,7 +245,8 @@ glue includes is [`runtime/rt.rs`](runtime/rt.rs), the one the C++ header includ `--census dir` exports nothing. It writes `.md` for each exported package, which counts what exports and ranks every refusal by construct and by the type it names, lists each refused item at its span, and ends with the `exclude` list that exports the -rest. It ignores the config's `exclude`. +rest. It ignores the config's `exclude`. It still fails on an `instance not inferred` +refusal, which is a bug in the exporter's inference rather than in the crate. ## Tests diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index 72be6a09e..17c7cebd2 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -36,6 +36,9 @@ pub struct Why { pub note: Option<(Span, String)>, } +/// The construct of an instance inference missed: a bug in the exporter, not the crate. +pub const NOT_INFERRED: &str = "instance not inferred"; + fn why(construct: &'static str, detail: impl Into) -> Why { Why { construct, @@ -2476,9 +2479,9 @@ impl<'tcx> Collector<'tcx> { return Err(why("type parameter", name)); } // Inference admits or rejects each instance a signature names, so one - // it did not is a gap in inference, which the census counts. + // it did not is a gap in inference, which even a census fails on. if key.args.is_some() && self.items.iter().any(|(item, _)| *item == did) { - let mut why = why("instance not inferred", name); + let mut why = why(NOT_INFERRED, name); let note = format!("`{}` exports only at the instances it infers", strip_args(tcx, did)); why.note = Some((tcx.def_span(did), note)); diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index cb6e3e74a..07cb633f6 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -115,35 +115,24 @@ impl Callbacks for Export { )); } let written = match &self.output { - Output::Census(dir) => collected.reports.iter().enumerate().try_for_each(|(i, report)| { - let text = census::render(&collected.api, report, i == 0, &abi.clashes, &|span| at(tcx, span)); - write(&dir.join(format!("{}.md", report.package)), &text) - }), + Output::Census(dir) => { + let written = collected.reports.iter().enumerate().try_for_each(|(i, report)| { + let text = census::render(&collected.api, report, i == 0, &abi.clashes, &|span| at(tcx, span)); + write(&dir.join(format!("{}.md", report.package)), &text) + }); + // A census reports what a crate uses, but a missed instance is the exporter's bug. + for refusal in collected.reports.iter().flat_map(|report| &report.refusals) { + if refusal.why.iter().any(|why| why.construct == collect::NOT_INFERRED) { + refuse(tcx, refusal, "inference missed an instance, a bug in rust2-ffi"); + } + } + written + } Output::Dir(out) => { for report in &collected.reports { let table = self.table(&collected, &report.krate); for refusal in &report.refusals { - let reasons: Vec = refusal - .why - .iter() - .map(|why| match why.detail.is_empty() { - true => why.construct.to_string(), - false => format!("{} `{}`", why.construct, why.detail), - }) - .collect(); - let mut err = tcx.dcx().struct_span_err( - refusal.span, - format!( - "rust2-ffi: cannot export {} `{}`: {}; exclude it in {table} to leave it out", - refusal.kind, - refusal.path, - reasons.join("; ") - ), - ); - for (span, note) in refusal.why.iter().filter_map(|why| why.note.as_ref()) { - err = err.with_span_note(*span, note.clone()); - } - err.emit(); + refuse(tcx, refusal, &format!("exclude it in {table} to leave it out")); } for (path, count) in &report.excluded { if *count == 0 { @@ -271,6 +260,31 @@ fn canonical(path: &Path) -> Option { std::fs::canonicalize(path).ok() } +/// Emits `refusal` as an error at its span, with every reason and its notes, then `advice`. +fn refuse(tcx: TyCtxt<'_>, refusal: &collect::Refusal, advice: &str) { + let reasons: Vec = refusal + .why + .iter() + .map(|why| match why.detail.is_empty() { + true => why.construct.to_string(), + false => format!("{} `{}`", why.construct, why.detail), + }) + .collect(); + let mut err = tcx.dcx().struct_span_err( + refusal.span, + format!( + "rust2-ffi: cannot export {} `{}`: {}; {advice}", + refusal.kind, + refusal.path, + reasons.join("; ") + ), + ); + for (span, note) in refusal.why.iter().filter_map(|why| why.note.as_ref()) { + err = err.with_span_note(*span, note.clone()); + } + err.emit(); +} + /// Where `span` starts, relative to the crate's directory when inside it. fn at(tcx: TyCtxt<'_>, span: Span) -> String { let sm = tcx.sess.source_map(); diff --git a/quest/m1/ffi-export/README.md b/quest/m1/ffi-export/README.md index 2b5000354..93fccbcec 100644 --- a/quest/m1/ffi-export/README.md +++ b/quest/m1/ffi-export/README.md @@ -49,7 +49,6 @@ Every generator on the C ABI: - [Payloads cross as bytes](/quest/m1/ffi-export/payload-bytes.md) - a payload that is not UTF-8 crosses unchanged, where today it aborts from C, C++, and Kotlin - [Iterator and JSON arguments the exporter can't map yet](/quest/m1/ffi-export/instance-keys.md) - `IntoIterator` as a `Vec`, and `serde_json::Value` -- [Fail CI on an instance not inferred](/quest/m1/ffi-export/inference-gate.md) - a gap in instance inference fails CI instead of sitting in the census - [moq-clock's C names once it moves into kio](/quest/m1/ffi-export/crates.md) - `moq_now` and `moq_origin` become the clock's, after moq moves it into `kio::clock` - [Setters for an object's pub fields](/quest/m1/ffi-export/field-setters.md) - C fills in a session's config, as Rust assigns it - [Session config's foreign types](/quest/m1/ffi-export/foreign-types.md) - `Url`, `SocketAddr`, `PathBuf`, and `Vec` cross the C ABI diff --git a/quest/m1/ffi-export/inference-gate.md b/quest/m1/ffi-export/inference-gate.md deleted file mode 100644 index 47e659c4b..000000000 --- a/quest/m1/ffi-export/inference-gate.md +++ /dev/null @@ -1,20 +0,0 @@ -# [XS] Fail CI on an instance not inferred - -## Goal - -CI fails when any crate's census reports `instance not inferred`, so a gap in the -exporter's instance inference is caught when it appears instead of sitting in a census no -one reads. - -## Plan - -[#188](https://github.com/kixelated/rust2/pull/188) made inference one pass before typing. -Where inference misses an instance typing reaches, typing refuses the item as -`instance not inferred`. That refusal means the exporter has a bug, not that the crate uses -something unsupported. No crate reports it today, so the check passes from the start. - -- Check every census the exporter runs: the fixtures' in the merge gate, and moq's in the - job that already runs it. -- Fail with the item and its span, so the report says what to fix. - -Public API: none.