Zulip Chat Archive

Stream: lean4

Topic: memory model of natural numbers


Schrodinger ZHU Yifan (Aug 27 2023 at 02:57):

Is it true that all lean_nat related API does not "consume" the object except for those declared with dec?

James Gallicchio (Aug 27 2023 at 04:33):

I don't entirely understand the question, but I'll try to explain a bit -- for x : Nat there's two possible memory representations.

  • If x < 2^63, it is represented as the uint64 value (n << 1) + 1
  • If x >= 2^63 it is represented as a lean_object* which contains a libgmp int.

So, since the objects might not be scalars, lean_inc and lean_dec are still called to maintain reference counts in the case where it's not scalar.

Mario Carneiro (Aug 27 2023 at 04:35):

As far as I can tell, the answer is yes (I don't see any lean_nat functions containing dec except lean_nat_dec_eq which is an unrelated use of dec). I'll make a PR to update lean.h with more accurate borrowing annotations

James Gallicchio (Aug 27 2023 at 04:41):

all the lean_nat functions I see take b_lean_obj_arg..? is there one that isn't accurate?

Mario Carneiro (Aug 27 2023 at 05:14):

lean_nat_big_succ takes object* for example

James Gallicchio (Aug 27 2023 at 05:29):

oh, all the lean_nat_big functions, i see


Last updated: Dec 20 2023 at 11:08 UTC