refactor(codegen): parameterise the copy-pasted IR-emission families

Emitted IR is byte-identical for every case — proven by the IR-pin
suites (eq_primitives_pin, ord_int_intercept_ir_pin, the raw_buf_*
and drop/leak pins) and the full e2e suite, all green.

intercepts.rs:
- The twelve emit_rawbuf_{new,get,set,size}_{int,float,bool} functions
  were copy-paste across three element types, differing only in the
  element width (8/8/1) and the LLVM load/store type (i64/double/i1).
  Collapsed to four parameterised cores; the element variants are thin
  call sites passing the (width, type) pair.
- Replaced the repeated, off-by-one-prone parameter-SSA extraction
  idiom (`locals[n-2]`, `locals[n-1]`) with an Emitter::last_param_ssas
  helper.
- Factored the shared IR-Str bytes GEP out of emit_eq_str /
  emit_compare_str into emit_str_bytes_gep.

drop.rs:
- The three emit_*_drop_fn_for_type methods shared one wrapping shape
  (monomorphic short-circuit, else loop over instantiations dispatching
  to a *_for_instantiation helper); hoisted into emit_drop_fn_wrapper
  taking the per-instantiation emitter as a fn pointer.
- emit_flat_intrinsic_drop_fn / _partial_drop_fn differed only in the
  symbol prefix and an ignored mask param; merged into one inner
  emitter.

No INTERCEPTS-registry or (intrinsic)-marker changes.
This commit is contained in:
2026-06-02 02:02:17 +02:00
parent 7ae92d3e60
commit 7d9ab4d29d
3 changed files with 196 additions and 220 deletions
+15
View File
@@ -3097,6 +3097,21 @@ impl<'a> Emitter<'a> {
self.counter += 1;
format!("%v{}", self.counter)
}
/// Return the SSA names of the last `count` locals, in their
/// original (ascending-index) order. Intercept emit fns use this
/// to pull their parameter SSAs off `self.locals` without the
/// off-by-one-prone `locals[len - k]` idiom. For `count == 2` the
/// result is `[locals[n-2].1, locals[n-1].1]`, i.e. first param
/// then second — identical to the hand-rolled extraction it
/// replaces.
pub(crate) fn last_param_ssas(&self, count: usize) -> Vec<String> {
let n = self.locals.len();
self.locals[n - count..]
.iter()
.map(|l| l.1.clone())
.collect()
}
pub(crate) fn fresh_id(&mut self) -> u64 {
self.counter += 1;
self.counter