pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
mark_66 has joined #crystal-lang
bjz has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
gewo has quit [Quit: WeeChat 1.0.1]
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 244 seconds]
soveran has joined #crystal-lang
tomchapin has joined #crystal-lang
tomchapi_ has quit [Ping timeout: 244 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
ponga has joined #crystal-lang
_jaitaiwan has joined #crystal-lang
<_jaitaiwan>
Hey guys, I'm attempting to use Types in a way I think is still potentially not decided on how crystal types should work
<_jaitaiwan>
I have a class B and C which inherits from A and have a variable which is [] of A. Unfortunately I get compile time errors trying to populate the array with B & C classes even though they both inherrit from A. Can anyone suggest some alternatives?
<RX14>
_jaitaiwan, i don't think crystal supports that yet, unfortunately. I think you have to wait until the next release and that should be fixed.
<_jaitaiwan>
Next release as in 1.0 or 0.19?
<RX14>
0.19, hpefully
<RX14>
it's an annoying limitation
<RX14>
it'll be gone before 1.0 at least
<_jaitaiwan>
Fair enough... bit of a shame considering it [seems to me to be] a fairly straight forward concept in the programming world
<_jaitaiwan>
If I understood the AST stuff I'd dig right in and make it happen myself
<_jaitaiwan>
Any idea where one might get started implementing this? Happy to help where I can
<RX14>
well i think the problem is actually how to represent it on the LLVM side
matp_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<FromGitter>
<splattael> BlaXpirit, I'm still struggling with "return types" during compile time :-(
<FromGitter>
<splattael> How can I find all `union_types`?
<FromGitter>
<splattael> `typeof({{yield}}).union_types` won't work
<FromGitter>
<splattael> The thing I want to build is to generate code depending on the block's return type passed to macro
<BlaXpirit>
splattael, the only idea i have right now is... more macros!
<BlaXpirit>
pass the result of typeof to a macro, and then the macro gets a TypeNode (possibly after calling .resolve) after which u can probably get union_types
<RX14>
macro expantion happens before type inference iirc
<RX14>
the Var macro type doesn't have a type on
<RX14>
so it's impossible
<FromGitter>
<splattael> But macro can see arguments' types
<RX14>
not if they aren't literalsd
<RX14>
if you pass a variable into a macro it can't know the type
<FromGitter>
<splattael> oh I see
<BlaXpirit>
makes sense, i agree that it's impossible
<BlaXpirit>
RX14, right now i'm thinking, why does power_assert have its own hierarchy of nodes, when what the compiler gives is already perfectly usable?
<BlaXpirit>
and with good rendering (node->code)
<BlaXpirit>
another fun thing with power_assert: def f; p rand(); end; assert f == 0 - executes f 3 times
<BlaXpirit>
i think it's possible to avoid multiple calls
<BlaXpirit>
rewrite the ast to wrap every expression into a function that saves the value for later, and only then execute everything
<BlaXpirit>
to me it seems like an obligatory feature. not sure what's worse - the fact that it calls everything multiple times or the fact that the assert output can be different than what was actually compared
<BlaXpirit>
easy example to see - def f; p rand(2); end; assert f == 0 - it can fail but show 0 == 0 in the breakdown
mark_66 has quit [Quit: Leaving.]
Renich has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
<BlaXpirit>
is it possible to create nodes in macros?
soveran has quit [Remote host closed the connection]
<RX14>
BlaXpirit, the reason why it needs two representations is because doing any serious computation in macro language is hell
<BlaXpirit>
indeed
<RX14>
so the best way to do it is to create nodes from the macro AST
<RX14>
and yes the calling multiple times is a bug
mhib has joined #crystal-lang
<BlaXpirit>
well it's impossible to resolve without a complete rewrite, i dont think
<RX14>
impossible to make fast
<RX14>
not impossible to solve multiple callings
<RX14>
thats easy enough
<BlaXpirit>
i'd like to know how
<RX14>
uhh
<RX14>
only paste once then use macro vars
pduncan has joined #crystal-lang
Renich has quit [Ping timeout: 244 seconds]
Renich has joined #crystal-lang
xmgx has quit [Remote host closed the connection]
kulelu88 has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 258 seconds]
pawnbox has quit [Remote host closed the connection]
matp has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
Renich has quit [Quit: leaving]
mhib has quit [Quit: Leaving]
mkl0501 has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
matp has joined #crystal-lang
soveran has quit [Remote host closed the connection]
bmcginty has joined #crystal-lang
<BlaXpirit>
is it possible to create nodes in macros?
<BlaXpirit>
RX14, oh yeah, next thing... since userspace power_assert is not fast enough, how about one in the compiler?
soveran has joined #crystal-lang
<RX14>
BlaXpirit, that would be much nicer
soveran has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<BlaXpirit>
because it's a transformation of the AST, maybe a good start would be a separate process that does the transformation, followed by an inquiry to include it in the compiler
<BlaXpirit>
process can receive a string and parse crystal code and it will be just the same, right?
pawnbox has quit [Ping timeout: 250 seconds]
soveran has joined #crystal-lang
<BlaXpirit>
hah this is ridiculously slow though
<RX14>
BlaXpirit, yes
<RX14>
which is why the best solution is to do it in the compiler
<BlaXpirit>
RX14, i know but i'm saying it's easy to develop a proof of concept this way, and it can be transfered into the compiler unchanged
<BlaXpirit>
do you think this is correct?
<RX14>
oh yes i misunderstood
sagax has joined #crystal-lang
soveran has quit [Remote host closed the connection]
perks has joined #crystal-lang
sagax has quit [Remote host closed the connection]
<BlaXpirit>
so i suggest generating as short code as possible, even if it's inefficient
<RX14>
it's cheaper to work it out in the compiler because computation of this kind is cheap
<RX14>
it's the inefficiency of marshalling it between different types thats expensive
<RX14>
i.e. macro code
<BlaXpirit>
oh well, it'll be interesting to benchmark
<RX14>
BlaXpirit, well
<RX14>
that optimization
<RX14>
which is send everything to a variable
<RX14>
thats optimal to me
<RX14>
i cant think of any shorter code
<BlaXpirit>
interesting points of view, but yours seems more plausible to me now
<RX14>
compared to everything else a compiler does, adding this is super cheap
<BlaXpirit>
but the number of asserts will be huge!
<RX14>
if you ahve that meany asserts you have that meany _more_ typings
<BlaXpirit>
there is another way to look at this, what if a runtime function is introduced, and the only generated code is the function call with a minimal set of data
<BlaXpirit>
what do you think
<RX14>
i thought of that
<RX14>
but the cost is in marshalling the data
<RX14>
by the time you've collected the data and serialized it for the rtuntime
<RX14>
you might as well construct the string
<BlaXpirit>
again you appear correct
Philpax has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
<BlaXpirit>
who needs video games, this is the real fun
<BlaXpirit>
i just dont like the part of implementing an actual assert statement