-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Instance guessing #32
Comments
This suggestion taps into the same idea as #17 (debugger type info). However, you seem to be proposing 2 changes with this issue:
Regarding Analysing unknown methodsIf I understand you correctly, you want to perform accessors or other small methods on existing objects in the system. This is problematic, not because of performance concerns, but rather because of possible side effects. Even if you try to analyse the method to find out, whether the method does have side-effects, you cannot be certain about this. Meta-Programming could have been used to perform any kind of nasty message rerouting. However, it would be possible to analyse the code of the method with conventional means to try to find the returned type. Regarding using objects to enhance type guessingThis should be the focus of this issue. In certain scenarios (Debugger, Workspace, etc.), it is possible, that some of the objects that type guessing is actually used for are available for further information. However, your proposed method This could considerably enhance type guessing for longer accessor chains (whether they are good coding practice is a different discussion). Answering your questions
instance guessing is not quite the thing we're planning to do here.
I hope I understood your intention correctly and this feedback is good food for thought. |
Concrete steps that would be a good implementation strategy: Add instance variables to the ECContext to support type info from Smalltalk-context or something similar. Enhance the existing guess... methods to use available instances as the first way to guess the type. During this step, it's necessary to implement a custom TypeInfo object, which can take either a class or an instance as the basis of type information. |
Hi, many thanks for your detailed answer! Let me start from the end:
Did you read my PR #29? I think this implements just what you wrote. Regarding Analysing unknown methods
What I wanted to propose was only to evaluate quick methods (see CompiledMethod>>#isQuick). If I understand their intention correctly, only methods that include nothing more than a quick return statement will return true for this test. Such methods thus cannot have side-effects. More complex methods like the following would not be covered by this proposal: foo
^ foo ifNil: [foo := self generateFoo] But aside from the special case of quick methods, I totally agree that scanning each method for possible side-effects, in order to possibly perform it, would be overengineering, respecting the fact that method chains should be used rarely following LoD (Law of Demeter). Regarding using objects to enhance type guessingI'm not sure why you would not like to implement #guessInstanceOf:. Even when we have no current execution context, there are some concrete instances to deal with, such as literals or global vars. Typing
Exactly :)
Then #guessArgument: should return an instance, not a class, so that we can use the result to perform further quick methods on it (see above). Can you see my point? One other problem with #guessObjectForName: would be the inability of the proposed protocol to differentiate between the guessed instance
Such a class could override #guessTypeForName:. Please also see my other answer in #33. |
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 typebounds origin sqr
. Currently, there is no suggestion forsqrt
, but as Rectangle>>#bounds is quick, it would be possible to find out the type ofbounds origin
and so to suggestsqrt
. It would be even possible to suggestself bounds origin x sqrt
etc.Possible sources for instance guessing
Proposed design changes
Questions
(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 :)
The text was updated successfully, but these errors were encountered: