Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Refactor effects.data into properties #1943

Closed

Conversation

pmrcunha
Copy link
Contributor

Release Note: none

Hi! I started trying to learn this codebase today and found this TODO from @cblappert in realm.js:
https://github.com/facebook/prepack/blob/aa700a2667f5c28754ae2dad2a64a3ad4191276a/src/realm.js#L88

Sounded like a good task to get into, so I went through the codebase and did the necessary replacements. If this wasn't the intent, please disregard this PR.

Copy link
Contributor

@hermanventer hermanventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for doing this. Please attend to the flow errors.

I would appreciate it if there are no formatting changes that are not absolutely required by our prettier rules.

This is probably also a great opportunity to get rid of the somewhat gratuitous abbreviations for the property names of Effects.

this.canBeApplied = true;
this._id = effects_uid++;
}

// TODO: Make these into properties
data: [EvaluationResult, Generator, Bindings, PropertyBindings, CreatedObjects];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would like to declare the properties here.

@@ -79,8 +79,8 @@ export default function(
let result = realm.evaluateForFixpointEffects(iteration);
if (result !== undefined) {
let [outsideEffects, insideEffects, cond] = result;
let [rval] = outsideEffects.data;
let [, bodyGenerator] = insideEffects.data;
let { result: rval } = outsideEffects;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all for consistency, but I do have to wonder if it would be more readable to just use the property directly, i.e.
let rval = outsideEffects.result;

@@ -216,7 +216,7 @@ function ForBodyEvaluation(
invariant(result instanceof JoinedAbruptCompletions);
invariant(result.consequent instanceof ContinueCompletion || result.alternate instanceof ContinueCompletion);
joinedEffects = extractAndSavePossiblyNormalCompletion(ContinueCompletion, result);
result = joinedEffects.data[0];
result = joinedEffects.result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example where we are already inconsistent and it doesn't seem quite so bad.

@@ -68,8 +68,14 @@ function joinArrayOfsMapEntries(
let n = Math.max((a1 && a1.length) || 0, (a2 && a2.length) || 0);
let result = [];
for (let i = 0; i < n; i++) {
let { $Key: key1, $Value: val1 } = (a1 && a1[i]) || { $Key: empty, $Value: empty };
let { $Key: key2, $Value: val2 } = (a2 && a2[i]) || { $Key: empty, $Value: empty };
let { $Key: key1, $Value: val1 } = (a1 && a1[i]) || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the formatting change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had prettier-eslint turned off. I'll fix it.

@@ -66,17 +66,29 @@ function callBothFunctionsAndJoinTheirEffects(
invariant(Value.isTypeCompatibleWith(func1.getType(), FunctionValue));
invariant(Value.isTypeCompatibleWith(func2.getType(), FunctionValue));

let [compl1, gen1, bindings1, properties1, createdObj1] = realm.evaluateForEffects(
let {
result: compl1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will probably be quite nice to just stick with the property names of Effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you say is more readable, to keep destructuring:

let {
    result: result1,
    generator: generator1,
    modifiedBindings: modifiedBindings1,
    modifiedProperties: modifiedProperties1,
    createdObjects: createdObjects1,
  } = realm.evaluateForEffects(...

or to name the objects and call their properties directly ?

const e1 = realm.evaluateForEffects(...)
...
new Effects(e1.result, e1.generator, e1.modifiedBindings, e1.modifiedProperties, e1.createdObjects),
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for the second option whenever possible, as it is a bit more terse.

@pmrcunha pmrcunha force-pushed the refactor-effects-properties branch from 48f2d10 to c3ced14 Compare May 11, 2018 21:40
@pmrcunha pmrcunha force-pushed the refactor-effects-properties branch from c3ced14 to 52c7bd2 Compare May 11, 2018 21:59
Copy link
Contributor

@hermanventer hermanventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think things can be made even more consistent, but this is already strictly better than before, so let's get this into master.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hermanventer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@pmrcunha pmrcunha deleted the refactor-effects-properties branch May 15, 2018 06:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants