mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
Specialize polymorphic values in record updates
This commit is contained in:
parent
8fd139ba67
commit
e7e2fa063f
1 changed files with 24 additions and 1 deletions
|
@ -4008,13 +4008,36 @@ pub fn with_hole<'a>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
CopyExisting(index) => {
|
CopyExisting(index) => {
|
||||||
|
let record_needs_specialization =
|
||||||
|
procs.partial_exprs.contains(structure);
|
||||||
|
let specialized_structure_sym = if record_needs_specialization {
|
||||||
|
// We need to specialize the record now; create a new one for it.
|
||||||
|
// TODO: reuse this symbol for all updates
|
||||||
|
env.unique_symbol()
|
||||||
|
} else {
|
||||||
|
// The record is already good.
|
||||||
|
structure
|
||||||
|
};
|
||||||
|
|
||||||
let access_expr = Expr::StructAtIndex {
|
let access_expr = Expr::StructAtIndex {
|
||||||
structure,
|
structure: specialized_structure_sym,
|
||||||
index,
|
index,
|
||||||
field_layouts,
|
field_layouts,
|
||||||
};
|
};
|
||||||
stmt =
|
stmt =
|
||||||
Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt));
|
Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt));
|
||||||
|
|
||||||
|
if record_needs_specialization {
|
||||||
|
stmt = reuse_function_symbol(
|
||||||
|
env,
|
||||||
|
procs,
|
||||||
|
layout_cache,
|
||||||
|
Some(record_var),
|
||||||
|
specialized_structure_sym,
|
||||||
|
stmt,
|
||||||
|
structure,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue