« first day (4904 days earlier)      last day (49 days later) » 

9:27 AM
@bwoebi Because that's what happened with array's internal pointers. It would have been weird to introduce an inconsistency back then.
 
9:38 AM
@Derick Oh… so, initially next() and foreach iterated the same internal pointer. Makes sense.
 
I believe so, yes.
 
 
6 hours later…
3:54 PM
Has anyone here tried adding a new type to the zval struct anytime somewhat recently? I mean like roughly PHP 7 and newer. It seems daunting to me just because there's so little documented about this kind of stuff!
 
4:05 PM
@LeviMorrison What type are you planning on adding? I don't think this would be a good idea nowadays.
The impact on internals and extensions sounds too overwhelming. It might be acceptable for a very important feature, but not much else IMO.
 
@IluTov I'm partly just curious. I have a few different ideas. One of them is value-types. Types like vec and dict which are pass-by-value, copy-on-write like array.
 
@LeviMorrison I've had some thought experiments on classes as value types. Unfortunately, it does not seem easy (but that's not related to them being classes).
 
Definitely not easy!
 
I've been thinking about them because Derick and Larry were planning on adding a Collection class. However, I would hate if they were reference types.
 
4:19 PM
@LeviMorrison gist.github.com/iluuu1994/cc62341ebab8018e8d69f30dd17a6dda The main issue I've encountered (without actually implementing anything) is that it's unclear when an object must be separated due to a method call.
 
It's really too bad we don't have it rust-style ^_^
 
In the example $rect->pos->double();, both $rect and $rect->pos are value types. That means, if $rect has a RC of >1, it must be cloned so that we don't influence other references. However, we don't know that double will influence the object before we have fetched pos. So thi sis kind of a catch-22.
 
function double(&$this) { /* ... */ }
 
This means that, we'd essentially need to backtrack, separating the chain once we know that the method is indeed mutating. However, we cannot backtrack to instructions that have already destroyed their operands. I'm currently not sure if there's a good way to solve this.
 
4:41 PM
I suppose we could pessimistically separate those chains on method calls. Not great, but deeply nested value types should be rare, and method calls on the nested values even rarer.
 
4:57 PM
If it could be made to work, just a data modifier on classes a la Kotlin that makes it behave more array-ish would be all we need. Everything else is up to user space or particular core classes (like the collection classes we have discussed). Maybe we could include a default __toString or such as well as Kotlin and Python do.
 
 
1 hour later…
6:21 PM
@Crell What would a default __toString be used for?
data class Foo should be ok, and probably makes more sense than struct.
 
@IluTov Probably something like [list of arg values]. I mention it because Kotlin and Python both have implicit string casting, debug dump, and various other implementations for their data classes.
I don't know what set would make sense for PHP, but it would be worth exploring that to see what would make sense, and what other languages have found useful.
Eg, Python also auto-implements comparison and equality operators in a reasonable default way. Had operator overloading passed, it would make sense to do the same.
 
I think auto-__toString only makes sense if the language is lacking other means to inspect the value at runtime. For PHP, var_dump seems sufficient.
But that's just my initial gut feeling. Inspecting this further would make sense ofc.
 
Yeah, I don't know what things would make sense. Just that it would be wise for us to do that research, since so many other languages have found it useful to do.
(Eg, might a default __set_state make sense?)
 
6:55 PM
@IluTov it should not be too bad to add/remove new types. Have a look at how many direct usages of IS_RESOURCE there are.
@IluTov Maybe it would be reasonable to have a special token to call methods. I.e. instead of ->. Whenever that token is encountered, separation (copy if RC>1) is performed. It would make it clear to the reader and the engine. Basically on-demand clone.
I find it anyway so annoying when languages having the same by-ref and by-val access syntax.
Then you can have mutating methods marked accordingly (e.g. every withSomething() method on the planet you have to add a modifier - let's say autoclone, whatever) - and you call these with the particular syntax
And the getters are accessed normally, i.e. in a by-ref way.
Or probably … you mark the classes as data and the non-mutating methods as noclone or such.
This would still allow internal mutation for example to build an index on a non-mutating getter call and store it internally on the class.
At least I think for properly unleashing the power of by-value, it should not be as dumb as plain arrays, where every single modification always, necessarily, triggers a separation.
So, ultimately boiling down to what @LeviMorrison proposes, function double(&$this) … whatever way round it's expressed, it should be expressed on the function signature.
 
7:26 PM
@bwoebi Maybe I'm misunderstanding your message. The problem I'm referring to isn't the method calls themselves, which can indeed be marked as mutating in it's definition rather than the call-site. The problem lies in the chain before the method call. E.g. for $canvas->shapes[0]->position->zero(). If zero() is mutating, every object from $canvas onward must be separated. Access here isn't by-ref anywhere.
 
@IluTov yes, but that's not different to multi dimensional array access - assuming you know there's going to be a separation (if marked via syntax on call site), you can just write fetch the whole call chain?
 
@bwoebi Yes, but how do you know there will be separation? Sure, !-> (replace with any other symbol) would indicate it. But this sounds extremely error prone.
I suppose we could error if the wrong symbol is used on a mutating function. But... meh...
 
@IluTov I'm saying call and definition sites should have it.
@IluTov that's what I'm proposing, yes. why would that be meh?
 
I guess that also has advantages: It becomes immediately obvious that the value is modified.
 
Yes, that's the big advantage
 
7:32 PM
@bwoebi Just my immediate gut feeling, which is regularly wrong. :D
 
@IluTov I think it really depends on how … accessible the syntax is.
A !-> feels like an extra ! somehow.
|> looks more like a separating operator
 
~> is free, since we didn't use it for arrow functions :P
 
@IluTov (looks very similar tbh)
 
As in too similar?
 
yes
I'd rather use |>
 
7:35 PM
That one is commonly used as the pipe operator, though.
 
Right, |> would be much too confusing. Also, Larry would not be happy. ^^
 
We're sort of piping the object to a method, copy on writing it
I don't know about the pipe operator except that I've never used it in any language which has it.
 
Basically foo(bar($baz, "bar"), "foo") could be rewritten as $baz |> bar("baz") |> foo("foo") to avoid the deep nesting. So it would indeed be somewhat similar to ->, except we're not dealing with methods and “implicitly passing $this”, but rather the first argument of the function (or last depending on language design).
Which, seeing yesterday's discussion about the Iterator API, would make this proposal (which I very much like) pretty convenient: externals.io/message/118896#118896
Given that we can't extend classes with additional methods after the fact, free-standing functions would be more ergonomic.
 
 
4 hours later…
11:15 PM
Assume I have an object with exactly 1 property. I have the stub generated. What's the proper way to allocate and initialize it? Like what are the functions I should use? Weirdly, I have almost exclusively worked with custom structs lol
 
@LeviMorrison zend_objects_new()?
 
That's it, thanks.
 
11:53 PM
zend_object *object = zend_objects_new(ce);
object_properties_init(object, ce);
zval *prop = OBJ_PROP(object, 0);
// todo: is this the right copy macro/function for a typed property?
// I don't think so.
ZVAL_COPY(prop, val);
return object;
 
@LeviMorrison If you control the ce (i.e. you know val is of the right type), then that's totally fine
 
It's mixed, so only technically a typed property. It's what the gen_stub generated.
I saw this when var_dumping it and made me think maybe you need to do more: uninitialized(mixed)
 
it just means that nothing was assigned
 
But I did "assign" with the ZVAL_COPY? Or maybe I screwed up the zval for the thing I passed in too.
 
the latter probably
 

« first day (4904 days earlier)      last day (49 days later) »