You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dead code in PL IR: unused fold_func_param, write-only prev_columns, unreachable display_ids #5793
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:74display_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 default fold_func at line 271 folds body and args via struct spread but never calls fold_func_param for params or named_params. Worth noting: if a fold pass ever needs to visit FuncParam::default_value, this function would be the right vehicle — so this is either dead code to remove or a missing call in fold_func.
Lineage::prev_columns (lineage.rs:21) — confirmed write-only. Lineage::clear() at transforms.rs:830-831 moves columns into prev_columns, but nothing reads prev_columns afterward. The comment mentions ExprKind::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 passes false, making the true branch 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.
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 separatePlFold-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:
(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 the Lexer(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.
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.
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 (785f9e3). 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_pipelinesplits 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.
Activity
prql-bot commentedon Apr 12, 2026
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_funcvisit 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.
prql-bot commentedon Apr 25, 2026
4.
has_otherinResolver::infer_typeis unreachableWhile reviewing
semantic/resolver/types.rsin the 2026-04-25 nightly survey, I found another instance of the same pattern as #3 in this issue.semantic/resolver/types.rs:36declareslet has_other = false;(immutably) inside theExprKind::Tuplearm ofinfer_type. It is then only checked at line 58:Since
has_otheris never reassigned, theWildcardpush is unreachable.This may be a missing feature rather than dead code: compare
type_intersection_of_tuplesat lines 415-446, which uses the same pattern but correctly setshas_other = truewhen one side of the intersection contributes wildcard fields, and the same file'sflattencase at line 41-46 which extends the inner tuple's fields without preserving any wildcard. So a tuple flatten where the inner type has aTyTupleField::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.
prql-bot commentedon May 24, 2026
Item 4 from my 2026-04-25 comment (
has_otherinResolver::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.prql-bot commentedon Jul 22, 2026
5.
fold_optional_boxinir/rq/fold.rshas no callers (RQ counterpart of item 1)The 2026-07-22 nightly survey of
ir/rq/fold.rsturned up an unused fold helper directly analogous to item 1'sfold_func_param.ir/rq/fold.rs:234-242definesfold_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 separatePlFold-boundfold_optional_boxinir/pl/fold.rs:152— not thisRqFoldone. The RQ IR structures folded byRqFoldcurrently have noOption<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::*;inir/rq/mod.rs, andiris a public module), and it exactly mirrors thefold_*helper family inir/pl/fold.rs. So it may be intentional API symmetry — kept for downstream consumers implementingRqFold— rather than something to delete. Flagging it here alongside the siblingfold_func_paramfinding so the two can be considered together; low priority, and the symmetry argument may well win.prql-bot commentedon Sep 3, 2026
6.
WithErrorInfo::with_sourceis a no-op at all 7 call sitesThe 2026-09-03 nightly survey of
prqlc-parser/src/error.rsturned 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-210implementswith_sourceby discarding its argument:It can't do otherwise — the
sourcefield onErroris commented out aterror.rs:17. So every one of these throws its argument away:lexer/mod.rs:61Lexer(error_source)lib.rs:196NameResolverlib.rs:199SQLlib.rs:385NameResolverlib.rs:395NameResolverlib.rs:400SQL(
lexer/mod.rs:61is the seventh — theLexervariant is constructed there and at no other site.) TheTypeResolver,InternalandUnknownvariants ofErrorSourceare never constructed at all, andUnknownis theDefaultfor a type whoseDefaultis never called.ErrorSourceis re-exported fromprqlc/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:ErrorMessage. The call sites suggest someone intended error provenance to be machine-readable, and theLexer(String)payload implies it once carried detail worth keeping.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.
prql-bot commentedon Oct 3, 2026
7.
TableColumninir/decl.rshas no usesThe 2026-10-03 nightly survey of
prqlc/prqlc/src/ir/decl.rsfoundpub enum TableColumn { Wildcard, Single(Option<String>) }with no references anywhere in the workspace or the bindings. It is reachable asprqlc::ir::decl::TableColumnbecauseiris 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.prql-bot commentedon Nov 1, 2026
8.
IndirectionKindandGenericTypeParaminprqlc-parser's PR AST have no usesFound 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 refactor: remove arbitrary indirections #5122, which removed arbitrary indirections.pub struct GenericTypeParam { name, domain }appears to be left over from refactor: remove generics #5119, which removed generics.They're re-exported through
pub use expr::*, so deleting them is technically a breaking change toprqlc-parser's public API, and like the items above it's left here for a maintainer to decide.prql-bot commentedon Nov 15, 2026
9. The
restrict_modulechain insemantic/ast_expand.rshas no callers outside itselfrestrict_module,restrict_decl,new_internal_stmt,restrict_module_def,restrict_stmts,restrict_stmtandrestrict_annotationonly call one another. Each name appears just at its definition and inside the chain. The last outside caller was removed in #5121 (785f9e3). The compiler doesn't warn becausesemanticis apub mod. The otherrestrict_*helpers (restrict_expr,try_restrict_range,restrict_null_literal) are still used.10.
Transform::Unionin the aggregate split insql/gen_query.rscan't matchtranslate_pipelinesplits the pipeline at the firstUnion/Except/Intersectbefore it callstranslate_select_pipeline. So theTransform::Union { .. }alternative in thebreak_upat line 155 never sees aUnion.Found by the 2026-11-15 nightly survey.