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);
|
build_fresh_opaque_variables(var_store, introduced_variables);
|
||||||
let pattern = Pattern::UnwrappedOpaque {
|
let pattern = Pattern::UnwrappedOpaque {
|
||||||
whole_var,
|
whole_var,
|
||||||
opaque: effect,
|
opaque: effect_symbol,
|
||||||
argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))),
|
argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))),
|
||||||
specialized_def_type,
|
specialized_def_type,
|
||||||
type_arguments,
|
type_arguments,
|
||||||
|
@ -1405,7 +1405,7 @@ pub fn build_host_exposed_def(
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
ident: &str,
|
ident: &str,
|
||||||
effect_tag_name: TagName,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
annotation: crate::annotation::Annotation,
|
annotation: crate::annotation::Annotation,
|
||||||
) -> Def {
|
) -> Def {
|
||||||
|
@ -1418,8 +1418,15 @@ pub fn build_host_exposed_def(
|
||||||
let mut linked_symbol_arguments: Vec<(Variable, Expr)> = Vec::new();
|
let mut linked_symbol_arguments: Vec<(Variable, Expr)> = Vec::new();
|
||||||
let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new();
|
let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new();
|
||||||
|
|
||||||
|
let crate::annotation::Annotation {
|
||||||
|
mut introduced_variables,
|
||||||
|
typ,
|
||||||
|
aliases,
|
||||||
|
..
|
||||||
|
} = annotation;
|
||||||
|
|
||||||
let def_body = {
|
let def_body = {
|
||||||
match annotation.typ.shallow_dealias() {
|
match typ.shallow_dealias() {
|
||||||
Type::Function(args, _, _) => {
|
Type::Function(args, _, _) => {
|
||||||
for i in 0..args.len() {
|
for i in 0..args.len() {
|
||||||
let name = format!("closure_arg_{}_{}", ident, i);
|
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)),
|
loc_body: Box::new(Loc::at_zero(low_level_call)),
|
||||||
});
|
});
|
||||||
|
|
||||||
let body = Expr::Tag {
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
variant_var: var_store.fresh(),
|
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
||||||
ext_var: var_store.fresh(),
|
let body = Expr::OpaqueRef {
|
||||||
name: effect_tag_name,
|
opaque_var: var_store.fresh(),
|
||||||
arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))],
|
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 {
|
Expr::Closure(ClosureData {
|
||||||
|
@ -1541,20 +1552,24 @@ pub fn build_host_exposed_def(
|
||||||
loc_body: Box::new(Loc::at_zero(low_level_call)),
|
loc_body: Box::new(Loc::at_zero(low_level_call)),
|
||||||
});
|
});
|
||||||
|
|
||||||
Expr::Tag {
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
variant_var: var_store.fresh(),
|
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
||||||
ext_var: var_store.fresh(),
|
Expr::OpaqueRef {
|
||||||
name: effect_tag_name,
|
opaque_var: var_store.fresh(),
|
||||||
arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))],
|
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 {
|
let def_annotation = crate::def::Annotation {
|
||||||
signature: annotation.typ,
|
signature: typ,
|
||||||
introduced_variables: annotation.introduced_variables,
|
introduced_variables,
|
||||||
aliases: annotation.aliases,
|
aliases,
|
||||||
region: Region::zero(),
|
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
|
/// Effect a := {} -> a
|
||||||
fn build_effect_opaque(
|
fn build_effect_opaque(
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
|
@ -1615,26 +1640,6 @@ fn build_fresh_opaque_variables(
|
||||||
(Box::new(actual), type_arguments, lambda_set_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)]
|
#[inline(always)]
|
||||||
fn empty_record_pattern(var_store: &mut VarStore) -> Pattern {
|
fn empty_record_pattern(var_store: &mut VarStore) -> Pattern {
|
||||||
Pattern::RecordDestructure {
|
Pattern::RecordDestructure {
|
||||||
|
|
|
@ -8,8 +8,8 @@ use crate::pattern::Pattern;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_collections::{MutMap, SendMap, VecSet};
|
use roc_collections::{MutMap, SendMap, VecSet};
|
||||||
|
use roc_module::ident::Ident;
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::ident::{Ident, TagName};
|
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_parse::header::HeaderFor;
|
use roc_parse::header::HeaderFor;
|
||||||
|
@ -116,13 +116,11 @@ impl GeneratedInfo {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let effect_tag_name = TagName::Private(effect_symbol);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let a_var = var_store.fresh();
|
let a_var = var_store.fresh();
|
||||||
|
|
||||||
let actual = crate::effect_module::build_effect_actual(
|
let actual = crate::effect_module::build_effect_actual(
|
||||||
effect_tag_name,
|
effect_symbol,
|
||||||
Type::Variable(a_var),
|
Type::Variable(a_var),
|
||||||
var_store,
|
var_store,
|
||||||
);
|
);
|
||||||
|
@ -132,7 +130,7 @@ impl GeneratedInfo {
|
||||||
Region::zero(),
|
Region::zero(),
|
||||||
vec![Loc::at_zero(("a".into(), a_var))],
|
vec![Loc::at_zero(("a".into(), a_var))],
|
||||||
actual,
|
actual,
|
||||||
AliasKind::Structural,
|
AliasKind::Opaque,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +431,7 @@ pub fn canonicalize_module_defs<'a>(
|
||||||
&mut scope,
|
&mut scope,
|
||||||
*symbol,
|
*symbol,
|
||||||
&ident,
|
&ident,
|
||||||
TagName::Private(effect_symbol),
|
effect_symbol,
|
||||||
var_store,
|
var_store,
|
||||||
annotation,
|
annotation,
|
||||||
);
|
);
|
||||||
|
|
|
@ -845,9 +845,16 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f
|
||||||
for var in slice {
|
for var in slice {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"<{:?}>{:?} ",
|
"<{:?}>{} ",
|
||||||
var,
|
var,
|
||||||
|
if var.index() == 304 {
|
||||||
|
format!("{}", "*304")
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"{:?}",
|
||||||
SubsFmtContent(subs.get_content_without_compacting(*var), subs)
|
SubsFmtContent(subs.get_content_without_compacting(*var), subs)
|
||||||
|
)
|
||||||
|
}
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
write!(f, ", ")?;
|
write!(f, ", ")?;
|
||||||
|
|
|
@ -387,7 +387,8 @@ impl<'a> RocDocAllocator<'a> {
|
||||||
match tn {
|
match tn {
|
||||||
TagName::Global(uppercase) => self.global_tag_name(uppercase),
|
TagName::Global(uppercase) => self.global_tag_name(uppercase),
|
||||||
TagName::Private(symbol) => self.private_tag_name(symbol),
|
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