Review & fix acceptance tests
Temporarily using the 'specialize-dict-key' branch from the stdlib which makes use of Pair where relevant. Once this is merged back into 'main' we should update the acceptance test toml files to keep getting them automatically upgraded. This commit also fixes an oversight in the reification of data-types now properly distinguishing between pairs and 2-tuples. Co-authored-by: Microproofs <kasey.white@cardanofoundation.org>
This commit is contained in:
@@ -5,8 +5,8 @@ use crate::{
|
||||
},
|
||||
expr::TypedExpr,
|
||||
tipo::{
|
||||
fields::FieldMap, AccessorsMap, RecordAccessor, Type, TypeAliasAnnotation, TypeConstructor,
|
||||
TypeInfo, TypeVar, ValueConstructor, ValueConstructorVariant,
|
||||
fields::FieldMap, Type, TypeAliasAnnotation, TypeConstructor, TypeInfo, TypeVar,
|
||||
ValueConstructor, ValueConstructorVariant,
|
||||
},
|
||||
IdGenerator,
|
||||
};
|
||||
@@ -343,59 +343,6 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
||||
.types_constructors
|
||||
.insert(PAIR.to_string(), vec![PAIR.to_string()]);
|
||||
|
||||
let mut pair_fields = HashMap::new();
|
||||
pair_fields.insert("fst".to_string(), (0, Span::empty()));
|
||||
pair_fields.insert("snd".to_string(), (1, Span::empty()));
|
||||
prelude.values.insert(
|
||||
PAIR.to_string(),
|
||||
ValueConstructor::public(
|
||||
function(
|
||||
vec![fst_parameter.clone(), snd_parameter.clone()],
|
||||
pair(fst_parameter.clone(), snd_parameter.clone()),
|
||||
),
|
||||
ValueConstructorVariant::Record {
|
||||
module: "".into(),
|
||||
name: PAIR.to_string(),
|
||||
field_map: Some(FieldMap {
|
||||
arity: 2,
|
||||
fields: pair_fields,
|
||||
is_function: false,
|
||||
}),
|
||||
arity: 2,
|
||||
location: Span::empty(),
|
||||
constructors_count: 1,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
let mut accessors = HashMap::new();
|
||||
accessors.insert(
|
||||
"fst".to_string(),
|
||||
RecordAccessor {
|
||||
index: 0,
|
||||
label: "fst".to_string(),
|
||||
tipo: fst_parameter.clone(),
|
||||
},
|
||||
);
|
||||
|
||||
accessors.insert(
|
||||
"snd".to_string(),
|
||||
RecordAccessor {
|
||||
index: 1,
|
||||
label: "snd".to_string(),
|
||||
tipo: snd_parameter.clone(),
|
||||
},
|
||||
);
|
||||
|
||||
prelude.accessors.insert(
|
||||
PAIR.to_string(),
|
||||
AccessorsMap {
|
||||
public: true,
|
||||
tipo: pair(fst_parameter.clone(), snd_parameter.clone()),
|
||||
accessors,
|
||||
},
|
||||
);
|
||||
|
||||
// String
|
||||
prelude.types.insert(
|
||||
STRING.to_string(),
|
||||
|
||||
@@ -793,11 +793,10 @@ impl UntypedExpr {
|
||||
},
|
||||
|
||||
uplc::ast::Constant::ProtoPair(_, _, left, right) => match tipo {
|
||||
Type::Tuple { elems, .. } => Ok(UntypedExpr::Tuple {
|
||||
location: Span::empty(),
|
||||
elems: [left.as_ref(), right.as_ref()]
|
||||
Type::Pair { fst, snd, .. } => {
|
||||
let elems = [left.as_ref(), right.as_ref()]
|
||||
.into_iter()
|
||||
.zip(elems)
|
||||
.zip([fst, snd])
|
||||
.map(|(arg, arg_type)| {
|
||||
UntypedExpr::do_reify_constant(
|
||||
generics,
|
||||
@@ -806,10 +805,16 @@ impl UntypedExpr {
|
||||
arg_type,
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
}),
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(UntypedExpr::Pair {
|
||||
location: Span::empty(),
|
||||
fst: elems.first().unwrap().to_owned().into(),
|
||||
snd: elems.last().unwrap().to_owned().into(),
|
||||
})
|
||||
}
|
||||
_ => Err(format!(
|
||||
"invalid type annotation. expected Tuple but got: {tipo:?}"
|
||||
"invalid type annotation. expected Pair but got: {tipo:?}"
|
||||
)),
|
||||
},
|
||||
|
||||
@@ -904,9 +909,10 @@ impl UntypedExpr {
|
||||
location: Span::empty(),
|
||||
elements: kvs
|
||||
.into_iter()
|
||||
.map(|(k, v)| UntypedExpr::Tuple {
|
||||
.map(|(k, v)| UntypedExpr::Pair {
|
||||
location: Span::empty(),
|
||||
elems: vec![UntypedExpr::reify_blind(k), UntypedExpr::reify_blind(v)],
|
||||
fst: UntypedExpr::reify_blind(k).into(),
|
||||
snd: UntypedExpr::reify_blind(v).into(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
tail: None,
|
||||
@@ -1022,6 +1028,21 @@ impl UntypedExpr {
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
}),
|
||||
Type::Pair { fst, snd, .. } => {
|
||||
let mut elems = args
|
||||
.into_iter()
|
||||
.zip([fst, snd])
|
||||
.map(|(arg, arg_type)| {
|
||||
UntypedExpr::do_reify_data(generics, data_types, arg, arg_type)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(UntypedExpr::Pair {
|
||||
location: Span::empty(),
|
||||
fst: elems.remove(0).into(),
|
||||
snd: elems.remove(0).into(),
|
||||
})
|
||||
}
|
||||
_ => Err(format!(
|
||||
"invalid type annotation. expected List but got: {tipo:?}"
|
||||
)),
|
||||
|
||||
Reference in New Issue
Block a user