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

Allow _ in async use! _ pattern (lift FS1228 restriction) #18189

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Dec 30, 2024

Description

Fixes #16343

Before

open System
let doSomething () =
    async {
        use! _ = Async.OnCancel (fun () -> printfn "disposed") // FS1228: 'use!' bindings must be of the form 'use! <var> = <expr>'
        use! res = Async.OnCancel (fun () -> printfn "disposed")
        return ()
    }

After

open System
let doSomething () =
    async {
        use! _ = Async.OnCancel (fun () -> printfn "disposed") //  Works
        use! res = Async.OnCancel (fun () -> printfn "disposed")
        return ()
    }

Checklist

  • Test cases added
  • Release notes entry updated

Copy link
Contributor

github-actions bot commented Dec 30, 2024

❗ Release notes required

@edgarfgp,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.300.md No release notes found or release notes format is not correct

✅ Found changes and release notes in following paths:

Change path Release notes path Description
LanguageFeatures.fsi docs/release-notes/.Language/preview.md

@edgarfgp edgarfgp marked this pull request as ready for review December 31, 2024 10:15
@edgarfgp edgarfgp requested a review from a team as a code owner December 31, 2024 10:15
@edgarfgp edgarfgp closed this Dec 31, 2024
@edgarfgp edgarfgp reopened this Dec 31, 2024
@auduchinok
Copy link
Member

This is a change in what does the language allow. I think it should be guarded with a language version, so the tooling could suggest using _ safely only when the supported language version is used.

@edgarfgp edgarfgp requested review from T-Gro and auduchinok January 2, 2025 16:02

error (Error(FSComp.SR.tcInvalidUseBangBindingNoAndBangs (), m))
mkSynCall "Bind" mBind [ rhsExpr; consumeExpr ] ceenv.builderValName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting a call to "Using" somewhere, but cannot find it.
Is it implicit by recursive calling into a different handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I understood the logic was that _ (wild) will need to be Bind in the same way that ident(any ident) __ (double underscore). But Im not very familiar with the CE Translation logic.

Tested this to "Using" and it does not work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it only does "Bind" and not an "Using", it will lack the CE's implementation of disposal (which can be anything the CE wants to do to cleanup).

@@ -214,6 +214,70 @@ let run r2 r3 =
(Error 3345, Line 18, Col 9, Line 18, Col 13, "use! may not be combined with and!")
]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do add positive tests which include a run operation and demonstrate that a resource which is being use! _ ='d get's cleaned up with a custom .Using method of the builder.

@edgarfgp edgarfgp marked this pull request as draft January 7, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow _ in async use! _ pattern (lift FS1228 restriction)
3 participants