Skip to content

Commit

Permalink
refactor!: Seal trait AIR
Browse files Browse the repository at this point in the history
The pubic trait `AIR` used to be implementable downstream. This was
never intended. Now, by sealing the trait, downstream dependencies
cannot implement the trait.
  • Loading branch information
jan-ferdinand committed Sep 16, 2024
1 parent b769392 commit 44d9484
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 1 deletion.
16 changes: 15 additions & 1 deletion triton-air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub mod cross_table_argument;
pub mod table;
pub mod table_column;

mod private {
pub trait Seal {}
}

/// The degree of the AIR after the degree lowering step.
///
/// Using substitution and the introduction of new variables, the degree of the AIR as specified
Expand All @@ -28,7 +32,17 @@ pub mod table_column;
/// The degree lowering happens in Triton VM's build script, `build.rs`.
pub const TARGET_DEGREE: isize = 4;

pub trait AIR {
/// The main trait for the [tables]' Arithmetic Intermediate Representation.
///
/// This is a _sealed_ trait. It is not intended (or possible) to implement this
/// trait outside the crate defining it.
///
/// [tables]: table::TableId
///
/// ### Object safety
///
/// This trait is _not_ object safe.
pub trait AIR: private::Seal {
type MainColumn: MasterMainColumn + EnumCount;
type AuxColumn: MasterAuxColumn + EnumCount;

Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/cascade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use crate::AIR;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct CascadeTable;

impl crate::private::Seal for CascadeTable {}

impl AIR for CascadeTable {
type MainColumn = crate::table_column::CascadeMainColumn;
type AuxColumn = crate::table_column::CascadeAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub type PermutationTrace = [[BFieldElement; tip5::STATE_SIZE]; PERMUTATION_TRAC
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct HashTable;

impl crate::private::Seal for HashTable {}

type MainColumn = <HashTable as AIR>::MainColumn;
type AuxColumn = <HashTable as AIR>::AuxColumn;

Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/jump_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use crate::AIR;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct JumpStackTable;

impl crate::private::Seal for JumpStackTable {}

impl AIR for JumpStackTable {
type MainColumn = crate::table_column::JumpStackMainColumn;
type AuxColumn = crate::table_column::JumpStackAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use crate::AIR;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct LookupTable;

impl crate::private::Seal for LookupTable {}

impl AIR for LookupTable {
type MainColumn = LookupMainColumn;
type AuxColumn = LookupAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/op_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub const PADDING_VALUE: BFieldElement = BFieldElement::new(2);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct OpStackTable;

impl crate::private::Seal for OpStackTable {}

impl AIR for OpStackTable {
type MainColumn = crate::table_column::OpStackMainColumn;
type AuxColumn = crate::table_column::OpStackAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub const NUM_HELPER_VARIABLE_REGISTERS: usize = 6;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct ProcessorTable;

impl crate::private::Seal for ProcessorTable {}

type MainColumn = <ProcessorTable as AIR>::MainColumn;
type AuxColumn = <ProcessorTable as AIR>::AuxColumn;

Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::AIR;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct ProgramTable;

impl crate::private::Seal for ProgramTable {}

impl AIR for ProgramTable {
type MainColumn = crate::table_column::ProgramMainColumn;
type AuxColumn = crate::table_column::ProgramAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub const PADDING_INDICATOR: BFieldElement = BFieldElement::new(2);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct RamTable;

impl crate::private::Seal for RamTable {}

impl AIR for RamTable {
type MainColumn = crate::table_column::RamMainColumn;
type AuxColumn = crate::table_column::RamAuxColumn;
Expand Down
2 changes: 2 additions & 0 deletions triton-air/src/table/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::AIR;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct U32Table;

impl crate::private::Seal for U32Table {}

impl AIR for U32Table {
type MainColumn = crate::table_column::U32MainColumn;
type AuxColumn = crate::table_column::U32AuxColumn;
Expand Down

0 comments on commit 44d9484

Please sign in to comment.