Skip to content

Proposal: Instance guessing #32

@LinqLover

Description

@LinqLover

Type guessing is a very nice feature, but I think in some cases, information about the actual accessed instance could be useful for further type guessing.

There are many quick methods in Squeak (accessors or magic number returns) which are very fast and side-effect-free. We could guess the instance of the last typed expression in some cases and then perform a possible quick method, to "guess" the type of its return value.

One popular scenario might be Autocompletion in Inspector: Do Morph new inspect, then type bounds origin sqr. Currently, there is no suggestion for sqrt, but as Rectangle>>#bounds is quick, it would be possible to find out the type of bounds origin and so to suggest sqrt. It would be even possible to suggest self bounds origin x sqrt etc.

Possible sources for instance guessing

Proposed design changes

  • In ECContext, introduce #guessInstanceOf:
  • In #guessTypeOf:, first check #guessInstanceOf:
    • clean up here and move at least global and constant checks into #guessInstanceOf:
  • In #guessInstanceOf: ...
    • check globals and constant
    • check context
    • invoke #guessUnaryInstance:. There, try to guess instance of previous range and lookup latest selector on its class; if is quick, perform it on the latest object and return the result (already spiked this)
  • It would be even possible to invoke #respondsTo: for truely late-bound suggestions 🤩 (useful in case of transparent wrappers)
  • In all Model classes, replace #guessTypeForName: with #guessObjectForName:

Questions

  • I don't get the actual task of the current #guessUnaryAccessorClass: implementation. What does it do? Would it be still relevant after applying this proposal?
  • Naming issue: "instance guessing" sounds quite inelaborate
  • Is there be any imaginable case where a model could implement #guessTypeForName:, but could not implement #guessObjectForName:? It would be possible to keep the base implementation and forward it to (self guessObjectForName: aString) class

These are only some thoughts by someone who is not deep into the implementation, so I would be very happy about your feedback! So long, best success for your thesis, @MrModder :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions