refactor: collapse duplicated helpers and drop dead code across check/core/codegen

Pure simplification pass, no behaviour change — hashes, canonical
forms, diagnostic codes, and emitted IR are byte-identical (hash-pin
and IR-pin tests unchanged and green).

ailang-check:
- strip_forall and collect_pattern_binders were triplicated verbatim
  across linearity.rs / reuse_shape.rs / uniqueness.rs; hoisted each to
  a single pub(crate) fn in lib.rs.
- mono.rs::pattern_binders was a fourth copy of collect_pattern_binders
  (iterative style, same result for every Pattern shape); deleted, now
  calls the shared fn.
- maybe_instantiate and expect_eq were single-call wrappers; inlined
  at their sole call sites and removed.

ailang-core:
- collect_used_in_pattern was a verbatim duplicate of pattern_binds;
  deleted, call site repointed. pattern_binds made private (no external
  callers; the doc-comment's lift_letrecs claim was stale).
- is_false serde helper replaced by std::ops::Not::not at the four
  skip_serializing_if sites (all plain-bool fields); helper removed.
- test-only any_nested_ctor / any_let_rec folded into one generic
  any_term(t, &pred) walker.
- removed dead test helpers tmp_dir / examples_dir, orphaned when their
  tests relocated to tests/workspace_pin.rs.

ailang-codegen:
- removed the write-only Emitter::types field, its populating loop, and
  the now-unused CtorInfo struct it fed.
- adt_drop_symbol / adt_partial_drop_symbol differed only in a prefix
  literal; folded into one adt_symbol(prefix, ...). Symbol strings
  unchanged.

Net -180 LOC.
This commit is contained in:
2026-06-02 01:39:35 +02:00
parent e25580e3a3
commit ac9171ebf0
10 changed files with 112 additions and 293 deletions
+13 -12
View File
@@ -501,16 +501,7 @@ impl<'a> Emitter<'a> {
/// with the emission loop, so a call symbol matches its definition
/// byte-for-byte (a mismatch is an IR link error).
pub(crate) fn adt_drop_symbol(&self, name: &str, args: &[Type]) -> String {
let key = super::dropmono::resolve_adt_key(
name,
self.module_name,
&self.import_map,
);
let base = format!("drop_{owner}_{bare}", owner = key.0, bare = key.1);
match self.drop_monos.suffix_for(&key, args) {
Some(suffix) => format!("{base}{suffix}"),
None => base,
}
self.adt_symbol("drop_", name, args)
}
/// resolve the `partial_drop_<owner>_<T>` symbol for an ADT
@@ -518,13 +509,23 @@ impl<'a> Emitter<'a> {
/// to [`Self::adt_drop_symbol`]. The caller has already excluded
/// `Str` / non-`Con` shapes.
pub(crate) fn adt_partial_drop_symbol(&self, name: &str, args: &[Type]) -> String {
self.adt_symbol("partial_drop_", name, args)
}
/// shared core of [`Self::adt_drop_symbol`] and
/// [`Self::adt_partial_drop_symbol`]: build the `<prefix><owner>_<bare>`
/// base from the resolved ADT key and append the leg-C per-monomorph
/// suffix when one applies. The two public symbols differ only in the
/// `prefix` literal (`drop_` vs `partial_drop_`); the emitted string is
/// byte-identical to the pre-dedup form, which matters because these are
/// IR symbol names (a mismatch is a link error).
fn adt_symbol(&self, prefix: &str, name: &str, args: &[Type]) -> String {
let key = super::dropmono::resolve_adt_key(
name,
self.module_name,
&self.import_map,
);
let base =
format!("partial_drop_{owner}_{bare}", owner = key.0, bare = key.1);
let base = format!("{prefix}{owner}_{bare}", owner = key.0, bare = key.1);
match self.drop_monos.suffix_for(&key, args) {
Some(suffix) => format!("{base}{suffix}"),
None => base,
-42
View File
@@ -787,12 +787,6 @@ struct Emitter<'a> {
/// `drop_`/`partial_drop_` symbol. Shared by reference with every
/// `Emitter`.
drop_monos: &'a dropmono::DropAdtMeta,
/// ADT table: type_name -> list of ctors in definition order.
/// Tag of a ctor = index in this list.
/// Kept around for future tools (pretty-printer for ADT values,
/// decision-tree optimization).
#[allow(dead_code)]
types: BTreeMap<String, Vec<CtorInfo>>,
/// cross-module ctor index, keyed by module name. Used by
/// `lookup_ctor_by_type` (for `Term::Ctor.type_name`) and
/// `lookup_ctor_in_pattern` (for `Pattern::Ctor.ctor`). Built once
@@ -938,13 +932,6 @@ struct Emitter<'a> {
entry_block_end_marker: Option<usize>,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
struct CtorInfo {
name: String,
fields: Vec<String>, // llvm types
}
#[derive(Debug, Clone)]
struct CtorRef {
type_name: String,
@@ -993,34 +980,6 @@ impl<'a> Emitter<'a> {
drop_monos: &'a dropmono::DropAdtMeta,
alloc: AllocStrategy,
) -> Self {
let mut types: BTreeMap<String, Vec<CtorInfo>> = BTreeMap::new();
for def in &module.defs {
if let Def::Type(td) = def {
let mut infos = Vec::new();
for c in td.ctors.iter() {
// precomputed LLVM field types are only
// meaningful for monomorphic ADTs. For parameterised
// ADTs the field types reference free `Type::Var`s
// and must be derived per use site after
// substituting; we still populate the slot with
// `i64`/`ptr` placeholders so the index shape stays
// uniform, but neither `lower_ctor` nor
// `lower_match` reads from it when `type_vars` is
// non-empty.
let fields: Vec<String> = c
.fields
.iter()
.map(|t| llvm_type(t).unwrap_or_else(|_| "ptr".into()))
.collect();
infos.push(CtorInfo {
name: c.name.clone(),
fields,
});
}
types.insert(td.name.clone(), infos);
}
}
// mir.3a: read the per-binder consume_count off MIR (filled by
// lower_to_mir from the single uniqueness pass) instead of
// re-running the uniqueness pass here.
@@ -1049,7 +1008,6 @@ impl<'a> Emitter<'a> {
module_user_fns,
import_map,
drop_monos,
types,
module_ctor_index,
module_consts,
current_block: String::new(),