<bmcginty>
All, doing a test on the latest compiler, and getting `Module validation failed: Function return type does not match operand type of return inst!`.
<bmcginty>
I'd like to go digging through the compiler myself and see if I can fix the issue, but I can't even tell what function is throwing this out. Obviously I can't emit llvm-ir before it's created, and when I did an inspect on the module, it printed everything, but without function names...which is less than helpful for seeing where in my code the issue is being created.
<bmcginty>
I'm going to see if I can strip the parts that are at issue, but if not, anyone have suggestions on how to figure out what's going on?
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<j8r> But you have written tests, and in this case they will help you to find where the issues' is... don't you?
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<bmcginty>
j8r: Yes, but it only happened when things were nested a certainw ay, or if there was an extra if statement. Very odd.
<bmcginty>
j8r: turns out I had a macro appending to an array, but the macro wasn't defining return types for each key it went through ended up like `a << @name\na << @value\na << @something_else\n`. still not sure why it happened, and I still can't strip the breaking bits into a single example, but it's fixed for now. :(
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 256 seconds]
<FromGitter>
<faustinoaq> Interesting, the new atom text editor core is written in Rust https://github.com/atom/xray/
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<PlayLights_twitter> Like firefox
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<sherjilozair> Hey guys, loving reading the crystal-lang book right now. So many good design decisions have been made here that I feel like writing a love letter to the developers. I'm going to work on game development using crystal and crSFML. Had a doubt about one of the syntax. What exactly is the behaviour of `break "something"`? The obvious case of a single loop is easy, but what about multiple loops, etc.?
Nathanaelle has joined #crystal-lang
<FromGitter>
<Blacksmoke16> `break can also take a parameter which will then be the value that gets returned`
<FromGitter>
<Blacksmoke16> if you made it `break "foo"` it would return "foo" with typeof "String"
<FromGitter>
<sherjilozair> Got it. It only returns "foo" for that loop, and other loops don't get broken. The presence of the function made me think the function also gets returned.
<FromGitter>
<Blacksmoke16> yea afaik its akin to `return x` but for a loop vs a function
<FromGitter>
<Blacksmoke16> where by default `return` would be nil type but if you return a value then its that value ofc
bmcginty has quit [Ping timeout: 255 seconds]
<FromGitter>
<sherjilozair> Has anyone managed to static link a project in OSX? I can't seem to do that even for an empty project.
<FromGitter>
<sherjilozair> Get this error: `ld: library not found for -lcrt0.o`
<FromGitter>
<oprypin> no, nobody has
<FromGitter>
<sherjilozair> Ouch. Is there a plan to make it possible to static link on OSX? I want to make games with CrSFML (thanks @oprypin for that btw), but without static linking it'd be pretty pointless since I won't be able to distribute.
<FromGitter>
<faustinoaq> @sherjilozair Static linking on macOS is a bit different 😅
<FromGitter>
<faustinoaq> In linux you need `.a` files available in the right place
<FromGitter>
<faustinoaq> but in macOS I guess you need other settings 😅
<FromGitter>
<sherjilozair> Do you know what these other settings are? I'll be happy to write the wiki on this, if I get this working.
<FromGitter>
<bew> looks like it's not really supported officially on osx
<FromGitter>
<sherjilozair> I see. So I guess it's safe to assume that a dynamically linked program would run fine on most macoses?
<FromGitter>
<sherjilozair> And only static link for other OSes.
<FromGitter>
<faustinoaq> @sherjilozair Yep
<FromGitter>
<sherjilozair> Would dynamic linking require users to have crystal installed?
<FromGitter>
<faustinoaq> no
<FromGitter>
<sherjilozair> Oh okay. I wish this was documented somewhere better.
<FromGitter>
<faustinoaq> I would recommend you to check dynamic dependencies by using `ldd mybinary`
<FromGitter>
<faustinoaq> I guess crystal still needs some things like libevent, libpcre, and others libs that should come by default 😅
<FromGitter>
<sherjilozair> That's still asking for a lot. Most non-coder users won't have libevent, libpcre, etc.
<FromGitter>
<bew> "by default" => that depends on what you mean by "default" :P
<FromGitter>
<sherjilozair> Is it possible to include as many libraries as possible in the binary and dynamically load others like `crt0`?
<FromGitter>
<faustinoaq> Also be aware of those "external" libs you're using in your apps, like libyaml, libxml, database libs, openssl and other common used libs.
<FromGitter>
<sherjilozair> How do other languages/engines solve this problem? This problem shouldn't be new to crystal.
<FromGitter>
<faustinoaq> @sherjilozair First try to compile a simple program in crystal and try to execute it on other mac machine, and see what happens 😉
<FromGitter>
<faustinoaq> Languages like Go has his own libc and all the "essential" libs developed by Go Team, so they can include all them in one executable. ⏎ ⏎ Crystal resuse most libraries like libc, libevent, libpcre, etc.
<FromGitter>
<sherjilozair> So why not include them (even if they are not developed by Crystal team)?
<FromGitter>
<faustinoaq> @sherjilozair Because those libraries are dynamic by default 😅
<FromGitter>
<faustinoaq> You can try to compile "statically" by installing all `-dev` packages and ensure you have the right `.a` files
<FromGitter>
<faustinoaq> Commonly static compilation is a "bad practice" on Linux world
<FromGitter>
<faustinoaq> You should be able to compile dynamically and fix the dependencies by using `ldd myexecutable`
<FromGitter>
<sherjilozair> You should be able to compile dynamically and fix the dependencies by using `ldd myexecutable`. Users won't do this though.
<FromGitter>
<faustinoaq> Yeah, I know that
<FromGitter>
<faustinoaq> That's why I use copy all required libs aside my app-binary, let me explain:
<FromGitter>
<faustinoaq> @sherjilozair you can always copy those libs (`ldd myexecutable`) to a lib folder aside your app-binary and use `LD_LIBRARY_PATH=$(pwd)/lib ./app-executable`
<FromGitter>
<sherjilozair> Interesting.
<FromGitter>
<faustinoaq> Yeah, You can put that inside a shell script and execute it without any issue
<FromGitter>
<sherjilozair> That's dirty. I love it. Thanks!
<FromGitter>
<faustinoaq> Yeah, Finally you got a `lib` folder with your `app-executable` and a `app.sh` script to execute `LD_LIBRARY_PATH=`pwd`/lib ./app-executable`
<FromGitter>
<sherjilozair> @faustinoaq Nice. Except macos doesn't have ldd. Has otool isntead, so would need some modifcation.
<FromGitter>
<sherjilozair> This is a great PoC though. Do you recommend this approach? Or is this only a hack?
<FromGitter>
<sherjilozair> I'm thinking of creating a game framework (like love2d) which generates executables, so would require static linking. Would you recommend doing the above?
<FromGitter>
<Jens0512> Static linking is experimental is it not? :/
<FromGitter>
<Jens0512> (Currently)
<FromGitter>
<faustinoaq> @sherjilozair I think you should use dynamic linking, because static linking is possible but not to easy to achieve ( you need the right dependencies in the right location, sometimes compiling them by yourself)
<FromGitter>
<faustinoaq> > Do you recommend this approach? Or is this only a hack?
<FromGitter>
<faustinoaq> I guess is kinda hack, but works pretty well
<FromGitter>
<faustinoaq> You don't need to worry about libraries in the client, because you're already including all them in your `deps` folder, an using just that, so, no conflict with os libraries, just like a static compiled executable 😉
Nathanaelle has quit [Ping timeout: 256 seconds]
<FromGitter>
<sherjilozair> How do you make the binaries loop for the dynamic libraries in the deps/libs folder?
<FromGitter>
<sherjilozair> I did what you said, but the binary is still trying to search for the deps elsewhere. Says `Library not loaded: @rpath/libvoidcsfml-graphics.2.4.dylib`
<FromGitter>
<faustinoaq> Oh, you need to compile it using `LIBRARY_PATH=$(pwd)/deps crystal build snakes.cr` (first copy the current libs dependencies to your `deps`folder in your project workspace)
<FromGitter>
<faustinoaq> I just forgot that 😅
<FromGitter>
<sherjilozair> I see, thanks. btw, is it possible to load dynamic libraries without mentioning them in the binary?
<FromGitter>
<sherjilozair> i.e., have code load them from a known path, without telling the compiler about it.
<FromGitter>
<faustinoaq> Well, I guess yes, then you need to specify them during compilation with `--link-flags`
<FromGitter>
<faustinoaq> I mean, You can try first 😅 , sometimes you can be surprised of crystal capabilities
<FromGitter>
<sherjilozair> nah I get `ld: library not found for -lvoidcsfml-graphics` when I use your command.
<FromGitter>
<sherjilozair> i.e. `LIBRARY_PATH=$(pwd)/deps crystal build snakes.cr`
<FromGitter>
<sherjilozair> even though I have copied it over to deps.
<FromGitter>
<bew> you forgot `LD_` at the beginning of the env var
<FromGitter>
<bew> it should be `LD_LIBRARY_PATH=...`
<FromGitter>
<sherjilozair> snakes still has old path.
<FromGitter>
<bew> did you re-built with the correct env var?
<FromGitter>
<sherjilozair> SherjilOzair:examples sherjilozair$ LD_LIBRARY_PATH=$(pwd)/deps crystal build snakes.cr ⏎ SherjilOzair:examples sherjilozair$ otool -L snakes ⏎ snakes: ⏎ @rpath/libvoidcsfml-graphics.2.4.dylib (compatibility version 2.4.0, current version 2.4.0) ⏎ @rpath/libvoidcsfml-window.2.4.dylib (compatibility version 2.4.0, current version 2.4.0) ... [https://gitter.
<FromGitter>
<bew> and can you show the content of the `deps` folder?
<FromGitter>
<sherjilozair> SherjilOzair:examples sherjilozair$ ls deps ⏎ libvoidcsfml-audio.2.4.dyliblibvoidcsfml-graphics.2.4.dyliblibvoidcsfml-network.2.4.dyliblibvoidcsfml-system.2.4.dyliblibvoidcsfml-window.2.4.dylib ⏎ libvoidcsfml-audio.dyliblibvoidcsfml-graphics.dyliblibvoidcsfml-network.dyliblibvoidcsfml-system.dyliblibvoidcsfml-window.dylib
<FromGitter>
<sherjilozair> Just realized that I had global env variables set for LD_LIBRARY and LIBRARY. I removed them, and now the commands do this:
<FromGitter>
<sherjilozair> SherjilOzair:examples sherjilozair$ LD_LIBRARY_PATH=$(pwd)/deps crystal build snakes.cr ⏎ ld: library not found for -lvoidcsfml-graphics ⏎ clang: error: linker command failed with exit code 1 (use -v to see invocation) ⏎ Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/sherjilozair/CrystalProjects/crsfml/examples/snakes' -rdynamic -lvoidcsfml-graphics -lvoidcsfml-window
<FromGitter>
<sherjilozair> I just looked inside another macos game, and it seems the practice is to put the dylibs in the same path as the executable.
<FromGitter>
<faustinoaq> Oh, ok, you can try to use `-L$(pwd)` as well with `--link-flags`
<FromGitter>
<faustinoaq> like this:
<FromGitter>
<sherjilozair> However, when I ran otool -L on the executable, those dylibs were NOT mentioned. Which makes me think they were loading those DLLs from code.
<FromGitter>
<bararchy> and it will pull all needed dynamic libs into the deps folder
<FromGitter>
<sherjilozair> 👍
<FromGitter>
<bew> @bararchy actually the compiler knows which libs are necessary, we could have an option to at compile time to create an additional file with that list, to allow another tool to generate the deps folder
<FromGitter>
<bararchy> @bew great idea :)
<FromGitter>
<bararchy> it could also help all those people who wants to static compile, because you can just ship your app with all needed libs, while the systems tries first to use the system wide libs
<FromGitter>
<faustinoaq> Oh, nice 👍
<FromGitter>
<sherjilozair> This seems like an easy enough task that someone like new could contribute.
<FromGitter>
<bew> if anyone wants to fill an issue for that, please do it (I can't do it right now), but makes sure that only 1 person does that ^^
<FromGitter>
<bararchy> Should I do it? or @faustinoaq ?
<FromGitter>
<bararchy> so we wont both open the issue haha
<FromGitter>
<faustinoaq> @bararchy Yeah, go ahead! I think this can be very useful even on Linux, I just tried the command I shared above, and...:
<FromGitter>
<faustinoaq> ^^ It works, but I had to fix a bunch of things before get the executable running on a new fresh machine
<FromGitter>
<sherjilozair> How would you do the bundling in linux? Would you just put it all in the binary? Or is there something similar to macos App bundle in linux?
<FromGitter>
<bew> nice! It could also be used when buiding a Docker scratch Dockerfile with all the libs and all
<FromGitter>
<faustinoaq> I copied the full directory with all libraries inside a `deps`, then I used `LD_LIBRARY_PATH` to specify my path folder, and removing libpthread, libc, and ld-linux, because some incompatibilities issues. Finally I got my dynamic linked executable running 😄
<FromGitter>
<sherjilozair> And you had the path set to `deps/`?
<FromGitter>
<bew> 'm not sure about getting the paths in that file, as the compiler probably don't know them
<FromGitter>
<sherjilozair> @bararchy I think it would be nice to have an option to copy the libs as well, and to modify the executable to point to the copied libs instead of the old locations. That would be a truly complete solution.
<FromGitter>
<bew> @sherjilozair see my last msg
<FromGitter>
<bararchy> @bew hm, how come ldd can get them?
<FromGitter>
<sherjilozair> The compiler won't, but crystal could search for them and then copy them over?
<FromGitter>
<bew> well, it resolves everything I guess?
<FromGitter>
<bararchy> anyway, I would configure to try and take system libs, only then fallback to deps dir
<FromGitter>
<bararchy> like Steam is doing
<FromGitter>
<faustinoaq> Yeah 👍
<FromGitter>
<sherjilozair> Great. Btw, I really think Crystal should try to become a language for game development. It's fast and productive, so it's gonna be very useful for game development.
<FromGitter>
<sherjilozair> Lua is the other language popular, but it doesn't have classes, and so can't really do big projects with it.
<FromGitter>
<bararchy> @sherjilozair we got lots of game devs here, Groogy, oprypin, etc..
<FromGitter>
<faustinoaq> Even electron apps use something like that, electron includes all dynamic libraries dependencies for chromium inside your app folder
<FromGitter>
<sherjilozair> @bew I just mean game developers who used to use lua could start using crystal because it's so much better. Faster, as good syntax, static typing, classes, good for larger projects.
<FromGitter>
<sherjilozair> It'll also attract C++ and some C# game developers. C# doesn't work well outside MSFT environment (even though mono is cool), and C++ is productive for few people.
<FromGitter>
<bew> @bararchy I was checking C# lately, it doesn't look that bad
<FromGitter>
<sherjilozair> Glove and Cray seems very experimental. I think only CrSFML is usable right now.
<FromGitter>
<Qwerp-Derp> @sherjilozair C++ is still the gold standard for making games though
<FromGitter>
<sherjilozair> @Qwerp-Derp Yeah, because no other languages is fast enough. Maybe Crystal (in a few years) could supercede it.
<FromGitter>
<Qwerp-Derp> Like not many people make games with Java or C# because it doesn't offer the flexibility and such that C++ has, despite the fact that C++ is literally a frankenstein of a language
<FromGitter>
<sherjilozair> C# is pretty good too btw, for gamedev.
<FromGitter>
<Qwerp-Derp> @sherjilozair I guess, Unity's pretty good
<FromGitter>
<sherjilozair> Unity, MonoGame both use C#.
<FromGitter>
<bew> @bararchy mind changed x)
<FromGitter>
<faustinoaq> txdv I have been using C#/.Net on latest months and CoreCLR looks pretty nice 👍
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<Qwerp-Derp> I tried making a game in Crystal and it completely, utterly failed, maybe it'll work out again in a couple of years when it has IDE support
<FromGitter>
<bew> @bararchy but I think you can do `var obj = new Newclass()` too, which is better
<FromGitter>
<sherjilozair> I'm actually quite confident that if Crystal has a very good chance of becoming an indie gamedev favorite.
<FromGitter>
<sherjilozair> @Qwerp-Derp What did you use? And do you have prior gamedev experience?
<FromGitter>
<Qwerp-Derp> @sherjilozair I used CrSFML, and I didn't have any prior gamedev experience
<FromGitter>
<faustinoaq> Qwerp-Derp Did you tried VSCode? or even Scry? 😅
<FromGitter>
<sherjilozair> I think the "no prior experience" might have been the issue. SFML is not easy for beginners.
<FromGitter>
<Qwerp-Derp> @faustinoaq I used VSCode
<FromGitter>
<sherjilozair> I use your package in VSCode @faustinoaq , but how do I get Scry to work with it?
<FromGitter>
<faustinoaq> Oh, nice, then you should wait for next version of scry, this Language Server Protocol for crystal is getting better every day 😉
<FromGitter>
<faustinoaq> I already sent some fixes
<FromGitter>
<faustinoaq> Yeah, We're trying to use Scry on Intellij-idea, the fixes are already merged, waiting for the issue author to confirm this is fixed ( or someone else 😉 )
<FromGitter>
<bararchy> ```Logger.new```
<FromGitter>
<bararchy> much better :)
<FromGitter>
<sherjilozair> @faustinoaq Can I use Scry now?
<FromGitter>
<bew> but not as modular/configurable though
<FromGitter>
<bararchy> @sherjilozair I use Scry with vscode
<FromGitter>
<sherjilozair> @bararchy How to set it up?
<FromGitter>
<bararchy> @bew yeha, I hope the new logger issue will fix that
<FromGitter>
<faustinoaq> @bew I already sent a PR to change the verbosity level 😄
<FromGitter>
<bew> yeah I saw ty @faustinoaq (I did a hard change for my scry, but it would be better with your change :) )
<FromGitter>
<faustinoaq> 👍
<FromGitter>
<bararchy> @faustinoaq when is new version coming for Scry?
<FromGitter>
<bew> after his last fixes are merged I quess
<FromGitter>
<bararchy> when are you going to merge them? :)
<FromGitter>
<bew> 'll sleep now, good day/night!
<FromGitter>
<faustinoaq> > but not as modular/configurable though ⏎ ⏎ @bew We're thinking on separate the protocol from scry, @keplersj already created a `lsp` repository for that https://github.com/crystal-lang-tools/lsp
<FromGitter>
<bew> lking about @faustinoaq I was talking about the logger here ^^
<FromGitter>
<faustinoaq> Oh, ok, no problem 👍
<livcd>
Is there some regional promoting for Crystal ? bararchy: do you write articles in hebrew ? :D
<FromGitter>
<bararchy> livcd sadly no, I think I should promote Crystal in Israel, but it seems we already attrected some people with 3 israeli in the channel :)
<FromGitter>
<sherjilozair> Is scry able to pull up information from the requires?
<FromGitter>
<sherjilozair> It doesn't seem to for me.
<FromGitter>
<sherjilozair> For the autocomplete, that is.
<FromGitter>
<sherjilozair> It was able to show an error when I wrote the whole thing.
<FromGitter>
<faustinoaq> @bew I guess you're right 😅
<FromGitter>
<faustinoaq> @sherjilozair I already sent a bunch of fixes, just wait for the next version 😉
guilleiguaran has quit [Quit: Connection closed for inactivity]
<FromGitter>
<j8r> I'm starting to think that having a 2nd channel might be good - sometimes, specially when answering questions, we have hard time to keep up with the discussion
<FromGitter>
<sherjilozair> I just noticed that Crystal doesn't have any cuda binding. Or am I wrong?
<FromGitter>
<bararchy> @sherjilozair it does not, It's one of the things I really want to add but which are really really hard to do
<FromGitter>
<sherjilozair> @bararchy What makes it hard?
<FromGitter>
<bararchy> @sherjilozair cuda, cuda makes it hard XD ⏎ It's really annoying to bind
<FromGitter>
<bararchy> have you ever played around with it?
<FromGitter>
<sherjilozair> Yeah, I used python ctypes to create Python bindings once.
<FromGitter>
<sherjilozair> At the time it was very undocumented, and it was a pain.
<FromGitter>
<sherjilozair> I assume that it's probably better now.
<FromGitter>
<sherjilozair> It's also become a huge library now. So that doesn't help.
<FromGitter>
<bararchy> When you see people are still trying to get multi-threading to be painless in langs like C++, and you feel ashame you even expected Crystal to support it
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter>
<r00ster91> when defining a method: how do I say that a block can be specified but it doesnt needs to? I mean that this both works: ⏎ ⏎ ```def method(&block = Proc(Nil)) ⏎ ⏎ def method(&block = {})``` ⏎ ⏎ but it doesnt works [https://gitter.im/crystal-lang/crystal?at=5ade07fd27c509a77440f92b]
<FromGitter>
<bew> can you show an example of what you're trying to do in http://carc.in/ ?
GoldenBear has joined #crystal-lang
<FromGitter>
<everdev> hi guys, loving Crystal so far :) quick question: I'm unable to make an array using a variable class (ex. [] of myClassVar). Here's the code: https://play.crystal-lang.org/#/r/3xfc Any idea what I'm doing wrong?
<FromGitter>
<sherjilozair> Class names have to be capitalized.
<FromGitter>
<elorest> Usertesting is a pretty big company with around 170 rails devs.
<FromGitter>
<sherjilozair> How to represent `void **` in crystal? I'm binding a library which uses `void **`.
<oprypin>
sherjilozair, `Void**`
<FromGitter>
<sherjilozair> That's... neat. :D
<FromGitter>
<faustinoaq> @elorest Great! ✨
<FromGitter>
<bew> @sherjilozair in the lib binding you should make a `type RelevantName = Void**` and only use `RelevantName` in the binding
<FromGitter>
<sherjilozair> Oh okay. Why is that though?
<FromGitter>
<bew> in lib bindings, `type` is a strong alias, that ensures type safety
<FromGitter>
<bew> So that when a method returns `RelevantName` and another return `OtherName` (e.g: defined as `type OtherName = Void*`, they will be 2 different types, and you won't be able to pass a `OtherName` when a `RelevantName` is expected (even if you could do that with bare pointers)
<FromGitter>
<sherjilozair> I see.
<FromGitter>
<sherjilozair> I can't seem to be able to call functions in a module using `::Module.func` or `Module.func` or `Module::func`?
<FromGitter>
<j8r> don't forget `self`
<FromGitter>
<j8r> 1) when called externally
<FromGitter>
<bew> @sherjilozair can you show an example of what you're trying to do in http://carc.in/ ?
<FromGitter>
<sherjilozair> `self` did it. Didn't know I had to do `extend self`.
<FromGitter>
<sherjilozair> I come from Python where everything is always visible. :|
<FromGitter>
<sherjilozair> I got this message! `Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues`
<FromGitter>
<sherjilozair> Does it actually mean I've found a bug or is it because I'm using unsafe things.
<FromGitter>
<bew> you can add `cr` or `crystal` after code backticks to get syntax highliting
<FromGitter>
<bew> (in github)
<FromGitter>
<bew> you didn't provided `check_success`
<FromGitter>
<bew> nvm you provided a link to your repo ^^
DTZUZO has quit [Quit: WeeChat 2.0]
DTZUZO has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 264 seconds]
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
pbodev1 has quit [Quit: ChatZilla 0.9.93 [Firefox 56.0/20170903140023]]
return0e has quit [Read error: Connection reset by peer]
<FromGitter>
<sherjilozair> While I have provided a link to the repo, the code does depend on certain c libraries being placed in certain strategic locations, so I don't think you'd be able to run the code. But you could dry run it.
<FromGitter>
<bew> sure, but when those file in specific locations will be needed during the compilation, it would mean that the module validation passed, and that there is no error :)
mps has left #crystal-lang [#crystal-lang]
<FromGitter>
<sherjilozair> So is the error that the library cannot be found? Is that the issue?
<FromGitter>
<bew> no the issue is that there is a bug in the compiler I think... (I trying to push #5820 so that it's easier to debug problems like this one)
<FromGitter>
<sherjilozair> Kinda surprised crystal still has such bugs. Not ready for prime time it seems.
<FromGitter>
<sherjilozair> How are you sure this is a compiler bug? Because of the emitted message?
<FromGitter>
<bew> yes the module validation failed error is most probably a bug in the LLVM IR we generate
duane has quit [Ping timeout: 248 seconds]
<FromGitter>
<sherjilozair> Is there a way to guarantee that a certain function will be called when a certain object ends its lifecycle?
<FromGitter>
<sherjilozair> I'm basically asking for destructor methods.
<FromGitter>
<bew> yes, but you don't know if and when they will be called
<FromGitter>
<bew> the method to implement is called `finalize`
<FromGitter>
<sherjilozair> Yeah, I found it weird that it's not guaranteed to run.
<FromGitter>
<sherjilozair> What if I've allocated GPU memory, and the program ends.
<FromGitter>
<bew> it is called just before the GC reclaim a memory area
<FromGitter>
<sherjilozair> The allocated GPU memory is now orphan.
<RX14>
it's guaranteed to run
<RX14>
in infinite time
<RX14>
ok, it's guaranteed to run if the object is collected
<RX14>
it's not guaranteed to be collected
<FromGitter>
<sherjilozair> What if the program is killed?
<RX14>
nope
<FromGitter>
<sherjilozair> yeah.
<RX14>
how would that work?
<FromGitter>
<sherjilozair> haha
<RX14>
it can't work
<FromGitter>
<sherjilozair> oh so destructors in other langs also don't have that property.
<FromGitter>
<sherjilozair> got it.
<RX14>
the assumption in linux has always been that the OS cleans up resources when you close the process
<RX14>
you can always kill -9
<RX14>
and there is no way to trap or run anything when that happens
<FromGitter>
<sherjilozair> but their destructors are called as soon as the object goes out of scope, right? In C# or C++?
<RX14>
GPU memory surely is an OS resource
<RX14>
which is returned when a process is killed
<RX14>
@sherjilozair not in crystal
<RX14>
in C++ structs can have destructors
<RX14>
and they're called when they go out of scope
<FromGitter>
<sherjilozair> Why did crystal choose to be different in this regard?
<RX14>
but in crystal structs cannot have destructors
<RX14>
and there's no RAII
<RX14>
there's just GC finalizers
<RX14>
@sherjilozair idk, hard to implement I think
<RX14>
desides you can just do it with blocks
<FromGitter>
<sherjilozair> But RAII is awesome, so I don't understand.. oh.
<RX14>
look at File.open(&block)
<RX14>
that's the "crystal" way to do it
<RX14>
automatic RAII is limited to method scope anyway (i think)
<RX14>
so the crystal blocks solution is just as powerful yet more explicit
<FromGitter>
<sherjilozair> Are you referring to the `ensure` syntax?
<RX14>
partially
<RX14>
blocks + ensure syntax really
<RX14>
ensure is just like `try {} finally {}` in C++
<RX14>
but in crystal you can pass blocks to other methods so it's super simple to just yield a handle into a block and clean it up once the block returns