Core Lint error in HEAD and others only with profiling: Invalid occurrence of a join variable
## Summary
When profiling in `-fprof-late-inline` mode I'm getting many alike lint errors, the first of which reads
```
[5 of 7] Compiling MnistFcnnRanked2 ( example/MnistFcnnRanked2.hs, dist-newstyle/build/x86_64-linux/ghc-9.15.20251212/horde-ad-0.3.0.0/l/exampleLibrary/build/exampleLibrary/MnistFcnnRanked2.p_o )
*** Core Lint errors : in result of Simplifier ***
<no location info>: warning:
join set {}
Invalid occurrence of a join variable: cont2_a37V9
The binder is either not a join point, or not valid here
In the RHS of $s$w$w$sastCastS3_s1hQy :: forall (sh :: [Nat]).
AstTensor AstMethodLet DualSpan (TKS sh Float)
-> AstTensor AstMethodLet DualSpan (TKS sh Double)
In the body of lambda with binder sh_a1hMj :: [Nat]
In the body of lambda with binder eta_a1hMo :: AstTensor
AstMethodLet DualSpan (TKS sh_a1hMj Float)
In a case alternative: (False)
In a case alternative: (FTKS sh1_a1hME :: [Nat],
x_a1hMF :: TK,
co_a1hMO :: (TKS sh_a1hMj Float :: TK)
~# (TKS2 sh1_a1hME x_a1hMF :: TK),
ds_a1hMP :: ShS sh1_a1hME,
ds1_a1hMQ :: FullShapeTK x_a1hMF)
In the body of lambda with binder ds2_a1hMG :: (# #)
In the body of a let with binder cont2_a37V9 :: ((sh_a1hMj :: [Nat])
~ ('[] @Nat :: [Nat])) =>
AstTensor AstMethodLet DualSpan (TKScalar Float)
-> AstTensor
AstMethodLet DualSpan (TKS sh_a1hMj Double)
In a case alternative: (AstConvert a_a37Wa :: TK,
c_a37Wb :: TKConversion a_a37Wa (TKS sh_a1hMj Float),
t_a37Wc :: AstTensor AstMethodLet DualSpan a_a37Wa)
In the body of a let with binder wild_a37Vl :: AstTensor
AstMethodLet DualSpan (TKS sh_a1hMj Float)
In a case alternative: (Just ds_a37Wg :: ((:~:)
@{[Nat]} sh_a1hMj ('[] @Nat),
AstTensor AstMethodLet DualSpan (TKScalar Float)))
In a case alternative: ((,) ds1_a37Wk :: (:~:)
@{[Nat]} sh_a1hMj ('[] @Nat),
t_a37Wl :: AstTensor AstMethodLet DualSpan (TKScalar Float))
In a case alternative: (Refl co_a37Wo :: ('[] @Nat :: [Nat])
~# (sh_a1hMj :: [Nat]))
In an occurrence of cont2_a37V9 :: ((sh_a1hMj :: [Nat])
~ ('[] @Nat :: [Nat])) =>
AstTensor AstMethodLet DualSpan (TKScalar Float)
-> AstTensor AstMethodLet DualSpan (TKS sh_a1hMj Double)
Substitution: <InScope = {sh_a1hMj sh1_a1hME x_a1hMF co_a1hMO
a_a37Wa co_a37Wo}
IdSubst = []
TvSubst = []
CvSubst = []>
```
## Steps to reproduce
```
git clone git@github.com:Mikolaj/horde-ad.git
cd horde-ad
git checkout lint-profile
cabal update
cabal build exampleLibrary --enable-optimization --allow-newer -w /home/mikolaj/r/ghc.Andreas3/ghc/_build/stage1/bin/ghc --constraint=ghc-typelits-natnormalise==0.9.1 --ghc-options="-dcore-lint -dstg-lint -dcmm-lint -dtag-inference-checks" --enable-profiling --profiling-detail=late --ghc-options='-fno-prof-late -fprof-late-inline'
```
This is not minimized in any way so far, except that only a small portion of the project is compiled and `-fpolymorphic-specialisation` is removed, which speeds up the compilation a lot, but it still requires some hours to get to the errors.
## Expected behavior
Compiles without lint errors. The test suite of horde-ad compiles with profiling when linting is disabled, but it segfaults when run (it also segfaults with some other profiling modes, probably not all triggering the linter, but I haven't investigated fully), so a more demanding expectation is that the tests complete without crashing.
## Environment
* GHC version used: ghc-9.15.20251212, it probably fails in the same way with GHC 9.14.1, 9.12.3 and 9.10.3 (at least, it segfaults when compiled without linting).
Optional:
* Operating System: Ubuntu
* System Architecture: amd64
issue