Version française
Home     About     Download     Resources     Contact us    
Browse thread
Class runtime representation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Class runtime representation
From: "Dmitry Bely" <dmitry.bely@gmail.com>
> Just curious: why Ocaml runtime should know class method names? Why
> the method tag (a hash value computed from the name) is not enough?

Good question.
Names are only used during class construction, which is dynamic in
ocaml. Names are used for methods (both public and private) and
instance variables. Of all those, only public methods use a hashed
values in other operations, and for this reason public methods in the
same class are guaranteed to have no hash conflicts. But this is not
enforced for private methods, which can always be called in a more
direct way. And since some internal data structures mix private and
public methods, it seems simpler to have names for all.

Now, as we can also statically detect potential conflicts between
private methods, it would be possible to use hashed tags for private
methods too (and even instance variables). This might improve code
size, as names would disappear from the runtime. This would not change
performance however, as class construction only occurs once for most
class declarations, and a fixed number of times in more complex
examples combining inheritance and functors. And it would introduce a
new restriction on the naming of private methods.

Another reason names were kept is to eventually allow runtime
introspection. This is not accessible currently, but the runtime knows
the names of all methods in a class.

Jacques Garrigue