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

pierre misse pierre_misse25 at msn.com
Wed Dec 18 06:36:09 UTC 2019


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<mailto: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.

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 looses the type. This seems to be easily improvable in the future if you'd like.

returnTempFloatConstantNode
    | t |
    t := 1.0.
    ^ t

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.

    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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20191218/4f46ff90/attachment.html>


More information about the Vm-dev mailing list