mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Fix effect module
This commit is contained in:
parent
e543dd4fe6
commit
23bbe0863b
4 changed files with 56 additions and 45 deletions
|
@ -978,7 +978,7 @@ fn build_effect_forever_inner_body(
|
|||
build_fresh_opaque_variables(var_store, introduced_variables);
|
||||
let pattern = Pattern::UnwrappedOpaque {
|
||||
whole_var,
|
||||
opaque: effect,
|
||||
opaque: effect_symbol,
|
||||
argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))),
|
||||
specialized_def_type,
|
||||
type_arguments,
|
||||
|
@ -1405,7 +1405,7 @@ pub fn build_host_exposed_def(
|
|||
scope: &mut Scope,
|
||||
symbol: Symbol,
|
||||
ident: &str,
|
||||
effect_tag_name: TagName,
|
||||
effect_symbol: Symbol,
|
||||
var_store: &mut VarStore,
|
||||
annotation: crate::annotation::Annotation,
|
||||
) -> Def {
|
||||
|
@ -1418,8 +1418,15 @@ pub fn build_host_exposed_def(
|
|||
let mut linked_symbol_arguments: Vec<(Variable, Expr)> = Vec::new();
|
||||
let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new();
|
||||
|
||||
let crate::annotation::Annotation {
|
||||
mut introduced_variables,
|
||||
typ,
|
||||
aliases,
|
||||
..
|
||||
} = annotation;
|
||||
|
||||
let def_body = {
|
||||
match annotation.typ.shallow_dealias() {
|
||||
match typ.shallow_dealias() {
|
||||
Type::Function(args, _, _) => {
|
||||
for i in 0..args.len() {
|
||||
let name = format!("closure_arg_{}_{}", ident, i);
|
||||
|
@ -1480,11 +1487,15 @@ pub fn build_host_exposed_def(
|
|||
loc_body: Box::new(Loc::at_zero(low_level_call)),
|
||||
});
|
||||
|
||||
let body = Expr::Tag {
|
||||
variant_var: var_store.fresh(),
|
||||
ext_var: var_store.fresh(),
|
||||
name: effect_tag_name,
|
||||
arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))],
|
||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
||||
let body = Expr::OpaqueRef {
|
||||
opaque_var: var_store.fresh(),
|
||||
name: effect_symbol,
|
||||
argument: Box::new((var_store.fresh(), Loc::at_zero(effect_closure))),
|
||||
specialized_def_type,
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
};
|
||||
|
||||
Expr::Closure(ClosureData {
|
||||
|
@ -1541,20 +1552,24 @@ pub fn build_host_exposed_def(
|
|||
loc_body: Box::new(Loc::at_zero(low_level_call)),
|
||||
});
|
||||
|
||||
Expr::Tag {
|
||||
variant_var: var_store.fresh(),
|
||||
ext_var: var_store.fresh(),
|
||||
name: effect_tag_name,
|
||||
arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))],
|
||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
||||
Expr::OpaqueRef {
|
||||
opaque_var: var_store.fresh(),
|
||||
name: effect_symbol,
|
||||
argument: Box::new((var_store.fresh(), Loc::at_zero(effect_closure))),
|
||||
specialized_def_type,
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let def_annotation = crate::def::Annotation {
|
||||
signature: annotation.typ,
|
||||
introduced_variables: annotation.introduced_variables,
|
||||
aliases: annotation.aliases,
|
||||
signature: typ,
|
||||
introduced_variables,
|
||||
aliases,
|
||||
region: Region::zero(),
|
||||
};
|
||||
|
||||
|
@ -1567,6 +1582,16 @@ pub fn build_host_exposed_def(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn build_effect_actual(effect_symbol: Symbol, a_type: Type, var_store: &mut VarStore) -> Type {
|
||||
let closure_var = var_store.fresh();
|
||||
|
||||
Type::Function(
|
||||
vec![Type::EmptyRec],
|
||||
Box::new(Type::Variable(closure_var)),
|
||||
Box::new(a_type),
|
||||
)
|
||||
}
|
||||
|
||||
/// Effect a := {} -> a
|
||||
fn build_effect_opaque(
|
||||
effect_symbol: Symbol,
|
||||
|
@ -1615,26 +1640,6 @@ fn build_fresh_opaque_variables(
|
|||
(Box::new(actual), type_arguments, lambda_set_variables)
|
||||
}
|
||||
|
||||
pub fn build_effect_actual(
|
||||
effect_tag_name: TagName,
|
||||
a_type: Type,
|
||||
var_store: &mut VarStore,
|
||||
) -> Type {
|
||||
let closure_var = var_store.fresh();
|
||||
|
||||
Type::TagUnion(
|
||||
vec![(
|
||||
effect_tag_name,
|
||||
vec![Type::Function(
|
||||
vec![Type::EmptyRec],
|
||||
Box::new(Type::Variable(closure_var)),
|
||||
Box::new(a_type),
|
||||
)],
|
||||
)],
|
||||
TypeExtension::Closed,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn empty_record_pattern(var_store: &mut VarStore) -> Pattern {
|
||||
Pattern::RecordDestructure {
|
||||
|
|
|
@ -8,8 +8,8 @@ use crate::pattern::Pattern;
|
|||
use crate::scope::Scope;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::{MutMap, SendMap, VecSet};
|
||||
use roc_module::ident::Ident;
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::ident::{Ident, TagName};
|
||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||
use roc_parse::ast;
|
||||
use roc_parse::header::HeaderFor;
|
||||
|
@ -116,13 +116,11 @@ impl GeneratedInfo {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let effect_tag_name = TagName::Private(effect_symbol);
|
||||
|
||||
{
|
||||
let a_var = var_store.fresh();
|
||||
|
||||
let actual = crate::effect_module::build_effect_actual(
|
||||
effect_tag_name,
|
||||
effect_symbol,
|
||||
Type::Variable(a_var),
|
||||
var_store,
|
||||
);
|
||||
|
@ -132,7 +130,7 @@ impl GeneratedInfo {
|
|||
Region::zero(),
|
||||
vec![Loc::at_zero(("a".into(), a_var))],
|
||||
actual,
|
||||
AliasKind::Structural,
|
||||
AliasKind::Opaque,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -433,7 +431,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
&mut scope,
|
||||
*symbol,
|
||||
&ident,
|
||||
TagName::Private(effect_symbol),
|
||||
effect_symbol,
|
||||
var_store,
|
||||
annotation,
|
||||
);
|
||||
|
|
|
@ -845,9 +845,16 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f
|
|||
for var in slice {
|
||||
write!(
|
||||
f,
|
||||
"<{:?}>{:?} ",
|
||||
"<{:?}>{} ",
|
||||
var,
|
||||
if var.index() == 304 {
|
||||
format!("{}", "*304")
|
||||
} else {
|
||||
format!(
|
||||
"{:?}",
|
||||
SubsFmtContent(subs.get_content_without_compacting(*var), subs)
|
||||
)
|
||||
}
|
||||
)?;
|
||||
}
|
||||
write!(f, ", ")?;
|
||||
|
|
|
@ -387,7 +387,8 @@ impl<'a> RocDocAllocator<'a> {
|
|||
match tn {
|
||||
TagName::Global(uppercase) => self.global_tag_name(uppercase),
|
||||
TagName::Private(symbol) => self.private_tag_name(symbol),
|
||||
TagName::Closure(_symbol) => unreachable!("closure tags are internal only"),
|
||||
TagName::Closure(symbol) => self.private_tag_name(symbol),
|
||||
// TagName::Closure(_symbol) => unreachable!("closure tags are internal only"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue