internal/conformance API
Purpose
internal/conformance is the shared result model of the conformance
frontends: source locations, per-case results with a disposition, run
summaries with fixed counting rules, and deterministic shard selection.
frontend/gda_expr, frontend/itl_expr, frontend/mpfr_expr,
frontend/testfloat_expr and internal/runner_cli build on it and wrap its
types in their own public types. It is an internal package: code outside
the Luna-Flow/floating module cannot import it, and its interface may change
without notice. See the tutorial and
the design page.
Importing
Inside the module, add the package to moon.pkg:
import {
"Luna-Flow/floating-tools/internal/conformance",
}
The examples call the package as @conformance.. The manual’s example checker
has no alias for internal subpackages, so they are marked nocheck; each one
is a copy of behaviour checked by the package’s own tests or verified by hand
against the source.
Source locations
SourceLocation
SourceLocation is a position in a named source.
pub struct SourceLocation {
// private fields
} derive(Eq, @debug.Debug)
SourceLocation::new
SourceLocation::new(source, line, column?) creates a location.
pub fn SourceLocation::new(String, Int, column? : Int) -> Self
column defaults to 1. Line and column are clamped to at least 1, so a
location always points at a real character position.
SourceLocation::source, SourceLocation::line, SourceLocation::column
These accessors return the components.
pub fn SourceLocation::source(Self) -> String
pub fn SourceLocation::line(Self) -> Int
pub fn SourceLocation::column(Self) -> Int
///|
test "locations are one-based" {
let location = @conformance.SourceLocation::new("a.txt", 0, column=-3)
inspect(location.line(), content="1")
inspect(location.column(), content="1")
}
Case results
CaseDisposition
CaseDisposition classifies a selected case.
pub(all) enum CaseDisposition {
Executable
Diagnostic(String)
Legacy(String)
Unsupported(String)
} derive(Eq, @debug.Debug)
Executable: the case was run; itspassedflag is meaningful.Diagnostic(reason): the case is not a valid test of this kind (for example a placeholder row).Legacy(reason): the case belongs to an older version of the corpus format.Unsupported(reason): the case is valid but the implementation does not provide the feature.
CaseResult
CaseResult is the outcome of one case.
pub struct CaseResult {
// private fields
} derive(Eq, @debug.Debug)
CaseResult::new, CaseResult::executable
CaseResult::new(id, disposition, passed, message?) builds a result;
CaseResult::executable(id, passed, message?) is new with Executable.
pub fn CaseResult::new(String, CaseDisposition, Bool, message? : String) -> Self
pub fn CaseResult::executable(String, Bool, message? : String) -> Self
message defaults to "". No consistency check is made between
disposition and passed; summaries only read passed for executable
results.
CaseResult::id, CaseResult::disposition, CaseResult::passed, CaseResult::message
These accessors return the stored fields.
pub fn CaseResult::id(Self) -> String
pub fn CaseResult::disposition(Self) -> CaseDisposition
pub fn CaseResult::passed(Self) -> Bool
pub fn CaseResult::message(Self) -> String
Sharding
ShardSpec
ShardSpec is a validated pair (shard count, shard index).
pub struct ShardSpec {
// private fields
} derive(Eq, @debug.Debug)
ShardSpec::try_new, ShardSpec::new
ShardSpec::try_new(count, index) validates and builds a shard;
ShardSpec::new aborts with the same message instead of returning Err.
pub fn ShardSpec::try_new(Int, Int) -> Result[Self, String]
pub fn ShardSpec::new(Int, Int) -> Self
Errors: "shard count must be positive" when count <= 0, and
"shard index must be within shard count" unless 0 <= index < count.
ShardSpec::count, ShardSpec::index
These accessors return the count and the index .
pub fn ShardSpec::count(Self) -> Int
pub fn ShardSpec::index(Self) -> Int
ShardSpec::selects
shard.selects(k) is true when the case with ordinal k belongs to this
shard, that is when .
pub fn ShardSpec::selects(Self, Int) -> Bool
Ordinals are expected to be non-negative. MoonBit’s % keeps the sign of
the dividend, so a negative ordinal is selected by shard 0 when
divides and by no shard otherwise (ShardSpec::new(3, 0).selects(-3) is
true, selects(-1) is false for every index).
///|
test "round-robin selection" {
let shard = @conformance.ShardSpec::new(3, 1)
let picked = [0, 1, 2, 3, 4, 5, 6].filter(k => shard.selects(k))
debug_inspect(picked, content="[1, 4]")
inspect(@conformance.ShardSpec::try_new(0, 0) is Err(_), content="true")
}
Run summaries
RunSummary
RunSummary counts the results of one run or shard.
pub struct RunSummary {
// private fields
} derive(Eq, @debug.Debug)
RunSummary::from_results
RunSummary::from_results(total, results) counts results and records
total as the number of cases before shard selection.
pub fn RunSummary::from_results(Int, Array[CaseResult]) -> Self
Each result is counted once: an Executable result as passed or failed
according to passed(), any other result as skipped and in its own
disposition counter. The results are copied.
RunSummary::merge
RunSummary::merge(parts) combines shard summaries.
pub fn RunSummary::merge(Array[Self]) -> Self
All counters are summed except total_cases, which is the maximum over the
parts; results are concatenated in the order of parts. An empty array gives
an empty summary.
RunSummary::total_cases, RunSummary::selected_cases, RunSummary::executable_cases, RunSummary::passed_cases, RunSummary::failed_cases
These accessors return the run-level counters.
pub fn RunSummary::total_cases(Self) -> Int
pub fn RunSummary::selected_cases(Self) -> Int
pub fn RunSummary::executable_cases(Self) -> Int
pub fn RunSummary::passed_cases(Self) -> Int
pub fn RunSummary::failed_cases(Self) -> Int
total_cases is the caller’s total (the maximum over merged parts);
selected_cases is the number of results.
RunSummary::skipped_cases, RunSummary::diagnostic_cases, RunSummary::legacy_cases, RunSummary::unsupported_cases
These accessors return the skip counters, in total and per disposition.
pub fn RunSummary::skipped_cases(Self) -> Int
pub fn RunSummary::diagnostic_cases(Self) -> Int
pub fn RunSummary::legacy_cases(Self) -> Int
pub fn RunSummary::unsupported_cases(Self) -> Int
RunSummary::results, RunSummary::success, RunSummary::success_with_counts
results() returns a copy of the results in counting order; success() is the
verdict, and success_with_counts is the verdict that also states how many
skipped, diagnostic, legacy and unsupported cases there must be.
pub fn RunSummary::results(Self) -> Array[CaseResult]
pub fn RunSummary::success(Self) -> Bool
pub fn RunSummary::success_with_counts(Self, skipped~ : Int32, diagnostic~ : Int32, legacy~ : Int32, unsupported~ : Int32) -> Bool
The identities
hold for every summary built by from_results or merge. success() is
failed_cases() == 0; skipped cases never make it false, and a summary with
no executable case (including merge([])) is a success. Frontends that need
a stricter verdict (itl_expr also fails on diagnostics) add their own rule.
success_with_counts is success() and exactly the four stated counts: a
corpus or phase with a known number of skipped cases uses it, so that a row that
silently turns into a skipped or unsupported case fails the run instead of
passing.
///|
test "summary counting" {
let summary = @conformance.RunSummary::from_results(10, [
@conformance.CaseResult::executable("a", true),
@conformance.CaseResult::executable("b", false, message="mismatch"),
@conformance.CaseResult::new("c", @conformance.Unsupported("op"), false),
])
inspect(summary.total_cases(), content="10")
inspect(summary.selected_cases(), content="3")
inspect(summary.skipped_cases(), content="1")
inspect(summary.success(), content="false")
}
Trait implementations
All five types derive Eq and Debug; the promoted methods below compare all
fields and render values. Use ==, != and debug_inspect in new code.
SourceLocation::equal, SourceLocation::not_equal, SourceLocation::to_repr
pub fn SourceLocation::equal(Self, Self) -> Bool
pub fn SourceLocation::not_equal(Self, Self) -> Bool
pub fn SourceLocation::to_repr(Self) -> @debug.Repr
CaseDisposition::equal, CaseDisposition::not_equal, CaseDisposition::to_repr
pub fn CaseDisposition::equal(Self, Self) -> Bool
pub fn CaseDisposition::not_equal(Self, Self) -> Bool
pub fn CaseDisposition::to_repr(Self) -> @debug.Repr
Two dispositions with the same constructor and different reasons are different.
CaseResult::equal, CaseResult::not_equal, CaseResult::to_repr
pub fn CaseResult::equal(Self, Self) -> Bool
pub fn CaseResult::not_equal(Self, Self) -> Bool
pub fn CaseResult::to_repr(Self) -> @debug.Repr
ShardSpec::equal, ShardSpec::not_equal, ShardSpec::to_repr
pub fn ShardSpec::equal(Self, Self) -> Bool
pub fn ShardSpec::not_equal(Self, Self) -> Bool
pub fn ShardSpec::to_repr(Self) -> @debug.Repr
RunSummary::equal, RunSummary::not_equal, RunSummary::to_repr
pub fn RunSummary::equal(Self, Self) -> Bool
pub fn RunSummary::not_equal(Self, Self) -> Bool
pub fn RunSummary::to_repr(Self) -> @debug.Repr
Summary equality includes the order of the result list, so a merged summary equals the serial summary only in its counters, not as a value (see the design page).
///|
test "debug rendering" {
debug_inspect(
@conformance.SourceLocation::new("a", 0),
content="{ source: \"a\", line: 1, column: 1 }",
)
debug_inspect(@conformance.CaseDisposition::Legacy("x"), content="Legacy(\"x\")")
}
Complete public interface
This snapshot is the generated pkg.generated.mbti of the package. It is the authority when prose and interface disagree.
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating-tools/internal/conformance"
import {
"moonbitlang/core/debug",
}
// Values
// Errors
// Types and methods
#derive(Eq, @debug.Debug)
pub(all) enum CaseDisposition {
Executable
Diagnostic(String)
Legacy(String)
Unsupported(String)
}
pub fn CaseDisposition::equal(Self, Self) -> Bool
pub fn CaseDisposition::not_equal(Self, Self) -> Bool
pub fn CaseDisposition::to_repr(Self) -> @debug.Repr
#derive(Eq, @debug.Debug)
pub struct CaseResult {
// private fields
}
pub fn CaseResult::disposition(Self) -> CaseDisposition
pub fn CaseResult::equal(Self, Self) -> Bool
pub fn CaseResult::executable(String, Bool, message? : String) -> Self
pub fn CaseResult::id(Self) -> String
pub fn CaseResult::message(Self) -> String
pub fn CaseResult::new(String, CaseDisposition, Bool, message? : String) -> Self
pub fn CaseResult::not_equal(Self, Self) -> Bool
pub fn CaseResult::passed(Self) -> Bool
pub fn CaseResult::to_repr(Self) -> @debug.Repr
#derive(Eq, @debug.Debug)
pub struct RunSummary {
// private fields
}
pub fn RunSummary::diagnostic_cases(Self) -> Int32
pub fn RunSummary::equal(Self, Self) -> Bool
pub fn RunSummary::executable_cases(Self) -> Int32
pub fn RunSummary::failed_cases(Self) -> Int32
pub fn RunSummary::from_results(Int32, Array[CaseResult]) -> Self
pub fn RunSummary::legacy_cases(Self) -> Int32
pub fn RunSummary::merge(Array[Self]) -> Self
pub fn RunSummary::not_equal(Self, Self) -> Bool
pub fn RunSummary::passed_cases(Self) -> Int32
pub fn RunSummary::results(Self) -> Array[CaseResult]
pub fn RunSummary::selected_cases(Self) -> Int32
pub fn RunSummary::skipped_cases(Self) -> Int32
pub fn RunSummary::success(Self) -> Bool
pub fn RunSummary::success_with_counts(Self, skipped~ : Int32, diagnostic~ : Int32, legacy~ : Int32, unsupported~ : Int32) -> Bool
pub fn RunSummary::to_repr(Self) -> @debug.Repr
pub fn RunSummary::total_cases(Self) -> Int32
pub fn RunSummary::unsupported_cases(Self) -> Int32
#derive(Eq, @debug.Debug)
pub struct ShardSpec {
// private fields
}
pub fn ShardSpec::count(Self) -> Int32
pub fn ShardSpec::equal(Self, Self) -> Bool
pub fn ShardSpec::index(Self) -> Int32
pub fn ShardSpec::new(Int32, Int32) -> Self
pub fn ShardSpec::not_equal(Self, Self) -> Bool
pub fn ShardSpec::selects(Self, Int32) -> Bool
pub fn ShardSpec::to_repr(Self) -> @debug.Repr
pub fn ShardSpec::try_new(Int32, Int32) -> Result[Self, String]
#derive(Eq, @debug.Debug)
pub struct SourceLocation {
// private fields
}
pub fn SourceLocation::column(Self) -> Int32
pub fn SourceLocation::equal(Self, Self) -> Bool
pub fn SourceLocation::line(Self) -> Int32
pub fn SourceLocation::new(String, Int32, column? : Int32) -> Self
pub fn SourceLocation::not_equal(Self, Self) -> Bool
pub fn SourceLocation::source(Self) -> String
pub fn SourceLocation::to_repr(Self) -> @debug.Repr
// Type aliases
// Traits