Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boxed tuple identity when type identifiers differ #2009

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

Praetonus
Copy link
Member

Previously, boxed tuples with different type identifiers wouldn't be considered as having the same identity even when containing the same objects, for example when comparing (U32(0), U32(0)) through (U32, U32) and (Any, Any) tuples.

The new identity algorithm for boxed values follows. "unchanged" means that this step of the algorithm didn't need any changes.

  • Check if the addresses are the same (unchanged)
    • If they are, the identities are the same (unchanged)
    • Otherwise, check the kind of the LHS object
      • If it's an unboxed type, the identities are different (unchanged)
      • If it's a boxed number, check the type of the RHS object
        • If the types are the same, check the values via memcmp (unchanged)
        • Otherwise, the identities are different
      • If it's a boxed tuple, check the kind of the RHS object
        • If it's a boxed tuple of any type, check the values via the LHS's __is function
        • Otherwise, the identities are different

The algorithm of the __is function was also changed. Since it now needs to compare against any possible type, multiple cases are generated in the function, which each case unboxing to a particular type and doing the comparison. The case to execute is chosen based on the type ID of the RHS object.

Fixes #1950.

Previously, boxed tuples with different type identifiers wouldn't be
considered as having the same identity even when containing the same
objects, for example when comparing `(U32(0), U32(0))` through
`(U32, U32)` and `(Any, Any)` tuples.

The new identity algorithm for boxed values follows. "unchanged" means
that this step of the algorithm didn't need any changes.

- Check if the addresses are the same (unchanged)
  - If they are, the identities are the same (unchanged)
  - Otherwise, check the kind of the LHS object
    - If it's an unboxed type, the identities are different (unchanged)
    - If it's a boxed number, check the type of the RHS object
      - If the types are the same, check the values via `memcmp`
        (unchanged)
      - Otherwise, the identities are different
    - If it's a boxed tuple, check the kind of the RHS object
      - If it's a boxed tuple of any type, check the values via the
        LHS's `__is` function
      - Otherwise, the identities are different

The algorithm of the `__is` function was also changed. Since it now
needs to compare against any possible type, multiple cases are
generated in the function, which each case unboxing to a particular
type and doing the comparison. The case to execute is chosen based on
the type ID of the RHS object.

Fixes ponylang#1950.
@jemc jemc added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Jul 3, 2017
@sylvanc sylvanc merged commit cf970d2 into ponylang:master Jul 12, 2017
ponylang-main added a commit that referenced this pull request Jul 12, 2017
@Praetonus Praetonus deleted the fix-tuple-identity branch July 21, 2017 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comparison of boxed tuples returns false if type identifiers are different.
4 participants