Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Duplicate exports and large hygiene debt (orphans, missing signatures, dodgy imports, type-defaults, unused) #356

Closed

Description

@yellowbean

Location src/Asset.hs:12, 13; src/InterestRate.hs:9; src/Liability.hs:26 (duplicate exports). Plus project-wide: 177 × -Worphans, 38 × -Wmissing-signatures, 37 × -Wdodgy-imports, 35 × -Wtype-defaults, 1483 × -Wunused-matches, 510 × -Wunused-imports, 98 × -Wunused-top-binds, 73 × -Wunused-local-binds, 215 × -Wname-shadowing.

Cause The codebase was never built with -Wall; unused imports/bindings, missing signatures, orphan instances, and defaulting warnings accumulated. Many import Debug.Trace / debug = flip trace bindings are dead.

Evidence (GHC 9.12.3) Full build with -Wall -Wincomplete-patterns -Wincomplete-uni-patterns -Wunused-matches -Wunused-imports produces 3,108 warnings; -Wduplicate-exports at the lines above.

Impact Noise hides real defects; harder maintenance.

Suggested fix Enable -Wall (and -Werror incrementally) in Hastructure.cabal, remove dead Debug.Trace/debug code, add signatures, and resolve duplicates.

Activity

  1. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    Re-measured this issue's census at HEAD 28ec30e (Dec26), GHC 9.12.3, by compiling all 44 built library modules + the test suite with -Wall -Wincomplete-patterns -Wincomplete-uni-patterns -Wmissing-signatures -Wdodgy-exports -Wdodgy-imports -Wtype-defaults -Wname-shadowing -Worphans -Wduplicate-exports. Counts below are per-warning-instance; the app (2 files) is excluded, and so is src/AssetClass/StudentLoan.hs — more on that at the bottom, because it is itself a finding.

    Verified census

    warning class lib (44 mods) test what it actually is
    unused-matches 1,484 1 cosmetic (rename to _x)
    unused-imports 404 125 stale imports
    incomplete-patterns 223 3 reachable runtime error
    name-shadowing 221 21 can hide typos/bugs
    unused-top-binds 94 14 dead code
    unused-local-binds 68 37 dead code
    x-partial 61 22 head/tail crash risk
    dodgy-imports 37 0 stale hiding (...) lists
    missing-signatures 35 173 32 of the 35 are copies of one binding (below)
    type-defaults 35 45 silent numeric semantics
    incomplete-uni-patterns 34 4 one-sided pattern binding crash risk
    orphans 32 0 instance visibility/hygiene
    duplicate-exports 8 0 headline item
    dodgy-exports 3 0 (..) on types with no constructors
    tabs + $-prefix ambiguity 5 2 formatting
    total 2,744 486 ≈ the issue's 3,108 (scope/method differs slightly)

    1. The 8 duplicate exports (issue headline, exact)

    • src/Asset.hs:12-13 — getObligorFields, getObligorTags, getObligorId, getOriginInfo are all Asset class methods already exported by Asset(..); the explicit names are redundant: 4 duplicates.
    • src/InterestRate.hs:9 — getSpread is already exported by UseRate(..): 1 duplicate.
    • src/Liability.hs:17,19 vs :26 — _Bond, _MultiIntBond, _BondGroup are literally listed twice in the export list: 3 duplicates.

    Fixes are pure deletions with zero behavior change. Caveat: Liability.hs currently carries in-flight WIP, so it must wait; Asset.hs/InterestRate.hs are committable now.

    2. The most-repeated single defect: 33 copies of debug = flip trace

    • 33 modules each define their own debug = flip trace (one uses Debug.Trace.trace).
    • The trace call sites survive only as comments (`debug` "..." left dead at line ends), so GHC flags 32 of the 33 as missing their signature AND never used.
    • Right fix: one shared, typed helper in a low-level module + delete the 33 copies. That also wipes out ~32 missing-signature warnings in one stroke. Deferred: all 33 files touch, many are in the WIP set.

    3. Dead code (verified not in the module's export list → safe to delete)

    Util.debugLine, Util.mulIntegerR, Util.getIndexRateByDates (the RateCurve branch), Util.testSumToOne, Lib.addD, Lib.floatToFixed, Analytics.toTimeYield, Analytics.pv3', Asset.normalPerfVector, Deal.updateSrtRate, Deal.queryTrigger, Lease.calcGapDays, plus never-constructed data types (DealBase.ActionTypeOnDate, DealBase.UnderBond) and ~17 unused type synonyms (Comment, Yield, Amounts, Prepayments, Rates, Recoveries, CapRate, PeriodAmount, RentChangeRate, RentChangeCurve, LastAccuredDate, PaymentCap, BookLedgers, PoolBalanceSnapshot, ExtendCashflowDates, AmountToBuy, ReceiveAmount, PayoutAmount) and unused makeLensesFor lens bundles (Ledger, Triggers, Hedge, Accounts). Roughly −60 warnings with zero API impact — but each name deserves a final grep before deletion since exported-but-unused-by-the-library API should not be treated as dead (clients may use it).

    4. Orphan instances (32)

    • ToSchema ... ×18 in AssetClass.AssetBase (swagger for Ts, TsPoint, Period, ARM, DatePattern, CutoffType, ...) — all orphans because the ToSchema class is foreign.
    • ToJSON/FromJSON (DecimalRaw i) ×2, ToJSONKey/FromJSONKey DealStatFields ×2 (DealBase), Ord Txn / TimeSeries Txn ×2.
    • instance Asset X ×1 in each of the 8 asset-class modules — structural, since the class lives in Asset.hs and the types in AssetBase.hs.

    Recommendation: group them into one barrel module (guarantees instance visibility for clients importing it) and suppress -Worphans locally there. Do not newtype-wrap to silence them — that changes JSON/serialization output (breaking).

    5. Where real bugs can hide (the noise is dangerous)

    • incomplete-patterns (223): e.g. DateUtil.hs:151,304 fall through a case dp of over DatePattern missing MidYear, SemiAnnual, DaysInYear, ... — public constructors, so a client using them gets a runtime "non-exhaustive patterns" exception inside date generation. Cashflow.hs alone has 44.
    • x-partial (61) + incomplete-uni-patterns (34): head/tail/one-sided bindings, e.g. InterestRate.hs:64 fr:rrs = ... fails on an empty reset vector.
    • type-defaults (35/45): Util.toPeriodRateByInterval (Util.hs:427) silently computes in Double although the engine's money math is Rational — a precision/semantics decision made by the type default, not by anyone. DealQuery.hs has 20 more.
    • name-shadowing (221): e.g. Deal.hs:525 extractTestDates shadows itself; DealAction shadows pre, index, ... Worth a sweep for genuine mistakes when the noise is cleared.

    6. A finding outside the categories: src/AssetClass/StudentLoan.hs

    Tracked since the Dec 25 release (#312), declares module AssetClass.Mortgage (copy-paste header), is not in the cabal other-modules, is imported nowhere, and AssetBase.hs defines its own independent StudentLoan type. The file is unreachable duplicate content — a build with -isrc fails with "module AssetClass.Mortgage is defined in multiple files". Decision needed: delete it, or rename its header to AssetClass.StudentLoan and wire it in. Also 4 files contain tab characters (DealRun.hs has 69) and Util.hs:187 $findIndex is a TH-prefix ambiguity hazard ($ findIndex fixes it).

    Suggested low-hanging fruit (respecting the in-flight WIP files)

    1. Duplicate exports — delete the 5 redundant names from Asset.hs (2 lines) and getSpread from InterestRate.hs (1 line). Minutes of work, zero behavior change, committable today. (Liability.hs trio waits for its WIP to land.)
    2. Dead internal code purge from §3 (unexported names only) — ≈ −60 warnings, no API change.
    3. Stale hiding (...) imports (37 dodgy-imports) in non-WIP modules — one-liners.
    4. $ findIndex in Util.hs and the tab cleanup.
    5. Lock each cleaned category with -Werror=<flag> in the lib stanza — the house precedent already exists (-Werror=missing-fields, -Werror=incomplete-record-updates on lib; the exe even errors on incomplete-patterns). Adding plain -Wall before cleanup would dump ~3,230 warnings into every build instead of enforcing anything.
    6. After the WIP lands: shared debug helper (+32 missing-sigs), then unused-imports/matches/shadowing sweeps under -Wall, missing-signatures in tests, and incomplete-pattern fixes — the last one is behavioral and should ride on the golden/regression test corpus so cashflow outputs are provably unchanged.

    Items 1 and 4 are the single most low-hanging: 3 warnings for 3 deleted lines, no API, no behavior, no test risk.

  2. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    Verification pass at HEAD — the issue is valid, and two of these warnings are real bugs

    I re-ran the census with the library + executable scope (that is the scope the counts in this issue came from — my previous comment's table was library-only, which I correct below). Verdict: every category in this issue is genuine and reproducible. Several counts match exactly.

    warning class lib app total issue says verdict
    orphans 32 145 177 177 exact
    dodgy-imports 37 0 37 37 exact
    type-defaults 35 0 35 35 exact
    missing-signatures 35 1 36 38 −2 (drift)
    unused-top-binds 94 0 94 98 −4
    unused-local-binds 68 1 69 73 −4
    name-shadowing 221 1 222 215 +7
    unused-imports 404 79 483 510 −27
    unused-matches 1,484 10 1,494 1,483 +11

    (The test suite adds 486 more; the issue's scope excludes it.)

    Corrections to my previous comment

    1. Orphans: 177 is exact, and the hotspot is the app, not the library. app/MainBase.hs alone declares 145 orphan instances — mostly ToSchema for library types (the swagger layer), plus ToSchema (DL.DList a), etc. AssetClass.AssetBase has 18. So my "32" was lib-only; project-wide the issue's number is right, and a dedupe/grouping effort should start in app/MainBase.hs.
    2. debug is 34 copies, not 33, and all are dead. 33 files under src/ (including the unbuilt StudentLoan.hs) + app/Main.hs:108. Zero non-comment uses of debug anywhere; GHC flags 33 of them, the 34th sits in the unbuilt file. So it is not "32 of 33" — every copy is unused.
    3. Tabs: DealRun.hs has 70 tab characters (GHC's "69 further locations"), Deal.hs 8, DealAction.hs 5, Assumptions.hs 4.
    4. No -Wall is needed to see the duplicate exports. -Wduplicate-exports is on by default in GHC 9.12, so a normal cabal build already prints all 8. The fix stays a pure deletion (5 names across 3 lines in Asset.hs/InterestRate.hs; Liability.hs waits for its WIP).
    5. Project-wide -Wall today is ~3,468 warnings (lib 2,744 + app 238 + test 486), not ~3,230.

    Two confirmed real defects behind the noise

    This issue's core argument ("noise hides real defects") is justified by these two, both surfaced only by -Wname-shadowing / -Wincomplete-uni-patterns:

    1. src/Deal.hs:524-525 — callWhen is silently disabled.

      let extractTestDates (AP.CallOnDates dp _) = [...]
      let extractTestDates _ = []                 -- ← shadows the line above

      The second let is a separate binding, so the CallOnDates branch is unreachable and callDates is always []. A callable-bond callWhen assumption therefore never produces TestCall dates. No test exercises callWhen/CallOnDates. This is a behavioural bug, so fixing it needs an explicit decision + regression test, not a drive-by cleanup.

    2. src/Deal/DealAction.hs:93-94 — ByMaturity/ByStartDate crash on MultiIntBond.

      (\(b1@L.Bond{...},_) (b2@L.Bond{...},_) -> ...)

      only matches the Bond constructor; MultiIntBond (a public, JSON-derivable constructor, exercised in BondTest) falls through with a pattern-match failure when a waterfall uses those pay-order options.

    Also verified while checking the "reachability" claims:

    • DateUtil.hs:151,304 really can crash on client input: DatePattern(..) is exported and JSON-derived, genSerialDates is exported, and MidYear/SemiAnnual/DaysInYear are handled nowhere.
    • Util.toPeriodRateByInterval really computes in Double: signature is Rate -> Int -> Rate, but ** defaults to Double (GHC-18042).

    Bottom line

    All nine problem classes in this issue are valid; counts differ only by snapshot/drift. The lowest-hanging fruit is unchanged — the 8 duplicate exports (3 lines, 5 names, zero behaviour change; now confirmed visible in default builds). The highest-value real defect the noise has hidden so far is the callWhen shadowing in Deal.hs.

  3. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    ✅ Duplicate exports: fixed (5 of 8) in 53267b8 on Dec26.

    Removed the redundant explicit re-exports; the names stay exported, so it's a pure warning fix with no API or behavior change:

    • src/Asset.hs — getObligorFields, getObligorTags, getObligorId, getOriginInfo (all Asset class methods, already exported by Asset(..))
    • src/InterestRate.hs — getSpread (already exported by UseRate(..)); _getSpread untouched

    Verification: clean typecheck (0 duplicate-export warnings in these two files) and 609/609 tests pass.

    Remaining: the 3 duplicates in Liability.hs (_Bond, _MultiIntBond, _BondGroup, lines 17/19 vs 26) are deferred until that file's current WIP lands — the patch is one-line deletions in the earlier export-list lines.

  4. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    ✅ Dead debug copies: removed (25 of 34) in 69d982a on Dec26.

    All 34 copies of debug = flip trace project-wide are dead (zero non-comment call sites). This commit removes the 24 removable ones — 49 pure deletions, 0 insertions:

    • 23 src modules: dropped import Debug.Trace + the debug binding (Asset, Assumptions, Cashflow, DateUtil, Deal, DealAction, DealBase, DealMod, DealQuery, DealRun, InterestRate, Ledger, Lib, Pool, Stmt, Types, Util, Installment, Lease, Loan, Mortgage, ProjectedCashFlow, AssetCashflow)
    • app/Main.hs: dropped its dead copy (the 3 apparent call sites were inside comments; module Main never gets unused-top-bind warnings, which is why GHC only flagged it missing-signature)
    • MixedAsset.hs: dropped the lone stranded import Debug.Trace (no def, already flagged [-Wunused-imports])

    Verification: build clean; 609/609 tests; lib census deltas match exactly — unused-top-binds 94→71, missing-signatures 35→12, unused-imports 404→403, every other flag unchanged, so no behavior or API change.

    Remaining 10 copies are deferred:

    • 9 in the current WIP files (Accounts, Analytics, CreditEnhancement, Expense, Hedge, Liability, AssetBase, FixedAsset, Receivable) — same 1-line-each pattern, ready to apply once the WIP lands
    • 1 in unbuilt StudentLoan.hs — pending the delete vs. rename decision
  5. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    Open-item risk evaluation + no-risk fixes landed in be7302b

    Landed (zero-risk only) in be7302b — 24 files, +30/−64

    1. 27 stale hiding clauses (dodgy-imports) fixed — every name hidden from a module that doesn't export it, so the clause is a parse-level no-op:
      • import Data.Aeson hiding (json) ×21 (aeson ≥ 2 dropped the json alias); Data.Fixed hiding (Ratio) ×1; Types hiding (Current) ×2; Types hiding (getOriginDate) ×1
      • Cascade handled in-commit: 12 of those Data.Aeson imports became instance-only → now import Data.Aeson () (GHC's suggested form); the rest are genuinely used and stay unqualified.
    2. 11 dead internal bindings removed — all unexported, zero call sites, 9 proven by GHC Defined but not used; the 2 DealBase data types proven by reference exhaustion + constructor scan + absence from the deriveJSON splice (so no JSON output change): Util.mulIntegerR/debugLine/testSumToOne, Lib.addD/floatToFixed, Asset.normalPerfVector, Deal.updateSrtRate/queryTrigger, Lease.calcGapDays, DealBase.ActionTypeOnDate, DealBase.UnderBond.
    3. Util.hs $findIndex → $ findIndex — identical parse (no TH pragma in the file), kills the only -Woperator-whitespace-ext-conflict.

    Verification: build clean; 609/609 tests; lib census vs the 28ec30e baseline — dodgy-imports 37→10 (remaining 10 are all in WIP files), duplicate-exports 8→3 (earlier commit), unused-top-binds 94→56, missing-signatures 35→12, x-partial/incomplete-patterns/name-shadowing unchanged (no new warnings), total 2,744→2,634.

    Remaining #356 items, with risk classification

    Item Risk Status
    10 dodgy-import clauses in the 9 WIP files (+StudentLoan) none (same pattern) blocked by WIP landing
    Liability.hs trio: 3 duplicate exports + dead debug none blocked by WIP landing
    §3 remainder: ~17 "dead" type synonyms + unused lens bundles API risk — if exported via (..)/explicit lists, removing them changes the public surface (lens prisms like _Bond may be used by clients); needs a per-name export audit → deferring decision needed
    Deal.hs:524-525 callWhen shadowing (TestCall dates never generated) behavior change (enables a feature silently disabled) decision + regression test needed
    DealAction.hs:93-94 ByMaturity/ByStartDate crash on MultiIntBond behavior change decision needed
    DealRun.hs 70 tabs + 3 more low, but blanket tab→space trading can corrupt tab characters inside string literals; needs whitespace-role-aware edit deferred
    -Werror ratchet in cabal policy change; brittle while WIP files keep landing deferred until cleanup settles
    StudentLoan.hs (declares module AssetClass.Mortgage, not built) deletion = API-visible for anyone importing it; rename+canon = behavior-neutral if it was ever importable elsewhere decision: delete vs rename

    Next natural step after the WIP lands: the 10 WIP dodgy clauses + Liability trio in one pass, then per-candidate export audit for the synonyms/prisms.

  6. yellowbean commented on Oct 24, 2026

    @yellowbean
    CollaboratorAuthor

    Closing this issue. The hygiene debt it described is substantially cleared — everything that carried zero behavioral/API risk has landed on Dec26, and every count reported in the census has been reproduced and re-verified:

    warning class census (28ec30e) now
    duplicate-exports 8 3 (all in WIP Liability.hs)
    dodgy-imports 37 10 (all in WIP files)
    unused-top-binds 94 56
    missing-signatures 35 12
    operator-whitespace-ext-conflict 1 0
    lib total -Wall 2,744 2,634 (−110, rest is WIP-in-flight)

    Landed commits (all with 609/609 tests, no API/behavior change):

    • 53267b8 — duplicate exports (item 1)
    • 69d982a — 24 dead debug copies + stray import (item 2)
    • be7302b — 27 stale hiding clauses, 11 dead internal bindings, $-splice-conflict spacing

    The audit also surfaced two real behavioral defects (callWhen silently disabled; ByMaturity/ByStartDate crash on MultiIntBond) — demonstrating the issue's own premise that the noise hid real bugs.

    Work deliberately left open is now tracked so it can't be lost:

    Census + verification trail: census · verification · dup-export fix · debug removal · hygiene round

    Thanks for the nudge — this one cleaned up a lot more than warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions