Skip to content

Commit

Permalink
Cargo fmt + clippy, with latest rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation authored and MicroProofs committed Aug 7, 2023
1 parent 0d99afe commit f464eb3
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 85 deletions.
58 changes: 39 additions & 19 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.")
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!()
};
Expand Down Expand Up @@ -1914,7 +1923,9 @@ impl<'a> CodeGenerator<'a> {
complex_clause,
..
} = props
else { unreachable!() };
else {
unreachable!()
};

let list_elem_types = subject_tipo.get_inner_types();

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -2925,7 +2943,9 @@ impl<'a> CodeGenerator<'a> {
builtin: None,
..
} = &constructor.variant
else { return };
else {
return;
};

let function_var_tipo = &constructor.tipo;

Expand All @@ -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)
Expand All @@ -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();

Expand Down
17 changes: 9 additions & 8 deletions crates/aiken-lang/src/tipo/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -356,7 +358,8 @@ fn infer_definition(
environment,
tracing,
kind,
)? else {
)?
else {
unreachable!(
"validator definition inferred as something other than a function?"
)
Expand Down Expand Up @@ -398,8 +401,6 @@ fn infer_definition(
})
.transpose();



Ok(Definition::Validator(Validator {
doc,
end_position,
Expand Down
5 changes: 2 additions & 3 deletions crates/aiken-project/src/tests/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ fn assert_uplc(source_code: &str, expected: Term<Name>, should_fail: bool) {
true,
);

let Some(checked_module) = modules.values().next()
else {
unreachable!("There's got to be one right?")
let Some(checked_module) = modules.values().next() else {
unreachable!("There's got to be one right?")
};

let mut scripts = vec![];
Expand Down
67 changes: 44 additions & 23 deletions crates/uplc/src/machine/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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()))
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -838,7 +843,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnConstrData".to_string(),
v.clone(),
))
));
};

let constant = Constant::ProtoPair(
Expand Down Expand Up @@ -876,7 +881,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnMapData".to_string(),
v.clone(),
))
));
};

let constant = Constant::ProtoList(
Expand Down Expand Up @@ -909,7 +914,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnListData".to_string(),
v.clone(),
))
));
};

let value = Value::list(
Expand All @@ -933,7 +938,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnIData".to_string(),
v.clone(),
))
));
};

let value = Value::integer(from_pallas_bigint(b));
Expand All @@ -951,7 +956,7 @@ impl DefaultFunction {
return Err(Error::DeserialisationError(
"UnBData".to_string(),
v.clone(),
))
));
};

let value = Value::byte_string(b.to_vec());
Expand All @@ -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();

Expand All @@ -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,
Expand Down
Loading

0 comments on commit f464eb3

Please sign in to comment.