use crate::descriptor::{CanonicalRowBytes, RevisionBinding, TrialKey};
use crate::identity::ContentAddress;
use crate::report::{
ByteBudget, CaseBudget, CheckRevisionId, EXECUTION_KEY_TAG, ExecutionKey, ExecutionRevisions,
InvocationProfile, ProfiledTrial, ROW_REVISION_TAG, RowRevisionId, SubjectRevisionId,
TRIAL_IDENTITY_TAG, TargetBinding, TargetTriple, TimeBudget, ToolchainIdentity, TrialId,
TrialProfile, TrialSite, execution_key_preimage, trial_preimage,
};
impl ProfiledTrial {
#[must_use]
pub const fn of_key(key: TrialKey, profile: TrialProfile) -> Self {
Self { key, profile }
}
#[must_use]
pub const fn key(self) -> TrialKey {
self.key
}
#[must_use]
pub const fn profile(self) -> TrialProfile {
self.profile
}
}
impl TrialId {
#[must_use]
pub fn over(profiled: ProfiledTrial) -> Self {
Self(ContentAddress::derived(
TRIAL_IDENTITY_TAG,
&trial_preimage(profiled),
))
}
#[must_use]
pub fn of_key(key: TrialKey, profile: TrialProfile) -> Self {
Self::over(ProfiledTrial::of_key(key, profile))
}
}
crate::identity::content_address_reference! {
borrowed TrialId;
}
impl TrialSite {
#[must_use]
pub const fn located(
module_path: &'static str,
file: &'static str,
line: u32,
name: &'static str,
) -> Self {
Self {
module_path,
file,
line,
name,
}
}
#[must_use]
pub const fn module_path(&self) -> &'static str {
self.module_path
}
#[must_use]
pub const fn file(&self) -> &'static str {
self.file
}
#[must_use]
pub const fn line(&self) -> u32 {
self.line
}
#[must_use]
pub const fn name(&self) -> &'static str {
self.name
}
}
impl RowRevisionId {
#[must_use]
pub fn over(canonical_row: &CanonicalRowBytes) -> Self {
Self(ContentAddress::derived(
ROW_REVISION_TAG,
canonical_row.as_bytes(),
))
}
}
crate::identity::content_address_reference! {
borrowed RowRevisionId;
}
impl SubjectRevisionId {
#[must_use]
pub const fn of_binding(binding: RevisionBinding) -> Self {
Self(binding.revision())
}
}
crate::identity::content_address_reference! {
borrowed SubjectRevisionId;
}
impl CheckRevisionId {
#[must_use]
pub const fn of_binding(binding: RevisionBinding) -> Self {
Self(binding.revision())
}
}
crate::identity::content_address_reference! {
borrowed CheckRevisionId;
}
impl ExecutionRevisions {
#[must_use]
pub const fn bound(subject: SubjectRevisionId, check: CheckRevisionId) -> Self {
Self { subject, check }
}
#[must_use]
pub const fn subject(self) -> SubjectRevisionId {
self.subject
}
#[must_use]
pub const fn check(self) -> CheckRevisionId {
self.check
}
}
impl TargetTriple {
#[must_use]
pub fn declared(spelling: &str) -> Self {
Self(spelling.to_owned())
}
#[must_use]
pub fn spelling(&self) -> &str {
&self.0
}
}
impl ToolchainIdentity {
#[must_use]
pub fn declared(spelling: &str) -> Self {
Self(spelling.to_owned())
}
#[must_use]
pub fn spelling(&self) -> &str {
&self.0
}
}
impl TargetBinding {
#[must_use]
pub fn bound(target: TargetTriple, toolchain: ToolchainIdentity) -> Self {
Self { target, toolchain }
}
#[must_use]
pub const fn target(&self) -> &TargetTriple {
&self.target
}
#[must_use]
pub const fn toolchain(&self) -> &ToolchainIdentity {
&self.toolchain
}
}
impl CaseBudget {
#[must_use]
pub const fn declared(cases: u32) -> Self {
Self(cases)
}
#[must_use]
pub const fn cases(self) -> u32 {
self.0
}
}
impl ByteBudget {
#[must_use]
pub const fn declared(bytes: u64) -> Self {
Self(bytes)
}
#[must_use]
pub const fn bytes(self) -> u64 {
self.0
}
}
impl TimeBudget {
#[must_use]
pub const fn declared(nanoseconds: u64) -> Self {
Self(nanoseconds)
}
#[must_use]
pub const fn nanoseconds(self) -> u64 {
self.0
}
}
impl InvocationProfile {
#[must_use]
pub const fn declared(cases: CaseBudget, bytes: ByteBudget, time: TimeBudget) -> Self {
Self { cases, bytes, time }
}
#[must_use]
pub const fn cases(self) -> CaseBudget {
self.cases
}
#[must_use]
pub const fn bytes(self) -> ByteBudget {
self.bytes
}
#[must_use]
pub const fn time(self) -> TimeBudget {
self.time
}
}
impl ExecutionKey {
#[must_use]
pub fn over(
trial: TrialId,
subject: SubjectRevisionId,
check: CheckRevisionId,
invocation: InvocationProfile,
target: TargetBinding,
) -> Self {
Self {
trial,
revisions: ExecutionRevisions::bound(subject, check),
invocation,
target,
}
}
#[must_use]
pub const fn trial(&self) -> TrialId {
self.trial
}
#[must_use]
pub const fn subject(&self) -> SubjectRevisionId {
self.revisions.subject()
}
#[must_use]
pub const fn check(&self) -> CheckRevisionId {
self.revisions.check()
}
#[must_use]
pub const fn revisions(&self) -> ExecutionRevisions {
self.revisions
}
#[must_use]
pub const fn invocation(&self) -> InvocationProfile {
self.invocation
}
#[must_use]
pub const fn target(&self) -> &TargetBinding {
&self.target
}
#[must_use]
pub fn address(&self) -> ContentAddress {
ContentAddress::derived(
EXECUTION_KEY_TAG,
&execution_key_preimage(
self.trial,
self.revisions.subject(),
self.revisions.check(),
self.invocation,
&self.target,
),
)
}
}