#Phobos discussion

1 messages ยท Page 1 of 1 (latest)

lusty shoal
#

Better late than never for a thread ๐Ÿ˜›

feral geyser
#

a thread.

slow vault
#

yea it doesn't. I/we might request that to change now, but for now you gotta --use-load

feral geyser
#

that doesn't seem to be documented anywhere

#

did you talk to therenas or jarg about it

slow vault
shy pollen
#

i was the one who did it

#

it was going to get locked down entirely and i pushed back and got to save load loading bytecode

#

i suspect if phobos gets popular it might be permissible to relax it back

feral geyser
#

what if you had a wrapper script that would automatically compile mods for you

shy pollen
#

especially since we're now doing a little sanity checking on the loaded bytecode too, to keep it from doing anything to crazy

feral geyser
#

for free (minor) performance benefits

shy pollen
#

debugger can do that :)

#

oh, you mean just do it to every mod

feral geyser
#

yep

shy pollen
#

that'd take a bit more doing

slow vault
#

there'd also be the issue of compilation taking time. I suspect release builds with a bunch of optimizations on big mods to take minutes, but that's a very rough guess

shy pollen
#

yeah that'll get interesting

feral geyser
#

kinda want to talk to jcranmer on the topic of compiler optimizations

#

he has a fair bit of domain knowledge

slow vault
#

I might also look into multithreading libs for that, but those are troublesome

feral geyser
#

"do you want to install the recommended extensions for this repository?" :p

shy pollen
#

but yeah, factorio's strictness around bytecode is basically defence against memory bugs in the vm, all the ones we know about have been fixed, but it's hard to say if that's really all of them...

slow vault
lusty shoal
#

Eyyyyy Rate Calculator is now compiled with Phobos!

#

And it works flawlessly so far

slow vault
#

Yay! ๐ŸŽ‰

shy pollen
#

hard to read because it's all lua's c-programmer-disease macros?

slow vault
#

mhmm :D

lusty shoal
#

Ultimate awesomeness would be getting phobos down to a single executable binary, but I'm not sure that that's even possible with lua

slow vault
#

Oh something I didn't make super clear: the debug build profile currently disables tailcalls, which I find to be very useful. (release is default for the record)

feral geyser
#

mhm

#

just ship a single native binary

#

alternatively, do the sane thing and ship a (VM? interpreter? idk)

shy pollen
#

single binary of a lua vm that just loads a bytecode blob on startup is probably not too hard to do

slow vault
#

Sounds incredibly hard to a noob like me ๐Ÿ˜…

lusty shoal
#

C is ridiculously easy to compile if you're on Linux ๐Ÿ˜›

#

make

#

Bam!

#

||Sometimes||

feral geyser
#

gcc, you mean

shy pollen
#

but separate .lua file for phobos in a factorio mod is still useful for other mods that want to consume code from a user

#

which might want to invoke it in-game on those little bits of code from textboxes

lusty shoal
#

๐Ÿค” I haven't thought about how it would work with library mods

feral geyser
#

perhaps a FUSE fs for resolving deps

slow vault
#

library mods compiled with Phobos (or the Phobos mod itself) is pretty interesting. In the end it will probably have an option to include the external libraries directly into the compiled files, or to link to their compiled files. I'm not sure, it's going to be hard

lusty shoal
#

Honestly, if we want full optimization and interlinking, the best solution would be to include libraries in your mod. But then that removes the entire advantage of mod portal dependencies
Oh, you just said the same thing lol

feral geyser
#

ooh

#

what if you compile the base game

slow vault
#

It's possible... as long as you don't play multiplayer

feral geyser
slow vault
#

Unless we get wube to compile base using Phobos

lusty shoal
#

Unfortunately they need to actually document their stuff first, otherwise you wouldn't know what is available

slow vault
lusty shoal
#

That's the other big reason for including libraries - if you include compiled phobos files, you can't go to definition to see how anything works

shy pollen
#

you can still call require directly to get stuff from other mods just fine

shy pollen
#

and if that happesn to load a phobos compiled blob, great, if it loads plain lua, whatever ๐Ÿคท

lusty shoal
#

Or can you?

slow vault
shy pollen
#

you publish type defs with your lib

#

and it consumes those

lusty shoal
#

That would work

slow vault
#

and regarding source, you can still include your .pho source files if you want to. the bytecode itself points to .pho files in it's source field

shy pollen
#

(or publish them separaately, for non-phobos libs)

slow vault
lusty shoal
#

๐Ÿค” Could phobos compress the entire mod into the base files if it wanted?

#

(control.lua, data.lua, etc)

slow vault
#

Yep it could

shy pollen
#

that gets complicated in some cases, but yes in theory it could

feral geyser
#

is .. optional chaining?

shy pollen
#

.. is string concat

#

same as it is in lua

lusty shoal
#

Oooh lambdas

feral geyser
#

one other useful one is ??

#

as well as the counterpart ||

shy pollen
#

|| is just or

#

?? is just slightly more specific or

feral geyser
#

shortcut for true ? true : false

#

for ||

#

and ?? is nullish coalescing

shy pollen
#

what language does that useage of || come from? i've never seen it anythign other than logical or?

feral geyser
#

JS has it

lusty shoal
#

Yeah, JS

shy pollen
#

like foo || bar?

feral geyser
#

yeah

lusty shoal
#

Also Rust

shy pollen
#

that's logical or

#

it works exactly like lua's or

feral geyser
#

d'oh

#

I categorize it in my head differently when used in that context

shy pollen
#

it's the counterpart of &&

shy pollen
#

because that's... not ||

feral geyser
#

"truthy" ? "truthy" : "some other value" is what I really meant

shy pollen
#

oh, a ? a : b with only one eval of a

#

then yes

feral geyser
#

for ??, the equivalent is:

if (value === undefined || value === null) {
  value = rightHandSide
}```
#

another one that may or may not be useful is the pipeline operator

slow vault
#

you mean for bitwise or? so syntatic sugar for bit32.lor (right?)?

shy pollen
#

no

#

|| is literally exactly the logical or that lua already has as or, ?? is just that but instead of testing truthiness it explicitly tests against nil

slow vault
shy pollen
#

iirc ?? was always on my "eh, maybe?" list

#

yes, single | is bitwise, but nobody's talking about that :)

slow vault
#

another one that may or may not be useful is the pipeline operator
it's how I parsed that statement, but regardless, it's resolved :P

slow vault
feral geyser
slow vault
#

Anything javascript related is very most likely out the window. I dislike the language and believe it's syntax is simply bad. I'll take a look at it, sure, but I'm definitely biased to say "no"

lusty shoal
#

===
๐Ÿ˜ฑ

#

I do like that it uses braces instead of do/then/end though ๐Ÿ˜„

feral geyser
#

I believe that at this point JS is borrowing stuff from other languages to make it nice to use

#

so you shouldn't be biased against modern features

shy pollen
#

everyone is borrowing from everyone these days

#

but there's plenty on the list already :p

shy pollen
#

(i'm not suggesting that === should be sugar for it though, in general i think symbols that are sugar for more function calls are asking for trouble down the line)

lusty shoal
#

True, I forgot about raweq

slow vault
#

in general i think symbols that are sugar for more function calls are asking for trouble down the line
good point... though for some things it's really tempting

lusty shoal
#

But at least Lua doesn't automatically try to type coerce when you use ==

#

In javascript, "2" == 2 is true and I hate it with every fiber of my being

shy pollen
#

that function that you're presumably getting, at lesat originally, from a global

slow vault
#

Phobos has to be smart enough to keep the function it actually wants in some local/upvalue ;)

shy pollen
#

or maybe they replaced it for a good reason, and you should use the replacement

feral geyser
#

so operator overrides?

shy pollen
#

yeah, it's a tricky subject, which is why my general reaction is to leave it to the vm to decide that sort of stuff

#

(where the metatables/operator overrides are happening)

slow vault
#

The one time i thought about inlineing metamethods it seemed like a good idea because it makes things like Postion math more usable

#

but yea, i didn't think about it much

feral geyser
#

(besides, JS syntax is just C-like syntax)

slow vault
#

I suppose the definition of syntax matters at that point. I consider the real meaning of some syntax, so what it actually ends up doing, to be part of the syntax, because it ultimately affects how I read code. But that's semantics at that point, and I'd rather just leave it at "I don't like JS"

feral geyser
#

yeah let's discuss... something else, that doesn't incite tensions and language flamewars

slow vault
feral geyser
#

do you have brackets for begin/end planned or done?

shy pollen
#

back when it was my project htat was alwasy a hard no

slow vault
#

nope, because it breaks far too much syntax, which means it would require a big change in syntax, making even "just" an option to allow for it unreasonable

feral geyser
#

not even as a preprocessor that replaces them with the appropriate keywords?

shy pollen
#

would it really improve the language though?

slow vault
#
if foo {
}

compilatron what the heck do you mean ๐Ÿ”ฅ

#

(if it's not clear, that's ambiguous between a function call and a block)

feral geyser
#

ah right, that was the main issue

shy pollen
#

i've never heard anyone argue for braces actually explain a way in which they improve the language, rather than just being "what i like"

feral geyser
#

and you can't simply remove implicit calls because of the goal to remain a strict superset of lua

lusty shoal
# shy pollen would it really *improve the language* though?

It would improve navigation. I cannot count how many times I have had to scroll up and down to make sure I have the right end for the then/do. If the language used brackets then I could just hit m to jump to the matching one, and it would work with bracket coloring.

shy pollen
#

that's a language server deficiency to find the matching keyword :p

#

they can do it for words just as well as they can for brackets

lusty shoal
#

The language server does highlight it when I hover it. But it doesn't remain highlighted as soon as I move off of it

#

So I can't use that when it's more than a screen tall

slow vault
#

because of the goal to remain a strict superset of lua
nod *

  • Some features can end up breaking regular Lua code, such as adding a switch keyword. That's something I'm fine with, but any such features will be opt in
shy pollen
#

what strategy would you use to implement switch?

#

it always annoyed me that hte vm doesn't support the computed-jump needed to do it "correctly"

slow vault
#

That's one hard question. Some way where it doesn't need to recreate a table and a bunch of closures every time

#

I did notice something though, which i didn't investigate yet, but it might help... maybe. one sec, let me get the screenshot

shy pollen
#

yeah if you do a table of functions for the easy dispatch then you get so many complications about linking upvals right

#

but you could also just try and work out an efficient tree of ifs for it

#

to keep it all inline within the function

slow vault
#

tailcall just kind of continues?!

shy pollen
#

huh?

#

๐Ÿค”

slow vault
#

this tailcall weirdness is actually a bit of a tangent, now that i think about it, but yea everything you said previously is exactly my train of thought

#

and i haven't decided yet

shy pollen
#

oh

#

you can't actually tailcall c functions

#

if you try to it turns into a regular call

#

i dunno if that's actually relevant though

slow vault
#

hm, i'll try with a Lua function then

shy pollen
#

but i'm looking at OP_TAILCALL in the vm now and it looks like it does the thing by actually replacing the current function on the lua stack with the other one

#

so i'm not entirely clear on how it would continue from it if it really did tailcall

#

i assume the extra OP_RETURN is to deal with if it turns out to have been a c function

#

and therefor the lua function is still on the stack to be returned to

#

but yeah, have a look at vmcase(OP_TAILCALL and luaD_precall

slow vault
#

yea it does return if it's a Lua function. Alright, not useful then but still interesting

shy pollen
#

arguably the return after tailcall should probably be required then ๐Ÿค”

slow vault
shy pollen
#

the improtant bit is to see that it does basically nothing for c functions and all that extra shit for lua functions

slow vault
#

I can't think of anything that would cause issues (in regards to memory/security), but better save than sorry

shy pollen
#

the one i'm imagining is if you run off the end of a function

#

but i'm pretty sure the vm will stop you there anyway

#

but yeah, i'll probably go add that to the bytecode sanity checks later before anyone does discover something evil to do with it

slow vault
# feral geyser (pipeline operator is different, btw: <https://github.com/tc39/proposal-pipeline...

I've looked into this a bit and thought about it. I can definitely see it's use, but interestingly enough I mostly remember having the issue the pipe operator solves in C# but hardly in Lua. While I'm not entirely certain what the cause of that is, I believe it's related to Lua mostly using pure (ish) functions and very few class like objects. While it is possible to have a coding style using a lot of metatables and userdata objects (if the c libraries use them), I myself tend to use those pretty rarely. (Inspired by factorio, and I've grown to like the simplicity of it).

Now I do see it's pros, I cannot look past the cons. I've ignored its origin, I'm sorry for not remaining object objective earlier, and when looking at it the first time, without any context, it was nearly impossible to guess what it could mean; What that code was doing. When reading that it is meant to solve/improve big nested expressions or function call chains I could guess what it was doing, but still wasn't certain. Only once I read its actual description for how it works it made sense. While this is fine and part of learning a language, it is still a downside I like to avoid, and as I mentioned previously I don't actually see much gain from it specifically in Lua and in factorio.

Lua currently suffers from very little obscure syntax (see for and metatables), so unless this pipe operator |> becomes very commonly understood, I consider it unlikely. (Note that my opinion is very mutable through many means)

feral geyser
#

I do agree that it gets a bit difficult to understand wtf is happening

#

but that's pretty much always in the case where it's already difficult to discern

slow vault
#

That's true, but it wouldn't just end up being used in cases that are difficult to discern currently, if that makes sense

#

Hm, i think this is a good (long winded) way to put it:
Complex/Weird syntax is fine and to be expected as long as it is kept to a minimum.
Lua's manual is quite literally a single page, where you can read the sections about its syntax in like an hour (rough estimate). Adding a little bit of complex syntax to that is fine, because at the end of the day it's still not a lot of syntax. Now imagine a language that has nearly every syntax any language has implemented in some way shape or form... While each individual piece of syntax is easy to understand if you read through the manual about it for 5 minutes, you still don't know what's going on. I think a great example of this is powershell or bash or whatever it's called. Unfortunately looking up some specific syntax you don't understand is very difficult, because you don't know the name of it.

eager cave
#

A temporary variable beats pipeline operator on readability 10 times out of 10.

shy pollen
#

ah, the "pretend i'm writing a shell script" operator :p

slow vault
#

Actually, even better way to put it: The less syntax, the better. ๐Ÿ‘Œ

shy pollen
#

and yes, keeping it simple enough to explain in one page seems good :)

slow vault
#

(obligatory note: @feral geyser we (at least I) are/am not arguing against you, but the syntax/nature of languages)

feral geyser
#

I understand

#

I was thinking of saying similar earlier

shy pollen
#

programmer-debate mode where the people disappear and the ideas fight it out compilatron โš”๏ธ compilatron_flipped

feral geyser
#

sockpuppet for ideas mode