Skip to content

Commit

Permalink
More code cleanup, features, tests, t and bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgswords authored and tzakian committed Jan 24, 2024
1 parent 721f9fa commit 7d8f642
Show file tree
Hide file tree
Showing 19 changed files with 558 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 5 tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//# init --edition 2024.alpha

//# publish
module 0x42::D {
public enum T {
A,
}

public fun foo(): T {
T::A
}
}

//# publish
module 0x42::C {
public enum T has drop {
A,
}

public fun foo(): T {
T::A
}
}

//# publish
// names used to try to force an ordering of depedencies
module 0x42::B {
public fun foo(): (0x42::C::T, 0x42::D::T) {
(0x42::C::foo(), 0x42::D::foo())
}
}

//# publish
module 0x42::A {
public struct T {
t_c: 0x42::C::T,
t_d: 0x42::D::T,
}
public fun foo(): T {
let (t_c, t_d) = 0x42::B::foo();
T { t_c, t_d }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
translate::{display_var, DisplayVar},
},
parser::ast::BinOp_,
shared::{ast_debug::AstDebug, unique_map::UniqueMap, CompilationEnv},
shared::{unique_map::UniqueMap, CompilationEnv},
};
use move_ir_types::ast::UnpackType;
use state::{Value, *};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl PatternMatrix {
let xloc = x.loc;
if let Some(y) = env.get(&x) {
TP::At(
sp(xloc, y.value.clone()),
sp(xloc, y.value),
Box::new(apply_pattern_subst(*inner, env)),
)
} else {
Expand All @@ -318,7 +318,7 @@ impl PatternMatrix {
TP::Binder(x) => {
let xloc = x.loc;
if let Some(y) = env.get(&x) {
TP::Binder(sp(xloc, y.value.clone()))
TP::Binder(sp(xloc, y.value))
} else {
TP::Wildcard
}
Expand Down Expand Up @@ -662,7 +662,7 @@ pub fn compile_match(
let subject_borrow_rhs = make_var_ref(subject_entry.clone());

let match_entry = FringeEntry {
var: match_var.clone(),
var: match_var,
ty: subject_borrow_rhs.ty.clone(),
};

Expand Down Expand Up @@ -1049,11 +1049,10 @@ fn resolve_result(
let false_arm = resolve_result(context, init_subject, false_arm_result);
let result_type = true_arm.ty.clone();

let result = make_copy_bindings(
make_copy_bindings(
bindings,
make_if_else(lit_subject, true_arm, false_arm, result_type),
);
result
)
}
WorkResult::LiteralSwitch {
subject,
Expand Down Expand Up @@ -1161,15 +1160,12 @@ fn make_arm_unpack(
match pat.pat.value {
TP::Constructor(mident, enum_, variant, tyargs, fields)
| TP::BorrowConstructor(mident, enum_, variant, tyargs, fields) => {
if matches!(entry.ty.value, N::Type_::Ref(_, _)) {
if fields
.iter()
.all(|(_, _, (_, (_, pat)))| matches!(pat.pat.value, TP::Wildcard))
|| fields.is_empty()
{
continue;
}
}
let all_wild = fields
.iter()
.all(|(_, _, (_, (_, pat)))| matches!(pat.pat.value, TP::Wildcard)) || fields.is_empty();
if matches!(entry.ty.value, N::Type_::Ref(_, _)) && all_wild {
continue;
}
let field_pats = fields.clone().map(|_key, (ndx, (_, pat))| (ndx, pat));

let field_tys = fields.map(|_key, (ndx, (ty, _))| (ndx, ty));
Expand All @@ -1185,7 +1181,7 @@ fn make_arm_unpack(

let mut unpack_fields: Vec<(Field, Var, Type)> = vec![];
for (fringe_exp, (_, field, _)) in fringe_exps.iter().zip(ordered_pats.iter()) {
unpack_fields.push((*field, fringe_exp.var.clone(), fringe_exp.ty.clone()));
unpack_fields.push((*field, fringe_exp.var, fringe_exp.ty.clone()));
}
for (fringe_exp, (_, _, ordered_pat)) in
fringe_exps.into_iter().zip(ordered_pats.into_iter()).rev()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ pub fn write_module_to_string(
members.push("".to_string());
}

for _edef in module.enum_defs() {
todo!();
}
if !module.enum_defs().is_empty() {
members.push("".to_string());
}

let mut externally_visible_funs = module
.function_defs()
.iter()
Expand Down
24 changes: 19 additions & 5 deletions external-crates/move/crates/move-compiler/src/naming/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ impl<'env> Context<'env> {
(ename, type_info)
})
.collect::<BTreeMap<_, _>>();
let emems_set = emems.keys().collect::<BTreeSet<_>>();
let smems_set = smems.keys().collect::<BTreeSet<_>>();
assert!(emems_set.intersection(&smems_set).count() == 0);
/* duplicates were already reported by expasion */
smems.append(&mut emems);
smems
};
Expand Down Expand Up @@ -934,13 +932,29 @@ fn module(
let unscoped = context.save_unscoped();
let use_funs = use_funs(context, euse_funs);
let friends = efriends.filter_map(|mident, f| friend(context, mident, f));
let struct_names = estructs
.key_cloned_iter()
.map(|(k, _)| k)
.collect::<BTreeSet<_>>();
let enum_names = eenums
.key_cloned_iter()
.map(|(k, _)| k)
.collect::<BTreeSet<_>>();
let enum_struct_intersection = enum_names
.intersection(&struct_names)
.collect::<BTreeSet<_>>();
let structs = estructs.map(|name, s| {
context.restore_unscoped(unscoped.clone());
struct_def(context, name, s)
});
let enums = eenums.map(|name, e| {
// simply for compilation to continue in the presence of errors, we remove the duplicates
let enums = eenums.filter_map(|name, e| {
context.restore_unscoped(unscoped.clone());
enum_def(context, name, e)
if enum_struct_intersection.contains(&name) {
None
} else {
Some(enum_def(context, name, e))
}
});
let functions = efunctions.map(|name, f| {
context.restore_unscoped(unscoped.clone());
Expand Down
7 changes: 7 additions & 0 deletions external-crates/move/crates/move-compiler/src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,20 +741,27 @@ pub type MatchArm = Spanned<MatchArm_>;

#[derive(Debug, Clone, PartialEq)]
pub enum MatchPattern_ {
// T<t1, ..., tn>(pat1, ..., patn)
PositionalConstructor(
NameAccessChain,
Option<Vec<Type>>,
Spanned<Vec<MatchPattern>>,
),
// T<t1, ..., tn> { x1: pat1, ..., xn: patn }
FieldConstructor(
NameAccessChain,
Option<Vec<Type>>,
Spanned<Vec<(Field, MatchPattern)>>,
),
// T<t1, ..., tn>
Name(NameAccessChain, Option<Vec<Type>>),
//
Literal(Value),
// _
Wildcard,
// pat1 | pat2
Or(Box<MatchPattern>, Box<MatchPattern>),
// x @ pat
At(Var, Box<MatchPattern>),
}

Expand Down
Loading

0 comments on commit 7d8f642

Please sign in to comment.