Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coverage/translation-postgres/form-links.toml
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,12 @@ forms = ["pg.expressions.sql-syntax-lexical.binary-integer"]
constructs = ["spelling:digit_separators"]
forms = ["pg.expressions.sql-syntax-lexical.digit-separators"]

# A shell: nearly every statement names a column or table, so identifier takes credit only from
# its own hand cases and blame only for a refusal of identifiers or of the whole statement.
[[link]]
constructs = ["spelling:identifier"]
forms = ["pg.expressions.sql-syntax-lexical.identifier"]
shell = true

[[link]]
constructs = ["spelling:quoted_identifier"]
Expand Down
2 changes: 1 addition & 1 deletion coverage/translation-postgres/results-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3692,7 +3692,7 @@
"pg.expressions.sql-syntax-lexical.function-style-string": "matching",
"pg.expressions.sql-syntax-lexical.hex-bit-string": "matching",
"pg.expressions.sql-syntax-lexical.hex-integer": "matching",
"pg.expressions.sql-syntax-lexical.identifier": "refused",
"pg.expressions.sql-syntax-lexical.identifier": "matching",
"pg.expressions.sql-syntax-lexical.integer": "matching",
"pg.expressions.sql-syntax-lexical.line-comment": "matching",
"pg.expressions.sql-syntax-lexical.octal-integer": "matching",
Expand Down
8 changes: 7 additions & 1 deletion coverage/translation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ separately from syntax coverage, and every figure comes from the checker.
function form whose grammar calls that name; this file links operators, clauses, casts and the
rest, and lists the constructs that name no form of their own. A `[[link]]` with
`except_within_ulps = true` skips statements matching only within ULPs: they count neither for
nor against its forms, while every other statement it links still does.
nor against its forms, while every other statement it links still does. A `[[link]]` with
`shell = true` marks its forms as shells, grammar nearly every statement wraps other forms in,
such as identifiers. Only the cases a shell form's own required obligations cite credit it. A
refused statement counts against it when the refusal names one of its constructs or the whole
statement, or when the statement links no form but shells; a statement that differs counts
against it only in that last case. A shell form needs a required obligation citing a case, and
its links are all shells or none.
- `argument-types.toml` (optional): for a function name several forms share, the type families
each form's first argument takes (`[[form]]` with `id` and `first`), as the dialect's converter
names them. A statement recording its calls with their argument types links a call only to the
Expand Down
40 changes: 34 additions & 6 deletions tools/sqlbabel-coverage-check/src/results/_helpers/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn is_slug(id: &str) -> bool {
})
}

/// Every problem with the links: malformed keys, unknown forms, a construct both linked and not, or a cited form also linked by key.
/// Every problem with the links: malformed keys, unknown forms, a construct both linked and not, a form in shell and other links, or a cited form also linked by key.
fn check_links(links: &LinksFile, catalogued: &BTreeSet<&str>) -> Vec<String> {
let mut problems: Vec<String> = Vec::new();
let mut linked: BTreeSet<&str> = BTreeSet::new();
Expand Down Expand Up @@ -91,6 +91,19 @@ fn check_links(links: &LinksFile, catalogued: &BTreeSet<&str>) -> Vec<String> {
}
}
}
let shells = shell_forms(links);
for link in links.links.iter().filter(|link| !link.shell) {
for form in link
.forms
.iter()
.filter(|form| shells.contains(form.as_str()))
{
problems.push(format!(
"link {}: {form} is a shell form in another link; a form's links are all shells or none",
link.constructs.join(" + ")
));
}
}
let keyed: BTreeSet<&str> = links
.links
.iter()
Expand Down Expand Up @@ -319,17 +332,32 @@ pub(crate) fn cited_forms(links: &LinksFile) -> BTreeSet<&str> {
.collect()
}

/// A problem for each cited form that no required obligation of its own cites a case for.
/// The forms of `[[link]]` entries marked `shell`.
pub(crate) fn shell_forms(links: &LinksFile) -> BTreeSet<&str> {
links
.links
.iter()
.filter(|link| link.shell)
.flat_map(|link| link.forms.iter().map(String::as_str))
.collect()
}

/// A problem for each cited or shell form that no required obligation of its own cites a case for, as only those cases credit it.
fn uncited_forms(links: &LinksFile, obligations: &[TranslationObligation]) -> Vec<String> {
let citing: BTreeSet<&str> = obligations
.iter()
.filter(|obligation| obligation.required && !obligation.cases.is_empty())
.map(|obligation| obligation.form.as_str())
.collect();
cited_forms(links)
.difference(&citing)
.map(|form| format!("cited_forms: {form} has no required obligation citing a case"))
.collect()
let cited = cited_forms(links)
.into_iter()
.filter(|form| !citing.contains(form))
.map(|form| format!("cited_forms: {form} has no required obligation citing a case"));
let shells = shell_forms(links)
.into_iter()
.filter(|form| !citing.contains(form))
.map(|form| format!("shell link: {form} has no required obligation citing a case"));
cited.chain(shells).collect()
}

/// The SHA-256 a group's sign-off binds: its reason, then each form on its own line.
Expand Down
28 changes: 24 additions & 4 deletions tools/sqlbabel-coverage-check/src/results/_helpers/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::{BTreeMap, BTreeSet};

use crate::formats::main::content_sha256::content_sha256;
use crate::formats::models::{FormStatus, SyntaxCoverage};
use crate::results::_helpers::files::shell_forms;
use crate::results::constants::{
CALL, CALL_BARE, CALL_NAMED, CALL_OVER, CALL_PREFIXES, FUNCTION_PREFIX, FUNCTIONS_FAMILY,
STATEMENT_REFUSAL,
Expand All @@ -23,8 +24,13 @@ pub(crate) struct FunctionIndex {

/// The forms a statement links to, and those its refusal names.
pub(crate) struct StatementLinks {
/// Every form it links, shells included.
pub(crate) forms: BTreeSet<String>,
/// The forms of its refused constructs; every linked form when they name none or the whole.
/// The forms it credits when it matches: every linked form but shells.
pub(crate) credited: BTreeSet<String>,
/// The forms a statement that differs counts against: as `credited`, or every linked form when it links only shells.
pub(crate) carried: BTreeSet<String>,
/// The forms of its refused constructs, with its shells when it links nothing else; every linked form when it refuses the whole, and `carried` when its refused constructs name no form.
pub(crate) refused_forms: BTreeSet<String>,
/// Whether a refusal of it is the whole statement's: it names the whole, or no key names a form.
pub(crate) whole_refusal: bool,
Expand Down Expand Up @@ -239,13 +245,27 @@ pub(crate) fn link_statement(
.0,
);
}
let whole_refusal = whole || named.is_empty();
let refused_forms: BTreeSet<String> = match whole_refusal {
let shells = shell_forms(links);
let credited: BTreeSet<String> = forms
.iter()
.filter(|form| !shells.contains(form.as_str()))
.cloned()
.collect();
let carried = match credited.is_empty() {
true => forms.clone(),
false => named,
false => credited.clone(),
};
let whole_refusal = whole || named.is_empty();
let refused_forms: BTreeSet<String> = match (whole, named.is_empty()) {
(true, _) => forms.clone(),
(false, true) => carried.clone(),
(false, false) if credited.is_empty() => named.union(&forms).cloned().collect(),
(false, false) => named,
};
StatementLinks {
forms,
credited,
carried,
refused_forms,
whole_refusal,
unaccounted,
Expand Down
47 changes: 34 additions & 13 deletions tools/sqlbabel-coverage-check/src/results/_helpers/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet};

use crate::formats::models::SyntaxCoverage;
use crate::results::_helpers::files::{
cited_forms, declared_sha256, group_sha256, signed, subjects,
cited_forms, declared_sha256, group_sha256, shell_forms, signed, subjects,
};
use crate::results::_helpers::forms::{family_tallies, form_result, statement_tally};
use crate::results::_helpers::links::{FunctionIndex, link_statement};
Expand Down Expand Up @@ -85,9 +85,10 @@ fn unmapped(construct: &str, references: &[&str]) -> String {
)
}

/// The cited forms of the links file by each statement reference their required obligations cite.
/// The cited and shell forms of the links file by each statement reference their required obligations cite.
fn cited_cases(files: &ResultsFiles) -> BTreeMap<&str, BTreeSet<String>> {
let forms: BTreeSet<&str> = cited_forms(&files.links);
let mut forms: BTreeSet<&str> = cited_forms(&files.links);
forms.extend(shell_forms(&files.links));
let mut cases: BTreeMap<&str, BTreeSet<String>> = BTreeMap::new();
for obligation in &files.obligations {
if !obligation.required || !forms.contains(obligation.form.as_str()) {
Expand All @@ -104,13 +105,25 @@ fn cited_cases(files: &ResultsFiles) -> BTreeMap<&str, BTreeSet<String>> {
cases
}

/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, and a cited case also for the cited forms its obligations name unless its refusal names other forms.
/// The forms declaring an effect obligation, which only effect statements count for.
fn effect_forms(files: &ResultsFiles) -> BTreeSet<&str> {
files
.obligations
.iter()
.filter(|obligation| obligation.kind == ObligationKind::Effect)
.map(|obligation| obligation.form.as_str())
.collect()
}

/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, a refused or differing one also for its shells when no other form it names takes it, any other for its forms other than shells, and a cited case also for the cited and shell forms its obligations name unless its refusal names other forms.
pub(crate) fn link_all<'a>(
statements: &'a [RecordedStatement],
functions: &FunctionIndex,
files: &ResultsFiles,
) -> Result<Links<'a>, Vec<String>> {
let cited = cited_cases(files);
let shells = shell_forms(&files.links);
let effect_forms = effect_forms(files);
let uncredited = uncredited_cases(&files.links);
let mut links: Links = BTreeMap::new();
let mut unaccounted: BTreeMap<String, Vec<&str>> = BTreeMap::new();
Expand All @@ -123,10 +136,23 @@ pub(crate) fn link_all<'a>(
.push(&statement.reference);
}
let refused = statement.outcome.refused();
let mut forms = match refused {
true => linked.refused_forms,
false => linked.forms,
let mut forms = match (refused, statement.outcome) {
(true, _) => linked.refused_forms,
(false, StatementOutcome::Differs) => linked.carried,
(false, _) => linked.credited,
};
let counts =
|form: &String| statement.effect.is_some() || !effect_forms.contains(form.as_str());
if (refused || statement.outcome == StatementOutcome::Differs) && !forms.iter().any(counts)
{
forms.extend(
linked
.forms
.iter()
.filter(|form| shells.contains(form.as_str()))
.cloned(),
);
}
if uncredited.contains_key(statement.reference.as_str()) {
forms.clear();
} else if !refused || linked.whole_refusal {
Expand Down Expand Up @@ -164,12 +190,7 @@ pub(crate) fn form_results(
) -> Result<Vec<FormResult>, Vec<String>> {
let mut unmet: BTreeMap<&str, Vec<String>> = BTreeMap::new();
let mut declared: BTreeSet<&str> = BTreeSet::new();
let effect_forms: BTreeSet<&str> = files
.obligations
.iter()
.filter(|obligation| obligation.kind == ObligationKind::Effect)
.map(|obligation| obligation.form.as_str())
.collect();
let effect_forms = effect_forms(files);
for obligation in files
.obligations
.iter()
Expand Down
3 changes: 3 additions & 0 deletions tools/sqlbabel-coverage-check/src/results/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ pub struct FormLink {
/// Whether a statement matching only within ULPs skips this link, counting neither for nor against its forms.
#[serde(default)]
pub except_within_ulps: bool,
/// Whether the forms are shells: grammar most statements wrap other forms in, such as identifiers. A shell form is credited only by the cases its own required obligations cite, and blamed only for a refusal of its own constructs, of the whole statement, or of a statement that links no other form.
#[serde(default)]
pub shell: bool,
}

/// Forms whose grammar no construct key tells apart, each linked only to the cases its own required obligations cite.
Expand Down
Loading
Loading