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
Original bug ID: 7861 Reporter: freyr Assigned to:@lpw25 Status: resolved (set by @lpw25 on 2018-10-22T08:08:23Z) Resolution: not a bug Priority: high Severity: minor Platform: x86_64 OS: linux OS Version: 4.18.11-arch1-1 Version: 4.07.1 Category: middle end (typedtree to clambda) Monitored by:@nojb
Bug description
For some reason GC collects react events borrowed in Lwt_react.E.select. Lwt_react in flambda build.E.keep or saving event in some variable or reference does not help either. Without flambda GC does not collect values it seems.
Steps to reproduce
A trivial example is attached. With flambda switch Lwt_react.E.with_finaliser functions print, without flambda they do not.
I had a look into this, and it seems to be an issue with the implementation of Lwt_react.with_finaliser rather than with the OCaml GC. That function is implemented as follows:
let with_finaliser f event =
let r = ref () in
Gc.finalise (finalise f) r;
map (fun x -> ignore r; x) event
The idea is to add a finaliser to the reference 'r', and ensure that the reference 'r' is reachable from the returned event. However, flambda (correctly!) notices that 'r' is not used in the returned event (since it is ignored), and optimises the use of 'r' away. This means that the GC is free to collect 'r' and run the finaliser immediately.
The simplest fix is to ensure that the reference to 'r' is not optimised away, by hiding the fact that it is unused from the optimiser using Sys.opaque_identity:
map (fun x -> ignore (Sys.opaque_identity r); x) event
I've made an issue on the Lwt bugtracker about this at ocsigen/lwt#626. I'm afraid I won't have time to follow up on this immediately (I'm just about to go on vacation for a couple of weeks), but I'll have a look later on.
Original bug ID: 7861
Reporter: freyr
Assigned to: @lpw25
Status: resolved (set by @lpw25 on 2018-10-22T08:08:23Z)
Resolution: not a bug
Priority: high
Severity: minor
Platform: x86_64
OS: linux
OS Version: 4.18.11-arch1-1
Version: 4.07.1
Category: middle end (typedtree to clambda)
Monitored by: @nojb
Bug description
For some reason GC collects react events borrowed in Lwt_react.E.select. Lwt_react in flambda build.E.keep or saving event in some variable or reference does not help either. Without flambda GC does not collect values it seems.
Steps to reproduce
A trivial example is attached. With flambda switch
Lwt_react.E.with_finaliser
functions print, without flambda they do not.File attachments
The text was updated successfully, but these errors were encountered: