prepack
prepack copied to clipboard
Does Simple Assume Partial?
var c = __abstract('boolean', 'c');
var y = __abstract('object', 'y');
__makeSimple(y);
var obj = Object.assign({}, y);
has = 'anything' in obj;
desc = Object.getOwnPropertyDescriptor(obj, 'anything');
This doesn't define a partial object, or even a template at all, but it does define it as simple. The call to Object.assign
makes it partial. At that point, we assume that any queried property will be there and that there's no way to access the prototype chain.
Is this expected?
In regards to your question, yes, making things simple assumes they are partial too in this given case:
https://github.com/facebook/prepack/blob/master/src/values/AbstractObjectValue.js#L164
In my opinion though, I think we should remove the whole makeSimple
system from Prepack. It made sense to have it when we didn't have the pure scope system, but with the pure scope system, I think the simple system gets in the way and is somewhat confusing. It's actually somewhat bad naming too, as it's most definitely not "simple" to understand. "Simple" should never be used in any computer-science terminology in my opinion, but that's a different topic.
I also looked into the output of your above case. I wasn't sure if you were trying to outline a bug too. The output of this with current master is:
(function () {
var _$4 = this;
var _$5 = _$4.Object;
var _$6 = _$5.assign;
var _5 = {};
var _$0 = _$6(_5, y);
_$4.has = true;
var _$2 = _5.anything;
_$4.desc = {
value: _$2,
writable: true,
enumerable: true,
configurable: true
};
}).call(this);
It's interesting that has
is true
here and there is even a descriptor.
Another interesting Object.assign pattern that doesn't optimize well with simple/partial is:
function fn(x) {
var obj1 = Object.assign({}, x);
delete obj1.foo;
var obj2 = Object.assign({}, obj1, { a: 0 });
return [obj2.foo, obj2.a];
}
__optimize(fn);
Simple is a property that can be checked on concrete objects and something that is declared for partial and abstract objects. It applies to any kind of object.