checkpoint

This commit is contained in:
microproofs 2023-07-14 17:04:43 -04:00 committed by Kasey
parent 9704cafefe
commit 947c118175
3 changed files with 45 additions and 165 deletions

View File

@ -377,7 +377,6 @@ impl<'a> CodeGenerator<'a> {
&clauses, &clauses,
last_clause, last_clause,
&subject.tipo(), &subject.tipo(),
tipo,
&mut ClauseProperties::init( &mut ClauseProperties::init(
&subject.tipo(), &subject.tipo(),
constr_var.clone(), constr_var.clone(),
@ -1356,7 +1355,6 @@ impl<'a> CodeGenerator<'a> {
clauses: &[TypedClause], clauses: &[TypedClause],
final_clause: TypedClause, final_clause: TypedClause,
subject_tipo: &Arc<Type>, subject_tipo: &Arc<Type>,
return_tipo: &Arc<Type>,
props: &mut ClauseProperties, props: &mut ClauseProperties,
) -> AirTree { ) -> AirTree {
assert!( assert!(
@ -1414,7 +1412,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
complex_clause, complex_clause,
@ -1426,7 +1423,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
) )
@ -1441,7 +1437,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
complex_clause, complex_clause,
@ -1477,7 +1472,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
); );
@ -1554,7 +1548,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
) )
@ -1567,7 +1560,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
next_tail_name, next_tail_name,
@ -1611,7 +1603,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
) )
@ -1626,7 +1617,6 @@ impl<'a> CodeGenerator<'a> {
rest_clauses, rest_clauses,
final_clause, final_clause,
subject_tipo, subject_tipo,
return_tipo,
&mut next_clause_props, &mut next_clause_props,
), ),
props.complex_clause, props.complex_clause,

View File

@ -87,19 +87,19 @@ pub enum Air {
subject_name: String, subject_name: String,
}, },
Clause { Clause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
subject_name: String, subject_name: String,
complex_clause: bool, complex_clause: bool,
}, },
ListClause { ListClause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
tail_name: String, tail_name: String,
next_tail_name: Option<String>, next_tail_name: Option<String>,
complex_clause: bool, complex_clause: bool,
}, },
WrapClause, WrapClause,
TupleClause { TupleClause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
predefined_indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>,
subject_name: String, subject_name: String,
@ -108,16 +108,16 @@ pub enum Air {
}, },
ClauseGuard { ClauseGuard {
subject_name: String, subject_name: String,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
}, },
ListClauseGuard { ListClauseGuard {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
tail_name: String, tail_name: String,
next_tail_name: Option<String>, next_tail_name: Option<String>,
inverse: bool, inverse: bool,
}, },
TupleGuard { TupleGuard {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
subject_name: String, subject_name: String,
type_count: usize, type_count: usize,
@ -181,118 +181,4 @@ pub enum Air {
ListEmpty, ListEmpty,
} }
impl Air { impl Air {}
pub fn tipo(&self) -> Option<Arc<Type>> {
match self {
Air::Int { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "Int".to_string(),
args: vec![],
}
.into(),
),
Air::String { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "String".to_string(),
args: vec![],
}
.into(),
),
Air::ByteArray { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "ByteArray".to_string(),
args: vec![],
}
.into(),
),
Air::Bool { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "Bool".to_string(),
args: vec![],
}
.into(),
),
Air::Void { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "Void".to_string(),
args: vec![],
}
.into(),
),
Air::WrapData { .. } => Some(
Type::App {
public: true,
module: String::new(),
name: "Data".to_string(),
args: vec![],
}
.into(),
),
Air::Var { constructor, .. } => Some(constructor.tipo.clone()),
Air::List { tipo, .. }
| Air::Tuple { tipo, .. }
| Air::Call { tipo, .. }
| Air::Builtin { tipo, .. }
| Air::BinOp { tipo, .. }
| Air::UnWrapData { tipo, .. }
| Air::When { tipo, .. }
| Air::Clause { tipo, .. }
| Air::ListClause { tipo, .. }
| Air::TupleClause { tipo, .. }
| Air::ClauseGuard { tipo, .. }
| Air::TupleGuard { tipo, .. }
| Air::If { tipo, .. }
| Air::ListClauseGuard { tipo, .. }
| Air::Constr { tipo, .. }
| Air::RecordUpdate { tipo, .. }
| Air::RecordAccess { tipo, .. }
| Air::ListAccessor { tipo, .. }
| Air::ListExpose { tipo, .. }
| Air::TupleAccessor { tipo, .. }
| Air::TupleIndex { tipo, .. }
| Air::ErrorTerm { tipo, .. }
| Air::Trace { tipo, .. } => Some(tipo.clone()),
Air::DefineFunc { .. }
| Air::Fn { .. }
| Air::Let { .. }
| Air::WrapClause { .. }
| Air::AssertConstr { .. }
| Air::AssertBool { .. }
| Air::Finally { .. }
| Air::FieldsExpose { .. }
| Air::FieldsEmpty { .. }
| Air::ListEmpty { .. }
| Air::NoOp { .. } => None,
Air::UnOp { op, .. } => match op {
UnOp::Not => Some(
Type::App {
public: true,
module: String::new(),
name: "Bool".to_string(),
args: vec![],
}
.into(),
),
UnOp::Negate => Some(
Type::App {
public: true,
module: String::new(),
name: "Int".to_string(),
args: vec![],
}
.into(),
),
},
}
}
}

View File

@ -47,17 +47,17 @@ pub enum AirStatement {
// Clause Guards // Clause Guards
ClauseGuard { ClauseGuard {
subject_name: String, subject_name: String,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
pattern: Box<AirTree>, pattern: Box<AirTree>,
}, },
ListClauseGuard { ListClauseGuard {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
tail_name: String, tail_name: String,
next_tail_name: Option<String>, next_tail_name: Option<String>,
inverse: bool, inverse: bool,
}, },
TupleGuard { TupleGuard {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
subject_name: String, subject_name: String,
type_count: usize, type_count: usize,
@ -167,7 +167,7 @@ pub enum AirExpression {
clauses: Box<AirTree>, clauses: Box<AirTree>,
}, },
Clause { Clause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
subject_name: String, subject_name: String,
complex_clause: bool, complex_clause: bool,
pattern: Box<AirTree>, pattern: Box<AirTree>,
@ -175,7 +175,7 @@ pub enum AirExpression {
otherwise: Box<AirTree>, otherwise: Box<AirTree>,
}, },
ListClause { ListClause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
tail_name: String, tail_name: String,
next_tail_name: Option<String>, next_tail_name: Option<String>,
complex_clause: bool, complex_clause: bool,
@ -187,7 +187,7 @@ pub enum AirExpression {
otherwise: Box<AirTree>, otherwise: Box<AirTree>,
}, },
TupleClause { TupleClause {
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
predefined_indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>,
subject_name: String, subject_name: String,
@ -418,13 +418,13 @@ impl AirTree {
pub fn clause( pub fn clause(
subject_name: impl ToString, subject_name: impl ToString,
pattern: AirTree, pattern: AirTree,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
then: AirTree, then: AirTree,
otherwise: AirTree, otherwise: AirTree,
complex_clause: bool, complex_clause: bool,
) -> AirTree { ) -> AirTree {
AirTree::Expression(AirExpression::Clause { AirTree::Expression(AirExpression::Clause {
tipo, subject_tipo,
subject_name: subject_name.to_string(), subject_name: subject_name.to_string(),
complex_clause, complex_clause,
pattern: pattern.into(), pattern: pattern.into(),
@ -434,14 +434,14 @@ impl AirTree {
} }
pub fn list_clause( pub fn list_clause(
tail_name: impl ToString, tail_name: impl ToString,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
then: AirTree, then: AirTree,
otherwise: AirTree, otherwise: AirTree,
next_tail_name: Option<String>, next_tail_name: Option<String>,
complex_clause: bool, complex_clause: bool,
) -> AirTree { ) -> AirTree {
AirTree::Expression(AirExpression::ListClause { AirTree::Expression(AirExpression::ListClause {
tipo, subject_tipo,
tail_name: tail_name.to_string(), tail_name: tail_name.to_string(),
next_tail_name, next_tail_name,
complex_clause, complex_clause,
@ -451,17 +451,17 @@ impl AirTree {
} }
pub fn tuple_clause( pub fn tuple_clause(
subject_name: impl ToString, subject_name: impl ToString,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
predefined_indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>,
then: AirTree, then: AirTree,
otherwise: AirTree, otherwise: AirTree,
complex_clause: bool, complex_clause: bool,
) -> AirTree { ) -> AirTree {
let type_count = tipo.get_inner_types().len(); let type_count = subject_tipo.get_inner_types().len();
AirTree::Expression(AirExpression::TupleClause { AirTree::Expression(AirExpression::TupleClause {
tipo, subject_tipo,
indices, indices,
predefined_indices, predefined_indices,
subject_name: subject_name.to_string(), subject_name: subject_name.to_string(),
@ -477,11 +477,15 @@ impl AirTree {
otherwise: otherwise.into(), otherwise: otherwise.into(),
}) })
} }
pub fn clause_guard(subject_name: impl ToString, pattern: AirTree, tipo: Arc<Type>) -> AirTree { pub fn clause_guard(
subject_name: impl ToString,
pattern: AirTree,
subject_tipo: Arc<Type>,
) -> AirTree {
AirTree::Statement { AirTree::Statement {
statement: AirStatement::ClauseGuard { statement: AirStatement::ClauseGuard {
subject_name: subject_name.to_string(), subject_name: subject_name.to_string(),
tipo, subject_tipo,
pattern: pattern.into(), pattern: pattern.into(),
}, },
hoisted_over: None, hoisted_over: None,
@ -489,13 +493,13 @@ impl AirTree {
} }
pub fn list_clause_guard( pub fn list_clause_guard(
tail_name: impl ToString, tail_name: impl ToString,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
inverse: bool, inverse: bool,
next_tail_name: Option<String>, next_tail_name: Option<String>,
) -> AirTree { ) -> AirTree {
AirTree::Statement { AirTree::Statement {
statement: AirStatement::ListClauseGuard { statement: AirStatement::ListClauseGuard {
tipo, subject_tipo,
tail_name: tail_name.to_string(), tail_name: tail_name.to_string(),
next_tail_name, next_tail_name,
inverse, inverse,
@ -505,15 +509,15 @@ impl AirTree {
} }
pub fn tuple_clause_guard( pub fn tuple_clause_guard(
subject_name: impl ToString, subject_name: impl ToString,
tipo: Arc<Type>, subject_tipo: Arc<Type>,
indices: IndexSet<(usize, String)>, indices: IndexSet<(usize, String)>,
) -> AirTree { ) -> AirTree {
AirTree::Statement { AirTree::Statement {
statement: AirStatement::TupleGuard { statement: AirStatement::TupleGuard {
indices, indices,
subject_name: subject_name.to_string(), subject_name: subject_name.to_string(),
type_count: tipo.get_inner_types().len(), type_count: subject_tipo.get_inner_types().len(),
tipo, subject_tipo,
}, },
hoisted_over: None, hoisted_over: None,
} }
@ -785,37 +789,37 @@ impl AirTree {
} }
AirStatement::ClauseGuard { AirStatement::ClauseGuard {
subject_name, subject_name,
tipo, subject_tipo,
pattern, pattern,
} => { } => {
air_vec.push(Air::ClauseGuard { air_vec.push(Air::ClauseGuard {
subject_name: subject_name.clone(), subject_name: subject_name.clone(),
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
}); });
pattern.create_air_vec(air_vec); pattern.create_air_vec(air_vec);
} }
AirStatement::ListClauseGuard { AirStatement::ListClauseGuard {
tipo, subject_tipo,
tail_name, tail_name,
next_tail_name, next_tail_name,
inverse, inverse,
} => { } => {
air_vec.push(Air::ListClauseGuard { air_vec.push(Air::ListClauseGuard {
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
tail_name: tail_name.clone(), tail_name: tail_name.clone(),
next_tail_name: next_tail_name.clone(), next_tail_name: next_tail_name.clone(),
inverse: *inverse, inverse: *inverse,
}); });
} }
AirStatement::TupleGuard { AirStatement::TupleGuard {
tipo, subject_tipo,
indices, indices,
subject_name, subject_name,
type_count, type_count,
} => { } => {
air_vec.push(Air::TupleGuard { air_vec.push(Air::TupleGuard {
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
indices: indices.clone(), indices: indices.clone(),
subject_name: subject_name.clone(), subject_name: subject_name.clone(),
type_count: *type_count, type_count: *type_count,
@ -983,7 +987,7 @@ impl AirTree {
clauses.create_air_vec(air_vec); clauses.create_air_vec(air_vec);
} }
AirExpression::Clause { AirExpression::Clause {
tipo, subject_tipo,
subject_name, subject_name,
complex_clause, complex_clause,
pattern, pattern,
@ -991,7 +995,7 @@ impl AirTree {
otherwise, otherwise,
} => { } => {
air_vec.push(Air::Clause { air_vec.push(Air::Clause {
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
subject_name: subject_name.clone(), subject_name: subject_name.clone(),
complex_clause: *complex_clause, complex_clause: *complex_clause,
}); });
@ -1000,7 +1004,7 @@ impl AirTree {
otherwise.create_air_vec(air_vec); otherwise.create_air_vec(air_vec);
} }
AirExpression::ListClause { AirExpression::ListClause {
tipo, subject_tipo,
tail_name, tail_name,
next_tail_name, next_tail_name,
complex_clause, complex_clause,
@ -1008,7 +1012,7 @@ impl AirTree {
otherwise, otherwise,
} => { } => {
air_vec.push(Air::ListClause { air_vec.push(Air::ListClause {
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
tail_name: tail_name.clone(), tail_name: tail_name.clone(),
next_tail_name: next_tail_name.clone(), next_tail_name: next_tail_name.clone(),
complex_clause: *complex_clause, complex_clause: *complex_clause,
@ -1022,7 +1026,7 @@ impl AirTree {
otherwise.create_air_vec(air_vec); otherwise.create_air_vec(air_vec);
} }
AirExpression::TupleClause { AirExpression::TupleClause {
tipo, subject_tipo,
indices, indices,
predefined_indices, predefined_indices,
subject_name, subject_name,
@ -1032,7 +1036,7 @@ impl AirTree {
otherwise, otherwise,
} => { } => {
air_vec.push(Air::TupleClause { air_vec.push(Air::TupleClause {
tipo: tipo.clone(), subject_tipo: subject_tipo.clone(),
indices: indices.clone(), indices: indices.clone(),
predefined_indices: predefined_indices.clone(), predefined_indices: predefined_indices.clone(),
subject_name: subject_name.clone(), subject_name: subject_name.clone(),
@ -1170,8 +1174,8 @@ impl AirTree {
| AirExpression::TupleClause { then, .. } | AirExpression::TupleClause { then, .. }
| AirExpression::Finally { then, .. } => then.get_type(), | AirExpression::Finally { then, .. } => then.get_type(),
AirExpression::FieldsEmpty { constr } => todo!(), AirExpression::FieldsEmpty { constr } => constr.get_type(),
AirExpression::ListEmpty { list } => todo!(), AirExpression::ListEmpty { list } => list.get_type(),
}, },
_ => unreachable!(), _ => unreachable!(),
} }