<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
I think you may be missing out on the goal here.  This is not an exploration of the user model (value vs primitive class, val/ref/bang/etc), this is an exploration of the underlying translation / implementation scheme *that might inform* future evolution of
 the user model.  
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 11, 2023, at 12:29 PM, Anderson Vasconcelos Pires <<a href="mailto:andvasp@gmail.com" class="">andvasp@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">Thanks for the prompt response!<br class="">
</div>
<div class="gmail_quote"><br class="">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class="">
<div class=""></div>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div dir="ltr" class=""><span style="font-family:arial,helvetica,sans-serif;font-size:12pt" class="">Mostly prototyping a proposal to remove Q-types (descriptor that starts with Q...;) and replace them by an attribute on methods and fields indicating if the
 value can be null.</span><br class="">
</div>
</blockquote>
<div class="">see <a href="https://mail.openjdk.org/pipermail/valhalla-spec-experts/2023-January/002217.html" target="_blank" class="">
https://mail.openjdk.org/pipermail/valhalla-spec-experts/2023-January/002217.html</a></div>
<div class=""><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small" class=""></span></div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">So if you want to remove Q types it means that L type does not need the identity information, right? </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div dir="ltr" class="">
<div class=""><br class="">
</div>
</div>
</blockquote>
<div class="">There is no notion of .val or .ref, if you want a field to be flattened, use a @Zero-Default and declare the field @NonNull.<br class="">
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Pretty good if we do not need to use .val or .ref!</div>
<div class="">
<div class=""><br class="gmail-Apple-interchange-newline">
Could the @NonNull be replaced by "!" but writing the attribute in the class file?<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">I Like @NonNull but I believe the "!" would be more practical.</div>
<div class="">  <br class="">
</div>
<div class="">As @Nullable is the default, maybe it would not be necessary to have it.</div>
</div>
<div class=""> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class="">
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div dir="ltr" class=""><span style="font-family:arial,helvetica,sans-serif;font-size:12pt" class="">yes, the prototype does not do any verification that the compiler does, i'm too lazy for that but the VM will catch you and throw an Error</span></div>
</blockquote>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Pretty good for a prototype! </div>
<div class=""> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class="">
<div class=""></div>
<div class="">About the mutability of fields, fundamentally, value type is about saying, i give up the notion of identity, if you have no identity, you have no location in memory (you can have more than one if you prefer) so the VM is free to pass by reference
 or pass by value. So you can not mutate a field, because you can only do that if you have one location in memory.<br class="">
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Ok for mutability but now I am a little bit confused about references, identity and memory location. Value class is a reference type that does not have identity. So it means that it can be allocated in the heap, right? So allocating it in the
 heap will have a memory location, do not? </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class=""></div>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div dir="ltr" class=""><span style="font-family:arial,helvetica,sans-serif;font-size:12pt" class="">regards,</span><br class="">
</div>
</blockquote>
<div class="">Rémi<br class="">
</div>
<div class=""><br class="">
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Thanks for the explanation!</div>
<div class=""><br class="">
</div>
<div class="">Regards,</div>
<div class="">Anderson. </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class=""></div>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Jan 10, 2023 at 7:39 PM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank" class="">forax@univ-mlv.fr</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hi all,<br class="">
i've developed a small prototype of what the semantics for the next round could be<br class="">
  <a href="https://github.com/forax/civilizer/" rel="noreferrer" target="_blank" class="">
https://github.com/forax/civilizer/</a><br class="">
<br class="">
The prototype works with the latest valhalla early access build<br class="">
  <a href="https://jdk.java.net/valhalla/" rel="noreferrer" target="_blank" class="">
https://jdk.java.net/valhalla/</a><br class="">
<br class="">
Basically, everything is an object, using @Value in front of a class or a record transforms it to a value class, a class with no identity<br class="">
(== compares the fields, synchronized throws an IllegalMonitorStateException, new WeakRef<>(...) throws an IdentityException).<br class="">
Adding @ZeroDefault means that the default value of the value class which is not null is all fields filled with zero.<br class="">
<br class="">
@NonNull allows to declare a non-null type (there is also @Nullable which is the default if there is no null aware annotation).<br class="">
For parameters, like Kotlin, sending null to a parameter of a method annotated with @NonNull throws a NPE.<br class="">
For a field a zero-default annotated with @NonNull ask for flattening, trying to store null also throws a NPE.<br class="">
For a field which is not a zero-default, even if declared @NonNull, the runtime will *not* throw a NPE because the field is null before reaching its initialization assignment in the constructor (and a constructor can call any methods).<br class="">
<br class="">
From the VM POV, a Q-type never appears inside a method descriptor. It appears inside field descriptor but putfield, getfield and withfield allows a field declared as a Q-type to be accessed as a L-type (this is currently simulated for getfield and putfield
 with an invokedynamic). This is very similar to the way the VM deals with arrays. And the VM knows if a parameter is a Q-type or not despite the fact that only L-type appears in the method descriptor because the Q-type are declared in the Preload table of
 the class. <br class="">
<br class="">
It means that if a class/record is not accessed directly by a constructor but by some static factories (like Optional) then moving in between an identity type, a value type (with zero-default or not) are backward compatible changes.<br class="">
<br class="">
regards,<br class="">
Rémi<br class="">
</blockquote>
</div>
<br class="">
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>