Revert "fix: nested list issues in when statements"
This reverts commit 542962a2ea
.
This commit is contained in:
parent
613fb3c957
commit
4b34617466
|
@ -134,6 +134,7 @@ pub enum Air {
|
||||||
tail_name: String,
|
tail_name: String,
|
||||||
next_tail_name: Option<String>,
|
next_tail_name: Option<String>,
|
||||||
complex_clause: bool,
|
complex_clause: bool,
|
||||||
|
inverse: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
TupleClause {
|
TupleClause {
|
||||||
|
@ -152,14 +153,6 @@ pub enum Air {
|
||||||
tipo: Arc<Type>,
|
tipo: Arc<Type>,
|
||||||
},
|
},
|
||||||
|
|
||||||
ListClauseGuard {
|
|
||||||
scope: Vec<u64>,
|
|
||||||
tipo: Arc<Type>,
|
|
||||||
tail_name: String,
|
|
||||||
next_tail_name: Option<String>,
|
|
||||||
inverse: bool,
|
|
||||||
},
|
|
||||||
|
|
||||||
Discard {
|
Discard {
|
||||||
scope: Vec<u64>,
|
scope: Vec<u64>,
|
||||||
},
|
},
|
||||||
|
@ -271,7 +264,6 @@ impl Air {
|
||||||
| Air::Clause { scope, .. }
|
| Air::Clause { scope, .. }
|
||||||
| Air::ListClause { scope, .. }
|
| Air::ListClause { scope, .. }
|
||||||
| Air::ClauseGuard { scope, .. }
|
| Air::ClauseGuard { scope, .. }
|
||||||
| Air::ListClauseGuard { scope, .. }
|
|
||||||
| Air::Discard { scope }
|
| Air::Discard { scope }
|
||||||
| Air::Finally { scope }
|
| Air::Finally { scope }
|
||||||
| Air::If { scope, .. }
|
| Air::If { scope, .. }
|
||||||
|
|
|
@ -1283,6 +1283,7 @@ pub fn monomorphize(
|
||||||
tail_name,
|
tail_name,
|
||||||
complex_clause,
|
complex_clause,
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
|
inverse,
|
||||||
} => {
|
} => {
|
||||||
if tipo.is_generic() {
|
if tipo.is_generic() {
|
||||||
let mut tipo = tipo.clone();
|
let mut tipo = tipo.clone();
|
||||||
|
@ -1294,6 +1295,7 @@ pub fn monomorphize(
|
||||||
tail_name,
|
tail_name,
|
||||||
complex_clause,
|
complex_clause,
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
|
inverse,
|
||||||
};
|
};
|
||||||
needs_variant = false;
|
needs_variant = false;
|
||||||
}
|
}
|
||||||
|
@ -1315,27 +1317,6 @@ pub fn monomorphize(
|
||||||
needs_variant = false;
|
needs_variant = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Air::ListClauseGuard {
|
|
||||||
scope,
|
|
||||||
tipo,
|
|
||||||
tail_name,
|
|
||||||
next_tail_name,
|
|
||||||
inverse,
|
|
||||||
} => {
|
|
||||||
if tipo.is_generic() {
|
|
||||||
let mut tipo = tipo.clone();
|
|
||||||
find_generics_to_replace(&mut tipo, &generic_types);
|
|
||||||
|
|
||||||
new_air[index] = Air::ListClauseGuard {
|
|
||||||
scope,
|
|
||||||
tipo,
|
|
||||||
tail_name,
|
|
||||||
next_tail_name,
|
|
||||||
inverse,
|
|
||||||
};
|
|
||||||
needs_variant = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Air::RecordAccess {
|
Air::RecordAccess {
|
||||||
scope,
|
scope,
|
||||||
index: record_index,
|
index: record_index,
|
||||||
|
|
|
@ -617,6 +617,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tail_name: subject_name,
|
tail_name: subject_name,
|
||||||
next_tail_name: next_tail,
|
next_tail_name: next_tail,
|
||||||
complex_clause: *clause_properties.is_complex_clause(),
|
complex_clause: *clause_properties.is_complex_clause(),
|
||||||
|
inverse: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
match clause_properties {
|
match clause_properties {
|
||||||
|
@ -757,6 +758,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
*clause_properties.needs_constr_var() = false;
|
*clause_properties.needs_constr_var() = false;
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
self.when_recursive_ir(
|
self.when_recursive_ir(
|
||||||
pattern,
|
pattern,
|
||||||
pattern_vec,
|
pattern_vec,
|
||||||
|
@ -1186,12 +1191,29 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let new_tail_name = "__list_tail".to_string();
|
let new_tail_name = "__list_tail".to_string();
|
||||||
|
|
||||||
if elements.is_empty() {
|
if elements.is_empty() {
|
||||||
pattern_vec.push(Air::ListClauseGuard {
|
pattern_vec.push(Air::ListClause {
|
||||||
scope,
|
scope: scope.clone(),
|
||||||
tipo: pattern_type.clone(),
|
tipo: pattern_type.clone(),
|
||||||
tail_name: item_name.clone(),
|
tail_name: item_name.clone(),
|
||||||
next_tail_name: None,
|
next_tail_name: None,
|
||||||
inverse: false,
|
complex_clause: false,
|
||||||
|
inverse: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Var {
|
||||||
|
scope,
|
||||||
|
constructor: ValueConstructor::public(
|
||||||
|
pattern_type.clone(),
|
||||||
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
location: Span::empty(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name: "__other_clauses_delayed".to_string(),
|
||||||
|
variant_name: String::new(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
for (index, _) in elements.iter().enumerate() {
|
for (index, _) in elements.iter().enumerate() {
|
||||||
|
@ -1219,12 +1241,29 @@ impl<'a> CodeGenerator<'a> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
pattern_vec.push(Air::ListClauseGuard {
|
pattern_vec.push(Air::ListClause {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: pattern_type.clone(),
|
tipo: pattern_type.clone(),
|
||||||
tail_name: prev_tail_name,
|
tail_name: prev_tail_name,
|
||||||
next_tail_name: Some(tail_name),
|
next_tail_name: Some(tail_name),
|
||||||
inverse: true,
|
complex_clause: false,
|
||||||
|
inverse: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Var {
|
||||||
|
scope: scope.clone(),
|
||||||
|
constructor: ValueConstructor::public(
|
||||||
|
pattern_type.clone(),
|
||||||
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
location: Span::empty(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name: "__other_clauses_delayed".to_string(),
|
||||||
|
variant_name: "".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.when_ir(
|
self.when_ir(
|
||||||
|
@ -1236,20 +1275,54 @@ impl<'a> CodeGenerator<'a> {
|
||||||
scope.clone(),
|
scope.clone(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
pattern_vec.push(Air::ListClauseGuard {
|
pattern_vec.push(Air::ListClause {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: pattern_type.clone(),
|
tipo: pattern_type.clone(),
|
||||||
tail_name: prev_tail_name,
|
tail_name: prev_tail_name,
|
||||||
next_tail_name: Some(tail_name.clone()),
|
next_tail_name: Some(tail_name.clone()),
|
||||||
inverse: true,
|
complex_clause: false,
|
||||||
|
inverse: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
pattern_vec.push(Air::ListClauseGuard {
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Var {
|
||||||
|
scope: scope.clone(),
|
||||||
|
constructor: ValueConstructor::public(
|
||||||
|
pattern_type.clone(),
|
||||||
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
location: Span::empty(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name: "__other_clauses_delayed".to_string(),
|
||||||
|
variant_name: String::new(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::ListClause {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: pattern_type.clone(),
|
tipo: pattern_type.clone(),
|
||||||
tail_name: tail_name.clone(),
|
tail_name: tail_name.clone(),
|
||||||
next_tail_name: None,
|
next_tail_name: None,
|
||||||
inverse: false,
|
complex_clause: false,
|
||||||
|
inverse: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Var {
|
||||||
|
scope: scope.clone(),
|
||||||
|
constructor: ValueConstructor::public(
|
||||||
|
pattern_type.clone(),
|
||||||
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
location: Span::empty(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name: "__other_clauses_delayed".to_string(),
|
||||||
|
variant_name: String::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.when_ir(
|
self.when_ir(
|
||||||
|
@ -1268,12 +1341,29 @@ impl<'a> CodeGenerator<'a> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
pattern_vec.push(Air::ListClauseGuard {
|
pattern_vec.push(Air::ListClause {
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
tipo: pattern_type.clone(),
|
tipo: pattern_type.clone(),
|
||||||
tail_name: prev_tail_name,
|
tail_name: prev_tail_name,
|
||||||
next_tail_name: Some(tail_name),
|
next_tail_name: Some(tail_name),
|
||||||
inverse: true,
|
complex_clause: false,
|
||||||
|
inverse: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Discard {
|
||||||
|
scope: scope.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
pattern_vec.push(Air::Var {
|
||||||
|
scope: scope.clone(),
|
||||||
|
constructor: ValueConstructor::public(
|
||||||
|
pattern_type.clone(),
|
||||||
|
ValueConstructorVariant::LocalVariable {
|
||||||
|
location: Span::empty(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name: "__other_clauses_delayed".to_string(),
|
||||||
|
variant_name: "".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.when_ir(
|
self.when_ir(
|
||||||
|
@ -3392,6 +3482,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.into(),
|
.into(),
|
||||||
argument: Term::Delay(term.into()).into(),
|
argument: Term::Delay(term.into()).into(),
|
||||||
}
|
}
|
||||||
|
.force_wrap()
|
||||||
} else {
|
} else {
|
||||||
term = delayed_if_else(
|
term = delayed_if_else(
|
||||||
Term::Apply {
|
Term::Apply {
|
||||||
|
@ -3408,11 +3499,26 @@ impl<'a> CodeGenerator<'a> {
|
||||||
Air::ListClause {
|
Air::ListClause {
|
||||||
tail_name,
|
tail_name,
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
|
inverse,
|
||||||
complex_clause,
|
complex_clause,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
|
// discard to pop off
|
||||||
|
let _ = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
// the body to be run if the clause matches
|
||||||
|
// the next branch in the when expression
|
||||||
|
let (body, mut term) = if inverse {
|
||||||
|
let term = arg_stack.pop().unwrap();
|
||||||
let body = arg_stack.pop().unwrap();
|
let body = arg_stack.pop().unwrap();
|
||||||
let mut term = arg_stack.pop().unwrap();
|
|
||||||
|
(body, term)
|
||||||
|
} else {
|
||||||
|
let body = arg_stack.pop().unwrap();
|
||||||
|
let term = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
(body, term)
|
||||||
|
};
|
||||||
|
|
||||||
let arg = if let Some(next_tail_name) = next_tail_name {
|
let arg = if let Some(next_tail_name) = next_tail_name {
|
||||||
Term::Apply {
|
Term::Apply {
|
||||||
|
@ -3513,7 +3619,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
} else if tipo.is_list() {
|
} else if tipo.is_list() {
|
||||||
unreachable!()
|
todo!()
|
||||||
} else {
|
} else {
|
||||||
Term::Apply {
|
Term::Apply {
|
||||||
function: DefaultFunction::EqualsInteger.into(),
|
function: DefaultFunction::EqualsInteger.into(),
|
||||||
|
@ -3540,70 +3646,6 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
Air::ListClauseGuard {
|
|
||||||
tail_name,
|
|
||||||
next_tail_name,
|
|
||||||
inverse,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
// the body to be run if the clause matches
|
|
||||||
// the next branch in the when expression
|
|
||||||
let mut term = arg_stack.pop().unwrap();
|
|
||||||
|
|
||||||
term = if let Some(next_tail_name) = next_tail_name {
|
|
||||||
Term::Apply {
|
|
||||||
function: Term::Lambda {
|
|
||||||
parameter_name: Name {
|
|
||||||
text: next_tail_name,
|
|
||||||
unique: 0.into(),
|
|
||||||
},
|
|
||||||
body: term.into(),
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
argument: Term::Apply {
|
|
||||||
function: Term::Builtin(DefaultFunction::TailList).force_wrap().into(),
|
|
||||||
argument: Term::Var(Name {
|
|
||||||
text: tail_name.clone(),
|
|
||||||
unique: 0.into(),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
term
|
|
||||||
};
|
|
||||||
|
|
||||||
if !inverse {
|
|
||||||
term = choose_list(
|
|
||||||
Term::Var(Name {
|
|
||||||
text: tail_name,
|
|
||||||
unique: 0.into(),
|
|
||||||
}),
|
|
||||||
Term::Delay(term.into()),
|
|
||||||
Term::Var(Name {
|
|
||||||
text: "__other_clauses_delayed".to_string(),
|
|
||||||
unique: 0.into(),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.force_wrap();
|
|
||||||
} else {
|
|
||||||
term = choose_list(
|
|
||||||
Term::Var(Name {
|
|
||||||
text: tail_name,
|
|
||||||
unique: 0.into(),
|
|
||||||
}),
|
|
||||||
Term::Var(Name {
|
|
||||||
text: "__other_clauses_delayed".to_string(),
|
|
||||||
unique: 0.into(),
|
|
||||||
}),
|
|
||||||
Term::Delay(term.into()),
|
|
||||||
)
|
|
||||||
.force_wrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_stack.push(term);
|
|
||||||
}
|
|
||||||
Air::Finally { .. } => {
|
Air::Finally { .. } => {
|
||||||
let _clause = arg_stack.pop().unwrap();
|
let _clause = arg_stack.pop().unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue