From: Ryohei Tokuda <tokuda@sf.ecei.tohoku.ac.jp>
To: caml-list@inria.fr
Subject: [Caml-list] Data representation of records
Date: Tue, 19 Jan 2016 17:54:27 +0900 [thread overview]
Message-ID: <CALahJKBRxsNvz4dcd+KSuZFSMhoJeOauXAbyNEEad+cjr72DDg@mail.gmail.com> (raw)
Dear the compiler developers,
I am just curious about memory representation of records.
When I read dump of `clambda`, I felt the representation of records a
little bit strange.
In the following program, functions just create the variants and records.
a.ml
type t = A of int | B of float
type r1 = {x:int; y:float}
let make_a x = A x
let make_b x = B x
let make_r1 x y = {x;y}
type r2 = {a:int; b:int}
let make_r2 a b = {a; b}
The result of `ocamlopt -dclambda -c a.ml` show the following.
(seq
(let
(make_a/1014
(closure (fun camlA__make_a_1014 1 x/1015 (makeblock 0 x/1015)) ))
(setfield_imm 0 (global camlA!) make_a/1014))
(let
(make_b/1016
(closure (fun camlA__make_b_1016 1 x/1017 (makeblock 1 x/1017)) ))
(setfield_imm 1 (global camlA!) make_b/1016))
(let
(make_r/1018
(closure
(fun camlA__make_r_1018 2 x/1019 y/1020 (makeblock 0 x/1019
y/1020)) ))
(setfield_imm 3 (global camlA!) make_r/1018))
(let
(make_r/1024
(closure
(fun camlA__make_r_1024 2 a/1025 b/1026 (makeblock 0 a/1025
b/1026)) ))
(setfield_imm 2 (global camlA!) make_r/1024))
0a)
This dump of IL is likely to show:
- `makeblock` seems like `alloc`, which first argument is the label.
- `makeblock` creates variants, and labels are different in A and B
(0 for A, and 1 for B).
- `makeblock` also creates records, and the label seems always 0.
I checked the above understanding by reading output assemblies,
I believe it is right comprehension.
My question is, why records need the labels.
In my comprehension, there is no chance that we check the label of records.
Thanks.
--
Ryohei Tokuda
next reply other threads:[~2016-01-19 8:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 8:54 Ryohei Tokuda [this message]
2016-01-19 9:07 ` Leo White
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALahJKBRxsNvz4dcd+KSuZFSMhoJeOauXAbyNEEad+cjr72DDg@mail.gmail.com \
--to=tokuda@sf.ecei.tohoku.ac.jp \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).