typers in Pharo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

typers in Pharo

Peter Uhnak
Hi,

apparently neither RoelTyper nor RefactoryTyper is capable of doing elementary type inference for methods, such as

[[[
cls := Object subclass: #Something.
cls compile: 'method ^ 1'.
typer := RBRefactoryTyper new.
typer guessTypeFromAssignment: (Something>>#method) ast body "Object
"
all := (TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something) asDictionary.
(all at: '^') types "an OrderedCollection(Object)"
]]]

Of course both of those tools have different objectives so I am not surprised.

Are there however other options? Roel Typer paper makes mention of Chuck, but that seems to be for Squeak only.

As for RoelTyper I've also encountered very strange behavior:
[[[
cls := Object subclass: #Something.
cls compile: 'method ^ 1'.
all := TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something.

all at: '^' ifAbsent: [ 'Not Found' ]. "'Not Found'"

all asDictionary at: '^' "ExtractedType: Sends: {}
Assignments: {}
".

all associations detect: [ :pair | pair key = '^' ] "'^'->ExtractedType: Sends: {}
Assignments: {}
"
]]]

Why does the first #at: fail if the second and especially third succeeds? My debugging lead me to IdentityDictionary>>#scanFor: but I don't know why that method is written in such a way so I stopped there.

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: typers in Pharo

Henrik Sperre Johansen
I don't know why, but return typing seems explicitly disabled in Pharo for RoelTyper.

Add the extraction in: 
PharoInstVarInterfaceExtractor >> #methodReturnTop
collector addAssignmentForReturn: stack last.
^self pop

and it seems to work for me at least.


The dictionary access failure is a bug in packagedResultsForCompiledMethod: , since the results are kept in an IdentityDictionary, we need to use as keys symbols, not strings, if we later want to fetch them using literals:

packagedResultsForCompiledMethod: aCompiledMethod
| results arr tmpNames|
results := IdentityDictionary new.
arr := (localTypingResults at: aCompiledMethod).
tmpNames := [aCompiledMethod methodNode tempNames] on: Error do: [aCompiledMethod tempNames].
1 to: arr size - 1 do: [:i | results at: (tmpNames at: i) put: (arr at: i)].
results at: #'^' put: (arr last).  
^results

Cheers,
Henry

On 15 Nov 2015, at 11:16 , Peter Uhnák <[hidden email]> wrote:

Hi,

apparently neither RoelTyper nor RefactoryTyper is capable of doing elementary type inference for methods, such as

[[[
cls := Object subclass: #Something.
cls compile: 'method ^ 1'.
typer := RBRefactoryTyper new.
typer guessTypeFromAssignment: (Something>>#method) ast body "Object
"
all := (TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something) asDictionary.
(all at: '^') types "an OrderedCollection(Object)"
]]]

Of course both of those tools have different objectives so I am not surprised.

Are there however other options? Roel Typer paper makes mention of Chuck, but that seems to be for Squeak only.

As for RoelTyper I've also encountered very strange behavior:
[[[
cls := Object subclass: #Something.
cls compile: 'method ^ 1'.
all := TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something.

all at: '^' ifAbsent: [ 'Not Found' ]. "'Not Found'"

all asDictionary at: '^' "ExtractedType: Sends: {}
Assignments: {}
".

all associations detect: [ :pair | pair key = '^' ] "'^'->ExtractedType: Sends: {}
Assignments: {}
"
]]]

Why does the first #at: fail if the second and especially third succeeds? My debugging lead me to IdentityDictionary>>#scanFor: but I don't know why that method is written in such a way so I stopped there.

Thanks,
Peter


signature.asc (859 bytes) Download Attachment