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

Test failure for 0.4.6 on s390x #11619

Closed
WhyNotHugo opened this issue May 30, 2024 · 12 comments · Fixed by #11621
Closed

Test failure for 0.4.6 on s390x #11619

WhyNotHugo opened this issue May 30, 2024 · 12 comments · Fixed by #11621
Assignees
Labels
bug Something isn't working

Comments

@WhyNotHugo
Copy link
Contributor

The test rules::pyflakes::tests::preview_rules::rule_unusedimport_path_new_f401_28_all_multiple_init_py_expects is failing on s390x:

---- rules::pyflakes::tests::preview_rules::rule_unusedimport_path_new_f401_28_all_multiple_init_py_expects stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F401_F401_28__all_multiple____init__.py.snap
Snapshot: preview__F401_F401_28__all_multiple/__init__.py
Source: crates/ruff_linter/src/rules/pyflakes/mod.rs:228
────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬───────────────────────────────────────────────────────────────────
    8     8 │ 5 5 | from . import unused, renamed as bees  # F401: add to __all__
    9     9 │ 6 6 | 
   10    10 │ 7 7 | 
   11    11 │ 8   |-__all__ = [];
   12       │-  8 |+__all__ = ["bees", "unused"];
         12 │+  8 |+__all__ = ["unused", "bees"];
   13    13 │ 
   14    14 │ __init__.py:5:34: F401 [*] `.renamed` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
   15    15 │   |
   16    16 │ 5 | from . import unused, renamed as bees  # F401: add to __all__
┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
   22    22 │ 5 5 | from . import unused, renamed as bees  # F401: add to __all__
   23    23 │ 6 6 | 
   24    24 │ 7 7 | 
   25    25 │ 8   |-__all__ = [];
   26       │-  8 |+__all__ = ["bees", "unused"];
         26 │+  8 |+__all__ = ["unused", "bees"];
────────────┴───────────────────────────────────────────────────────────────────

(full CI run log here: https://gitlab.alpinelinux.org/WhyNotHugo/aports/-/jobs/1403448)

I think that the order of the items here is non-deterministic somehow and varies depending on CPU architecture.

@MichaReiser
Copy link
Member

@plredmond do you want to take a look at this? It probably requires sorting the items or to use an IndexSet.

@plredmond
Copy link
Contributor

plredmond commented May 30, 2024

@MichaReiser The implementation creates multiple insertion edits that use the same insertion point. AFAIK, their order is deterministic. The implementation has no logic for resolving the order that ruff applies the insertions. I.e. It should be deterministic.

Otherwise I guess this ordering could change if there was a change to how multi-edit fixes get applied.

... varies depending on CPU architecture.

Yikes. I'll uh take a look.

@MichaReiser
Copy link
Member

@plredmond I don't think it's about the edit ordering that is non deterministic but it is the order of the items in __all__ that is non deterministic (because it uses a hash set?)

@plredmond
Copy link
Contributor

@MichaReiser I'm not sure what you mean by "the items in __all__" because the rule implementation never creates or stores items in a data structure that represents __all__ nor uses the AST's "export" code. You might be referring to the list of unused import-bindings, which yes, could be introduce a nondeterministic order. I'll try to apply your advice there and rule it out. Is there any way for me to test this within our (astral) ci/cd infra?

plredmond added a commit that referenced this issue May 30, 2024
@plredmond plredmond self-assigned this May 30, 2024
plredmond added a commit that referenced this issue May 30, 2024
* Potentially resolves #11619 (nondeterministic hashmap order across
different architectures) in F401 by replacing a hashmap with
nondeterministic traversal order with an ordered mapping.

I'm not sure how to test this with our CI/CD. I don't have an s390x
machine at home. Should I try it in Qemu?
@plredmond plredmond reopened this May 30, 2024
@plredmond
Copy link
Contributor

@WhyNotHugo Can you check whether this issue is resolved on dcabd04 or in the next release?

@WhyNotHugo
Copy link
Contributor Author

WhyNotHugo commented May 31, 2024

I applied dcabd04 onto v0.4.6 and that failed:

>>> ruff: dcabd04caf85d7c0081ebba9f9028b9af9d686d3.patch
patching file crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
patching file crates/ruff_python_semantic/src/binding.rs

[...]

---- rules::pyflakes::tests::preview_rules::rule_unusedimport_path_new_f401_28_all_multiple_init_py_expects stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F401_F401_28__all_multiple____init__.py.snap
Snapshot: preview__F401_F401_28__all_multiple/__init__.py
Source: crates/ruff_linter/src/rules/pyflakes/mod.rs:228
────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬───────────────────────────────────────────────────────────────────
    8     8 │ 5 5 | from . import unused, renamed as bees  # F401: add to __all__
    9     9 │ 6 6 | 
   10    10 │ 7 7 | 
   11    11 │ 8   |-__all__ = [];
   12       │-  8 |+__all__ = ["bees", "unused"];
         12 │+  8 |+__all__ = ["unused", "bees"];
   13    13 │ 
   14    14 │ __init__.py:5:34: F401 [*] `.renamed` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
   15    15 │   |
   16    16 │ 5 | from . import unused, renamed as bees  # F401: add to __all__
┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
   22    22 │ 5 5 | from . import unused, renamed as bees  # F401: add to __all__
   23    23 │ 6 6 | 
   24    24 │ 7 7 | 
   25    25 │ 8   |-__all__ = [];
   26       │-  8 |+__all__ = ["bees", "unused"];
         26 │+  8 |+__all__ = ["unused", "bees"];
────────────┴───────────────────────────────────────────────────────────────────

@charliermarsh
Copy link
Member

I think the issue is that for binding_id in scope.binding_ids() is not deterministic. So we should enforce determinism elsewhere (e.g., by sorting in fix_by_reexporting or similar).

@charliermarsh charliermarsh added the bug Something isn't working label May 31, 2024
@plredmond
Copy link
Contributor

plredmond commented May 31, 2024

Wouldn't the nondeterminism of scope.binding_ids() result order be resolved by insertion into the BTreeMap? The only place this data comes back out is when we iterate over the BTreeMaps.

[Edit: Nevermind, I see that the test that is failing is the case where we have multiple import-bindings from a single import-statement. The order they're pushed into the import binding depends on the order they come from scope.binding_ids().]

I'll try sorting in fix_by_reexporting, anyhow.

@plredmond
Copy link
Contributor

plredmond commented May 31, 2024

@WhyNotHugo could you try out 15977ed?

charliermarsh pushed a commit that referenced this issue May 31, 2024
Sort the binding IDs before passing them to the add-to-`__all__`
function to address #11619.
@MichaReiser
Copy link
Member

MichaReiser commented Jun 4, 2024

I'll mark this as closed. @WhyNotHugo feel free to reopen if you keep running into this issue with 0.4.8. Thanks @plredmond for looking into and fixing the issue.

@plredmond
Copy link
Contributor

plredmond commented Jun 4, 2024 via email

@WhyNotHugo
Copy link
Contributor Author

0.4.7 builds okay on s390x. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants