jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
jemc has quit [Ping timeout: 250 seconds]
acarrico has joined #ponylang
endformationage has quit [Quit: WeeChat 2.3]
Foaly has joined #ponylang
<emilbayes> I'm having a bit of an issue with generics. I have a function that looks at the value of a bunch of Unsigned's and returns a U8. However I was wondering if I could do this with generics instead of writing a specialised function for each case. Here's my attempt at the moment: https://playground.ponylang.io/?gist=6979595a6c48c7e87853ec6e14afa6ac
<SeanTAllen> emilbayes: how is that an issue with generics? not trying to be pedantic, but i'm not sure i understand what the problem is.
<SeanTAllen> this doesnt look to me like its a problem related to wanted to be "generic" about some different possible set of types. it looks more like "i want to do something based on some unsigned value, regardless of the size in bytes of that value"
<SeanTAllen> the way i'm understanding the problem you solution seems reasonable to me, but, i'm doubting that i understand what the problem is/was and i'm reading a lot into it from the solution
<emilbayes> SeanTAllen: Maybe I'm using the wrong words :) I read the errors as the compiler being unable to compare the constants across all the types I want to allow
<emilbayes> Is there an elegant way to do this?
<SeanTAllen> AH, ok
<SeanTAllen> I think I get it now
<SeanTAllen> emilbayes: the goal is to do something based on the value though, right?
<SeanTAllen> am i correct in that?
<SeanTAllen> i believe you confirmed that but im not positive
<emilbayes> SeanTAllen: Yes exactly
<SeanTAllen> ok, one moment
<SeanTAllen> im going to go look at my pony-msgpack code and see if i had a similar issue
<emilbayes> SeanTAllen: It's a prefix based on the "size" of the number
<emilbayes> SeanTAllen: Ah cool! Was looking for other code that I could read
<SeanTAllen> Hmmm so i dont quite do what you are doing
<SeanTAllen> So message pack has types that dont match up with Pony's types so I ended up doing things like this... https://github.com/SeanTAllen/pony-msgpack/blob/master/msgpack/message_pack_encoder.pony#L472
<SeanTAllen> which is probably not really what you want
<SeanTAllen> One thing you could do is to convert all your different union types to a single type like: https://playground.ponylang.io/?gist=3ad652ab934c29971f7404dbb5a6cb3a
<SeanTAllen> that's probably what you were looking for, maybe?
<emilbayes> SeanTAllen: Will take a look
<SeanTAllen> it allows you to treat all of the types of the union in one way by converting them to the largest one.
<emilbayes> SeanTAllen: What are the implications of .u64()? This is going to be the hot path of a some parsing code. But maybe I should just be happy for now and move on :)
<SeanTAllen> im not sure
<SeanTAllen> im trying to look that up
<SeanTAllen> those are interesting constants btw
<SeanTAllen> im still not sure of the significance of each one
<SeanTAllen> the 0xfc in particular is throwing me in the first if
<SeanTAllen> im curious, what is this for?
<SeanTAllen> the code in general
<SeanTAllen> emilbayes: i dont know the compiler well enough to dig far enough down into what the compiler instrinsic is doing
<SeanTAllen> the conversion is a compiler intrinsic
<emilbayes> Ah it's just varint encoding
<SeanTAllen> so the .u64() call itself
<SeanTAllen> that is polymorphic
<SeanTAllen> it would use selector coloring to decide what to do normally, im not sure if that is the case with compiler_intrinsics
<SeanTAllen> so much to learn
<emilbayes> Haha yeah, and you're so much more experience here than I am
<emilbayes> Thanks anyway, I will do with this for now and go back to it if it becomes an issue :)
<SeanTAllen> and i just messaged sylvan to see if he is around to talk me through the nuances here
<SeanTAllen> if i knew the compiler better i could get answers for myself but, i don't. i understand what i'm looking at but its like parachuting into a field and seeing trees and trying to figure out the forest without context.
Foaly has quit [Quit: Now 'mid shadows deep falls blessed sleep.]
<emilbayes> hehe
<SeanTAllen> i will have answers for you in a bit
<SeanTAllen> hey emilbayes
<SeanTAllen> so sylvan is pointing out something important with that
<SeanTAllen> you have a big performance issue with the union type
<emilbayes> great haha
<SeanTAllen> that (U8 | U16 | U32 | U64) will result in all those being boxed
<SeanTAllen> which is true and i was too focused on the other part of it
<SeanTAllen> so thats a big performance problem
<SeanTAllen> he is writing up a playground right now
<emilbayes> SeanTAllen: This is the full code of where I'm at right now: https://playground.ponylang.io/?gist=c0ca716926951ea68826f5444adc534c
<emilbayes> I don't know it that's too messy for anyone else to look at
<emilbayes> Since it's for varint's maybe my type should just be USize and nothing else
<emilbayes> but with USize I'm not sure how I can "push" that into an array of U8's
<SeanTAllen> ah so...
<SeanTAllen> what is the purpose of Varint ?
<emilbayes> So my purpose is to use it for length-prefixed messages where I may send small or very large messages
<SeanTAllen> but converting all those things to USize would be less expensive than all that union boxing
<emilbayes> so varint saves me bytes when I send small messages (single byte length header) and grows for large messages
<emilbayes> SeanTAllen: Ah ok!
<SeanTAllen> which would avoid boxing
<emilbayes> So the boxing happens in my version because I'm not using generics?
<SeanTAllen> and he says "if we had a better type checker, we wouldn't have to tell it its comp over u16
<emilbayes> What's the purpose of the `& Real[A]` constraint?
<SeanTAllen> yes
<SeanTAllen> because it gets refied
<SeanTAllen> here's an updated one:
<emilbayes> But that version also extends to U128, no?
<SeanTAllen> compiles to a mv followed by 3 comparisons (so says sylvan). this is a really weird game of telephone right now.
<emilbayes> What does "refied" mean? Is that a compiler/type checker term?
<emilbayes> Haha
<SeanTAllen> sorry that was a mispelling
<emilbayes> I think it's amazing you called him up for my little issue
<SeanTAllen> Real[A] demands that A is constructable and a union type is not constructable.
<emilbayes> Ah ok
<emilbayes> This is awesome
<SeanTAllen> sylvan says "yeah that code is quite efficient"
<emilbayes> thank you for the help!
<emilbayes> Haha
<SeanTAllen> after looking at the assembly
<SeanTAllen> you are welcome
<emilbayes> Really excited about pony! Have been playing with it on/off for two years now, but never had the time or experience to sit down and actually write some code. Hope this will change now :)
<emilbayes> Threw some money at the open collective to help this keep going
<SeanTAllen> Thanks!
<emilbayes> Do you have any points to how I can turn usize into a bunch of bytes so I can put it into a Array[U8]?
<SeanTAllen> check out buffered/writer.pony in the stdlib
<SeanTAllen> that's what i use in pony-msgpack
<emilbayes> Ah cool, will do
<emilbayes> thanks
<emilbayes> Oh yeah, this is exactly what I need
<SeanTAllen> you're welcome
acarrico has quit [Ping timeout: 268 seconds]
Foaly has joined #ponylang
Foaly has quit [Ping timeout: 250 seconds]
Foaly has joined #ponylang
endformationage has joined #ponylang
acarrico has joined #ponylang
endformationage has quit [Ping timeout: 250 seconds]
endformationage has joined #ponylang
acarrico has quit [Ping timeout: 250 seconds]
endformationage has quit [Ping timeout: 250 seconds]
anthonybullard has joined #ponylang
<anthonybullard> Morning all! I'm beginning the design phase for the Pony LSP Language Server.
<anthonybullard> I want to start stubbing out a design doc, but I want to check in with everyone for prior art, any prior discussions about the priority of the various language features, and any other thoughts people have on this project.
<SeanTAllen> anthonybullard i think about 3-5 people previously started LSP projects and none of them not very far. I think if you searched you might find them on github. That said, none of them ever got very far as far as i know so... i'd consider it like you are starting from scratch. There was 1 person but I can't remember who- the decided to tackle it in Typescript because there's a lot more library support for LSP with it.
<SeanTAllen> That seemed like a good idea to me. They might still be working on it, but I haven't heard anything in a long time. vaninwagen do you remember who that was?
endformationage has joined #ponylang
<anthonybullard> SeanTAllen: I'm going to do the LSP client in Typescript
<anthonybullard> But I'd like to do the LSP server in Pony
<anthonybullard> A lot of the reason I want to take this project on is to have a large, non-trivial project to motivate me in learning Pony
<SeanTAllen> Whoever it was who I was thinking of was doing both in Typescript
<SeanTAllen> anthonybullard: it would certainly be a welcome addition to the community.
<anthonybullard> And hopefully incrementally increase my pleasure in writing Pony as I go along
<SeanTAllen> the JSON library in the standard library has fairly poor ergonomics and it seemed to trip up a lot of people when they took on the LSP project as a learning experience.
<anthonybullard> I know have a more corporate job that encourages me to not bring work home, so I should have much more after-hours time to work on it
<SeanTAllen> So, feel free to ditch it and start working on your own JSON stuff if it gets frustrating.
<SeanTAllen> I'd love to see an LSP server
<anthonybullard> I've worked with JSON in Elm, so I have a low bar :-D
<SeanTAllen> Sylvan and I have both been hoping that one appears (neither of us wants to work on it - sssshhh)
<SeanTAllen> If you need help or get stuck, hit folks up here or on the mailing list
<anthonybullard> I understand, keeping with Core development is hard on it's own
<SeanTAllen> definitely happy to help as best i can
<anthonybullard> I will probably need help with some design decisions, and how to get started with the RPC server portion
<SeanTAllen> i dont have a lot of time lately so i mostly try to help by helping people get past problems they have and what not
<SeanTAllen> yeah do up a design document and im sure folks including myself would be happy to give feedback
<anthonybullard> Awesome
<anthonybullard> Any good examples of setting up a simple http server?
<anthonybullard> I didn't see one in the examples
<SeanTAllen> vaninwagen is the best person to talk to
<anthonybullard> Cool.
<SeanTAllen> we removed the http server from the standard library because it was...
<SeanTAllen> well
<SeanTAllen> in my mind, subpar
<SeanTAllen> for various reasons
<anthonybullard> vaninwagen: When you see this, ping me. I'd love to talk about this
<SeanTAllen> someone started working on a new one (there's an email to the mailing list)
<anthonybullard> Ok, I'll check the list out
<SeanTAllen> the old is available at https://github.com/ponylang/http
<SeanTAllen> vaninwagen has been making some improvements slowly as time permits (he recently had a child so... time is not all that permitting)
<anthonybullard> I have a toddler, so I understand that
<anthonybullard> I'll take a look at the old implementation
<SeanTAllen> here's the mailing list announcement for new http server: https://pony.groups.io/g/user/message/1836
<SeanTAllen> Shetland (good name!) from Tommy McGuire
<anthonybullard> I'm going to look over the source. I've never implemented HTTP before, nor looked over an implementation thoroughly, so It will be a good learning experience
<anthonybullard> Is Tommy on irc?
<SeanTAllen> ive seen him here from time to time but not often lately. email might be the best way to contact him.
<anthonybullard> Will do if I have questions
<anthonybullard> First things first, figuring out what language service features to implement first
<vaninwagen> SeanTAllen: might be github user patroclos who starter an lsp server but i could be wrong
<SeanTAllen> ah that sounds familiar
<vaninwagen> anthonybullard: what might be a good way to start is to figure out what kind of questions the lsp needs to answer and what info you need from the AST for that
<SeanTAllen> yeah that looks right from the repos: https://github.com/patroclos?tab=repositories
<SeanTAllen> anthonybullard you might want to reach out to patroclos. His email is on this github profile.
<vaninwagen> There is https://github.com/jemc/ponycc for that, but there is quite some work to be done on it
<vaninwagen> If you need features like ponycc e.g. accessing the ast, extracting available symbols, finding definitions of symbols, types etc, we have to work on ponycc to provide that
<vaninwagen> Which is fine, but will be quite some effort
<anthonybullard> I mean some of that could be handled by using the ANTLR grammar to parse the source files right?
<anthonybullard> Ah, nevermind, I see the ast package in ponycc
<anthonybullard> Maybe we could split ponycc/ast as a separate package?
<SeanTAllen> anthonybullard ponycc is jemc's project, you'd need to speak to him.
<vaninwagen> Btw there is also another approach coming from the scala world, which produces kind of a symbol/type database during compilation and uses that to drive lsp-like tools: https://scalameta.org/docs/semanticdb/guide.html#what-is-semanticdb-good-for
<vaninwagen> Might also be an interesting approach
<vaninwagen> I mean to have ponyc produce some kind of additional output that can support LSP
<vaninwagen> Because in ponyc we have all info we need, and can easily (e.g. via a plugin) work with that
Foaly has quit [Quit: Now 'mid shadows deep falls blessed sleep.]
alxs has joined #ponylang
alxs has quit [Quit: Computer's gone to sleep. ZZZzzz…]
so has quit [Ping timeout: 246 seconds]
so has joined #ponylang
<anthonybullard> vaninwagen: Yeah, I was actually thinking that if we move to something like ponycc - a compiler written in pony - there is no reason for it to be limited to just being a compiler.
<anthonybullard> I work on a project called Flutter, and we have a tool that is actually a front(really, it's a just a shell script backed by a collection of executables).
<anthonybullard> It means that we can handle compilation, release builds, formatting, test, LSP, scaffolding and package management.
<anthonybullard> From one user facing command
<SeanTAllen> One could start to do that without rewriting the compiler in Pony.
<SeanTAllen> Honestly I think that would be an approach that would be like to provide dividends before Pony in Pony would
<anthonybullard> So maybe `ponycc lsp [opts]` could just start a long living process for the LSP server, and it could talk to whatever it needs to
<anthonybullard> For sure
<anthonybullard> I totally agree
<anthonybullard> Most recently successful languages follow this pattern
<SeanTAllen> I think you would find the core team in favor of that if someone wanted to start working that out.
<anthonybullard> Think cargo in Rust, the go tool, mix in Elixir
<anthonybullard> And Flutter is providing that in part to the Dart community(since it has dramatically increased the amount of interest in Dart)
endformationage has quit [Quit: WeeChat 2.3]