36
Some pieces of the Rust object system: extension, overriding, and self Lindsey Kuper Mozilla Research August 18, 2011 1

extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Some pieces of the Rust object system:extension, overriding, and self

Lindsey KuperMozilla ResearchAugust 18, 20111

Page 2: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

Page 3: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

Page 4: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

■ Web development at a (failed) startup, 2004–2006

Page 5: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

■ Web development at a (failed) startup, 2004–2006

■ Perl plumbing at a publishing company, 2006–2008

Page 6: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

■ Web development at a (failed) startup, 2004–2006

■ Perl plumbing at a publishing company, 2006–2008■ but in 2007, I moved in with

a couple of Haskell hackers...

Page 7: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

■ Web development at a (failed) startup, 2004–2006

■ Perl plumbing at a publishing company, 2006–2008■ but in 2007, I moved in with

a couple of Haskell hackers...

■ Ph.D. student at Indiana studying PL since fall 2008

Page 8: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

2

Me and how I got here

■ Graduated college (CS and music) in 2004

■ Web development at a (failed) startup, 2004–2006

■ Perl plumbing at a publishing company, 2006–2008■ but in 2007, I moved in with

a couple of Haskell hackers...

■ Ph.D. student at Indiana studying PL since fall 2008■ and then I saw a job posting

for Rust...

Page 9: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

3

What’s Rust?

a systems languagepursuing the trifecta:safe, concurrent, fast

Page 10: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

4

Page 11: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

■ I was intrigued by the idea of a classless object model and flexible prototype-style objects

4

Page 12: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

■ I was intrigued by the idea of a classless object model and flexible prototype-style objects■ and was told, “None of that’s implemented yet; go for it!”

4

Page 13: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

■ I was intrigued by the idea of a classless object model and flexible prototype-style objects■ and was told, “None of that’s implemented yet; go for it!”

■ No object extension, method overriding, or self-dispatch

4

Page 14: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

■ I was intrigued by the idea of a classless object model and flexible prototype-style objects■ and was told, “None of that’s implemented yet; go for it!”

■ No object extension, method overriding, or self-dispatch

■ During my internship, I implemented those things

4

Page 15: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

You’re working on the what system?!

■ I was intrigued by the idea of a classless object model and flexible prototype-style objects■ and was told, “None of that’s implemented yet; go for it!”

■ No object extension, method overriding, or self-dispatch

■ During my internship, I implemented those things■ and learned that they interact with each other in

interesting ways

4

Page 16: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch

5

Page 17: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch

5

Page 18: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension

6

Page 19: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension

6

Page 20: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

A brainteaser...

7

On my first attempt,this returned “lol”.

Why?

Page 21: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

A brainteaser...

7

longcat’s vtablelongcat’s vtablelongcat’s vtable

0 ack forward to shortcat.ack()1 lol ret “lol”

2 meow forward to shortcat.meow()3 nyan ret “nyan”

4 zzz forward to shortcat.zzz()

Page 22: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

A brainteaser...

7

longcat’s vtablelongcat’s vtablelongcat’s vtable

0 ack forward to shortcat.ack()1 lol ret “lol”

2 meow forward to shortcat.meow()3 nyan ret “nyan”

4 zzz forward to shortcat.zzz()

shortcat’s vtableshortcat’s vtableshortcat’s vtable

0 ack ret “ack”

1 meow ret “meow”

2 zzz ret self.meow()

Page 23: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

How to fix it

8

longcat’s vtablelongcat’s vtablelongcat’s vtable

0 ack forward to shortcat.ack()1 lol ret “lol”

2 meow forward to shortcat.meow()3 nyan ret “nyan”

4 zzz forward to shortcat.zzz()

shortcat’s vtableshortcat’s vtableshortcat’s vtable

0 ack ret “ack”

1 meow ret “meow”

2 zzz ret self.meow()

Page 24: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

How to fix it

8

longcat’s vtablelongcat’s vtablelongcat’s vtable

0 ack forward to shortcat.ack()1 lol ret “lol”

2 meow forward to shortcat.meow()3 nyan ret “nyan”

4 zzz forward to shortcat.zzz()

shortcat’s vtableshortcat’s vtableshortcat’s vtable

0 ack ret “ack”

1 meow ret “meow”

2 zzz ret self.meow()

shortcat’s backwarding vtableshortcat’s backwarding vtableshortcat’s backwarding vtable

0 ack backward to longcat.ack()

1 meow backward to longcat.meow()

2 zzz backward to longcat.zzz()

Page 25: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 26: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 27: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 28: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

longercat’s vtablelongercat’s vtablelongercat’s vtable

0 ack forward to shortcat.ack()1 meow ret “zzz”

2 zzz forward to shortcat.zzz()

Page 29: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

longercat’s vtablelongercat’s vtablelongercat’s vtable

0 ack forward to shortcat.ack()1 meow ret “zzz”

2 zzz forward to shortcat.zzz()

shortcat’s vtableshortcat’s vtableshortcat’s vtable

0 ack ret “ack”

1 meow ret “meow”

2 zzz ret self.meow()

Page 30: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

longercat’s vtablelongercat’s vtablelongercat’s vtable

0 ack forward to shortcat.ack()1 meow ret “zzz”

2 zzz forward to shortcat.zzz()

shortcat’s vtableshortcat’s vtableshortcat’s vtable

0 ack ret “ack”

1 meow ret “meow”

2 zzz ret self.meow()

shortcat’s backwarding vtableshortcat’s backwarding vtableshortcat’s backwarding vtable

0 ack backward to longcat.ack()

1 meow backward to longcat.meow()

2 zzz backward to longcat.zzz()

Page 31: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 32: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 33: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Self-dispatch + object extension + overriding

9

Page 34: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Go check it out!

10

http://rust-lang.org

Page 35: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

Life goal achieved!

11

Page 36: extension overriding and self - University of California ...lkuper/talks/rust-objects/rust-objects.pdfSelf-dispatch + object extension + overriding 9 longercat’s vtable 0 ack forward

12Photo by jamesrbowe on Flickr. Thanks!

Questions?

Thanks to: Graydon Hoare and everyone on the Rust team

Dave Herman and all of Mozilla Research

Me: [email protected]; @lindseyRust: http://rust-lang.org