From 537e65fc4fa0a24c4526b068856051b334b9ef59 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 16 May 2019 11:52:24 +0100 Subject: [PATCH] wip --- .gitignore | 1 + Makefile | 4 ++++ mm.fig | 55 ++++++++++++++++++++++++------------------------ talk.txt | 28 ++++++++++++------------ tour-example.txt | 9 ++++++++ tour-main.fig | 27 ++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 42 deletions(-) create mode 100644 tour-example.txt create mode 100644 tour-main.fig diff --git a/.gitignore b/.gitignore index c48427e..958665a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dangling.ps borrow-nonmut.ps bck-lifetimes.ps macros.ps +tour-main.ps *.1 *.txt.eps slides.pdf diff --git a/Makefile b/Makefile index b3a833c..b15cebe 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ SLIDES+= borrow-mut SLIDES+= dangling SLIDES+= borrow-nonmut +SLIDES+= tour-main #xxx + SLIDES+= bck-lifetimes SLIDES+= macros @@ -30,6 +32,8 @@ borrow-mut.ps: borrow-mut-example.txt.eps dangling.ps: dangling.txt.eps dangling-err.txt.eps borrow-nonmut.ps: borrow-nonmut.txt.eps borrow-nonmut-error.txt.eps +tour-main.ps: tour-example.txt.eps + %.eps: %.fig iconv <$< >$@.1 -f UTF-8 -t ISO-8859-1 # wtf! diff --git a/mm.fig b/mm.fig index 6450297..a38c251 100644 --- a/mm.fig +++ b/mm.fig @@ -7,34 +7,15 @@ A4 Single -2 1200 2 -6 8325 -1350 12150 6300 -4 0 0 50 -1 2 30 0.0000 4 435 930 10125 1800 Lisp\001 -4 0 0 50 -1 2 30 0.0000 4 330 1605 8325 2475 Haskell\001 -4 0 0 50 -1 2 30 0.0000 4 330 1425 8325 1800 Ocaml\001 -4 0 0 50 -1 2 30 0.0000 4 330 885 8325 1125 Perl\001 -4 0 0 50 -1 2 30 0.0000 4 435 1515 8325 450 Python\001 -4 0 0 50 -1 2 30 0.0000 4 375 525 10125 450 JS\001 -4 0 0 50 -1 2 30 0.0000 4 375 1020 10125 1125 Java\001 -4 0 0 50 -1 2 36 0.0000 4 420 900 8325 -900 GC\001 -4 0 0 50 -1 14 30 0.0000 4 210 900 8325 4050 new\001 -4 0 0 50 -1 15 30 0.0000 4 390 2100 8325 4500 Class()\001 -4 0 0 50 -1 0 30 0.0000 4 435 3645 8325 4950 implicit allocation\001 -4 0 0 50 -1 0 30 0.0000 4 330 2880 8325 5625 freed after last\001 -4 0 0 50 -1 0 30 0.0000 4 435 3795 8325 6075 referent goes away\001 --6 -6 225 -1350 3600 6075 -4 0 0 50 -1 14 30 0.0000 4 210 900 225 4050 new\001 -4 0 0 50 -1 14 30 0.0000 4 315 1800 225 4500 malloc\001 -4 0 0 50 -1 14 30 0.0000 4 315 1200 225 5625 free\001 -4 0 0 50 -1 14 30 0.0000 4 315 1800 225 6075 delete\001 -4 0 0 50 -1 2 30 0.0000 4 330 360 225 1350 C\001 -4 0 0 50 -1 2 30 0.0000 4 330 930 225 1920 C++\001 -4 0 0 50 -1 2 30 0.0000 4 330 2250 225 2490 Assembler\001 -4 0 0 50 -1 2 36 0.0000 4 420 1995 225 -900 Manual\001 -4 0 0 50 -1 2 36 0.0000 4 420 2130 225 -450 memory\001 -4 0 0 50 -1 2 36 0.0000 4 510 3285 225 0 management\001 +6 8370 540 11250 2970 +4 0 0 50 -1 2 30 0.0000 4 435 930 10215 2250 Lisp\001 +4 0 0 50 -1 2 30 0.0000 4 330 1605 8415 2925 Haskell\001 +4 0 0 50 -1 2 30 0.0000 4 330 1425 8415 2250 Ocaml\001 +4 0 0 50 -1 2 30 0.0000 4 330 885 8415 1575 Perl\001 +4 0 0 50 -1 2 30 0.0000 4 435 1515 8415 900 Python\001 +4 0 0 50 -1 2 30 0.0000 4 375 525 10215 900 JS\001 +4 0 0 50 -1 2 30 0.0000 4 375 1020 10215 1575 Java\001 -6 -4 0 0 60 -1 2 36 0.0000 4 420 1200 4500 1575 Rust\001 4 0 0 60 -1 0 30 0.0000 4 345 1665 4500 6300 checked\001 4 0 0 60 -1 0 30 0.0000 4 435 2235 4500 5850 sufficiency\001 4 0 0 60 -1 0 30 0.0000 4 330 1545 4500 5400 lifetime\001 @@ -43,3 +24,23 @@ Single 4 0 0 60 -1 2 36 0.0000 4 540 2835 4275 -900 Ownership\001 4 0 0 60 -1 2 30 0.0000 4 435 1755 4500 -450 (borrow\001 4 0 0 60 -1 2 30 0.0000 4 435 1830 4725 0 checker)\001 +4 0 0 50 -1 14 30 0.0000 4 210 900 225 4050 new\001 +4 0 0 50 -1 14 30 0.0000 4 315 1800 225 4500 malloc\001 +4 0 0 50 -1 14 30 0.0000 4 315 1200 225 5625 free\001 +4 0 0 50 -1 14 30 0.0000 4 315 1800 225 6075 delete\001 +4 0 0 50 -1 2 36 0.0000 4 420 1995 225 -900 Manual\001 +4 0 0 50 -1 2 36 0.0000 4 420 2130 225 -450 memory\001 +4 0 0 50 -1 2 36 0.0000 4 510 3285 225 0 management\001 +4 0 0 50 -1 2 30 0.0000 4 330 2250 225 2790 Assembler\001 +4 0 0 50 -1 2 30 0.0000 4 330 930 225 2160 C++\001 +4 0 0 50 -1 2 30 0.0000 4 330 360 225 1530 C\001 +4 0 0 60 -1 2 36 0.0000 4 420 1200 4500 1710 Rust\001 +4 0 1 60 -1 0 36 0.0000 4 405 1065 4500 630 Safe\001 +4 0 0 50 -1 2 36 0.0000 4 420 900 8325 -900 GC\001 +4 0 0 50 -1 14 30 0.0000 4 210 900 8325 4050 new\001 +4 0 0 50 -1 15 30 0.0000 4 390 2100 8325 4500 Class()\001 +4 0 0 50 -1 0 30 0.0000 4 435 3645 8325 4950 implicit allocation\001 +4 0 0 50 -1 0 30 0.0000 4 330 2880 8325 5625 freed after last\001 +4 0 0 50 -1 0 30 0.0000 4 435 3795 8325 6075 referent goes away\001 +4 0 4 50 -1 0 36 0.0000 4 405 1710 270 630 Unsafe\001 +4 0 1 50 -1 0 36 0.0000 4 405 1065 8370 0 Safe\001 diff --git a/talk.txt b/talk.txt index a25bddb..39996ab 100644 --- a/talk.txt +++ b/talk.txt @@ -3,7 +3,7 @@ Hi. This talk is going to be, mostly, a plug for Rust. -Those of you who know me may find this surprising. After all Rust in +Those of you who know me may find this surprising. After all, Rust in its current form is only about 4 years old, and I myself only learned it in December. I'm not known for liking new things :-). All I can say is that I tried it and have been impressed. @@ -98,7 +98,7 @@ be very fast. C======================================================================C -[ overview slide? | syntax ] +[ tour - syntax ] Apart from the ownership system, there is little new in Rust. Nevertheless, it is an advanced language with a lot of expressive @@ -110,20 +110,11 @@ to feel quite familiar. I have found it easy to learn and to use. I'm going to zoom through a few of Rust's most important properties: -[ syntax | safety ] - Rust's syntax is a conventional structure of curly braces, keywords, parentheses, and infix expressions. It looks a lot like C or JavaScript or something. -[ safety | type ] - -Rust is safe by default. That is, bugs in your code can't corrupt -memory the way that they do in C and C++. But, unlike most other safe -languages, if you really want full manual control, you can write -`unsafe'. This is rarely needed, even if you want really fast code. - -[ type | inference ] +[ tour - type annotations ] Rust is statically typed. The compiler will typecheck it. This is great. You may have heard Haskell and Ocaml programmers say "once you @@ -133,17 +124,24 @@ algorithm you can type some drivelous pseudocode into your text editor. Then keep fixing errors until it builds and lo! it will often work. +[ tour - type inference & polymorphism ] + Rust also has type inference (similar to Ocaml, Haskell, etc.), so you can often leave out the type annotations. -[ polymorphism ] - Rust supports polymorphism (also known as `generics'; it calls the feature `traits'. They're a bit bit like C++ templates, but not mad. Rust supports dynamic dispatch (like `virtual' in C++), or static dispatch, but in both cases the typechecking is done at compile time. -[ unsafe Rust/C/C++ example, chrobakpayne.rs glue.cpp ] +[ tour - safety ] + +Rust is safe by default. That is, bugs in your code can't corrupt +memory the way that they do in C and C++. But, unlike most other safe +languages, if you really want full manual control, you can write +`unsafe'. This is rarely needed, even if you want really fast code. + +[ tour - unsafe Rust/C/C++ example, chrobakpayne.rs glue.cpp ] Rust has a reasonably good system for interfacing to code written in other languages. With the appropriate annotations, you can call C diff --git a/tour-example.txt b/tour-example.txt new file mode 100644 index 0000000..ef36428 --- /dev/null +++ b/tour-example.txt @@ -0,0 +1,9 @@ +struct Point { + x: T, + y: T, +} + +fn main() { + let i = Point { x: 5, y: 10 }; + let f = Point { x: 1.0, y: 4.0 }; +} diff --git a/tour-main.fig b/tour-main.fig new file mode 100644 index 0000000..98dd96d --- /dev/null +++ b/tour-main.fig @@ -0,0 +1,27 @@ +#FIG 3.2 Produced by xfig version 3.2.6a +Landscape +Center +Metric +A4 +100.00 +Single +-2 +1200 2 +6 1080 -1080 4410 1170 +4 0 0 50 -1 2 30 0.0000 4 435 2655 1080 -720 Type system\001 +4 0 0 50 -1 2 30 0.0000 4 330 1965 1260 -90 inference\001 +4 0 0 50 -1 2 30 0.0000 4 435 3105 1260 450 polymorphism\001 +4 0 0 50 -1 2 30 0.0000 4 435 2625 1530 990 ("generics")\001 +-6 +2 5 0 1 0 -1 50 -1 -1 0.000 0 0 -1 0 0 5 + 0 tour-example.txt.eps + -1530 2106 9900 2106 9900 6300 -1530 6300 -1530 2106 +4 0 0 50 -1 2 30 0.0000 4 435 1335 4860 -720 Safety\001 +4 0 0 50 -1 2 30 0.0000 4 330 795 7650 -720 FFI\001 +4 0 0 50 -1 2 30 0.0000 4 435 1470 -1260 -720 Syntax\001 +4 0 0 50 -1 2 32 0.0000 4 465 11850 -1530 -1620 Other properties of Rust - illustrated in an example\001 +4 0 0 50 -1 2 27 0.0000 4 300 1260 4950 -180 unsafe\001 +4 0 0 50 -1 2 27 0.0000 4 300 1080 4950 720 hatch\001 +4 0 0 50 -1 2 27 0.0000 4 300 1245 4950 270 escape\001 +4 0 0 50 -1 2 27 0.0000 4 300 1605 7830 270 to C etc.\001 +4 0 0 50 -1 2 27 0.0000 4 390 1350 7830 -180 talking\001 -- 2.30.2