mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Compact lambda sets with structural derived ability impls
This commit is contained in:
parent
9caa09b2c0
commit
445d922f3b
6 changed files with 94 additions and 11 deletions
|
@ -11,7 +11,9 @@ use roc_collections::MutMap;
|
|||
use roc_derive_key::DeriveKey;
|
||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||
use roc_region::all::Loc;
|
||||
use roc_types::subs::{Content, Descriptor, Mark, OptVariable, Rank, Subs, Variable};
|
||||
use roc_types::subs::{
|
||||
copy_import_to, Content, Descriptor, Mark, OptVariable, Rank, Subs, Variable,
|
||||
};
|
||||
|
||||
mod encoding;
|
||||
|
||||
|
@ -91,6 +93,7 @@ fn build_derived_body(
|
|||
impl DerivedModule {
|
||||
pub fn get_or_insert(
|
||||
&mut self,
|
||||
// TODO: we only need "exposed by builtin modules that expose builtin abilities"
|
||||
exposed_by_module: &ExposedByModule,
|
||||
key: DeriveKey,
|
||||
) -> &(Symbol, Def, SpecializationLambdaSets) {
|
||||
|
@ -136,6 +139,11 @@ impl DerivedModule {
|
|||
pub fn iter_all(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (&DeriveKey, &(Symbol, Def, SpecializationLambdaSets))> {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
debug_assert!(!self.stolen);
|
||||
}
|
||||
|
||||
self.map.iter()
|
||||
}
|
||||
|
||||
|
@ -143,6 +151,11 @@ impl DerivedModule {
|
|||
/// module; other modules should use [`Self::get_or_insert`] to generate a symbol for a derived
|
||||
/// ability member usage.
|
||||
pub fn gen_unique(&mut self) -> Symbol {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
debug_assert!(!self.stolen);
|
||||
}
|
||||
|
||||
let ident_id = self.derived_ident_ids.gen_unique();
|
||||
Symbol::new(DERIVED_MODULE, ident_id)
|
||||
}
|
||||
|
@ -176,6 +189,30 @@ impl DerivedModule {
|
|||
self.subs = subs;
|
||||
self.derived_ident_ids = ident_ids;
|
||||
}
|
||||
|
||||
pub fn copy_lambda_set_var_to_subs(&self, var: Variable, target: &mut Subs) -> Variable {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
debug_assert!(!self.stolen);
|
||||
}
|
||||
|
||||
let copied_import = copy_import_to(
|
||||
&self.subs,
|
||||
target,
|
||||
// bookkeep unspecialized lambda sets of var - I think we want this here
|
||||
true,
|
||||
var,
|
||||
// TODO: I think this is okay because the only use of `copy_lambda_set_var_to_subs`
|
||||
// (at least right now) is for lambda set compaction, which will automatically unify
|
||||
// and lower ranks, and never generalize.
|
||||
//
|
||||
// However this is a bad coupling and maybe not a good assumption, we should revisit
|
||||
// this when possible.
|
||||
Rank::toplevel(),
|
||||
);
|
||||
|
||||
copied_import.variable
|
||||
}
|
||||
}
|
||||
|
||||
/// Thread-sharable [`DerivedMethods`].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue