+ All Categories
Transcript
Page 1: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

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

Type Inference and RDT http://soc.jayunit.net

Project Goals

Page 4: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

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

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

Type Inference and RDT http://soc.jayunit.net

Page 8: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Page 9: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Page 10: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Page 11: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Page 12: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

Type Inference and RDT http://soc.jayunit.net

Page 14: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

Type Inference and RDT http://soc.jayunit.net

Page 16: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

Type Inference and RDT http://soc.jayunit.net

Convert the natives!

Page 18: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Completion Features

Page 19: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

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

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

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

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

Type Inference and RDT http://soc.jayunit.net

Type Inference Algorithm

Page 25: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

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

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

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

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

Type Inference and RDT http://soc.jayunit.net

DataFlowTypeInferrer

Page 31: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

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

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

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

Page 34: Summer of Code 2006: Ruby Type Inference & Code Completion for RDT

Type Inference and RDT http://soc.jayunit.net

Q&A

Jason [email protected]

omhttp://soc.jayunit.net


Top Related