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

Fixed bugs involving unsafe atemporals and improved abstract concrete unions #2513

Closed

Conversation

sb98052
Copy link

@sb98052 sb98052 commented Aug 30, 2018

Release notes: Fixed bugs that could cause generated code to throw

A refactor of my previous attempt to address #2327, which I had to abandon because it was incompatible with the current implementation of certain modeling primitives. Like the previous version, this PR is an intermediate fix that will be refined in a follow up PR. It consists of three changes:

  1. It adds a new helper that discharges values from a union after deriving the abstract value in it if needed.

  2. It makes conditionally temporal values safe using a helper called convertToTemporalIfArgsAreTemporal.

  3. It makes the the abstract and concrete members explicit in the interface to Abstract Concrete Unions. Presently, two code sites make the assumption that the abstract member is the first element of args, while all others traverse the list to locate it.

Follow ups to come:

  1. Update convertToTemporalIfArgsAreTemporal to produce a conditional value left to be simplified by the serializer.
  2. Enforce the protocol temporal args should imply temporal results more generally (Enforce and document temporal args protocol #2489).

Fixes #2327 and #2406

@sb98052 sb98052 changed the title Fixed bugs involving unsafe atemporals and improved abstract concrete Fixed bugs involving unsafe atemporals and improved abstract concrete unions Aug 30, 2018
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.

This is getting close, but please make the type annotations less surprising. I would also like to understand why Optional3.js is now broken.

static createAbstractConcreteUnion(
realm: Realm,
abstractValue: AbstractValue,
concreteValues: Array<Value>
Copy link
Contributor

Choose a reason for hiding this comment

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

use Array<ConcreteValue>

@@ -67,7 +59,7 @@ export function createAbstract(
typeNameOrTemplate?: Value | string,
name?: string,
options?: ObjectValue,
...additionalValues: Array<ConcreteValue>
...additionalValues: Array<Value>
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather keep the type as Array<ConcreteValue> and fix up the call sites.

let args = savedUnion.args.slice(0);
args[savedIndex] = value;
value = AbstractValue.createAbstractConcreteUnion(realm, ...args);
let concreteValues = savedUnion.args.slice(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using a slice, use a filter.

}
}

static dischargeValuesFromUnion(realm: Realm, union: AbstractValue): [AbstractValue, Array<Value>] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Return Array<ConcreteValue>

invariant(union.args[0] instanceof AbstractValue);
invariant(union.args[1] instanceof ConcreteValue);

let [abstractValue, ...concreteValues] = union.args;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather use a filter to get the concrete values.

@@ -1,4 +1,3 @@
// Copies of f;:1
Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain why this is not longer desirable.

Copy link
Author

Choose a reason for hiding this comment

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

My changes broke the test by causing the value of f to be derived in the consequent branch of f && f(), which counts as a second occurrence of f; Since the derivation is legit, I considered updating the comparator to two. But upon digging further I found that I could not reproduce the original problem that you fixed with #1158, even after reverting your change, making me doubt if it was still relevant, so I dropped it. But in hindsight, now, perhaps it is not a bad thing to keep it around as a regression test, so I have added it back.

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.

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

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.

Bug with simplifying abstract binary expressions
3 participants