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
Matthias247 has quit [Read error: Connection reset by peer]
<doublec> tj800x: what chart are you referring to?
<TJ800X> The one with 9 squares. ISO, VAL and TAG are on the diagonal.
<TJ800X> I worked through a bunch of examples. I'm going to post a gist shortly.
<doublec> That post has some good diagrams of how capabilities can be converted to others
<TJ800X> Yes, I've seen that. I just wrote a chunk of code to prove it for myself.
<doublec> "it destructively reads the memory associated with refa_iso and essentially repoints that memory block to refb"
<doublec> That's not really how it works
<doublec> Since capabilities are at compile time and there's no repointing of things or reading of memory
<doublec> What consume does is removes an alias
<doublec> So "consume foo" stops foo from being an alias to a pointer
<doublec> Therefore the variable 'foo' can no longer be used
<doublec> so "let a: Foo val = consume foo" Where 'foo 'is a
<doublec> "Foo iso" removes the alias. It is now unliased and can safely be used as a val.
<TJ800X> The tabbing isn't perfect on that gist, but it might help some future newbie.
<TJ800X> What does recover do? It seems to work on an entire class, not a variable reference.
<TJ800X> My big hangup seems to be if I have a val and I need a ref, or vice versa.
<doublec> tj800x: recover creates a block (or scope) where variables that can be captured inside it are restricted to sendable variables.
<doublec> tj800x: and objects created inside it can't escape
<doublec> tj800x: this means a ref, val, etc created inside it can be safely converted to something else on exit
<doublec> tj800x: since it is known there can be no other aliases to those variables
<doublec> tj800x: this is the only way to convert a rev/val to an iso
<doublec> tj800x: create it as ref inside the recover. Mutate it as desired. Return it from the block as an iso.
smoon has quit [Quit: smoon]
<TJ800X> Ok. Thanks for the explanation. I'm going to have to explore to get it.
<doublec> tj800x: I give a couple of examples here https://bluishcoder.co.nz/2016/07/18/borrowing-in-pony.html
<doublec> although that's about getting 'ref' access to a 'ref' field in an 'iso' object
<doublec> But to do it you need to have a recover block where you convert the iso to a ref. Access the field (since it's a ref now you can access fields) and then return it back as an iso.
<TJ800X> Ok. I will have to take it piece-by-piece.
<TJ800X> About the val. How do convert it to a ref type? Do I do it inside a recover block somehow?
<doublec> tj800x: see here for converting a ref to an iso https://is.gd/KFSjUw
<doublec> tj800x: you can't actually convert a val to a ref
smoon has joined #ponylang
<TJ800X> I suspected that. ref to val seemed like it should be doable. I spent a whole bunch of time trying to figure out how to do that one.
<TJ800X> Thanks!
smoon has quit [Quit: smoon]
jemc has quit [Ping timeout: 248 seconds]
amclain has quit [Quit: Leaving]
jemc has joined #ponylang
jemc has quit [Ping timeout: 240 seconds]
<TJ800X> What is Pony trying to tell me when it says "receiver type: this->TimeContext ref"?
<TJ800X> The receiver type is this->TimeContext ref and the target type is simply TimeContext ref (without the this->)
jemc has joined #ponylang
<jemc> tj800x: `this->Foo` denotes a viewpoint adaptation - it represents "how `this` sees `Foo`"
<jemc> it's the next level of the learning curve :)
<TJ800X> I was just about to say....I should get me a shovel for this rabbit hole!
<jemc> however, I can say as a quick and dirty answer that the most common reason to see an error like that is that you're trying to grab a mutable field (`ref`) from an object inside its read-only method (`fun box`)
<jemc> note that the default *receiver capability* of a `fun` is `box` - usually when you see that error it means you need to turn it into a `fun ref`
<jemc> are you already familiar with the concept of the *receiver capability* of a method?
<TJ800X> I'm trying to run a function that mutates the object.
<TJ800X> Yes.
<TJ800X> I already added the ref capability to the function.
<jemc> can you gist/pastebin your code?
<TJ800X> Yes. One moment.
<TJ800X> I tried using the playground, but it doesn't recognize the Time package.
<TJ800X> Line 88 88:20: receiver type is not a subtype of target type
<TJ800X> 88:3: receiver type: this->TimeContext ref
<TJ800X> 55:2: target type: TimeContext ref
<doublec> tj800x: that's because it's case sensitive. It should be: use "time"
<TJ800X> 69:11: TimeContext box is not a subtype of TimeContext ref: box is not a subcap of ref
<doublec> doublec: ditto with format and assert
<TJ800X> OSX :( !
<TJ800X> Fixed it. Thx.
<doublec> tj800x: make_ts needs to be ref
<doublec> tj800x: fun ref make_ts():U128
<doublec> Good guess by jemc :)
<doublec> tj800x: Do you understand why that fixes it?
<TJ800X> Not fixing it for me
<doublec> tj800x: hmm, works for me and works in pony-playpen
<TJ800X> Broken for me in playpen. That's weird.
<TJ800X> Please share playpen.
<doublec> tj800x: https://is.gd/HTgMQc
<TJ800X> Maybe I mangled something else. Thanks.
<doublec> tj800x: I had to cut out the Main actor, etc to fit it in the character limit
<doublec> tj800x: but if you remove the 'ref' you see your error
<TJ800X> Ahh...maybe something weird with Sublime.
<TJ800X> Yea, I think that was a wrong version. It should be about 200 lines.
<doublec> tj800x: you've got the ref in the wrong place
<doublec> tj800x: you have "fun make_ts():U128 ref"
<doublec> tj800x: I had "fun ref make_ts():U128"
<doublec> tj800x: The first makes the result a U128 ref
<doublec> tj800x: The second makes the 'this' a ref.
<doublec> tj800x: ie. the receiver is a ref
<TJ800X> Okay. Now it compiles.
<TJ800X> Thanks so much. I'd be interested in any other thoughts on the code. This is a big effort for me. I appreciate all the experience and help I get on here.
<doublec> np, happy to help :)
_whitelogger has joined #ponylang
papey_lap has joined #ponylang
k0nsl has quit [Quit: “If we don't believe in freedom of expression for people we despise, we don't believe in it at all — Noam Chomsky”]
k0nsl_ has joined #ponylang
abeaumont has quit [Ping timeout: 276 seconds]
jemc has quit [Ping timeout: 248 seconds]
bimawa has quit [Quit: WeeChat 1.4]
g00s has joined #ponylang
abeaumont has joined #ponylang
vaninwagen has joined #ponylang
g00s has quit [Quit: Textual IRC Client: www.textualapp.com]
bimawa has joined #ponylang
Matthias247 has joined #ponylang
smoon has joined #ponylang
_andre has joined #ponylang
Praetonus has joined #ponylang
smoon has quit [Quit: smoon]
smoon has joined #ponylang
smoon has quit [Quit: smoon]
smoon has joined #ponylang
roscode has joined #ponylang
smoon has quit [Quit: smoon]
jemc has joined #ponylang
jemc has quit [Client Quit]
jemc has joined #ponylang
smoon has joined #ponylang
roscode has quit [Ping timeout: 260 seconds]
smoon has quit [Quit: smoon]
smoon has joined #ponylang
smoon has quit [Quit: smoon]
<vaninwagen> hi, maybe i am a stubborn old donkey, but why can't i reassign to a consumed var? https://is.gd/qaTpvS
smoon has joined #ponylang
<SeanTAllen> vaninwagen: you can do a destructive read
smoon has quit [Client Quit]
<jemc> vaninwagen: note the error says you can't do it *in a try expression*
<jemc> this is because the compiler has to assume the try expression could error out at any time, including the possibility of erroring out *after the consume*, but *before the assignment* - this would leave the compiler not knowing statically whether that reference is safe to use again
<jemc> does that make sense?
<jemc> that is, you can definitely do that kind of pattern, but it can't be in a try expression
smoon has joined #ponylang
<vaninwagen> jemc makes total sense
<vaninwagen> SeanTAllen thx, will try that :)
<vaninwagen> SeanTAllen does destructive read really work here if i have a method which consumes a var and i want to assign it's return value to that var?
smoon has quit [Quit: smoon]
<emilbayes> jemc: ping?
<emilbayes> jemc: Or I'll just ask
<emilbayes> jemc: Why did you decide to go with you own _make_buffer in pony-sodium instead of using ByteSeq?
smoon has joined #ponylang
smoon has quit [Quit: smoon]
<jemc> emilbayes: how would you use ByteSeq in its place?
<emilbayes> jemc: I was thinking String ref or Array[U8 val] ref
<emilbayes> jemc: But I'm still learning pony so I might be wrong
amclain has joined #ponylang
<jemc> I think we had a discussion about this at one point, and I mentioned I'd be open to letting it take a type parameter
<jemc> though note that strings and arrays can be converted between eachother without copying the underlying buffer
<emilbayes> jemc: ah yeah I think you're right
<jemc> so the API should be usable already, even if a bit more cumbersome
<emilbayes> jemc: I have toyed aroud with implementing the crypto_pwhash function but can't get it to work
<jemc> what's going wrong?
<emilbayes> jemc: eg. I pass it a string to store the hash in, hash.space() is 32 before passing to libsodium, but hash.space() is 33 after
<emilbayes> but the hash itself is still hash.size() == 0
<jemc> can you show your code so far?
<emilbayes> jemc: Doing a playpen now
<emilbayes> jemc: https://is.gd/1RgHqV
<emilbayes> the main actor might look a bit woonky because I messed around so much
<emilbayes> oh, and I forgot use "debug"
vaninwagen has quit [Ping timeout: 240 seconds]
<emilbayes> jemc: I'm also not sure what pattern is better when I get to other functions like pwhash_verify, which takes a password and a hash (and the settings). Should it take password as ref for consistency or as val because of least privilege?
<emilbayes> jemc: does it make sense or do you not have time to look at it right now?
<jemc> looking now
papey_lap has quit [Quit: WeeChat 1.9]
papey_lap has joined #ponylang
<jemc> emilbayes: hm, my version of libsodium doesn't hav the `crypto_pwhash` functions - they must be new-ish :/
<jemc> at any rate, note that the `String` class does some silly fiddling with the allocation length to account for a null terminator
<jemc> this is one reason why I use a `_make_buffer` method internally
<emilbayes> jemc: Ah
<emilbayes> jemc: I think pwhash came in 1.0.10, but that version is over a year old :)
<emilbayes> 1.0.12 is latest
<jemc> it's also for convenience, though - in C it is quite common to pass in an "out" argument, but in Pony it's somewhat non-idiomatic (unless it's in the hot path, and you're really pressed for avoiding memory allocations and want to reuse the buffers)
<emilbayes> jemc: Yeah
<emilbayes> jemc: Maybe I'm falling on old habits, but I help maintain the node.js bindings and we do it there to not deviate too much from the C api
<emilbayes> jemc: But I guess the cost of any of the crypto ops is much greater than allocating internally to the function
<emilbayes> jemc: The upside of letting the user pass in a out variable though is that it allows us to expose libsodium protected memory. Then the user can choose to use a normal ByteSeq or a SecureSeq (which I would implement)
<jemc> that could be enough of an upside to make the change - though I think I'd like to work out the design of the `SecureSeq` class first before changing the API of the other pieces of the package
<emilbayes> jemc: The protected memory stuff is like a custom malloc, all it takes as input is a length
<emilbayes> then it has some apis around locking and unlocking the memory, R/W access and such
<emilbayes> and a free method
<emilbayes> oh yeah, there's memory locking too, but I guess you could have a function allocated whatever you need and lock it right after it is returned to you
<emilbayes> i don't know if a swap can happen in the time between pony allocs and the "whatever" is returned to you
<jemc> I don't have much time at the moment to read through those docs today, but if you were planning on doing a Pony wrapper for it, I'd be interested to see what you think that API should look like
<emilbayes> jemc: Maybe I should take a stab at that in the meantime, do a PR and we can go from there?
<jemc> sounds good - but yeah, let's tackle the issue of adding the secure memory class separately from the issue of making the other types compatible with using it
Matthias247 has quit [Read error: Connection reset by peer]
jmiven has quit [Quit: co'o]
jmiven has joined #ponylang
tj800x_ has joined #ponylang
smoon has joined #ponylang
<tj800x_> How do I convert from a U128 to an array of U8s? I've tried a few things, but can't get it to go.
<jemc> tj800x_: the standard library has buffered.Writer, which can do something similar: https://github.com/ponylang/ponyc/blob/8781b654e9fddcf0236f41c822df35b0f749bad4/packages/buffered/writer.pony#L210-L252
<jemc> you could copy that code, replacing the `_byte` method with `my_array.push`, where `my_array` is your `Array[U8]`
<tj800x_> OK. I was trying with Array[U8].create...I'll will look into the buffer. I just assumed it was simple.
endformationage has joined #ponylang
<jemc> actually, come to think of it - you can use the "array literal" sugar to avoid explicitly calling `push` for every element
<jemc> be careful of the byte order, though - you've got to know whether you want big-endian or little-endian
<tj800x_> Yes, I've got some control over that. I basically get to decide the endian-ness for my library. I think I'm using little-endianness, but after I've played with the library a bit I might change my mind.
<tj800x_> I think I found a pretty obscure bug that causes the compiler to return without error. I'm doing something patently stupid. I know there are a ton of important things to be worked on. Should I report the bug or not?
<tj800x_> I don't want to waste people's time.
<jemc> sure, if you think you've found a compiler crash, please do report it
<tj800x_> It happens when passing in a bad precision value into the Format library. Like I said, patently stupid of me, but that's what learners do.
<tj800x_> That second one shows the compiler returning without error.
<tj800x_> I think it just needs a guard to not pass in a negative precision.
<tj800x_> Actually, I dont think its an error.
<tj800x_> I just told it to print a negative length string and got nothing.
Matthias247 has joined #ponylang
<Praetonus> tj800x_: This isn't a compiler bug, it's crashing at runtime
<jemc> tj800x_: actually, the issue is that you told it to allocate an 8-gigabyte string :)
<tj800x_> LOL. Fun stuff!
<jemc> the cause is that `USize(-1) == USize.max_value()`
<tj800x_> That can't be good. I'm not sure. My latest gist env.out.prints before and after, and I'm not getting anything outputted. I suppose the first output might not be getting flushed.
<jemc> do you have a local pony environment you can run it on?
<tj800x_> Sure do. Will do.
<jemc> (I imagine the web sandbox doesn't take kindly to an 8-GB memory allocation
<tj800x_> bin bash: line 1: 30940 Segmentation fault: 11 stupidgames
<tj800x_> Leave it to a newbie to wreck it good.
<tj800x_> IdiotGuard++
<tj800x_> For the record -- those above negative comments were self-directed. This is a great community and I appreciate it.
<jemc> no worries - I was trying to think if there's something that could be done as a sanity check in `Format` against very large values of `width`, but it seems that `width` is used for padding, and I'm not sure where to draw a "sane" limit for padding a string
<Praetonus> jemc: There's a bug in String.reserve too. If the reserved size is USize.max_value, the function will add 1 for the null terminator and overflow, resulting in a String that thinks it has lots of memory available but actually didn't allocate anything
<Praetonus> That's the reason of the crash here
<jemc> that darn null terminator
<tj800x_> Okay. I prepared a sample for a bug report. https://gist.github.com/tj800x/012f7403b95e2d9d2d22feba89f92c02 . When I file the bug report I will add a separate comment about String.reserve, so this can be figured out.
_andre has quit [Quit: leaving]
smoon has quit [Quit: smoon]
endforma1 has joined #ponylang
smoon has joined #ponylang
endformationage has quit [Ping timeout: 248 seconds]
smoon has quit [Quit: smoon]
papey_lap has quit [Ping timeout: 255 seconds]
smoon has joined #ponylang
smoon has quit [Quit: smoon]
smoon has joined #ponylang
endformationage has joined #ponylang
endforma1 has quit [Ping timeout: 240 seconds]