Skip to content

mypyc 1.16 regression: x86_64-cpython-3{9,10,11,12,13} error: ‘FOO_finalize’ undeclared here (not in a function); did you mean ‘FOO_init’? #19175

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

Open
mr-c opened this issue May 30, 2025 · 7 comments · May be fixed by #19188
Labels

Comments

@mr-c
Copy link
Contributor

mr-c commented May 30, 2025

Crash Report
compiling Python modules using mypyc failed with a gcc error, where it did not using mypy 1.15

Python 3.9: https://github.com/common-workflow-language/schema_salad/actions/runs/15347015751/job/43185437280?pr=927#step:6:450

Python 3.10: https://github.com/common-workflow-language/schema_salad/actions/runs/15347015751/job/43185437282?pr=927#step:6:439

Python 3.11: https://github.com/common-workflow-language/schema_salad/actions/runs/15347015751/job/43185437303?pr=927#step:6:433

Python 3.12: https://github.com/common-workflow-language/schema_salad/actions/runs/15347015751/job/43185437295?pr=927#step:6:425

Python 3.13: https://github.com/common-workflow-language/schema_salad/actions/runs/15347015751/job/43185437315?pr=927#step:6:425

Traceback

    building '5df31530eea7292b5dae__mypyc' extension
    creating build/temp.linux-x86_64-cpython-39/build
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tmp/pip-build-env-qntpj1xx/overlay/lib/python3.9/site-packages/mypyc/lib-rt -Ibuild -I/opt/_internal/cpython-3.9.22/include/python3.9 -c build/__native_5df31530eea7292b5dae.c -o build/temp.linux-x86_64-cpython-39/build/__native_5df31530eea7292b5dae.o -O3 -g0 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
    build/__native_5df31530eea7292b5dae.c:110530:32: error: ‘ref_resolver___NormDict_finalize’ undeclared here (not in a function); did you mean ‘ref_resolver___NormDict_init’?
    110530 |     .tp_finalize = (destructor)ref_resolver___NormDict_finalize,
           |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           |                                ref_resolver___NormDict_init
    cc1: note: unrecognized command-line option ‘-Wno-ignored-optimization-argument’ may have been intended to silence earlier diagnostics
    cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
    cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
    error: command '/opt/rh/gcc-toolset-14/root/usr/bin/gcc' failed with exit code 1
    error: subprocess-exited-with-error
    
    × Building wheel for schema-salad (pyproject.toml) did not run successfully.
    │ exit code: 1
    ╰─> See above for output.

To Reproduce

  1. Checkout https://github.com/common-workflow-language/schema_salad/tree/dependabot/pip/mypy-mypyc--1.16.0
  2. tox -e py39-mypy (or py310-mypy, up to py313-mypy); or make a virtualenv and activate it, and make dev mypyc

Your Environment

@JukkaL
Copy link
Collaborator

JukkaL commented May 30, 2025

Thanks for reporting the issue! The next step would be to find the root cause by bisecting mypy and mypyc commits.

@JukkaL
Copy link
Collaborator

JukkaL commented May 30, 2025

This PR looks related:

Now we need a self-contained reproducer, which we can use to check if the above PR is the root cause, or to bisect across all commits otherwise.

@mr-c
Copy link
Contributor Author

mr-c commented May 30, 2025

Thank you @JukkaL ; I have to finish other work right now, so I can't dig in further today. Here's the is Python source code for the class related to the error: https://github.com/common-workflow-language/schema_salad/blob/0f8e2e888b38bff4e07a91807da430ca2a635376/schema_salad/ref_resolver.py#L96-L119

@mr-c
Copy link
Contributor Author

mr-c commented May 30, 2025

I nerdsniped myself, here is a minimal reproducer

ref_resolver.py

from typing import Any, Callable, Union

from ruamel.yaml.comments import CommentedMap, CommentedSeq

class NormDict(dict[str, Union[CommentedMap, CommentedSeq, str, None]]):
    """A Dict where all keys are normalized using the provided function."""

    def __init__(self, normalize: Callable[[str], str] = str) -> None:
        super().__init__()
        self.normalize = normalize

    def __eq__(self, other: Any) -> bool:
        return super().__eq__(other)

    def __getitem__(self, key: Any) -> Any:
        return super().__getitem__(self.normalize(key))

    def __setitem__(self, key: Any, value: Any) -> Any:
        return super().__setitem__(self.normalize(key), value)

    def __delitem__(self, key: Any) -> Any:
        return super().__delitem__(self.normalize(key))

    def __contains__(self, key: Any) -> bool:
        return super().__contains__(self.normalize(key))

    def __del__(self) -> None:
        del self.normalize
$ pip install mypy==1.15.0
[…]
$ mypyc ref_resolver.py 
running build_ext
building 'ref_resolver' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/build
x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -g -fwrapv -O2 -fPIC -I/home/michael/ss2/env3.11/lib/python3.11/site-packages/mypyc/lib-rt -I/home/michael/ss2/env3.11/include -I/usr/include/python3.11 -c build/__native.c -o build/temp.linux-x86_64-cpython-311/build/__native.o -O3 -g1 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
creating build/lib.linux-x86_64-cpython-311
x86_64-linux-gnu-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -g -fwrapv -O2 build/temp.linux-x86_64-cpython-311/build/__native.o -L/usr/lib/x86_64-linux-gnu -o build/lib.linux-x86_64-cpython-311/ref_resolver.cpython-311-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-cpython-311/ref_resolver.cpython-311-x86_64-linux-gnu.so ->

$ rm -Rf ref_resolver.*.so .mypy_cache/ build/
$ pip install mypy==1.16.0
[…]
$ mypyc ref_resolver.py 
running build_ext
building 'ref_resolver' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/build
x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -g -fwrapv -O2 -fPIC -I/home/michael/ss2/env3.11/lib/python3.11/site-packages/mypyc/lib-rt -I/home/michael/ss2/env3.11/include -I/usr/include/python3.11 -c build/__native.c -o build/temp.linux-x86_64-cpython-311/build/__native.o -O3 -g1 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
build/__native.c:162:32: error: ‘NormDict_finalize’ undeclared here (not in a function); did you mean ‘NormDict_init’?
  162 |     .tp_finalize = (destructor)NormDict_finalize,
      |                                ^~~~~~~~~~~~~~~~~
      |                                NormDict_init
cc1: note: unrecognized command-line option ‘-Wno-ignored-optimization-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
error: command '/usr/lib/ccache/x86_64-linux-gnu-gcc' failed with exit code 1
$ x86_64-linux-gnu-gcc --version
x86_64-linux-gnu-gcc (Debian 12.2.0-14+deb12u1) 12.2.0

@JelleZijlstra
Copy link
Member

You nerd-sniped me further because surely that's too complex for a minimal reproducer. This still reproduces it:

class NormDict(dict):
    def __del__(self) -> None:
        pass
$ mypyc mypyc_crash.py 
running build_ext
building 'mypyc_crash' extension
clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall -I/Users/jelle/py/venvs/taxonomy312/lib/python3.12/site-packages/mypyc/lib-rt -I/Users/jelle/py/venvs/taxonomy312/include -I/Users/jelle/.pyenv/versions/3.12.2/include/python3.12 -c build/__native.c -o build/temp.macosx-14.4-arm64-cpython-312/build/__native.o -O3 -g1 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
build/__native.c:37:32: error: use of undeclared identifier 'NormDict_finalize'
    .tp_finalize = (destructor)NormDict_finalize,
                               ^
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1

@sterliakov sterliakov added the topic-mypyc mypyc bugs label May 30, 2025
@mr-c
Copy link
Contributor Author

mr-c commented May 31, 2025

I did a git bisect using the following script and @JelleZijlstra 's minimal reproducer

#!/bin/bash
python -m pip install -e .
rm -Rf build .mypy_cache mypyc_crash.*.so
python -m mypyc mypyc_crash.py

Which found 8104d01 from #18519 matching the previous suggestion by @JelleZijlstra .

@advait-dixit can you take a look at this?

@advait-dixit
Copy link
Contributor

Yes, I can take a look at this and report back on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants