Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False negative with TailCall attribute #18365

Open
BoundedChenn31 opened this issue Mar 6, 2025 · 2 comments · May be fixed by #18399
Open

False negative with TailCall attribute #18365

BoundedChenn31 opened this issue Mar 6, 2025 · 2 comments · May be fixed by #18399
Labels
Area-Compiler-Optimization The F# optimizer, release code gen etc. Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@BoundedChenn31
Copy link
Contributor

Repro steps

Consider the following code (the simplest example I could craft, don't expect anything sane):

type Value =
    { Code: string }

[<TailCall>]
let rec fooArray (values: Value[], code: string) =
    match values with
    | [||] -> seq { code }
    | values ->
        let replicatedValues =
            values
            |> Array.map (fun value -> fooArray (values, value.Code))
        replicatedValues |> Seq.concat

fooArray isn't called in tail recursive manner, however compiler does not issue a warning.

Curiously, after rewrite to Seq functions compiler does issue Warning FS3569 : The member or function 'fooSeq' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way.

[<TailCall>]
let rec fooSeq (values: Value[], code: string) =
    match values with
    | [||] -> seq { code }
    | values ->
        let replicatedValues =
            values
            |> Seq.map (fun value -> fooSeq (values, value.Code))
            |> Seq.toArray
        replicatedValues |> Seq.concat

Looking at decompiled code of assembly I would guess that compiler tries to optimise Array.map and TailCall analyser mistakes the result for tail-recursive function.

Expected behavior

Warning is issued for first code example.

Actual behavior

No warning.

Known workarounds

.

Related information

Provide any related information (optional):
.NET SDK 9.0.200

@github-actions github-actions bot added this to the Backlog milestone Mar 6, 2025
@abonie abonie added Area-Compiler-Optimization The F# optimizer, release code gen etc. Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage labels Mar 17, 2025
@abonie
Copy link
Member

abonie commented Mar 17, 2025

@dawedawe Any clues about this one?

@dawedawe
Copy link
Contributor

Not yet, need to look into it.

@dawedawe dawedawe linked a pull request Mar 21, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Optimization The F# optimizer, release code gen etc. Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Status: New
Development

Successfully merging a pull request may close this issue.

3 participants