mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Initial working version of proper try
keyword
This commit is contained in:
parent
a7168a4ad6
commit
eedade8e81
33 changed files with 1036 additions and 521 deletions
|
@ -31,6 +31,7 @@ pub struct Constraints {
|
|||
pub cycles: Vec<Cycle>,
|
||||
pub fx_call_constraints: Vec<FxCallConstraint>,
|
||||
pub fx_suffix_constraints: Vec<FxSuffixConstraint>,
|
||||
pub try_target_constraints: Vec<TryTargetConstraint>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Constraints {
|
||||
|
@ -87,6 +88,7 @@ impl Constraints {
|
|||
let cycles = Vec::new();
|
||||
let fx_call_constraints = Vec::with_capacity(16);
|
||||
let fx_suffix_constraints = Vec::new();
|
||||
let result_type_constraints = Vec::new();
|
||||
|
||||
categories.extend([
|
||||
Category::Record,
|
||||
|
@ -103,7 +105,6 @@ impl Constraints {
|
|||
Category::List,
|
||||
Category::Str,
|
||||
Category::Character,
|
||||
Category::Return,
|
||||
]);
|
||||
|
||||
pattern_categories.extend([
|
||||
|
@ -138,6 +139,7 @@ impl Constraints {
|
|||
cycles,
|
||||
fx_call_constraints,
|
||||
fx_suffix_constraints,
|
||||
try_target_constraints: result_type_constraints,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,6 +637,25 @@ impl Constraints {
|
|||
Constraint::FlexToPure(fx_var)
|
||||
}
|
||||
|
||||
pub fn try_target(
|
||||
&mut self,
|
||||
result_type_index: TypeOrVar,
|
||||
ok_payload_var: Variable,
|
||||
err_payload_var: Variable,
|
||||
region: Region,
|
||||
) -> Constraint {
|
||||
let constraint = TryTargetConstraint {
|
||||
target_type_index: result_type_index,
|
||||
ok_payload_var,
|
||||
err_payload_var,
|
||||
region,
|
||||
};
|
||||
|
||||
let constraint_index = index_push_new(&mut self.try_target_constraints, constraint);
|
||||
|
||||
Constraint::TryTarget(constraint_index)
|
||||
}
|
||||
|
||||
pub fn contains_save_the_environment(&self, constraint: &Constraint) -> bool {
|
||||
match constraint {
|
||||
Constraint::SaveTheEnvironment => true,
|
||||
|
@ -660,6 +681,7 @@ impl Constraints {
|
|||
| Constraint::Lookup(..)
|
||||
| Constraint::Pattern(..)
|
||||
| Constraint::ExpectEffectful(..)
|
||||
| Constraint::TryTarget(_)
|
||||
| Constraint::FxCall(_)
|
||||
| Constraint::FxSuffix(_)
|
||||
| Constraint::FlexToPure(_)
|
||||
|
@ -843,6 +865,8 @@ pub enum Constraint {
|
|||
FlexToPure(Variable),
|
||||
/// Expect statement or ignored def to be effectful
|
||||
ExpectEffectful(Variable, ExpectEffectfulReason, Region),
|
||||
/// Expect value to be some kind of Result
|
||||
TryTarget(Index<TryTargetConstraint>),
|
||||
/// Used for things that always unify, e.g. blanks and runtime errors
|
||||
True,
|
||||
SaveTheEnvironment,
|
||||
|
@ -909,6 +933,14 @@ pub struct IncludesTag {
|
|||
pub region: Region,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TryTargetConstraint {
|
||||
pub target_type_index: TypeOrVar,
|
||||
pub ok_payload_var: Variable,
|
||||
pub err_payload_var: Variable,
|
||||
pub region: Region,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Cycle {
|
||||
pub def_names: Slice<(Symbol, Region)>,
|
||||
|
@ -1000,6 +1032,9 @@ impl std::fmt::Debug for Constraint {
|
|||
Self::FlexToPure(arg0) => {
|
||||
write!(f, "FlexToPure({arg0:?})")
|
||||
}
|
||||
Self::TryTarget(arg0) => {
|
||||
write!(f, "ExpectResultType({arg0:?})")
|
||||
}
|
||||
Self::True => write!(f, "True"),
|
||||
Self::SaveTheEnvironment => write!(f, "SaveTheEnvironment"),
|
||||
Self::Let(arg0, arg1) => f.debug_tuple("Let").field(arg0).field(arg1).finish(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue