jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has quit [Ping timeout: 265 seconds]
deavmi has joined #crystal-lang
Dreamer3 has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 272 seconds]
<FromGitter> <HertzDevil> when should i add `inject_primitives: false` to compiler tests?
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
chachasmooth has quit [Ping timeout: 260 seconds]
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
<FromGitter> <HertzDevil> i think i have a fix for crystal-lang/crystal#8864
mps has left #crystal-lang [#crystal-lang]
chachasmooth has joined #crystal-lang
ua has quit [Ping timeout: 260 seconds]
ua has joined #crystal-lang
HumanG33k has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_ht has joined #crystal-lang
<hightower2> HertzDevil ooh, that's a nice one
HumanG33k has quit [Quit: Leaving]
HumanG33k has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter> <yb66_gitlab> Hi all. I'm looking for a bit of help parsing this JSON: ⏎ ⏎ `{ ⏎ "features": [ ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5fe9c79bde608143154a613c]
<FromGitter> <yb66_gitlab> and this class to wrap it all up: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Accessing that browser-name key is a pain. [https://gitter.im/crystal-lang/crystal?at=5fe9c98de7f693041f379f65]
<raz> yb66_gitlab: do you know all browser names beforehand?
<raz> if yes, you could create fields for them with a marco
<raz> but actually, probably cleaner/safer to have a class/struct for the body of each browser (assuming it's always identical) and populating it by iterating over the unmapped keys
<hightower2> mm, from a macro, if I have a method from `@type.methods`, can I append something to its documentation section?
<sorcus> Each `spawn` call requires 8kb of memory?
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
<raz> 4kb according to the docs
deavmi has joined #crystal-lang
<sorcus> raz: https://play.crystal-lang.org/#/r/a6ef - then why is it show 8768 bytes?
<raz> i would imagine the current fiber, plus the fiber you spawned? 🤔
<raz> maybe try to spawn a few more and see how that changes the reading
<sorcus> raz: If i add two `spawn` before `Benchmark.memory`, result increases by 80 bytes.
<raz> hmm, did the first perhaps finish before you spawned the second?
<raz> (a `sleep 1` inside the first spawn might avoid that)
<raz> but tbh, i'm not sure how/what Benchmark.memory even measures, so i'm only guessing here
<raz> lol, not quite
<raz> sec lemme try
<sorcus> raz: This shows 10528 bytes :-D
<raz> i got this, but i feel like Benchmark.memory isn't measuring what we think it measures, or i'm doing it wrong ;)
<sorcus> raz: if i move `Fiber.yield` outside of `Benchmark.memory` it shows 2080 bytes.
<sorcus> raz: Yeah, maybe asterite can explain that...
<raz> probably a heap vs stack kinda thing
<FromGitter> <HertzDevil> the fiber is definitely not the only thing you're allocating
<FromGitter> <HertzDevil> there's the scheduler, which comes with its own platform-specific stuffs
<sorcus> raz: Hmm... For stack allocated objects `Benchmark.memory` shows 0 bytes.
<FromGitter> <HertzDevil> `Benchmark.memory` measures anything that goes through the garbage collector
<sorcus> raz: If i measure it right of course :-D
<FromGitter> <HertzDevil> you're better off with something like valgrind (if that even works on crystal executables)
<raz> yea was also gonna say valgrind (but just because that makes me sound smart, i've never used it :p)
<sorcus> raz: :-D :-D :-D
<FromGitter> <HertzDevil> i had to use it once in a situation where only c++98 was allowed (no ext libraries)
<raz> apparently on linux you can also do this https://stackoverflow.com/a/54660855
<raz> but no idea if that gives the number we are looking for, or just yet another RSS vs VSZ vs ... puzzle
<sorcus> raz: Valgrind shows `153 errors from 15 contexts` :-D
<sorcus> raz: for 6 lines of crystal code X-)
<straight-shoota> @HertzDevil > when should i add `inject_primitives: false` to compiler tests?
<straight-shoota> Ideally for every test that works without it :D It just keeps the sample smaller, thus improving performance of the spec
<raz> sorcus: well, i guess at this point the task turns into a test of your curiosity ;)
<straight-shoota> *without it = without primitives
<sorcus> raz: And what should i do now? :-D
<raz> well, it seems like your options are to figure out valgrind, or to summon the all-knowing asterite ;)
<sorcus> asterite: where are you? :-D
<raz> does the "definitely lost" number change when you add more fibers?
<sorcus> raz: `Conditional jump or move depends on uninitialised value(s)` - mmm, a lot of this errors comes from libgc if i understand it right...
<raz> yea, i would guess valgrind struggles to follow what the GC is doing, but i'm really outta my depth there
<sorcus> raz: https://gist.github.com/MrSorcus/64558bf62e15f9a120c2b3e4d1e24669 - seems like nothing changed for `definitely lost`.
<raz> hm ya, sorry, no idea
<sorcus> raz: number of errors same too.
<sorcus> raz: i add `GC.collect` at end and now `755 errors from 37 contexts` :-D :-D :-D
<sorcus> raz: https://gist.github.com/MrSorcus/1956e1d1da85f062ab276e40ba1c4dbc - valgrind with `track-origins` flag.
<raz> sorry, i really can't help there
<sorcus> raz: Looks like i can ignore many of errors, because they are stack allocated...
<sorcus> raz: Yeah, i know... :-D
ua has quit [Ping timeout: 260 seconds]
ua has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <asterite> hi
<sorcus> asterite: Hi ;-)
<FromGitter> <asterite> What's the question?
<sorcus> asterite: Hmm... Good question... :-D
<sorcus> asterite: https://play.crystal-lang.org/#/r/a6ef - what does it really show?
<FromGitter> <asterite> GC memory al located in that block
<sorcus> asterite: So it doesn't show how much memory used by fibers?
<FromGitter> <asterite> It shows how much memory is allocated when you create a fiber, yes
<FromGitter> <asterite> And when you call yield, but I think that doesnt allocate
<sorcus> asterite: https://gist.github.com/MrSorcus/1956e1d1da85f062ab276e40ba1c4dbc - ok, another question. Line 210 shows 66 allocs and 21 frees. Where is the other 45?
<sorcus> asterite: ooops, duplicated `channel`. Anyway, it doesn't change the output from valgrind X-)
<FromGitter> <asterite> I don't have time to dig into that code, but vallgrind shows memory allocations not only through GC
<sorcus> asterite: Oh, ok.
<raz> can i somehow change the stdout/stderr of the current process to an IO of my choice?
<raz> (i want to capture the output instead of letting it through to stdout)
<sorcus> raz: IO::Memory?
<raz> yup, but how do i point STDOUT/STDERR to it?
<FromGitter> <Blacksmoke16> can you do it the other way? supply the io you want to write to?
<raz> nope, i need to capture all output that would normally go to stdout
<FromGitter> <Blacksmoke16> how is it currently being sent to stdout? `puts "foo"`?
<raz> yup, for example
<raz> in ruby you can just re-assign $stdout. i'm looking for the equivalent in crystal :)
<FromGitter> <Blacksmoke16> id vote you just dont do that
<FromGitter> <Blacksmoke16> like to be clear `puts "foo"` is the same as `STDOUT.puts "foo"`, when you could just do like `io.puts "foo"` where io could be like `io : IO = STDOUT`
<FromGitter> <Blacksmoke16> i.e. allow using a diff io but default to stdout
<raz> but then athena might never have a pre-forking webserver 😏
<FromGitter> <Blacksmoke16> what data is being sent to stdout anyway?
<raz> logging from the forked workers
<FromGitter> <Blacksmoke16> cant use MT mode?
<raz> not production ready and slower than multi-process
<raz> also less robust even when it's ready
<FromGitter> <Blacksmoke16> diff logging backend that doesnt use STDOUT?
<raz> won't capture other prints to stdout that the user may have
<FromGitter> <Blacksmoke16> i should hope someone isnt using `puts` in prod..
<FromGitter> <Blacksmoke16> could you redefine top level `puts` method?
<FromGitter> <Blacksmoke16> ```def puts(object) ⏎ MY_STDOUT.puts object ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fea04f8dbb17f28c5a5806b]
<FromGitter> <Blacksmoke16> but meh :/
<raz> exactly, meh ;)
<raz> i'll prob go with a hack for now (Process.exec(ARGV[0]..., my_stdout...)
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Log/IOBackend.html you can specify what io the logs should be written to
<raz> but that's not pretty and probably not robust either
<raz> i don't want to capture Log, i want to capture STDOUT/STDERR
<straight-shoota> you can use freopen to point fd 1 to something different
<raz> ahhhh!
<raz> now we are talking
<raz> thx, will look into that - that will most likely do it
<raz> hmpf, so close. but no way to get the FileDescriptor from an IO::Stapled or IO::Pipe it seems 😔
<oprypin> raz, why arent u just using systemd
<raz> cause it doesn't solve the problem. also docker
<oprypin> well it does solve the problem. docker doesn't though xD
<raz> neither does :) but i think i found a way to get at my pipes 🐿️
<oprypin> it's just so wrong to do it but sure. i think indeed this is a way to get at a filedescriptor. https://crystal-lang.org/api/0.35.1/IO.html#pipe(read_blocking=false,write_blocking=false):Tuple(IO::FileDescriptor,IO::FileDescriptor)-class-method
<hightower2> So printing with e.g.: ( io << "\x1b[" << row+1 << ';' << col+1 << "H" ) is better than ( io.print "\x1b[#{row+1};#{col+1}H" ) ? Is there anything even better?
Dreamer3 has quit [Quit: Leaving...]
teardown has quit [Remote host closed the connection]
Dreamer3 has joined #crystal-lang
<oprypin> hightower2, no there isnt
<hightower2> ++, thanks
<oprypin> actually there were talks to rewrite the latter into the former, closest i found in a quick search is https://github.com/crystal-lang/crystal/issues/5916#issuecomment-612644776
<oprypin> it is not the case though
teardown has joined #crystal-lang
<hightower2> If I get the args to print via say, *args tuple, then is it ok to do args.each { |a| io << a }, or some even simpler/more efficient loop can be done?
<oprypin> i dont think so
riffraff169 has left #crystal-lang [#crystal-lang]
<hightower2> Hm why isn't IO.copy @from, @to doing the same that @to << @from is doing
<oprypin> hightower2, an io has a position
<straight-shoota> `args.join(io)`
<oprypin> hightower2, your io is presumably positioned at the end, so it copies from the end to the end
<hightower2> aha interesting, since the description says: "Copy all contents from src to dst."
<hightower2> straight-shoota, awesome tip!
<FromGitter> <watzon> Is there a way in doc comments to make a word link to a specific namespace? I know the parser will automatically search for inline code fragments and link them if it can, but sometimes it would be nice to be able to semi-manually link to the specific type you want without using the full namespace.
<hightower2> straight-shoota I can use this for print, that is, when to_s is involved. Is there something similar (i.e. something other than each()) for when I need IO#write ?
<oprypin> watzon, no but my alternative doc generator supports it 😜 https://github.com/oprypin/mkdocstrings-crystal#identifier-linking-syntax
<straight-shoota> hightower2, no I don't think so
<FromGitter> <watzon> @oprypin that's great! thanks
<straight-shoota> oprypin, well usability isn't that great, though. You'd need proper type lookup to reference relative namespaces.
<oprypin> watzon, well let me know if you're interested. the migration to it is not trivial, and a proper release is still ~ a week away
<oprypin> straight-shoota, i have type lookup
<straight-shoota> like the same as the compiler?
<oprypin> i havent mentioned it anywhere, have it 😬
<oprypin> straight-shoota, with only tiny differences
<straight-shoota> oh, great. Never mind then
<straight-shoota> I'd still rather have that kind of stuff done by the compiler when extracting dos
<straight-shoota> *docs
<oprypin> that requires an interactive process
<straight-shoota> why?
<oprypin> straight-shoota, otherwise u need to predict all possible combinations
<straight-shoota> combinations of what?
<oprypin> lookups
<straight-shoota> I mean the compiler could just interpret the link syntax and replace it with fully resolved paths in the doc comment
<oprypin> thats not really how it works
<oprypin> do you want to feed markdown to the compiler again?
<straight-shoota> doesn't need markdown, just a simple regex replace
<straight-shoota> if it works outside the compiler, maybe it isn't that bad.
<hightower2> So based on collected advices, this should be the most optimal way to do it, right? https://carc.in/#/r/a6h5
<straight-shoota> I just imagine the lookup algorithms could get out of sync
<straight-shoota> but, even that's probably not a big deal (and there's not going to be much change to how lookup works)
<oprypin> straight-shoota, oh yea btw, anything i can do to push though my pull requests?
<oprypin> through *
<hightower2> if I do io << args.join(';') , does it figure out that the output for join() is to an IO, or it constructs a string locally and then sends to io?
<straight-shoota> hightwoer2, the latter
<straight-shoota> you need to pass io explicitly
<straight-shoota> oprypin, unfortunately no
<straight-shoota> unless there's one missing waiting on my approval?
<straight-shoota> apart from that, we just someone else from the core team to do reviews
_ht has quit [Remote host closed the connection]
<hightower2> how can I debug which overload is crystal choosing?
<hightower2> or rather, I am sure it is choosing a wrong overload, but can't reproduce it on carc
<hightower2> I call args.join(@some_io), and this gets treated as separator rather than io
<hightower2> which gets remedied if I prefix the argument with io: ...
<FromGitter> <Blacksmoke16> it should totally be hitting https://crystal-lang.org/api/master/Enumerable.html#join(io:IO,separator=%22%22)-instance-method
<hightower2> right, in theory.
<hightower2> can't reproduce on carc though
<hightower2> which is very unfortunate, since it seems very interesting
<FromGitter> <Blacksmoke16> do you get any warnings?
<hightower2> nothing
<hightower2> let me copy the code to a repo
<hightower2> git clone https://github.com/crystallabs/temp ; cd temp ; shards ; crystal examples/one.cr
<straight-shoota> hightower2, that example works for me, as expected
<straight-shoota> terminal title is Test 123
<straight-shoota> are you maybe using an older Crystal version?
<hightower2> Crystal 0.35.1 [5999ae29b] (2020-06-19) LLVM: 8.0.0 Default target: x86_64-unknown-linux-gnu
<hightower2> let me check with nightly
<straight-shoota> 0.35.1 should be good
<straight-shoota> I'm using exactly the same version
<hightower2> and just to check, you're not using tmux? (code hits a different path if tmux is used)
<straight-shoota> oh, I am using tmux
<straight-shoota> without tmux it reproduces as you said
<straight-shoota> this is really weird
<straight-shoota> typeof(@_buf) is IO::Memory, so there is really no reason why this could choose the wrong overload
<hightower2> right, checked that
<hightower2> but, it is interesting that if instead of io:, I prefix the argument with separator:, it accepts it
<straight-shoota> what?
<straight-shoota> oh you mean, as it compiles
<hightower2> yes, and has the same non-working behavior
<straight-shoota> sure, separator can be any type. `#join` just calls `#to_s` on it
<straight-shoota> it seems you've already tried to reduce the code, but can you reduce it further?
<straight-shoota> ideally without depending on libunibilium
<hightower2> yes since that's not relevant for the case, let me do that
<hightower2> thanks
<hightower2> straight-shoota, maniacal deletion worked in the end. check the repo now, doesn't use any dependencies. I will try to minimize further and delete even more.
<hightower2> (but same note applies - don't use tmux since it might confuse the results (by default it's not passing escape sequences into the underlying terminal emulator))
<straight-shoota> Can't you just print the memory io to stdout or something?
<straight-shoota> nice, oprypin
<hightower2> straight-shoota, yes, basically that is done in the end (there is just an optional buffer in between but... probably unrelated to the issue.. will check that specifically)
<hightower2> right, with STDOUT instead of that @_buf it's also reproducible
<straight-shoota> oh damn, it's so stupid
<hightower2> yes but why that overload got chosen?
<straight-shoota> because Indexable inherits from Enumerable
<straight-shoota> so if any method defined on Indexable matches, the overloads in Enumerable aren't even looked up
<straight-shoota> I think this is the first time I put the implementations tool to good use ^^
<straight-shoota> `crystal tool implementations examples/one.cr -c src/tput/output.cr:177:12`
<hightower2> ah, that's the answer to my question how to check the overload used :)
<hightower2> does anything have to be done about this, or?
<straight-shoota> I'll send a bugfix
<hightower2> great, thank you kindly for the discussion/involvement
<straight-shoota> sure, thanks for pointing it out
<FromGitter> <Blacksmoke16> i bet id work it the other overload was `separator : String = ""`
<FromGitter> <Blacksmoke16> if the*
deavmi has quit [Ping timeout: 272 seconds]
<straight-shoota> oh, right yeah
deavmi has joined #crystal-lang
<hightower2> right, but as straight-shoota pointed out, it's not desired to limit it to String
<hightower2> or is it?
<FromGitter> <Blacksmoke16> either way, id expect it to find the most specific one first
<straight-shoota> maybe for the optimized version
<FromGitter> <Blacksmoke16> PHP added a `Stringable` interface :S
<straight-shoota> everything's stringable in Crystal
<FromGitter> <Blacksmoke16> which is like `String | types_that_implement_to_string`
<straight-shoota> the thing is, the optimized version works differently from the non-optimized one.
<FromGitter> <Blacksmoke16> yea but cant really tell one that does it in a more meaningful, but i suppose it'd be easy enough to have your own stringify method
<straight-shoota> optimized calls separator.to_s once, whereas non-optimized appends separator to the IO each time, essentially calling separator.to_s(io)
<straight-shoota> if separator returns different values on each to_s, the optimized version doesn't do that
<straight-shoota> so maybe it's even better to just restrict the optimized version to String
deavmi_ has joined #crystal-lang
deavmi has quit [Ping timeout: 264 seconds]
MasterdonX has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a6j3
<FromGitter> <Blacksmoke16> totally should use the more specific overload defined on the parent for that
<hightower2> ++
<straight-shoota> surprisingly, I can't find any prior discussion about this behaviour
riffraff169 has joined #crystal-lang