Dead code in PL IR: unused fold_func_param, write-only prev_columns, unreachable display_ids
The nightly survey (2026-04-12) identified several pieces of dead code in the PL IR and related modules. These are structural enough that they may warrant maintainer review before removal.
1. fold_func_param is never called
fold.rs:289 exports fold_func_param but it has zero callers. The default fold_func implementation uses struct spread and only folds body and args, skipping FuncParam::default_value and Func::env. This means all PlFold implementors miss expressions within default parameter values and captured environments.
This could be a latent correctness issue if any fold pass needs to visit those fields, or it could be intentional if those fields are always resolved before folding occurs.
2. Lineage::prev_columns is write-only
lineage.rs:21 defines prev_columns which is populated by Lineage::clear() but never read anywhere. The comment says it is "A hack that allows name retention when applying ExprKind::All { except }", but no code reads it. It is also #[serde(skip)].
3. display_ids parameter is always false
lineage.rs:74 display_lineage accepts display_ids: bool but the only call site always passes false, making the true branch unreachable. Appears to be an unfinished debugging aid.
I verified all three findings against the current codebase:
-
fold_func_param(fold.rs:289) — confirmed zero callers. The defaultfold_funcat line 271 foldsbodyandargsvia struct spread but never callsfold_func_paramforparamsornamed_params. Worth noting: if a fold pass ever needs to visitFuncParam::default_value, this function would be the right vehicle — so this is either dead code to remove or a missing call infold_func. -
Lineage::prev_columns(lineage.rs:21) — confirmed write-only.Lineage::clear()attransforms.rs:830-831movescolumnsintoprev_columns, but nothing readsprev_columnsafterward. The comment mentionsExprKind::All { except }but the read side was never implemented or was removed. -
display_ids(lineage.rs:74) — confirmed. The sole call site at line 70 always passesfalse, making thetruebranch unreachable.
All three are safe to remove individually. Item 1 has a subtlety — removing it is straightforward, but the underlying question (should fold_func visit default values and env?) may be worth a quick check before closing. Items 2 and 3 are clean removals with no behavioral impact.
Leaving for a maintainer to decide on scope.
4. has_other in Resolver::infer_type is unreachable
While reviewing semantic/resolver/types.rs in the 2026-04-25 nightly survey, I found another instance of the same pattern as #3 in this issue.
semantic/resolver/types.rs:36 declares let has_other = false; (immutably) inside the ExprKind::Tuple arm of infer_type. It is then only checked at line 58:
if has_other {
ty_fields.push(TyTupleField::Wildcard(None));
}
Since has_other is never reassigned, the Wildcard push is unreachable.
This may be a missing feature rather than dead code: compare type_intersection_of_tuples at lines 415-446, which uses the same pattern but correctly sets has_other = true when one side of the intersection contributes wildcard fields, and the same file's flatten case at line 41-46 which extends the inner tuple's fields without preserving any wildcard. So a tuple flatten where the inner type has a TyTupleField::Wildcard(_) entry would silently drop the wildcard.
I have not been able to construct a query that exercises this gap (most flatten use cases in tests have fully-named inner tuples), so I am unsure whether this is a latent bug or a deliberately-trimmed branch. Flagging in this issue rather than opening a new one since it shares the "is this dead or unfinished?" character of the others.
Item 4 from my 2026-04-25 comment (has_other in Resolver::infer_type) was removed in #5937 (merged 2026-05-23). Items 1–3 from the original report (fold_func_param, Lineage::prev_columns, display_ids) are still open — leaving the issue open for those.
5. fold_optional_box in ir/rq/fold.rs has no callers (RQ counterpart of item 1)
The 2026-07-22 nightly survey of ir/rq/fold.rs turned up an unused fold helper directly analogous to item 1's fold_func_param.
ir/rq/fold.rs:234-242 defines fold_optional_box<F: ?Sized + RqFold> with zero call sites. All five in-tree uses of the name (ir/pl/fold.rs:130,144,145,224,297) resolve to the separate PlFold-bound fold_optional_box in ir/pl/fold.rs:152 — not this RqFold one. The RQ IR structures folded by RqFold currently have no Option<Box<Expr>> fields, so the helper is never needed internally.
Unlike items 2–4, this one is a weaker candidate for removal: it's re-exported as public API (pub use fold::*; in ir/rq/mod.rs, and ir is a public module), and it exactly mirrors the fold_* helper family in ir/pl/fold.rs. So it may be intentional API symmetry — kept for downstream consumers implementing RqFold — rather than something to delete. Flagging it here alongside the sibling fold_func_param finding so the two can be considered together; low priority, and the symmetry argument may well win.
6. WithErrorInfo::with_source is a no-op at all 7 call sites
The 2026-09-03 nightly survey of prqlc-parser/src/error.rs turned up a variant of this issue's pattern that is louder than the others: rather than a helper with no callers, this is a helper with seven callers that silently does nothing.
error.rs:207-210 implements with_source by discarding its argument:
fn with_source(self, _source: ErrorSource) -> Self {
// self.source = source;
self
}
It can't do otherwise — the source field on Error is commented out at error.rs:17. So every one of these throws its argument away:
| Call site | Source passed |
|---|---|
lexer/mod.rs:61 |
Lexer(error_source) |
lib.rs:196 |
NameResolver |
lib.rs:199 |
SQL |
lib.rs:385 |
NameResolver |
lib.rs:395 |
NameResolver |
lib.rs:400 |
SQL |
(lexer/mod.rs:61 is the seventh — the Lexer variant is constructed there and at no other site.) The TypeResolver, Internal and Unknown variants of ErrorSource are never constructed at all, and Unknown is the Default for a type whose Default is never called.
ErrorSource is re-exported from prqlc/src/lib.rs:112, so it's public API — which is why I'm raising this rather than opening a PR. There are two defensible directions and the choice looks like a maintainer call:
- Wire it up — uncomment the field, store the source, and surface it on
ErrorMessage. The call sites suggest someone intended error provenance to be machine-readable, and theLexer(String)payload implies it once carried detail worth keeping. - Remove it — drop
with_source,ErrorSource, and the seven calls. A breaking change to the public re-export, but it deletes an API that has never done anything.
Happy to open a PR for whichever direction you'd prefer.
7. TableColumn in ir/decl.rs has no uses
The 2026-10-03 nightly survey of prqlc/prqlc/src/ir/decl.rs found pub enum TableColumn { Wildcard, Single(Option<String>) } with no references anywhere in the workspace or the bindings. It is reachable as prqlc::ir::decl::TableColumn because ir is a public module, which is the only reason it compiles without a dead-code warning. Removing it is a one-line deletion, but it's technically an API change for the published crate, so it's listed here rather than opened as a PR.
8. IndirectionKind and GenericTypeParam in prqlc-parser's PR AST have no uses
Found by the 2026-11-01 nightly survey of prqlc-parser/src/parser/pr/expr.rs. Both are defined and never referenced anywhere in the workspace or the bindings: a grep for either name finds only its definition.
pub enum IndirectionKind { Name, Position, Star }appears to be left over from #5122, which removed arbitrary indirections.pub struct GenericTypeParam { name, domain }appears to be left over from #5119, which removed generics.
They're re-exported through pub use expr::*, so deleting them is technically a breaking change to prqlc-parser's public API, and like the items above it's left here for a maintainer to decide.
9. The restrict_module chain in semantic/ast_expand.rs has no callers outside itself
restrict_module, restrict_decl, new_internal_stmt, restrict_module_def, restrict_stmts, restrict_stmt and restrict_annotation only call one another. Each name appears just at its definition and inside the chain. The last outside caller was removed in #5121 (785f9e36). The compiler doesn't warn because semantic is a pub mod. The other restrict_* helpers (restrict_expr, try_restrict_range, restrict_null_literal) are still used.
10. Transform::Union in the aggregate split in sql/gen_query.rs can't match
translate_pipeline splits the pipeline at the first Union/Except/Intersect before it calls translate_select_pipeline. So the Transform::Union { .. } alternative in the break_up at line 155 never sees a Union.
Found by the 2026-11-15 nightly survey.