Cargo fmt + clippy, with latest rust

This commit is contained in:
Pi Lanningham 2023-08-07 18:43:44 -04:00 committed by Kasey
parent 0d99afe5e2
commit f464eb3702
6 changed files with 161 additions and 85 deletions

View File

@ -346,7 +346,9 @@ impl<'a> CodeGenerator<'a> {
let type_info = self.module_types.get(module_name).unwrap();
let value = type_info.values.get(name).unwrap();
let ValueConstructorVariant::ModuleFn { builtin, .. } = &value.variant else {unreachable!("Missing module function definition")};
let ValueConstructorVariant::ModuleFn { builtin, .. } = &value.variant else {
unreachable!("Missing module function definition")
};
let fun_arg_types = fun
.tipo()
@ -589,8 +591,10 @@ impl<'a> CodeGenerator<'a> {
)
} else {
let ValueConstructorVariant::ModuleFn {
builtin: Some(builtin), ..
} = &value.variant else {
builtin: Some(builtin),
..
} = &value.variant
else {
unreachable!("Didn't find the function definition.")
};
@ -1665,8 +1669,7 @@ impl<'a> CodeGenerator<'a> {
Pattern::List { .. } | Pattern::Var { .. } | Pattern::Discard { .. }
));
let Pattern::List { elements, tail, .. } = &clause.pattern
else {
let Pattern::List { elements, tail, .. } = &clause.pattern else {
let mut next_clause_props = ClauseProperties {
clause_var_name: props.clause_var_name.clone(),
complex_clause: false,
@ -1811,7 +1814,13 @@ impl<'a> CodeGenerator<'a> {
let (_, pattern_assigns) =
self.clause_pattern(&clause.pattern, subject_tipo, props);
let ClauseProperties{ specific_clause: SpecificClause::TupleClause { defined_tuple_indices }, ..} = props
let ClauseProperties {
specific_clause:
SpecificClause::TupleClause {
defined_tuple_indices,
},
..
} = props
else {
unreachable!()
};
@ -1914,7 +1923,9 @@ impl<'a> CodeGenerator<'a> {
complex_clause,
..
} = props
else { unreachable!() };
else {
unreachable!()
};
let list_elem_types = subject_tipo.get_inner_types();
@ -2341,11 +2352,12 @@ impl<'a> CodeGenerator<'a> {
current_index,
defined_tails,
checked_index: _,
},
..
} = props
else { unreachable!() };
else {
unreachable!()
};
defined_tails.push(props.original_subject_name.clone());
@ -2817,9 +2829,14 @@ impl<'a> CodeGenerator<'a> {
// In the case of zero args, we need to hoist the dependency function to the top of the zero arg function
if &dep_path.common_ancestor(func_path) == func_path || params_empty {
let UserFunction::Function { body: mut dep_air_tree, deps: dependency_deps, params: dependent_params } =
dep_function.clone()
else { unreachable!() };
let UserFunction::Function {
body: mut dep_air_tree,
deps: dependency_deps,
params: dependent_params,
} = dep_function.clone()
else {
unreachable!()
};
if dependent_params.is_empty() {
// continue for zero arg functions. They are treated like global hoists.
@ -2869,8 +2886,9 @@ impl<'a> CodeGenerator<'a> {
current_function_deps: &mut Vec<(FunctionAccessKey, String)>,
validator_tree_path: &mut TreePath,
) {
let Some((depth, index)) = validator_tree_path.pop()
else { return };
let Some((depth, index)) = validator_tree_path.pop() else {
return;
};
validator_tree_path.push(depth, index);
@ -2925,7 +2943,9 @@ impl<'a> CodeGenerator<'a> {
builtin: None,
..
} = &constructor.variant
else { return };
else {
return;
};
let function_var_tipo = &constructor.tipo;
@ -2936,8 +2956,7 @@ impl<'a> CodeGenerator<'a> {
let function_def = self.functions.get(&generic_function_key);
let Some(function_def) = function_def
else {
let Some(function_def) = function_def else {
let code_gen_func = self
.code_gen_functions
.get(&generic_function_key.function_name)
@ -2955,8 +2974,9 @@ impl<'a> CodeGenerator<'a> {
let (path, _) = func_variants.get_mut("").unwrap();
*path = path.common_ancestor(tree_path);
} else {
let CodeGenFunction::Function{ body, params } = code_gen_func
else { unreachable!() };
let CodeGenFunction::Function { body, params } = code_gen_func else {
unreachable!()
};
let mut function_variant_path = IndexMap::new();

View File

@ -269,7 +269,6 @@ fn infer_definition(
.get_variable(&fun.name)
.expect("Could not find preregistered type for function");
let preregistered_type = preregistered_fn.tipo.clone();
let (args_types, _return_type) = preregistered_type
@ -308,8 +307,11 @@ fn infer_definition(
environment,
tracing,
kind,
)? else {
unreachable!("validator definition inferred as something other than a function?")
)?
else {
unreachable!(
"validator definition inferred as something other than a function?"
)
};
if !typed_fun.return_type.is_bool() {
@ -319,7 +321,8 @@ fn infer_definition(
});
}
let typed_params = typed_fun.arguments
let typed_params = typed_fun
.arguments
.drain(0..params_length)
.map(|mut arg| {
if arg.tipo.is_unbound() {
@ -330,7 +333,6 @@ fn infer_definition(
})
.collect();
if typed_fun.arguments.len() < 2 || typed_fun.arguments.len() > 3 {
return Err(Error::IncorrectValidatorArity {
count: typed_fun.arguments.len() as u32,
@ -356,7 +358,8 @@ fn infer_definition(
environment,
tracing,
kind,
)? else {
)?
else {
unreachable!(
"validator definition inferred as something other than a function?"
)
@ -398,8 +401,6 @@ fn infer_definition(
})
.transpose();
Ok(Definition::Validator(Validator {
doc,
end_position,

View File

@ -35,8 +35,7 @@ fn assert_uplc(source_code: &str, expected: Term<Name>, should_fail: bool) {
true,
);
let Some(checked_module) = modules.values().next()
else {
let Some(checked_module) = modules.values().next() else {
unreachable!("There's got to be one right?")
};

View File

@ -712,8 +712,12 @@ impl DefaultFunction {
Ok(value)
}
DefaultFunction::HeadList => {
let c @ Value::Con(inner) = &args[0] else {unreachable!()};
let Constant::ProtoList(_, list) = inner.as_ref() else {unreachable!()};
let c @ Value::Con(inner) = &args[0] else {
unreachable!()
};
let Constant::ProtoList(_, list) = inner.as_ref() else {
unreachable!()
};
if list.is_empty() {
Err(Error::EmptyList(c.clone()))
@ -724,8 +728,12 @@ impl DefaultFunction {
}
}
DefaultFunction::TailList => {
let c @ Value::Con(inner) = &args[0] else {unreachable!()};
let Constant::ProtoList(r#type, list) = inner.as_ref() else {unreachable!()};
let c @ Value::Con(inner) = &args[0] else {
unreachable!()
};
let Constant::ProtoList(r#type, list) = inner.as_ref() else {
unreachable!()
};
if list.is_empty() {
Err(Error::EmptyList(c.clone()))
@ -784,12 +792,9 @@ impl DefaultFunction {
let mut map = Vec::new();
for item in list {
let Constant::ProtoPair(
Type::Data,
Type::Data,
left,
right
) = item else {unreachable!()};
let Constant::ProtoPair(Type::Data, Type::Data, left, right) = item else {
unreachable!()
};
match (left.as_ref(), right.as_ref()) {
(Constant::Data(key), Constant::Data(value)) => {
@ -838,7 +843,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnConstrData".to_string(),
v.clone(),
))
));
};
let constant = Constant::ProtoPair(
@ -876,7 +881,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnMapData".to_string(),
v.clone(),
))
));
};
let constant = Constant::ProtoList(
@ -909,7 +914,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnListData".to_string(),
v.clone(),
))
));
};
let value = Value::list(
@ -933,7 +938,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnIData".to_string(),
v.clone(),
))
));
};
let value = Value::integer(from_pallas_bigint(b));
@ -951,7 +956,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnBData".to_string(),
v.clone(),
))
));
};
let value = Value::byte_string(b.to_vec());
@ -964,18 +969,28 @@ impl DefaultFunction {
)),
},
DefaultFunction::EqualsData => {
let (Value::Con(inner1), Value::Con(inner2)) = (&args[0], &args[1]) else {unreachable!()};
let (Value::Con(inner1), Value::Con(inner2)) = (&args[0], &args[1]) else {
unreachable!()
};
let Constant::Data(d1) = inner1.as_ref() else {unreachable!()};
let Constant::Data(d2) = inner2.as_ref() else {unreachable!()};
let Constant::Data(d1) = inner1.as_ref() else {
unreachable!()
};
let Constant::Data(d2) = inner2.as_ref() else {
unreachable!()
};
let value = Value::bool(d1.eq(d2));
Ok(value)
}
DefaultFunction::SerialiseData => {
let Value::Con(inner) = &args[0] else {unreachable!()};
let Constant::Data(d) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = &args[0] else {
unreachable!()
};
let Constant::Data(d) = inner.as_ref() else {
unreachable!()
};
let serialized_data = plutus_data_to_bytes(d).unwrap();
@ -984,10 +999,16 @@ impl DefaultFunction {
Ok(value)
}
DefaultFunction::MkPairData => {
let (Value::Con(inner1), Value::Con(inner2)) = (&args[0], &args[1]) else {unreachable!()};
let (Value::Con(inner1), Value::Con(inner2)) = (&args[0], &args[1]) else {
unreachable!()
};
let Constant::Data(d1) = inner1.as_ref() else {unreachable!()};
let Constant::Data(d2) = inner2.as_ref() else {unreachable!()};
let Constant::Data(d1) = inner1.as_ref() else {
unreachable!()
};
let Constant::Data(d2) = inner2.as_ref() else {
unreachable!()
};
let constant = Constant::ProtoPair(
Type::Data,

View File

@ -66,56 +66,86 @@ impl Value {
}
pub(super) fn unwrap_integer(&self) -> &BigInt {
let Value::Con(inner) = self else {unreachable!()};
let Constant::Integer(integer) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::Integer(integer) = inner.as_ref() else {
unreachable!()
};
integer
}
pub(super) fn unwrap_byte_string(&self) -> &Vec<u8> {
let Value::Con(inner) = self else {unreachable!()};
let Constant::ByteString(byte_string) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::ByteString(byte_string) = inner.as_ref() else {
unreachable!()
};
byte_string
}
pub(super) fn unwrap_string(&self) -> &String {
let Value::Con(inner) = self else {unreachable!()};
let Constant::String(string) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::String(string) = inner.as_ref() else {
unreachable!()
};
string
}
pub(super) fn unwrap_bool(&self) -> &bool {
let Value::Con(inner) = self else {unreachable!()};
let Constant::Bool(condition) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::Bool(condition) = inner.as_ref() else {
unreachable!()
};
condition
}
pub(super) fn unwrap_pair(&self) -> (&Type, &Type, &Rc<Constant>, &Rc<Constant>) {
let Value::Con(inner) = self else {unreachable!()};
let Constant::ProtoPair(t1, t2, first, second) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::ProtoPair(t1, t2, first, second) = inner.as_ref() else {
unreachable!()
};
(t1, t2, first, second)
}
pub(super) fn unwrap_list(&self) -> (&Type, &Vec<Constant>) {
let Value::Con(inner) = self else {unreachable!()};
let Constant::ProtoList(t, list) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::ProtoList(t, list) = inner.as_ref() else {
unreachable!()
};
(t, list)
}
pub(super) fn unwrap_constant(&self) -> &Constant {
let Value::Con(item) = self else {unreachable!()};
let Value::Con(item) = self else {
unreachable!()
};
item.as_ref()
}
pub(super) fn unwrap_data_list(&self) -> &Vec<Constant> {
let Value::Con(inner) = self else {unreachable!()};
let Constant::ProtoList(Type::Data, list) = inner.as_ref() else {unreachable!()};
let Value::Con(inner) = self else {
unreachable!()
};
let Constant::ProtoList(Type::Data, list) = inner.as_ref() else {
unreachable!()
};
list
}

View File

@ -181,13 +181,15 @@ fn inline_direct_reduce(term: &mut Term<Name>) {
inline_direct_reduce(func);
inline_direct_reduce(arg);
let Term::Lambda { parameter_name, body } = func
let Term::Lambda {
parameter_name,
body,
} = func
else {
return;
};
let Term::Var(name) = body.as_ref()
else {
let Term::Var(name) = body.as_ref() else {
return;
};
@ -220,18 +222,23 @@ fn inline_identity_reduce(term: &mut Term<Name>) {
inline_identity_reduce(func);
inline_identity_reduce(arg);
let Term::Lambda { parameter_name, body } = func
let Term::Lambda {
parameter_name,
body,
} = func
else {
return;
};
let Term::Lambda { parameter_name: identity_name, body: identity_body } = arg
let Term::Lambda {
parameter_name: identity_name,
body: identity_body,
} = arg
else {
return;
};
let Term::Var(identity_var) = Rc::make_mut(identity_body)
else {
let Term::Var(identity_var) = Rc::make_mut(identity_body) else {
return;
};
@ -316,10 +323,7 @@ fn wrap_data_reduce(term: &mut Term<Name>) {
wrap_data_reduce(Rc::make_mut(body));
}
Term::Apply { function, argument } => {
let Term::Builtin(
first_action
) = function.as_ref()
else {
let Term::Builtin(first_action) = function.as_ref() else {
wrap_data_reduce(Rc::make_mut(function));
wrap_data_reduce(Rc::make_mut(argument));
return;
@ -330,8 +334,7 @@ fn wrap_data_reduce(term: &mut Term<Name>) {
argument: inner_arg,
} = Rc::make_mut(argument)
{
let Term::Builtin(second_action) = inner_func.as_ref()
else {
let Term::Builtin(second_action) = inner_func.as_ref() else {
wrap_data_reduce(Rc::make_mut(argument));
return;
};
@ -564,9 +567,11 @@ fn replace_identity_usage(term: &Term<Name>, original: Rc<Name>) -> Term<Name> {
let func = replace_identity_usage(func, original.clone());
let arg = replace_identity_usage(arg, original.clone());
let Term::Var(f) = function.as_ref()
else {
return Term::Apply { function: func.into(), argument: arg.into() }
let Term::Var(f) = function.as_ref() else {
return Term::Apply {
function: func.into(),
argument: arg.into(),
};
};
if f.as_ref() == original.as_ref() {