mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Store specialization lambda sets of derived ability impls
This commit is contained in:
parent
fbc2052e83
commit
e940fed3a8
1 changed files with 28 additions and 11 deletions
|
@ -3,6 +3,8 @@
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use roc_can::abilities::SpecializationLambdaSets;
|
||||||
|
use roc_can::expr::Expr;
|
||||||
use roc_can::pattern::Pattern;
|
use roc_can::pattern::Pattern;
|
||||||
use roc_can::{def::Def, module::ExposedByModule};
|
use roc_can::{def::Def, module::ExposedByModule};
|
||||||
use roc_collections::MutMap;
|
use roc_collections::MutMap;
|
||||||
|
@ -31,7 +33,7 @@ pub fn synth_var(subs: &mut Subs, content: Content) -> Variable {
|
||||||
/// Map of [`DeriveKey`]s to their derived symbols.
|
/// Map of [`DeriveKey`]s to their derived symbols.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct DerivedModule {
|
pub struct DerivedModule {
|
||||||
map: MutMap<DeriveKey, (Symbol, Def)>,
|
map: MutMap<DeriveKey, (Symbol, Def, SpecializationLambdaSets)>,
|
||||||
subs: Subs,
|
subs: Subs,
|
||||||
derived_ident_ids: IdentIds,
|
derived_ident_ids: IdentIds,
|
||||||
|
|
||||||
|
@ -45,14 +47,25 @@ pub struct StolenFromDerived {
|
||||||
pub ident_ids: IdentIds,
|
pub ident_ids: IdentIds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct DerivedBody {
|
||||||
|
pub body: Expr,
|
||||||
|
pub body_type: Variable,
|
||||||
|
/// mapping of lambda set region -> the specialization lambda set for this derived body
|
||||||
|
pub specialization_lambda_sets: SpecializationLambdaSets,
|
||||||
|
}
|
||||||
|
|
||||||
fn build_derived_body(
|
fn build_derived_body(
|
||||||
derived_subs: &mut Subs,
|
derived_subs: &mut Subs,
|
||||||
derived_ident_ids: &mut IdentIds,
|
derived_ident_ids: &mut IdentIds,
|
||||||
exposed_by_module: &ExposedByModule,
|
exposed_by_module: &ExposedByModule,
|
||||||
derived_symbol: Symbol,
|
derived_symbol: Symbol,
|
||||||
derive_key: DeriveKey,
|
derive_key: DeriveKey,
|
||||||
) -> Def {
|
) -> (Def, SpecializationLambdaSets) {
|
||||||
let (body, var) = match derive_key {
|
let DerivedBody {
|
||||||
|
body,
|
||||||
|
body_type,
|
||||||
|
specialization_lambda_sets,
|
||||||
|
} = match derive_key {
|
||||||
DeriveKey::ToEncoder(to_encoder_key) => {
|
DeriveKey::ToEncoder(to_encoder_key) => {
|
||||||
let mut env = encoding::Env {
|
let mut env = encoding::Env {
|
||||||
subs: derived_subs,
|
subs: derived_subs,
|
||||||
|
@ -64,13 +77,15 @@ fn build_derived_body(
|
||||||
DeriveKey::Decoding => todo!(),
|
DeriveKey::Decoding => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Def {
|
let def = Def {
|
||||||
loc_pattern: Loc::at_zero(Pattern::Identifier(derived_symbol)),
|
loc_pattern: Loc::at_zero(Pattern::Identifier(derived_symbol)),
|
||||||
loc_expr: Loc::at_zero(body),
|
loc_expr: Loc::at_zero(body),
|
||||||
expr_var: var,
|
expr_var: body_type,
|
||||||
pattern_vars: once((derived_symbol, var)).collect(),
|
pattern_vars: once((derived_symbol, body_type)).collect(),
|
||||||
annotation: None,
|
annotation: None,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
(def, specialization_lambda_sets)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerivedModule {
|
impl DerivedModule {
|
||||||
|
@ -78,7 +93,7 @@ impl DerivedModule {
|
||||||
&mut self,
|
&mut self,
|
||||||
exposed_by_module: &ExposedByModule,
|
exposed_by_module: &ExposedByModule,
|
||||||
key: DeriveKey,
|
key: DeriveKey,
|
||||||
) -> &(Symbol, Def) {
|
) -> &(Symbol, Def, SpecializationLambdaSets) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
debug_assert!(!self.stolen, "attempting to add to stolen symbols!");
|
debug_assert!(!self.stolen, "attempting to add to stolen symbols!");
|
||||||
|
@ -106,7 +121,7 @@ impl DerivedModule {
|
||||||
};
|
};
|
||||||
|
|
||||||
let derived_symbol = Symbol::new(DERIVED_MODULE, ident_id);
|
let derived_symbol = Symbol::new(DERIVED_MODULE, ident_id);
|
||||||
let derived_def = build_derived_body(
|
let (derived_def, specialization_lsets) = build_derived_body(
|
||||||
&mut self.subs,
|
&mut self.subs,
|
||||||
&mut self.derived_ident_ids,
|
&mut self.derived_ident_ids,
|
||||||
exposed_by_module,
|
exposed_by_module,
|
||||||
|
@ -114,11 +129,13 @@ impl DerivedModule {
|
||||||
key.clone(),
|
key.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(derived_symbol, derived_def)
|
(derived_symbol, derived_def, specialization_lsets)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_all(&self) -> impl Iterator<Item = (&DeriveKey, &(Symbol, Def))> {
|
pub fn iter_all(
|
||||||
|
&self,
|
||||||
|
) -> impl Iterator<Item = (&DeriveKey, &(Symbol, Def, SpecializationLambdaSets))> {
|
||||||
self.map.iter()
|
self.map.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue