Navigation Menu

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

finalisation + constants #2977

Closed
vicuna opened this issue Oct 4, 2001 · 2 comments
Closed

finalisation + constants #2977

vicuna opened this issue Oct 4, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 4, 2001

Original bug ID: 555
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hello,

although it is documented that finalisation does not work on constants,
there is somewhat inconsistent behaviour here between native code and
byte code, e.g.:

let rec loop () = Gc.full_major (); loop ()
let finaliser _ = print_endline "FINALISER!"; flush stdout
let _ = Gc.finalise finaliser [()]; loop ()

When called as byte code, nothing happens (finaliser isn't called). When
compiling to native code, the program bails out with an exception:

Fatal error: uncaught exception Invalid_argument("Gc.finalise")

I assume this is a consequence of the two compilers treating constants
slightly differently. Now we use the following line instead of the
last one:

let _ = Gc.finalise finaliser []; loop ()

This time the program will raise an exception in both cases as expected
considering the docs.

Now we write this instead:

let _ = let u = () in Gc.finalise finaliser [u]; loop ()

This will trigger the finaliser in both cases so constants are obviously
not substituted at compile time, which could be surprising to people in
such simple cases.

Regards,
Markus

--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus

@vicuna
Copy link
Author

vicuna commented Oct 5, 2001

Comment author: administrator

Hi Markus,

there is somewhat inconsistent behaviour here between native code and
byte code, e.g.:

That's what the doc means when it says "implementation-dependent". Byte-code
and native-code are two different implementations of the language.

let _ = let u = () in Gc.finalise finaliser [u]; loop ()

This will trigger the finaliser in both cases so constants are obviously
not substituted at compile time, which could be surprising to people in
such simple cases.

Things like finalisation and weak pointers do expose some details of the
implementation that would otherwise be impossible to see from user programs.
That's one reason why they are largely under-specified: the rest of the
O'Caml docs don't even define the concepts that would be needed to explain
what is going on.

The other reason is that we don't want to paint ourselves in a corner by
ruling out some optimisations that we might want to implement later.

I'm adding a sentence in gc.mli to say that the results of String.make,
String.create, and Array.make are guaranteed to be finalisable (on the
condition that the length argument is not zero). Maybe we'll add a few
others later.

-- Damien

@vicuna vicuna closed this as completed Oct 5, 2001
@vicuna
Copy link
Author

vicuna commented Oct 5, 2001

Comment author: administrator

On Fri, 05 Oct 2001, Damien Doligez wrote:

That's what the doc means when it says "implementation-dependent". Byte-code
and native-code are two different implementations of the language.

Ok, I see. I thought behaviour was merely "unspecified" like evaluation
order, but still the same for both byte and native code of the current
implementation. It's probably not a terribly big problem to have such
minor differences.

The other reason is that we don't want to paint ourselves in a corner by
ruling out some optimisations that we might want to implement later.

Understandable. It might be interesting to know what kind of optimisations
you are intending, a topic which surely many people on the mailing list
would be eager to learn about!

Regards,
Markus

--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus

@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant