Player is loading...

Embed

Copy embed code

Transcriptions

Note: this content has been automatically generated.
00:00:10
so um let's start first session on aunts colleges in web assembly
00:00:16
a tale of the dangers of the c. when i submitted talk effect like being very poetic
00:00:21
um and and then when you actually get to prepare the talk in the technical
00:00:25
details and then suddenly read as maybe i was not a good idea um thing
00:00:31
so um but anyway are otherwise will will of course take to due to the
00:00:36
content but you might not see as many images of carry this insecurity might have wanted
00:00:42
also for one eng harming there won't be any demo and
00:00:47
this talk another what i'm going to talk about works um
00:00:52
so if you wanted to uh see something that works hard
00:00:57
you still have time to run to one of the other talks you wanted to see
00:01:01
um so this is completely purely to radical uh if you
00:01:05
were ads i'm kelly stock just before she was talking about
00:01:09
talked driven development uh when she submits the talk and then
00:01:15
she learns or implements the things she's she was to talk
00:01:17
about that was kind of the idea of that stuff um i did with this topic that they didn't get to actually
00:01:24
take the time to uh implement any of this so this
00:01:28
is all dirty theoretical but hopefully it will still be interesting
00:01:33
okay let me start by i'm asking ah as
00:01:38
is is more question um basically like think about
00:01:42
for you what what is coloured is like is it is the compactor is the macro is the
00:01:47
language is that just a library um is this
00:01:50
side project uh and or or is it an ecosystem
00:01:55
and i want to assure transfixed complicated take teaching too
00:01:59
much time and i haven't prepared nice a nice online
00:02:02
polls like like keynote so let me just answer the question for you um to it as a competitor him
00:02:09
it is also when you insist him and for that i'm super glad that it's uh people
00:02:14
in the community actually like build ever isn't our it's uh it because otherwise it wouldn't be useful
00:02:20
uh but most importantly for the purpose of this talk it is eighty language
00:02:26
so i probably menu you taught it's colour with the language and storage areas
00:02:32
is like the same language so why why is it really language
00:02:35
well 'cause it's actually brunettes really distinct from scholar the v. m.
00:02:40
i i'm very proud of always talking about how portable it is and how you can take
00:02:44
any any library and just change to build and
00:02:48
then suddenly it also compiles for the java platform
00:02:51
but the real a a as a other also a few
00:02:54
things that make it's quite distinct from psychology um as a language
00:03:00
you might have heard of undefined behaviours um there was a talk yesterday
00:03:04
that said if you access and every other bounce it will just dues stuff
00:03:10
on instead of reliably throwing an array index audubon exception or something like
00:03:14
that to to to string call the primitive values is not quite the same
00:03:20
on the test typist as well but the other details in the grand scheme of things and especially um
00:03:27
for today what is relevant yeah is there is no java in syrup
00:03:31
of course but there is javascript interrupt and that actually a big part of what's
00:03:37
coverages as a language is you can't
00:03:40
just late compiles colour javascript and and corridor
00:03:44
they that's the easy parts ah m. fantasy easy i i truly mean it i
00:03:49
did that in two weeks so you think and then it took me six years
00:03:54
to get to where we are now so i'll so
00:03:58
javascript interrupt is really this all of its colour g. s.
00:04:03
and it's more it then just um what people
00:04:07
would call f. f. five so foreign function interface
00:04:10
it's really bi directional uh in trouble
00:04:14
in the with objects function values states
00:04:18
um properties and methods all of that you
00:04:21
can call javascript sayings jostle can call you
00:04:26
uh in synchronous way in asynchronous ways using call
00:04:29
backs using futures in promises all of that stuff
00:04:33
so you you have an example code that makes isn't match um
00:04:38
to the maximum a manage to do in six lines of code
00:04:42
java scripts and ends got um so you have to go to classes like points
00:04:47
which is even the case class and states which is a which inside contains so um
00:04:53
a reference to javascript array and that javascript array
00:04:57
contains itself points which are against all our constructs
00:05:02
and then you clean call the uh add events
00:05:05
listener method from javascript and given the land uh
00:05:09
and that land that is defined in this colour codes but it ends up being a javascript function
00:05:15
that holds in its captures this got lost eights and then it mute
00:05:19
it's that thing and so basically that you can do this sort of stuff
00:05:25
we'll come back to this example in about thirty eight slides
00:05:30
in the meantime ah let's go a lot of a talk a bit about
00:05:33
what is what by someone and that you might have even less of an idea
00:05:39
so if the compiler is the production machine is the the language the binary format
00:05:45
is specific to the web i mean you might you might expect that isn't open standards
00:05:51
so one is another compiler at all it's really a language a
00:05:56
binary format and an open standard and it's not specific to the web
00:06:02
and again most importantly for the purposes of this taught it is a language
00:06:07
so it's might not be a language that you might want
00:06:11
to write by hand at least not for more than ten
00:06:15
or twenty lines of codes um so in fact the it's
00:06:20
it's typically language that is the result of combining from another language
00:06:27
so this is a bit with white ass oblique in look like it's on
00:06:31
the left you have some ah c. plus plus code or or see or both
00:06:36
i never remember the difference ah it's a factorial it's not a recursive i
00:06:42
never write a recursive functions i don't know what people have with them um
00:06:47
and on the right if you compile this way
00:06:50
eighty um with the c. to web assembly compactor
00:06:56
that is um very smart what you might
00:07:00
yeah it's it's the results on the right
00:07:03
um this is not actually what you will get with typical
00:07:05
compares right no but it's the easiest code i could find
00:07:10
no kind of fits the bill um so you can see that it's our it's basically just check
00:07:15
machine so every instruction put something on the stack or pops things on the on the stack those computations
00:07:21
um it looks like by codes birds um control
00:07:27
flow is structured so instructions are all in there
00:07:31
expressions or express on the stack but control flow like an if
00:07:34
else is structured so there are blocks of if then else will will
00:07:40
look more into details later about what what kind of things we can do what
00:07:45
you can see there that we have our into sixty four years we have on some
00:07:51
primitive operations like a sob multiplication we can call methods
00:07:56
including um recursive really recursive calls and i kind of stuff
00:08:02
oh so basically this is what you have in whereas only him you um you have
00:08:08
a linear memory model so the kind of uh what you would get in in c. basically
00:08:14
so basically the memory as one giant array of parts and you can
00:08:21
have pointers into that array which are basically in this is into the array
00:08:27
and there is absolutely no g. c. okay so this is what you get what works what doesn't right now
00:08:33
so what i think we can sort of talk to javascript but in very limited ways and
00:08:38
in in the way that i would in this case qualify as an for a function interface
00:08:44
oh this is way too much codes for what you can see uh
00:08:48
as i have on the left on a on javascript functions that i
00:08:54
somehow give access to to javascript to web awesomely
00:08:59
in whereas only i can imports those functions that this is the fourth line on the slides
00:09:04
uh and then i can call them later on down down
00:09:08
the line isn't additive text version of web assembly which is
00:09:12
more like lisp um and the two versions are basically one
00:09:17
to one correspondence is just a different way of expressing some
00:09:21
intense that's that was just for the show are and also because it was the output of the compiler used um i
00:09:28
didn't want to translate to the other form but they will stick to the other for for the rest of the talk
00:09:34
um so here you can see that we have
00:09:37
uh functions industry but take floaters parameters and return um
00:09:43
sorry i probably get mixed up on the left of course you have some c. code um
00:09:51
so it explodes it returns floats or avoid
00:09:55
and that's about all you gets huh that's numbers and that's it
00:10:02
so you have of i would also to really limited to you are
00:10:06
passing thirty two bit integers to to within sixty four bit floats and that's it
00:10:12
like little it is all the only thing you can like give
00:10:16
between ah web s. and we and and and javascript so strings
00:10:21
nope objects nope higher order functions
00:10:26
definitely not he okay let's get two different light switches um
00:10:34
let's try and compile psychologist to was um was it was a shortening of or by someone
00:10:41
this is has got us works but and now you understand all astrology
00:10:46
is basically uh you have a scale as sources you give them to
00:10:50
discover compared to this gorgeous compared or it spits out some s. g.
00:10:54
s. r. r. file i. r. files which stands for psychology as intermediate representation
00:11:00
very large original and then uh i maybe put done maven or you pull
00:11:06
other artifacts from a vendor contain those edges are false and you give them due
00:11:13
to started to miser which message them spits out optimists i. r. and then
00:11:19
there was a lasted that things that are are and outputs one big javascript file
00:11:25
so if we want to compile psychologist web assembly we can
00:11:30
re user sources hopeful that we can reuse is gorgeous combined or we can reuse
00:11:35
the edges are for a files like all of that we can reuse gorgeous miser
00:11:40
to a large extent some of the things it does are specific
00:11:45
to optimising for javascript but would would just to activate those parts
00:11:50
the one thing that we need to rewrite is the very last part which
00:11:55
take the ultimate i. r. and in its web as somebody instead of transcripts
00:12:01
so that means that i will show a lot of starches ironies
00:12:05
talk because as our input format reality for what we're trying to do
00:12:10
so to give you an idea what it looks like here is a fact
00:12:13
or function again the non to records of one um but written in scar
00:12:19
law about for scholarships to be precise and if you compile it would discourage
00:12:24
us compare you end up with this i. r. which looks for is a matter
00:12:29
uh what you see uh is that all method names have a mangled names
00:12:35
of the overloading is i'll come by the way you have primitives like ins
00:12:40
every operation is stacked with the type of appearance it takes like the
00:12:45
equality compare isn't in the quality of instant not of on something else
00:12:50
and it has structure confer control flow or with if
00:12:54
else it's rhyme but is also has full blown expressions
00:12:58
um liked the um the the times operator and
00:13:02
the and the the best call an inside the subtraction
00:13:07
and basically type system is very similar to that of java or at this point
00:13:11
so it's objects i mean classes and interfaces without
00:13:15
type parameters that's all you raise the way and primitives
00:13:21
okay so let's take the s. r. a. r. and compile it you web as someone so um
00:13:28
we can start at the top at the top of the function um look
00:13:31
at the if else is structured and we can compile it down to the structured
00:13:36
um control flow if else of about somebody so far so good
00:13:42
then um you can see that's the that if in web
00:13:46
awesomely is annotated with the um artery to which means that the
00:13:50
result of stiffs of this if else is expression that returns
00:13:55
an industry too so it's like it's got a lot if else
00:13:59
our egg can be expressions and can return value if we can
00:14:04
compile the condition of the if which comes did for the structured if
00:14:10
because it's going to put on the stack it would in value that says yes or no
00:14:16
and so how we compile these things is
00:14:18
we loads the local viable zero which is an
00:14:22
we and we put it on the stack then we put the constant zero on the stack and
00:14:28
then we compare the two things on top of the stack and we put back the results and then
00:14:34
the if is going to pop the wooden value of the stack and
00:14:37
if it's true answer the denver engine otherwise under the outstretched as part
00:14:43
um so into that branch it's really easy we have
00:14:47
that constant one we can load it put on the stack
00:14:51
and it's it's so that thing that's that's on the stack at the end of the ten branch is going to be
00:14:55
the result of the if expression like a on the indy else parts we can look at what's the out the the top
00:15:04
most um operation it's the times so the very and we're
00:15:10
going to say multiply the two things there on top of the
00:15:13
stack and on the left we have the local variable and
00:15:19
witches so we load the local zero put it on the stack
00:15:22
on the rides we first need to compute the argument to the methods solo dan
00:15:28
put one on the stack subtracts and we get something else on the stack which
00:15:33
is then going to be the arguments to the call to the recursive call to factorial
00:15:38
and then the results of that call will be on top of
00:15:41
the stack so we can multiply the and the the two bodies
00:15:45
so this is the this is really how it works so so far it seems like we're good right
00:15:50
the transition from those colleges i. r. a. two web assembly as looks easy super easy
00:15:58
we can even now uh do it a recursive factorial
00:16:00
because otherwise someone will kill me at some point um mm
00:16:05
so this is the tail recursive factor or would not come later and it's if you comply with discourages i. r.
00:16:12
uh with this gorgeous complied or you get the i. r. that's at the bottom it is further complicated it's uh it has a
00:16:19
q. weird things like those labelled blogs this x.
00:16:24
in this whatever thingy then while through and then inside has returns
00:16:31
but with the label that's like the name of a blog anyway we're going to look
00:16:36
at it i don't really want to go into too much detail of how this really works
00:16:41
but we have this weird construct which is this little blog and the returns
00:16:45
and the fun part is that whereas somebody that has exactly the same weird construct that
00:16:52
nobody invented before intelligence invented it and what doesn't invented it and then get to the
00:16:56
same thing um so it's really nice because that means that when we come past deleterious
00:17:01
to web assembly we can nab one to the other because they mean the same thing so
00:17:07
ah here we make we can compare this thing um first we're going to look at the
00:17:11
local horrible decorations we're going to let them out at the top because we're about somebody only has
00:17:16
um look of our baltic or that that the top of the of functions
00:17:20
and then we start from the outermost i'm a part of the method
00:17:26
and we encountered is labelled block so we inmates
00:17:30
in web assembly a block whose name is dollar x.
00:17:34
and the return value of the block will be a in street you
00:17:40
and then inside we have this loop uh which is a while true so with loops indefinitely
00:17:46
so basically uh it wasn't you what you would do is have a a loop construct that has a name
00:17:51
at the at the end of the loop you branch
00:17:53
back to the group label so was going to look indefinitely
00:17:59
except of course if from with analogue at some point you accept it in the more brutal fashion
00:18:06
it's a inside when carter another labels block but this one
00:18:13
it returns um avoid or units uh or or whatever
00:18:17
so we translated to simply a label blocking where personally
00:18:21
and we have the same kind of if ah expression here
00:18:24
so same thing is before and the if is an expression
00:18:29
again we loads on the local which is like a moderator
00:18:34
then we have this thing to load and put one subtract store
00:18:40
same thing with that multiplication boring and then we have this thing where we just move things around
00:18:46
um by loading locals and setting locals somewhere else and finally
00:18:51
we have the return thing which is really like jump at
00:18:55
a break from this label so that's what we say um break from
00:18:59
this label in without somebody and it's the same thing it's it's amazing
00:19:03
and we have the same with the uh with the return but this return
00:19:07
takes actually a a parameter and that will be the return value of the block
00:19:12
so at the agenda the if else here it's it's
00:19:17
an expression if else with it put something on the stack
00:19:20
and this branch is going to pop that thing from the stack and return it as the results of the big
00:19:27
block that's artworks anyway uh there was just to show
00:19:32
off that's starches somewhere that's only ah have the same kind
00:19:36
of control flow so here for that i now things get
00:19:41
more complicated um classes as you know it's colour has classes
00:19:47
i'm here is the non jeez classes the final classed
00:19:51
meant and we haven't met that that just makes a point
00:19:56
and this is how you would be compiled into storage is i. r. so you can see
00:20:00
ah on a class that extends object has
00:20:02
fielded has accessories for these fields yeah the constructor
00:20:07
which takes to ins puts them into this and call the super
00:20:10
constructor it's really boring um and this is how you would somehow or
00:20:17
compile this to web assembly using the linen memory um so the
00:20:25
important thing here which apparently i forgot to highlight on the slide is
00:20:30
on the fact that we have a call to
00:20:34
dollar matlock so we're actually like allocating memory from
00:20:39
the litter memory and then we're putting things inside oh and and we end up with a pointer
00:20:47
related to to to the class and we have to store thing is like a reference to what
00:20:51
class there's says and then we store the values it's it's right we can we call the constructor
00:20:57
all of that kind of stuff and he was the body of the constructor
00:21:04
which uh also called the super constructor and then stores
00:21:07
things inside the fields that's relatively uh straightforward if you
00:21:13
imagine that an object leaves and a linear he and you have memory that you have to fill in i.
00:21:20
e. and the and the f. we have a lot of things that we need to encode from job from
00:21:28
oh oh well java hours colour is the same thing
00:21:30
basically at this point of virtual dispatch interfaces garbage collection
00:21:36
you can implement all of that um it's possible uh it's very tedious
00:21:42
but it's doable and then uh uh columns c. d. into per interoperable
00:21:50
eighty probably um and uh this is this is the attack of one
00:21:55
of a half the monsters of of the c. but uh yep um so
00:22:01
here is the simplify it's scenario and colour g. s. where would
00:22:07
use the uh javascript timers especially the the global function set timeout i
00:22:12
give it a function i give it a delay which is basically a number
00:22:16
and this is how we would become pilots to discard his i. r. so you have on your gets
00:22:23
um we have access to the global set timeout function and then we have a call
00:22:27
and then we have uh and i wrote them down so basically uh uh javascript anonymous function
00:22:33
that land uh oh calls on other methods
00:22:37
and that method also gets to global console object
00:22:41
called the log methods with apartment or hello as
00:22:44
the un arguments i and hear things are problematic because
00:22:52
just look at the at at the last line
00:22:54
which tries to write hello on the console this thing
00:23:00
runs to re to read access to global javascript value him
00:23:05
which is an object it's console problem there is no such
00:23:10
thing as an object in whether someone so you can't even
00:23:14
take that in your hands it there you have no handle to this thing
00:23:18
which is the javascript objects you can not gonna talk about it in web personally
00:23:23
you have strings you cannot talk about strings and where that's only what you can put this array of
00:23:29
cars in the memory but those are not just of strings there's the strings you
00:23:34
cannot hold in your hands of java scripts trying so you're stuck there as well
00:23:39
and then and then you have this this method call to reach out a script foundation which is which is
00:23:45
even more complicated like we would we can't even talk about the the things that that make up this
00:23:51
function call letter the function call itself and the ball of like imagine like you have a higher order
00:23:57
function like what what you do with these things so what that's only just just this in have you
00:24:05
billy to talk about these things it you you
00:24:10
can't you can't get access to any of these things
00:24:13
so if you write as god is like it's completely it's it's it's done right
00:24:20
so are we completely stalk like is the end of the talk
00:24:23
and uh um well there are a few things we control our
00:24:28
one is let's drop inter operability um maybe i don't know
00:24:35
um but the other monster if we do that says
00:24:40
well we basically lose all attempts of any kind of a portability of of
00:24:45
our code right that it's got just go there has been written for uh for
00:24:49
um several years just won't work and what you end up with actually
00:24:55
is a different language um you you basically drops in probably from saudi s.
00:25:01
which was the sole uh which i mean for which interrupt was caught um
00:25:05
the souls got is so what you get instead is another language you might
00:25:10
have heard about it's it's cold and your idea it's gonna native uh
00:25:20
and this is the the the third language that that you might want to
00:25:23
experiment with others coloured it in there is coloured isn't and there's gonna native
00:25:26
it's it's the third language that language uh can be compiled web as only
00:25:31
but that language doesn't talk to javascript so it's a different it's different
00:25:35
language different trade offs and that's not my project so i don't care
00:25:43
okay so now what we're what we're good it would do instead
00:25:46
well basically an n. y. them birds for even one do that
00:25:50
the wise in that is available today in your browsers are we are actually completely
00:25:56
starch there is nothing we can do about it who says god is is that
00:26:03
um but it's there is hope and proposals for future versions of of
00:26:10
web as somebody so now we start looking into the future
00:26:15
of what might be possible and there is
00:26:18
one um proposal which is about reference types
00:26:25
you can go and click on that link if you want um but i'm going to present
00:26:31
a bit what it does so basically the reference types proposal it is an extension to ads well
00:26:37
basically one type to web assembly which
00:26:40
so far had a integers floats and doubles
00:26:45
and now it has four types it has also any ref and and
00:26:51
and a ref is a reference to some thing from the host environments
00:26:58
it could be did javascript keep for example so it could be
00:27:02
a reference to jostle objects or it could be referenced which awesome string
00:27:06
or it could be referenced were javascript number because
00:27:11
that's also eighty javascript thing from the host environment
00:27:16
and you can have um you can have any ref in on the
00:27:21
stack 'em before local horrible for parameters to functions that is all the functions
00:27:27
and you have also a separate he is distinct from the lunar memory
00:27:32
in which you can store any reps so you still have the giant every of by its which
00:27:37
is that in a memory uh on which you can basically puts bites and then there was another array
00:27:44
um of any wraps it but you can not put any rests inside the linear
00:27:51
memory that's not possible and you cannot cast in any ref to an into pointer
00:27:56
either because otherwise the jaw scripts g. c. would have issues okay so what can we do with that
00:28:04
uh well let's look uh this look again at
00:28:08
our hello methods which was are impossible to get before
00:28:15
now it's it's only very awkward um so
00:28:20
what we can do as decompose the things
00:28:23
so the first thing we need to to do is reach the global horrible console
00:28:28
and for that on the web s. and decide on the right on um well you can't really
00:28:34
there is nothing in web assembly even with reference types that lets you
00:28:37
access a global variable from javascript younger thing you can do with imports
00:28:42
so um functions from javascript so you can write a function in javascript on the left
00:28:49
that is called get console that returns the console and you can
00:28:53
import that function from web assembling and then you can call that function
00:28:58
it doesn't take any part either and we'll put on the stack the result the function which is the console objects which isn't any ref
00:29:05
okay so for cigarettes um then i have to puts the
00:29:10
uh this to the string log on on the on the stack
00:29:15
but what that somebody doesn't know how to create a javascript string
00:29:20
but not it's not a problem we can write to
00:29:22
javascript function that returns the constant um log which is a
00:29:27
string and we can import that function and we can call that function and we receive the string as an any ref
00:29:34
that we can do the same with the other constants in our program like the string hello
00:29:39
and finally when we've put those three things on the stack
00:29:43
the the console object the log string and and uh hello strain
00:29:47
we want to call the methods but we're definitely doesn't know how to call it javascript met it but it's not a problem you can write
00:29:55
a job to function that is going to call it that it and
00:29:59
you call that method call method one it takes an object a matter it's
00:30:03
an an argument and is going to call the methods and then you
00:30:07
can import that function from what i somebody and you can call it
00:30:12
so you've called things from javascript outside to put things on your stack
00:30:17
and you called another jostle function to actually use those things from your stack
00:30:22
so let's get right we manage to fruit some fan
00:30:27
um which is a a step to step up from before
00:30:31
what how um let's look at the uh at the set time not playing with with the lambda right click can
00:30:37
we do something about that and uh it's it's very
00:30:42
awkward but uh we can we can creates a function in
00:30:47
so actually that this one is relatively easy 'cause it doesn't have any captures
00:30:52
so we can actually um write a function on on your right
00:30:58
with a on which is why personally function that is the
00:31:01
lambda and it's doesn't take any argument and returns an m.
00:31:05
f. a. called the the other uh the the the the
00:31:08
other actual method and you can actually use this ref that funk
00:31:13
uh upper operation in web as an we
00:31:16
to get eighty javascript version of that function
00:31:22
so that's possible but only because it doesn't have captures but that's that's already quite good
00:31:28
so you can put that on the stack up and then you can put the constant uh one thousand does double
00:31:35
on the stack but then um are you cannot actually give
00:31:40
that to javascript actually is not in a relatively generic way
00:31:44
because what you want is really any wraps so what you need is a function that takes a double
00:31:50
and returns and and a ref for that double and what doesn't it doesn't have an operation for that
00:31:56
but no problem you can write a function in javascript on the left which is called box double that takes up
00:32:03
a double and we change the same thing so that was useless rates
00:32:08
except that if you look at the right we give up a type
00:32:11
two that function from web assembly side and we say it takes as
00:32:15
a parameter and have sixty four so double and a retraction any ref
00:32:20
and because of how what gasoline javascript talks which other the double that was on the stack will be
00:32:26
given as an f. sixty four to javascript refrigerated into a primitive number
00:32:31
and we returns to to where that's only which expects in any ref
00:32:34
that number will be interpreted as an any rev version of that number so yeah it for that
00:32:41
no that we had those things on the stack we can we can use a similar mechanism to actually call the function et cetera et cetera
00:32:48
okay so so we can do that but he was a real proper of
00:32:54
uh references across sleeps because ah remember it'll do that and the rest you can put
00:33:00
them on the stack and on the separates keep you cannot put them inside the linear memory
00:33:09
so i told you we were going to come back to this example angie with
00:33:13
this command a vision of the references across the two heaps that we need here
00:33:19
um we need in in the dallas would keep idea they we end up with a done event
00:33:24
listeners thing from from the browser which reference land down which is a task on a transfer function
00:33:30
that doesn't function in its captures hold a um has access
00:33:36
to the the states thing which is an instance from discover he
00:33:40
and that thing contains a value points which is a g. s. a race so it
00:33:44
comes from the javascript heap and that thing again contains points which are things from this collection
00:33:51
so now you have a on the s. s. thing and
00:33:57
it's well i from pointers from the javascript heaped use colour heap
00:34:03
well the only thing we can remember that on the skull heap objects are just pointers in the random memories
00:34:09
to basically their numbers so yeah you could you can
00:34:14
hold a number in and out a script that's okay
00:34:17
but the problem is then that this colour g. c. can
00:34:21
not know which objects are reachable or not switching navigable collect anything
00:34:26
and then the the other arrows from started javascript since we cannot put any resin
00:34:31
that either memory what we're going to do is put ideas integer ideas that are basically
00:34:37
he's in the mapping javascript double actually map to the real objects from the javascript side
00:34:43
but then the javascript g. c. can never know when these things are not or any reachable
00:34:48
you can make this work to some extent but if you do have cycles at some point
00:34:54
then it's it's that like your cycle your cycles in never going to be collected
00:34:59
and i don't even want to talk about the performance aspect of
00:35:02
these things um so what you really need at some point is full
00:35:08
cooperation between the two g. sees the g. c. from the web
00:35:12
that somebody's got aside and the g. c. from the javascript our sides
00:35:17
big use unit to support cycles between um between that
00:35:21
usually dislikes got eyes full of cycles jaw successful cycles
00:35:25
um is coverages is full cycles between the two so if
00:35:29
we don't have support for cycles it it's it's a no go
00:35:34
so with any reps alone we can get far we can actually get something that is
00:35:41
correct that will implement the entire psychology a specification
00:35:47
correctly but there was just one little cafe yet
00:35:52
it won't garbage product if i don't know might be good enough for your ah okay so today and then what
00:36:03
well it was another proposal for web as only for
00:36:07
t. c. um so i'm very happy about this one it's
00:36:12
at the very vague stage though so but there is a
00:36:16
document that says more or less what they want to do
00:36:21
and basically what they want to do with you things they want new types ah in
00:36:25
addition to the integers the floats and the and the revs they want so balls and arrays
00:36:32
and then they want references to those things so you can have
00:36:36
it's not a pointer to reference no reference to double or reference
00:36:41
to an array and those references will
00:36:47
supposedly be garbage collected slide you can actually
00:36:50
creates a garbage collected heap in web as somebody that will be taken care off by the
00:36:56
web s. only g. c. and that one is a is designed to cooperate with the chastity
00:37:03
and it doesn't t. c. so that's good so let's let's look at what we could do
00:37:08
here i'm i'm so for for the uh for the class points which has a two ins
00:37:15
we would define a out two types first the type point destruct which
00:37:20
defines the the internal representation which is actually three ins not just to um
00:37:28
the first one is just the uh an identifier for the class point
00:37:33
'cause we need to remember that for instance off and that kind of stuff
00:37:36
and the two other ins or the actual x. and y. and then we define another type
00:37:40
which is point which we define as a reference to a points tracked and the state is similar
00:37:48
i'm here it has are we construct
00:37:52
within in switches again the class states
00:37:55
and and and the ref um because that's a that's
00:37:59
a job as a reading so here in in destruct
00:38:04
we can actually you have any rests in this time right so we can have
00:38:10
jeez eat objects in web assembly that actually refer directly
00:38:15
to g. c. stuff from the javascript world and vice versa
00:38:20
so yeah for that so if we if we had that we're probably will
00:38:27
have it at some point this is what we can do um the frog
00:38:32
is ah so first we create an an empty re but of course java
00:38:37
web s. and it doesn't know how to create an anti jobs array but
00:38:40
that's okay you can you can write a function in doubted that
00:38:43
creates an enduring returns to jot to to it doesn't we uh as
00:38:47
a as an any ref right and you can put it on the
00:38:49
stack okay um then there is a locating an instance of of state
00:38:57
first you would put on the stack the the identifier the that
00:39:01
that's uh for the class state and then you put a and all
00:39:06
on the stack which will be the initial value of the of the
00:39:08
plants field and and then you call this this new this operator from
00:39:15
web as somebody with ah with the g. c. proposal which is new
00:39:20
and then you give the type of destruct and that will uh locate obstruct with the initial values
00:39:26
taken from the stack and which are new a reference to that starts not the pointer or reference
00:39:33
and then you can call the constructor which will take the reference fit
00:39:37
in the of food in the on the field et cetera so that's good
00:39:41
and later when you want to create the land that that that has captures
00:39:45
he has a capture of type states which is the javascript um as colour object
00:39:50
and the reference um uh dave which is anything because it just
00:39:54
javascript thing you can actually do that um all you just have to
00:39:59
well it's whether somebody doesn't really know how to create captures for functions but that's okay you can
00:40:05
write a job as a function of the work capture things for you and you can call it um
00:40:11
and this is how you how you do it so basically if we have this
00:40:14
this cheesy proposal at some point will be able to encode all off colour g. is
00:40:18
to web assembly with reference types and a. g. c.
00:40:21
proposal in a way that's correct and um and that actually
00:40:27
garbage collect which would be a good thing so when do
00:40:33
we get this well first we need the reference types proposal
00:40:37
which is at the stage called implementation stage currently four of us and we
00:40:41
in so that means the um the engines are in court just to implement that
00:40:48
whatever the spectre is at the moment so that we can
00:40:50
get feedback on the proposal and uh so for as far as
00:40:55
i know um the uh the firefox engine implements the the
00:40:59
current state of reference sites then uh we need stitches a proposal
00:41:05
and that one is at a very early stage there is there isn't even a speck at this point it's
00:41:10
ideas emmy ideas for type system i'm more or less
00:41:15
specified but not really so that will take some time
00:41:21
and and the men that on there and then we can actually implement that
00:41:25
the um the supports in in scarred as or at least we hope to
00:41:29
actually do that in in colour with the development of g. of the just
00:41:32
a proposal so that we can feed back into the proposal if something is
00:41:37
is wrong for us so it will still take a while i'm sorry about that
00:41:44
so that's all i had um i'm happy to take one or two questions i think we have a few minutes
00:41:51
thanks
00:41:56
hi microphones common
00:42:02
there's little clues was no i'm i'm wondering because the there's another path
00:42:07
that can be taken but i wonder what where you cannot be taken here
00:42:10
uh for example maybe useful what um i think it's a stir use the name of the products which is
00:42:15
really did you she beckoned that goes to was an unnerving will be doing the the the story allows
00:42:20
the view the values between uh is it because those colours not preferentially transparent that you can uh dude
00:42:28
there is a um yeah so so certainly if you're languages entirely um
00:42:36
um preferentially transparent you can you can do that relies arenas and you have an overall
00:42:42
so you'll have to implement in the was under the new console logon for but it's a
00:42:47
bit of a lie though because what if you need to uh see rely is the
00:42:53
value of type io well you never do that as well as go you never knew that
00:42:59
yeah but the the thing is like this is the kind of expressive it see in
00:43:03
terms of communicating with javascript that's got his hands and that the uh language that there's ins
00:43:10
um doesn't have this this binary synchronise inter probably would javascript like
00:43:15
everything you can do in johnson you can do we discovered is
00:43:18
if i if you if you cannot see relies on an io basically
00:43:22
estate in between two calls to javascript well what would be you know
00:43:27
could use clues of that the what were you will need to send
00:43:29
that through the small snow but they show their your which inter leaves
00:43:34
calls to mutable javascript it's uh things and my own
00:43:38
code and then calls again something from the dos well
00:43:41
then when you are in was um how can you cool blue to external world who can you launched missile right
00:43:47
uh that you can do that because you can import also functions which we did with the
00:43:51
import a statement yes we hold it yes i mean if you pick up a few to you
00:43:56
all the regular communication between that's info interface right it's uh it it gets
00:44:01
um it gets an an an unwieldy in uh and at some point you realise
00:44:07
you can't get everything right but if you want to begin with and talk further uh of line
00:44:13
any other question that they're the back
00:44:20
uh_huh i sebastian uh so i guess like i should be this new let you presented good luck but
00:44:26
would what would be the advantage gained all of the car and encoding i is it was a big
00:44:32
changing including and possibly all the all the heads for the all the stuff that
00:44:36
you of all still didn't know that it just moved to a different one time passes
00:44:40
well we already have now is up in a transition to dallas get
00:44:45
uh you know the pros and cons of the two approaches given that people can work
00:44:50
well i um nobody where nobody really knows um if you if you ask random
00:44:56
people on the internet they will say compared with that somebody is going to be fast
00:45:03
no that's not how it works um if you compile
00:45:07
c. to web vaseline is going to be fast relative
00:45:11
to compiling c. to to javascript because compared to see
00:45:15
javascript has too many features and and we covering them from
00:45:21
to the level of c. is is is problematic to that is why wasn't wasn't button in the first place which is
00:45:27
going from city where that's only you don't have the impedance mismatch we're not losing banks
00:45:33
are also not gaining anything um if you compare the garbage collected language to address only
00:45:41
ah with the g. c. proposal uh hopefully you expect
00:45:45
to not lose things and that's how you get performance
00:45:49
you you all again performance aware that's only because going from your source language you're not using things
00:45:55
so why would we not what things would we not reduce
00:45:58
well we wouldn't lose for example are types or does or monolithic
00:46:02
types the same the same kind of times we have that on the g. d. n. so as long as you were staying
00:46:08
and you compute intensive for sound portion off your program that only many pretty it's gotta types
00:46:14
you remain in the realm of web assembly where everything is statically typed
00:46:19
n. t. re you can get something similar performance to the j. v. m.
00:46:24
except that of course the j. v. m. is going to do polymorphic in lying it comes things with age
00:46:30
in where that's on the right now is still a no go ahead you you cannot you cannot do um
00:46:35
mm a profile bayes optimisation zap fun time like
00:46:40
this is uh this this is not happening yet so
00:46:46
i think we we can gain if if we all of this happens is
00:46:50
for the large portions of starches programs that actually stay
00:46:55
within this colour um subsets those will basically perform better
00:47:04
but if you have a portion of just gorgeous problem just constantly talk to javascript back and forth
00:47:09
that might actually lose performance art because it would it's constantly like cross
00:47:14
the boundary between web assembly in java scripts and depending on how that's implemented
00:47:19
uh the engine level we could lose performance or at least we want to gain anything that's that's that definitely it
00:47:25
and then for things like virtual dispatch and and and and you know lining of those things
00:47:30
it's a it's an clear the futurists all very much uncertain at this point i
00:47:41
do you think you for the dog um maybe a crazy cushion
00:47:48
so uh do you think it's possible to uh um uh
00:47:52
to compile that you've been itself will bustling yes it's been done
00:47:59
so then this carriage is called can be a a can be
00:48:03
combined called and did you busy the can interpret nope half a um
00:48:11
this colour t. v. um source code can become byte code and can be interpreted by the g. d. m.
00:48:17
but again it's the same problem is with its colour native it's a different language
00:48:22
and if you write colour j. v. m. code you can call
00:48:25
java libraries but you cannot call javascript libraries you cannot manipulate the dawn
00:48:29
you cannot manipulate your web page you cannot use does aliens and p. m. packages out there
00:48:36
so again it's important to go back to the semantics of your
00:48:39
language and remember that psychology um start is is gonna is if
00:48:44
or three different languages with different semantics and different capabilities
00:48:49
and yes you can compare digit into web assembly and you can run psychology in
00:48:52
code on that t. m. you cannot runs colour j. s. code on the t. m.
00:49:01
the last question
00:49:03
oh and thanks for talk ah and sounds very exciting i look forward to
00:49:08
things happening in my bass and lisa they can also happen in his college yes
00:49:13
i was wondering if uh on the language scaling woodside
00:49:16
we got a f. x. with that uh improve the
00:49:19
performance r. r. x. oppose opportunities for certain kinds of
00:49:23
optimisation since we mention what d. c. is able to do
00:49:27
and also obviously garbage collection here is important so if you could establish a that it's
00:49:32
certain parts of code onto certain things ah how much do you think this is good help
00:49:39
or to not i'll always optimise for worst case do you have funding for p.
00:49:43
h. d. students um um the mm i i i i think it's a it's a
00:49:52
it's really research topic they we we we we we don't know how to how
00:49:56
to do these things like given the current hardware and the currents of to my there's
00:50:02
and uh it's it's still unclear words in effect system is
00:50:06
actually able to provide in terms of uh of optimisation is
00:50:10
in general so let alone in the constraints and norman's of of web as only
00:50:16
i think this is the um it's it's worth thinking about it the yeah as my
00:50:21
initial answers it just it it and it's probably worth and five p. h. d. oh yeah
00:50:29
thanks okay uh i'm i'll be happy to take
00:50:31
further questions uh here or

Share this talk: 


Conference Program

Welcome!
June 11, 2019 · 5:03 p.m.
1574 views
A Tour of Scala 3
Martin Odersky, Professor EPFL, Co-founder Lightbend
June 11, 2019 · 5:15 p.m.
8337 views
A story of unification: from Apache Spark to MLflow
Reynold Xin, Databricks
June 12, 2019 · 9:15 a.m.
1267 views
In Types We Trust
Bill Venners, Artima, Inc
June 12, 2019 · 10:15 a.m.
1569 views
Creating Native iOS and Android Apps in Scala without tears
Zahari Dichev, Bullet.io
June 12, 2019 · 10:16 a.m.
2231 views
Techniques for Teaching Scala
Noel Welsh, Inner Product and Underscore
June 12, 2019 · 10:17 a.m.
1295 views
Future-proofing Scala: the TASTY intermediate representation
Guillaume Martres, student at EPFL
June 12, 2019 · 10:18 a.m.
1156 views
Metals: rich code editing for Scala in VS Code, Vim, Emacs and beyond
Ólafur Páll Geirsson, Scala Center
June 12, 2019 · 11:15 a.m.
4695 views
Akka Streams to the Extreme
Heiko Seeberger, independent consultant
June 12, 2019 · 11:16 a.m.
1552 views
Scala First: Lessons from 3 student generations
Bjorn Regnell, Lund Univ., Sweden.
June 12, 2019 · 11:17 a.m.
577 views
Cellular Automata: How to become an artist with a few lines
Maciej Gorywoda, Wire, Berlin
June 12, 2019 · 11:18 a.m.
386 views
Why Netflix ❤'s Scala for Machine Learning
Jeremy Smith & Aish, Netflix
June 12, 2019 · 12:15 p.m.
5026 views
Massively Parallel Distributed Scala Compilation... And You!
Stu Hood, Twitter
June 12, 2019 · 12:16 p.m.
958 views
Polymorphism in Scala
Petra Bierleutgeb
June 12, 2019 · 12:17 p.m.
1113 views
sbt core concepts
Eugene Yokota, Scala Team at Lightbend
June 12, 2019 · 12:18 p.m.
1655 views
Double your performance: Scala's missing optimizing compiler
Li Haoyi, author Ammonite, Mill, FastParse, uPickle, and many more.
June 12, 2019 · 2:30 p.m.
837 views
Making Our Future Better
Viktor Klang, Lightbend
June 12, 2019 · 2:31 p.m.
1682 views
Testing in the postapocalyptic future
Daniel Westheide, INNOQ
June 12, 2019 · 2:32 p.m.
498 views
Context Buddy: the tool that knows your code better than you
Krzysztof Romanowski, sphere.it conference
June 12, 2019 · 2:33 p.m.
393 views
The Shape(less) of Type Class Derivation in Scala 3
Miles Sabin, Underscore Consulting
June 12, 2019 · 3:30 p.m.
2321 views
Refactor all the things!
Daniela Sfregola, organizer of the London Scala User Group meetup
June 12, 2019 · 3:31 p.m.
514 views
Integrating Developer Experiences - Build Server Protocol
Justin Kaeser, IntelliJ Scala
June 12, 2019 · 3:32 p.m.
551 views
Managing an Akka Cluster on Kubernetes
Markus Jura, MOIA
June 12, 2019 · 3:33 p.m.
735 views
Serverless Scala - Functions as SuperDuperMicroServices
Josh Suereth, Donna Malayeri & James Ward, Author of Scala In Depth; Google ; Google
June 12, 2019 · 4:45 p.m.
936 views
How are we going to migrate to Scala 3.0, aka Dotty?
Lukas Rytz, Lightbend
June 12, 2019 · 4:46 p.m.
709 views
Concurrent programming in 2019: Akka, Monix or ZIO?
Adam Warski, co-founders of SoftwareMill
June 12, 2019 · 4:47 p.m.
1974 views
ScalaJS and Typescript: an unlikely romance
Jeremy Hughes, Lightbend
June 12, 2019 · 4:48 p.m.
1377 views
Pure Functional Database Programming‚ without JDBC
Rob Norris
June 12, 2019 · 5:45 p.m.
6374 views
Why you need to be reviewing open source code
Gris Cuevas Zambrano & Holden Karau, Google Cloud;
June 12, 2019 · 5:46 p.m.
484 views
Develop seamless web services with Mu
Oli Makhasoeva, 47 Degrees
June 12, 2019 · 5:47 p.m.
785 views
Implementing the Scala 2.13 collections
Stefan Zeiger, Lightbend
June 12, 2019 · 5:48 p.m.
810 views
Introduction to day 2
June 13, 2019 · 9:10 a.m.
250 views
Sustaining open source digital infrastructure
Bogdan Vasilescu, Assistant Professor at Carnegie Mellon University's School of Computer Science, USA
June 13, 2019 · 9:16 a.m.
374 views
Building a Better Scala Community
Kelley Robinson, Developer Evangelist at Twilio
June 13, 2019 · 10:15 a.m.
245 views
Run Scala Faster with GraalVM on any Platform
Vojin Jovanovic, Oracle
June 13, 2019 · 10:16 a.m.
1340 views
ScalaClean - full program static analysis at scale
Rory Graves
June 13, 2019 · 10:17 a.m.
463 views
Flare & Lantern: Accelerators for Spark and Deep Learning
Tiark Rompf, Assistant Professor at Purdue University
June 13, 2019 · 10:18 a.m.
380 views
Metaprogramming in Dotty
Nicolas Stucki, Ph.D. student at LAMP
June 13, 2019 · 11:15 a.m.
1250 views
Fast, Simple Concurrency with Scala Native
Richard Whaling, data engineer based in Chicago
June 13, 2019 · 11:16 a.m.
624 views
Pick your number type with Spire
Denis Rosset, postdoctoral researcher at Perimeter Institute
June 13, 2019 · 11:17 a.m.
245 views
Scala.js and WebAssembly, a tale of the dangers of the sea
Sébastien Doeraene, Executive director of the Scala Center
June 13, 2019 · 11:18 a.m.
661 views
Performance tuning Twitter services with Graal and ML
Chris Thalinger, Twitter
June 13, 2019 · 12:15 p.m.
2003 views
Supporting the Scala Ecosystem: Stories from the Line
Justin Pihony, Lightbend
June 13, 2019 · 12:16 p.m.
163 views
Compiling to preserve our privacy
Manohar Jonnalagedda and Jakob Odersky, Inpher
June 13, 2019 · 12:17 p.m.
301 views
Building Scala with Bazel
Natan Silnitsky, wix.com
June 13, 2019 · 12:18 p.m.
565 views
244 views
Asynchronous streams in direct style with and without macros
Philipp Haller, KTH Royal Institute of Technology in Stockholm
June 13, 2019 · 3:45 p.m.
304 views
Interactive Computing with Jupyter and Almond
Sören Brunk, USU Software AG
June 13, 2019 · 3:46 p.m.
681 views
Scala best practices I wish someone'd told me about
Nicolas Rinaudo, CTO of Besedo
June 13, 2019 · 3:47 p.m.
2702 views
High performance Privacy By Design using Matryoshka & Spark
Wiem Zine El Abidine and Olivier Girardot, Scala Backend Developer at MOIA / co-founder of Lateral Thoughts
June 13, 2019 · 3:48 p.m.
753 views
Immutable Sequential Maps – Keeping order while hashed
Odd Möller
June 13, 2019 · 4:45 p.m.
276 views
All the fancy things flexible dependency management can do
Alexandre Archambault, engineer at the Scala Center
June 13, 2019 · 4:46 p.m.
389 views
ScalaWebTest - integration testing made easy
Dani Rey, Unic AG
June 13, 2019 · 4:47 p.m.
468 views
Mellite: An Integrated Development Environment for Sound
Hanns Holger Rutz, Institute of Electronic Music and Acoustics (IEM), Graz
June 13, 2019 · 4:48 p.m.
213 views
Closing panel
Panel
June 13, 2019 · 5:54 p.m.
400 views