[Vm-dev] Slang's type inference and typing

Eliot Miranda eliot.miranda at gmail.com
Wed Dec 18 08:25:39 UTC 2019


Hi Pierre,

On Tue, Dec 17, 2019 at 10:36 PM pierre misse <pierre_misse25 at msn.com>
wrote:

>
>
>
> On 18/12/2019 03:52, Eliot Miranda wrote:
>
>
> Hi Pierre,
>
> On Tue, Dec 17, 2019 at 9:50 AM pierre misse <pierre_misse25 at msn.com>
> wrote:
>
>>
>>
>> Hi,
>>
>> I saw my previous mistake, and corrected this.
>> This is a sample test, for a very simple inference.
>>
>> testReturnFloatConstantNode
>>     | ccg tMethod |
>>     ccg := CCodeGenerator new.
>>     ccg addClass: SlangTypeInferenceTestsClass.
>>     ccg inferTypesForImplicitlyTypedVariablesAndMethods.
>>     tMethod := ccg methodNamed: #returnAFloatConstantNode.
>>
>>     self assert: tMethod isNotNil.
>>     self assert: (ccg typeFor: tMethod statements first in: tMethod)
>> equals: #double.
>>     self assert: tMethod returnType equals: #double
>>
>
>  And perhaps have SlangTypeInferenceTestsClass inherit from
> StackInterpreter or InterpreterPrimitives.  That will give you much more
> context.
>
> I was currently inheriting from interpreterPlugin, but I can indeed switch.
>

I think you have it right.   interpreterPlugin should be fine.

My tests currently were as simple as it gets:
>
> constantNode
> Returm constant
> return Explicit argument
> return Explicit Temporary
> return temp assigned by constant.
>
> So it wasn't necessary.
>
> Only surprising result is the return temp assigned by constant, which
> loses the type. This seems to be easily improvable in the future if you'd
> like.
>
> returnTempFloatConstantNode
>     | t |
>     t := 1.0.
>     ^ t
>
Its its return type isn't inferred to be #double then that's a bug.

> testReturnTempFloatConstantNode
>     | ccg tMethod |
>     ccg := CCodeGenerator new.
>     ccg addClass: SlangTypeInferenceTestsClass.
>     ccg inferTypesForImplicitlyTypedVariablesAndMethods.
>     tMethod := ccg methodNamed: #returnTempFloatConstantNode.
>
>     self assert: tMethod isNotNil.
>     self assert: (ccg typeFor: tMethod statements first in: tMethod)
> equals: #double.
>     self assert: (ccg typeFor: tMethod statements first variable in:
> tMethod) equals: #sqInt.
>     self assert: tMethod returnType equals: #sqInt.
>

 Well, t is untyped and it is assigned a double.  So I would expect that
the inferencer infer the ty[e #double for f.  Then it should infer the type
#double for  returnTempFloatConstantNode since it answers t.


>     self error "wait what"
>
>
>
>  I need to work on ones with ambiguity.
>>
>>
>>  The instability I saw was in getErrorObjectFromPrimFailCode; its two
> locals clone & errObj are sometimes typed as squint and sometimes as
> usqInt.  Some times numPointerSlotsOf ends up with a return type of usqInt,
> some times as sqInt.  I've recently had success in another project
> substituting OrderedDictionary et al for Dictionary.  So I'm sure that
> solutions can be found easily.
>
>
> Thanks for the pointer !
>
>
> Pierre
>

Thanks for looking!!  It will be great to have tests for this, if only for
good documentation.  I never had the time, and always look at the diffs of
the generated code.  But that doesn't mean I don't want these tests.  Thank
you for your energy!

_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20191218/1e6d2902/attachment.html>


More information about the Vm-dev mailing list