<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi, <br>
</p>
<p>I saw my previous mistake, and corrected this. <br>
This is a sample test, for a very simple inference.<br>
</p>
<p>testReturnFloatConstantNode<br>
    | ccg tMethod |<br>
    ccg := CCodeGenerator new.<br>
    ccg addClass: SlangTypeInferenceTestsClass.<br>
    ccg inferTypesForImplicitlyTypedVariablesAndMethods.<br>
    tMethod := ccg methodNamed: #returnAFloatConstantNode.<br>
    <br>
    self assert: tMethod isNotNil.<br>
    self assert: (ccg typeFor: tMethod statements first in: tMethod) equals: #double.<br>
    self assert: tMethod returnType equals: #double<br>
   <br>
</p>
<p>I need to work on ones with ambiguity.</p>
<br>
<p>Pierre<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 17/12/2019 07:49, pierre misse wrote:<br>
</div>
<blockquote type="cite" cite="mid:DB6P18901MB021557FBD2A135409E96B741E5500@DB6P18901MB0215.EURP189.PROD.OUTLOOK.COM">
<pre class="moz-quote-pre" wrap=""> </pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<p>My first approach is very simple</p>
<p>create a CCodeGenerator<br>
add only my current class with independent methods<br>
infer the type<br>
check the types.</p>
<p>testConstantInt32<br>
    | ccg tMethod |<br>
    ccg := CCodeGenerator new.<br>
    ccg addClass: self class.<br>
    tMethod := ccg compileToTMethodSelector: #anInt32 in: self class.<br>
    ccg inferTypesForImplicitlyTypedVariablesAndMethods.<br>
    ccg typeFor: tMethod statements first expression variable in: tMethod. "#sqInt"   
<br>
    tMethod inferReturnTypeFromReturnsIn: ccg."a TMethod (SlangTypeInferenceTests>>anInt32)"   
<br>
    tMethod returnType."nil"</p>
<p>Applied in this case to:</p>
<p>anInt32<br>
    | a |<br>
    ^ a := 30<br>
</p>
<p>Maybe I misunderstood the type Inference that I read so far, but based on #TMethod >> #typeFor:in:,<br>
I would expect the ccg to keep the type information somewhere, which doesn't seem to be the case.</p>
<p>Maybe it's because my set up is wrong?<br>
</p>
<p>This part of the comment puzzles me "deferring to aCodeGen (which defers to the vmClass)", gonna dig into this method.</p>
<p><br>
</p>
<p>Thank you,<br>
</p>
<p>Pierre<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 17/12/2019 07:33, Eliot Miranda wrote:<br>
</div>
<blockquote type="cite" cite="mid:FCD7169B-C3D0-402E-B3CE-EC23F6033BB6@gmail.com">
<pre class="moz-quote-pre" wrap=""> </pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<div dir="ltr">Hi Pierre, and welcome.</div>
<div dir="ltr"><br>
<blockquote type="cite">On Dec 16, 2019, at 10:19 PM, pierre misse <a class="moz-txt-link-rfc2396E" href="mailto:pierre_misse25@msn.com" moz-do-not-send="true">
<pierre_misse25@msn.com></a> wrote:<br>
</blockquote>
</div>
<blockquote type="cite">
<div dir="ltr"><span>
<p>Hi Eliot,</p>
<p><br>
</p>
<p>Thanks for the detailed answer and all the pointers !</p>
<p>I must have misunderstood  #inferTypesForImplicitlyTypedVariablesAndMethods when I first came across it.<br>
</p>
<p><br>
</p>
<p>Have a nice day :)</p>
</span></div>
</blockquote>
<div><br>
</div>
thank you :)
<div><br>
<blockquote type="cite">
<div dir="ltr"><span>
<p>Pierre<br>
</p>
<div class="moz-cite-prefix">On 17/12/2019 01:14, Eliot Miranda wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAC20JE1HgpcKin2WFMe-X7qHiN-xS98ciqDN3WSjikkqpAfkWw@mail.gmail.com">
<pre class="moz-quote-pre" wrap=""> </pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi Pierre,</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, Dec 16, 2019 at 4:07 AM pierre misse <<a href="mailto:pierre_misse25@msn.com" moz-do-not-send="true">pierre_misse25@msn.com</a>> wrote:</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Hi,</p>
<p>I'm currently trying to understand Slang's type inference, and to do so trying to write tests.</p>
</div>
</blockquote>
<div>Is it your intention to contribute those tests back to VMMaker.oscog on <a href="http://source.squeak.org" moz-do-not-send="true">
source.squeak.org</a>? <br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
If I am able to, it is my intention. <br>
</span></div>
</blockquote>
<div><br>
</div>
Thank you. It be warmly appreciated.</div>
<div><br>
</div>
<div>One thing yo look at in your tests is instabilities in the algorithm, typically caused by the use of hashed collections (eg Set) that have different enumerations from run to run, usually due to hashes being pseudo-randomly computed.  If you look at the
 last commit of the Spur cointerp.c’s you’ll see one variable that changes type from sqInt to usqInt. This points to such a bug. I’ll try and provide you with specifics soon.</div>
</blockquote>
<p>Thanks for the warning. I was actually already aware of this bug, but now I also know the cause !<br>
</p>
<blockquote type="cite" cite="mid:FCD7169B-C3D0-402E-B3CE-EC23F6033BB6@gmail.com">
<div><br>
<blockquote type="cite">
<div dir="ltr"><span>
<blockquote type="cite" cite="mid:CAC20JE1HgpcKin2WFMe-X7qHiN-xS98ciqDN3WSjikkqpAfkWw@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>I'm using CCodeGenerator >> #compileToTMethodSelector:in: to get the TMethod, but i cannot seem to find how to use the type inference on this TMethod (or in the instance of CCodeGenerator).</p>
</div>
</blockquote>
<div><br>
</div>
<div>Here's some doit that run Slang including type inference:</div>
<div><br>
</div>
<div><a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/Slang%20Test%20Workspace.text" moz-do-not-send="true">https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/Slang%20Test%20Workspace.text</a></div>
<div><br>
</div>
<div>If you use <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/buildspurtrunkvmmaker64image.sh" moz-do-not-send="true">
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/buildspurtrunkvmmaker64image.sh</a> to build a VMMaker image it'll create an image containing g this and other useful workspaces that contain doit to launch a VM under the simulator, etc.</div>
<div><br>
</div>
<div>Type inference is driven by this loop in CCodeGeneraror>>inferTypesForImplicitlyTypedVariablesAndMethods which iterates, inferring types until no more types can b e inferred (until the algorithm has reached a fixed point).</div>
<div><br>
</div>
<div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>"now iterate until we reach a fixed point"</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>[| changedReturnType |</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>changedReturnType := false.</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>allMethods do:</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>[:m|</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>m inferTypesForImplicitlyTypedVariablesIn: self.</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>(m inferReturnTypeIn: self) ifTrue:</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>[changedReturnType := true]].</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"></span>changedReturnType] whileTrue.</div>
</div>
<div><br>
</div>
<div>Type information is derived from explicit return types in methods (the <returnTypeC: > pragma), types for "kernel" sends from CCodeGenerator>>#returnTypeForSend:in:ifNil:, and for types propagated to returns from variables that themselves are either explicitly
 typed using <var: ... type: ...> and <var: ... declareC: ...> pragmas, or get their types in assignments of the results of methods, where the type they acquire is the return types of those methods.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Also, I have been wondering what is the semantic of sqInt. I found out it was an alias for a long, but i couldn't find better than that.
</p>
</div>
</blockquote>
<div>#sqInt is first of all a pun for "squint"</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
nice , I was wondering if that was the case too :D<br>
<blockquote type="cite" cite="mid:CAC20JE1HgpcKin2WFMe-X7qHiN-xS98ciqDN3WSjikkqpAfkWw@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="gmail_quote">
<div>, a shortening of Squeak Integer.  It is an integer type of the same size as an "ordinary object pointer", or "oop". #usqInt, #sqLong & #usqLong are other important types.  #sqLong & #usqLong are 64-bit types.  #sqInt & #usqInt are 32-bit types in 32-bit
 VMs and 64-bit types in 64-bit VMs.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Are there offsets to find objects in the object memory?</p>
</div>
</blockquote>
<div>A #sqInt is typically used to hold the oop for an object and indeed it points to the header word of the object.  The object is preceded by an overflow header word if it has more than 254 slots.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Are there cast as pointers?<br>
</p>
</div>
</blockquote>
<div>Yes.  See the functions and macros in platforms/Cross/vm/sqMemoryAccess.h.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Thank you in advance :)<br>
</p>
<p>Pierre.</p>
</div>
</blockquote>
</div>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div><span style="font-size:small;border-collapse:separate">
<div>_,,,^..^,,,_</div>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</span></div>
</blockquote>
<blockquote type="cite">
<div dir="ltr"><span>
<blockquote type="cite" cite="mid:CAC20JE1HgpcKin2WFMe-X7qHiN-xS98ciqDN3WSjikkqpAfkWw@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div><span style="font-size:small;border-collapse:separate">
<div>best, Eliot</div>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</span></div>
</blockquote>
<br>
</div>
<div>Cheers</div>
</blockquote>
</blockquote>
</body>
</html>