HES2011 - joernchen - Ruby on Rails from a Code Auditor Perspective
Summer of Code 2006: Ruby Type Inference & Code Completion for RDT
-
Upload
jason-morrison -
Category
Business
-
view
1.630 -
download
3
description
Transcript of Summer of Code 2006: Ruby Type Inference & Code Completion for RDT
![Page 1: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/1.jpg)
http://soc.jayunit.net
Ruby Type Inference &
Code Completion for RDTGoogle Summer of Code
Jason Morrison
![Page 2: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/2.jpg)
Type Inference and RDT http://soc.jayunit.net
Overview
• Project Goals• Why Eclipse and Java?• Completion Features• Type Inference Algorithm• Issues• The Future
![Page 3: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/3.jpg)
Type Inference and RDT http://soc.jayunit.net
Project Goals
![Page 4: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/4.jpg)
Type Inference and RDT http://soc.jayunit.net
Project Goals
• Code completion for RDT– I’m lazy; Ruby is great and succinct, but…– And, it helps other developers!
![Page 5: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/5.jpg)
Type Inference and RDT http://soc.jayunit.net
Project Goals
• Ruby type inference– It’s fun! (Read: I knew very little about it)– Alternative implementation performance
• Priming the cache for polymorphic dispatch
![Page 6: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/6.jpg)
Type Inference and RDT http://soc.jayunit.net
Why Eclipse and Java?
![Page 7: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/7.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 8: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/8.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 9: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/9.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 10: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/10.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 11: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/11.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 12: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/12.jpg)
Type Inference and RDT http://soc.jayunit.net
“Eclipse is too big!”
![Page 13: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/13.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 14: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/14.jpg)
Type Inference and RDT http://soc.jayunit.net
“It’s bloated! :P”
![Page 15: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/15.jpg)
Type Inference and RDT http://soc.jayunit.net
![Page 16: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/16.jpg)
Type Inference and RDT http://soc.jayunit.net
Not targeting that guy
![Page 17: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/17.jpg)
Type Inference and RDT http://soc.jayunit.net
Convert the natives!
![Page 18: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/18.jpg)
Type Inference and RDT http://soc.jayunit.net
Completion Features
![Page 19: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/19.jpg)
Type Inference and RDT http://soc.jayunit.net
Completion Features
• Scoped object completion• Method completion
![Page 20: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/20.jpg)
Type Inference and RDT http://soc.jayunit.net
Scoped Object Completion
• Locals, Block Locals• @, @@, $• Pre-defined variables
– $_, $:, $”, $0 and friends
• Available classes
![Page 21: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/21.jpg)
Type Inference and RDT http://soc.jayunit.net
Scoped Object Completion
• Tricky spots:– Open classes– No explicit declaration– set_instance_var and friends
![Page 22: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/22.jpg)
Type Inference and RDT http://soc.jayunit.net
Method Completion
• Invocations are message passing• Type is a bag of possible methods
– Selector– [Args]– [Confidence]
![Page 23: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/23.jpg)
Type Inference and RDT http://soc.jayunit.net
Method Completion
• Many scoping and definition syntaxes:– class Foo;def method;…– instance_eval…– class_eval…– define_method…– include FooModule– Object#extend(module)– class << self; def method;…– method_missing…
![Page 24: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/24.jpg)
Type Inference and RDT http://soc.jayunit.net
Type Inference Algorithm
![Page 25: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/25.jpg)
Type Inference and RDT http://soc.jayunit.net
What is Type Inference?
• Determine the type of an expression
• Static analysis• Type versus Class• Not always definitive
![Page 26: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/26.jpg)
Type Inference and RDT http://soc.jayunit.net
Type Inference Algorithm
• Inspired by DDP by Lex Spoon:– Demand-Driven Analysis with Goal
Pruning
• Type flow analysis• Unions types over contours
![Page 27: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/27.jpg)
Type Inference and RDT http://soc.jayunit.net
DDP Structure
• Posts goals• Goals have sub-goals• Answered by judgements• Prunes low value goals
– High cost– Low impact on high level goals
![Page 28: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/28.jpg)
Type Inference and RDT http://soc.jayunit.net
DDP Goals
• 1. Type goal– What is the type of x?
• 2. Transitive flow– Where can objects flow from x?
• 3. Simple flow– Where can objects flow from x in one step?
• 4. Sender– What statements invoke FooClass#bar?
• 5. Responder– What methods are invoked by "foo.bar"?
![Page 29: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/29.jpg)
Type Inference and RDT http://soc.jayunit.net
DataFlowTypeInferrer
• infer(String source, int offset)• findSenders(String scope, String
selector)• findMethodDef(String scope, String
selector)
![Page 30: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/30.jpg)
Type Inference and RDT http://soc.jayunit.net
DataFlowTypeInferrer
![Page 31: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/31.jpg)
Type Inference and RDT http://soc.jayunit.net
Issues
• Eval• Data-bound flow control
– return ( rand() > 0.5 ) ? String.new : Array.new
• Metaprogramming• Collections• Builtins
![Page 32: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/32.jpg)
Type Inference and RDT http://soc.jayunit.net
The Future
• Statistical type inference• Type metadata (collections)• Rails tie-in
– AR querying for magic find– Instance vars in View templates
• TI for implementation optimizations
![Page 33: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT](https://reader030.fdocuments.us/reader030/viewer/2022020217/5498bb65b47959d8248b45b3/html5/thumbnails/33.jpg)
Type Inference and RDT http://soc.jayunit.net
Thanks!
• Chris Williams, project mentor!• Google Summer of Code• Everyone on the RDT and JRuby teams• All the folks at RubyCentral