Skip to content
Closed
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

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion crates/labcolors-core/src/constraints/exact.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::Srgb8;
use crate::appearance::ModeledSrgb8PointOccurrence;
use crate::constraints::{
Evaluator, HardClassifier, HardDecision, ProgramPointTargetV1, VisiblePointPassEvidence,
Evaluator, HardClassifier, HardDecision, ProgramConstraintContentV1,
ProgramPointEvaluatorContentV1, ProgramPointTargetV1, VisiblePointPassEvidence,
VisiblePointViolationEvidence, private,
};
use core::convert::Infallible;
Expand All @@ -12,19 +13,25 @@ use core::convert::Infallible;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ExactConstraintIdentityV1 {
FinalSrgb8IdentityV1,
#[cfg(test)]
MutationSentinelV1,
}

/// Версия формулы exact byte-identity evaluator-а.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ExactIdentityReleaseV1 {
V1,
#[cfg(test)]
MutationSentinelV1,
}

/// Узкая capability evaluator-а: только финальный modeled point occurrence в
/// encoded-sRGB8, не source Paint и не пиксели произвольного renderer-а.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ExactIdentityCapabilityV1 {
FinalOccurrenceSrgb8IdentityV1,
#[cfg(test)]
MutationSentinelV1,
}

/// Закрытые ZST payload-типы делают Pass и Violation несовместимыми, но не
Expand Down Expand Up @@ -111,6 +118,17 @@ impl Evaluator<ProgramPointTargetV1> for ExactSrgb8IdentityV1 {
}
}

impl ProgramPointEvaluatorContentV1 for ExactSrgb8IdentityV1 {
fn program_constraint_content_v1(&self, invocation: Srgb8) -> ProgramConstraintContentV1 {
ProgramConstraintContentV1::ExactSrgb8 {
identity: <Self as Evaluator<ProgramPointTargetV1>>::identity(self),
release: <Self as Evaluator<ProgramPointTargetV1>>::release(self),
capability: <Self as Evaluator<ProgramPointTargetV1>>::capability(self),
expected: invocation,
}
}
}

impl HardClassifier<Srgb8, Srgb8> for ExactSrgb8IdentityV1 {
type Pass = ExactIdentityPassV1;
type Violation = ExactIdentityViolationV1;
Expand Down
66 changes: 65 additions & 1 deletion crates/labcolors-core/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use crate::Srgb8;
use crate::appearance::{ModeledSrgb8PointOccurrence, ResolvedOccurrence, VisiblePointBindingV1};
use crate::lcs_occurrence::ModeledLcsOccurrenceV1;
use crate::wcag22::{Wcag22CriterionV1, Wcag22ProfileIdV1};

mod exact;
pub(crate) use exact::{
Expand All @@ -20,7 +21,7 @@ pub(crate) use exact::ExactIdentityPassV1;

mod wcag22;

pub(crate) use wcag22::Wcag22Srgb8V1;
pub(crate) use wcag22::{Wcag22Srgb8CapabilityV1, Wcag22Srgb8EvaluatorIdentityV1, Wcag22Srgb8V1};

#[cfg(test)]
pub(crate) use wcag22::{
Expand Down Expand Up @@ -266,16 +267,52 @@ pub(crate) trait ProgramPointEvaluatorV1:
Sized
+ Evaluator<ProgramPointTargetV1>
+ HardClassifier<ProgramPointInvocation<Self>, ProgramPointMeasurement<Self>>
+ ProgramPointEvaluatorContentV1
{
}

impl<Evaluation> ProgramPointEvaluatorV1 for Evaluation where
Evaluation: Sized
+ Evaluator<ProgramPointTargetV1>
+ HardClassifier<ProgramPointInvocation<Evaluation>, ProgramPointMeasurement<Evaluation>>
+ ProgramPointEvaluatorContentV1
{
}

/// Полное code-owned описание одного evaluator invocation для compile identity.
///
/// Здесь намеренно нет авторского constraint ID. Метаданные берутся из того же
/// закрытого определения evaluator-а, которое связывает runtime evidence, и не
/// могут разойтись с его identity, release или capability. Добавление либо
/// изменение production evaluator-а остаётся явной сменой схемы.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ProgramConstraintContentV1 {
ExactSrgb8 {
identity: ExactConstraintIdentityV1,
release: ExactIdentityReleaseV1,
capability: ExactIdentityCapabilityV1,
expected: Srgb8,
},
Wcag22Srgb8 {
identity: Wcag22Srgb8EvaluatorIdentityV1,
release: Wcag22ProfileIdV1,
capability: Wcag22Srgb8CapabilityV1,
criterion: Wcag22CriterionV1,
},
#[cfg(test)]
FinalRecheckMutantExactSrgb8 { expected: Srgb8 },
}

/// Внутрикрейтное описание generic test seam с одним evaluator-ом. Package
/// Program использует закрытое heterogeneous-множество, поэтому клиент не
/// может подменить descriptor.
pub(crate) trait ProgramPointEvaluatorContentV1: Evaluator<ProgramPointTargetV1> {
fn program_constraint_content_v1(
&self,
invocation: ProgramPointInvocation<Self>,
) -> ProgramConstraintContentV1;
}

#[cfg(test)]
impl Evaluator<ProgramPointTargetV1> for CountingProgramWcag22Srgb8V1 {
type Invocation = <Wcag22Srgb8V1 as Evaluator<ProgramPointTargetV1>>::Invocation;
Expand Down Expand Up @@ -313,6 +350,21 @@ impl Evaluator<ProgramPointTargetV1> for CountingProgramWcag22Srgb8V1 {
}
}

#[cfg(test)]
impl ProgramPointEvaluatorContentV1 for CountingProgramWcag22Srgb8V1 {
fn program_constraint_content_v1(
&self,
invocation: ProgramPointInvocation<Self>,
) -> ProgramConstraintContentV1 {
ProgramConstraintContentV1::Wcag22Srgb8 {
identity: self.identity(),
release: self.release(),
capability: self.capability(),
criterion: invocation,
}
}
}

#[cfg(test)]
impl
HardClassifier<
Expand Down Expand Up @@ -375,6 +427,18 @@ impl Evaluator<ProgramPointTargetV1> for FinalRecheckMutantProgramEvaluatorV1 {
}
}

#[cfg(test)]
impl ProgramPointEvaluatorContentV1 for FinalRecheckMutantProgramEvaluatorV1 {
fn program_constraint_content_v1(
&self,
invocation: ProgramPointInvocation<Self>,
) -> ProgramConstraintContentV1 {
ProgramConstraintContentV1::FinalRecheckMutantExactSrgb8 {
expected: invocation,
}
}
}

#[cfg(test)]
impl HardClassifier<Srgb8, Srgb8> for FinalRecheckMutantProgramEvaluatorV1 {
type Pass = MutantExactPassV1;
Expand Down
19 changes: 18 additions & 1 deletion crates/labcolors-core/src/constraints/wcag22.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::appearance::ModeledSrgb8PointOccurrence;
use crate::constraints::{Evaluator, HardClassifier, HardDecision, ProgramPointTargetV1, private};
use crate::constraints::{
Evaluator, HardClassifier, HardDecision, ProgramConstraintContentV1,
ProgramPointEvaluatorContentV1, ProgramPointTargetV1, private,
};
use crate::numerics::NumericalDecisionEvidenceV1;
use crate::wcag22::{
Wcag22ApplicableDecisionV1, Wcag22AssessmentV1, Wcag22ClientDeclaredNotApplicableV1,
Expand Down Expand Up @@ -175,6 +178,20 @@ impl Evaluator<ProgramPointTargetV1> for Wcag22Srgb8V1 {
}
}

impl ProgramPointEvaluatorContentV1 for Wcag22Srgb8V1 {
fn program_constraint_content_v1(
&self,
invocation: Wcag22CriterionV1,
) -> ProgramConstraintContentV1 {
ProgramConstraintContentV1::Wcag22Srgb8 {
identity: <Self as Evaluator<ProgramPointTargetV1>>::identity(self),
release: <Self as Evaluator<ProgramPointTargetV1>>::release(self),
capability: <Self as Evaluator<ProgramPointTargetV1>>::capability(self),
criterion: invocation,
}
}
}

impl HardClassifier<Wcag22CriterionV1, ApplicableWcag22MeasurementV1> for Wcag22Srgb8V1 {
type Pass = Wcag22PassV1;
type Violation = Wcag22ViolationV1;
Expand Down
36 changes: 34 additions & 2 deletions crates/labcolors-core/src/generic_boundary_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const OBSERVATION_SOURCE: &str = include_str!("observation.rs");
const OUTPUT_PROJECTION_SOURCE: &str = include_str!("output_projection.rs");
const PACKAGE_BRIDGE_SOURCE: &str = include_str!("package_bridge.rs");
const POINT_SUPPORT_SOURCE: &str = include_str!("point_support.rs");
const PROGRAM_IDENTITY_SOURCE: &str = include_str!("program_identity.rs");
const PROGRAM_SESSION_SOURCE: &str = include_str!("program_session.rs");
const SESSION_SOURCE: &str = include_str!("session.rs");
const WCAG22_CONSTRAINT_SOURCE: &str = include_str!("constraints/wcag22.rs");

const GENERIC_SOURCES: [(&str, &str); 3] = [
const GENERIC_SOURCES: [(&str, &str); 4] = [
("appearance.rs", APPEARANCE_SOURCE),
("lcs_occurrence.rs", LCS_OCCURRENCE_SOURCE),
("program_identity.rs", PROGRAM_IDENTITY_SOURCE),
("program_session.rs", PROGRAM_SESSION_SOURCE),
];

Expand Down Expand Up @@ -541,7 +543,7 @@ fn program_session_owns_context_bound_lcs_evidence_and_one_session_scratch_cache
"let outputs = compile_outputs(",
);
for required in [
"compile_constraints::<Evaluation>(&graph, &all_occurrence_contexts, program.constraints)?",
"compile_constraints::<Evaluation>(&graph, &all_occurrence_contexts, &program.constraints)?",
"compact_constraint_contexts(&all_occurrence_contexts, &mut constraints)?",
] {
assert!(
Expand Down Expand Up @@ -587,6 +589,36 @@ fn program_session_owns_context_bound_lcs_evidence_and_one_session_scratch_cache
}
}

#[test]
fn cold_program_normalization_reuses_owned_unordered_buffers() {
let compiler = PROGRAM_SESSION_SOURCE
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
for required in [
"authored_targets: &mut [Target]",
"authored_selection: Option<&mut DeclaredJointSelectionV1>",
"let TargetDomainV1::Finite(candidates) = &mut target.domain",
"authored_state .choices .sort_unstable_by_key",
"authored: &mut [OutputBinding]",
] {
assert!(
compiler.contains(required),
"cold Program compilation must normalize owned buffers in place; missing `{required}`",
);
}
for forbidden in [
"candidates.extend_from_slice(authored_candidates)",
"choices.extend_from_slice(&authored_state.choices)",
"authored.extend_from_slice(authored_outputs)",
] {
assert!(
!compiler.contains(forbidden),
"cold Program compilation must not restore avoidable shadow copy `{forbidden}`",
);
}
}

#[test]
fn program_lcs_boundary_has_no_legacy_color_or_projection_shortcuts() {
for forbidden in [
Expand Down
4 changes: 4 additions & 0 deletions crates/labcolors-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub(crate) mod program_session;
pub(crate) mod release_registry;
pub mod scale;
pub mod semantic;
pub(crate) mod sha256;
pub mod solve;
pub(crate) mod wcag;

Expand Down Expand Up @@ -102,6 +103,9 @@ mod program_joint_integration_tests;
#[cfg(test)]
mod program_mixed_evaluator_tests;

#[cfg(test)]
mod program_identity_tests;

#[cfg(test)]
mod release_registry_tests;

Expand Down
Loading
Loading