Skip to content

AttributeError: type object 'Missed' has no attribute 'demangler_lock' running opt-viewer #62403

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

Closed
nico opened this issue Apr 27, 2023 · 4 comments · Fixed by #131214
Closed
Labels
llvm-tools All llvm tools that do not have corresponding tag

Comments

@nico
Copy link
Contributor

nico commented Apr 27, 2023

On an M1 Max.

Compiling this file https://github.com/ibogosavljevic/johnysswlab/blob/f677ea00bde2fcc69f48e36d2028619e428c05ef/2022-12-optimizationreport/compiler-optimizations.cpp

Installed deps with pip3 install pygments and pip3 install PyYAML.

% clang -O3 comp-opt.cc -fsave-optimization-record -c -std=c++17

% python3 ~/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py comp-opt.opt.yaml     
Reading YAML files...
Rendering index page...
Rendering HTML files...
	2 of 2multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/optpmap.py", line 25, in _wrapped_func
    return func(argument, filter_)
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 243, in _render_file
    SourceFileRenderer(source_dir, output_dir, filename, no_highlight).render(remarks)
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 184, in render
    self.render_source_lines(self.source_stream, line_remarks)
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 105, in render_source_lines
    self.render_inline_remarks(remark, html_line)
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 108, in render_inline_remarks
    inlining_context = r.DemangledFunctionName
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/optrecord.py", line 146, in DemangledFunctionName
    return self.demangle(self.Function)
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/optrecord.py", line 70, in demangle
    with cls.demangler_lock:
AttributeError: type object 'Missed' has no attribute 'demangler_lock'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 379, in <module>
    main()
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 368, in main
    generate_report(all_remarks,
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 292, in generate_report
    optpmap.pmap(_render_file_bound,
  File "/Users/thakis/src/llvm-project/llvm/tools/opt-viewer/optpmap.py", line 50, in pmap
    result = pool.map(_wrapped_func, func_and_args, *args, **kwargs)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 364, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 771, in get
    raise self._value
AttributeError: type object 'Missed' has no attribute 'demangler_lock'

Works fine if I pass -j 1 too.

Also mentioned here androm3da/optviewer-demo#4 (comment) and here https://reviews.llvm.org/D41784.

This is at LLVM e23891a (yesterday's HEAD).

@anemet

@EugeneZelenko EugeneZelenko added llvm-tools All llvm tools that do not have corresponding tag and removed new issue labels Apr 27, 2023
@neboat
Copy link

neboat commented Nov 14, 2023

I ran into this same issue when running an existing opt-viewer test on macOS 14 (running on an M2 Max) using Python 3.12. In addition, I see a lot of SyntaxWarning messages before the crash.

Here's the crash I'm seeing, with some repeated messages removed:

$ python3 --version
Python 3.12.0
$ python3 llvm/tools/opt-viewer/opt-viewer.py -s llvm/test/tools/opt-viewer/Inputs -o tmp llvm/test/tools/opt-viewer/Inputs/basic/or.yaml --no-highlight --demangler=./build/bin/llvm-cxxfilt 
/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py:138: SyntaxWarning: invalid escape sequence '\S'
  indent = re.sub("\S", " ", indent)
Reading YAML files...
/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py:138: SyntaxWarning: invalid escape sequence '\S'
  indent = re.sub("\S", " ", indent)
(message repeats about a dozen times)
Rendering index page...
Rendering HTML files...
llvm/tools/opt-viewer/opt-viewer.py:138: SyntaxWarning: invalid escape sequence '\S'
  indent = re.sub("\S", " ", indent)
(message repeats about a dozen times)
	2 of 2multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/neboat/.pyenv/versions/3.12.0/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/.pyenv/versions/3.12.0/lib/python3.12/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/optpmap.py", line 25, in _wrapped_func
    return func(argument, filter_)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 293, in _render_file
    SourceFileRenderer(source_dir, output_dir, filename, no_highlight).render(remarks)
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 216, in render
    self.render_source_lines(self.source_stream, line_remarks)
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 123, in render_source_lines
    self.render_inline_remarks(remark, html_line)
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 126, in render_inline_remarks
    inlining_context = r.DemangledFunctionName
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/optrecord.py", line 153, in DemangledFunctionName
    return self.demangle(self.Function)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/optrecord.py", line 77, in demangle
    with cls.demangler_lock:
         ^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Missed' has no attribute 'demangler_lock'. Did you mean: 'demangler_proc'?
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 471, in <module>
    main()
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 457, in main
    generate_report(
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/opt-viewer.py", line 376, in generate_report
    optpmap.pmap(
  File "/Users/neboat/Software/llvm-project/llvm/tools/opt-viewer/optpmap.py", line 57, in pmap
    result = pool.map(_wrapped_func, func_and_args, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/.pyenv/versions/3.12.0/lib/python3.12/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/neboat/.pyenv/versions/3.12.0/lib/python3.12/multiprocessing/pool.py", line 774, in get
    raise self._value
AttributeError: type object 'Missed' has no attribute 'demangler_lock'

I'm not seeing these issues when using Python 3.9 on the same system. In addition, if I run opt-viewer with -j 1, everything works as expected, and I get neither the crash nor the SyntaxWarning messages.

I'm using LLVM 5fdb70b (HEAD of main this morning).

nvjle added a commit to anza-xyz/llvm-project that referenced this issue Dec 9, 2023
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
nvjle added a commit to anza-xyz/llvm-project that referenced this issue Dec 10, 2023
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
LucasSte pushed a commit to LucasSte/llvm-project that referenced this issue Jan 31, 2024
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
LucasSte pushed a commit to anza-xyz/llvm-project that referenced this issue Feb 16, 2024
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
LucasSte pushed a commit to LucasSte/llvm-project that referenced this issue Jun 28, 2024
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
LucasSte pushed a commit to anza-xyz/llvm-project that referenced this issue Aug 19, 2024
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
@dahyun-jeon-90
Copy link

Is this issue closed?

Seeing same error with Python 3.12 on my Mac book (Sequoia 15.1.1)

LucasSte pushed a commit to LucasSte/llvm-project that referenced this issue Feb 12, 2025
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
@hroncok
Copy link
Contributor

hroncok commented Mar 12, 2025

We see a very similar (if not the same) issue when trying to build the Fedora llvm package with Python 3.14: https://bugzilla.redhat.com/show_bug.cgi?id=2336915

Naïvely, trying this:

--- a/llvm/tools/opt-viewer/optrecord.py
+++ b/llvm/tools/opt-viewer/optrecord.py
@@ -64,17 +64,19 @@ class Remark(yaml.YAMLObject):
 
     default_demangler = "c++filt -n"
     demangler_proc = None
+    demangler_lock = Lock()
 
     @classmethod
     def set_demangler(cls, demangler):
         cls.demangler_proc = subprocess.Popen(
             demangler.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE
         )
-        cls.demangler_lock = Lock()
 
     @classmethod
     def demangle(cls, name):
         with cls.demangler_lock:
+            if not cls.demangler_proc:
+                cls.set_demangler(cls.default_demangler)
             cls.demangler_proc.stdin.write((name + "\n").encode("utf-8"))
             cls.demangler_proc.stdin.flush()
             return cls.demangler_proc.stdout.readline().rstrip().decode("utf-8")
@@ -323,8 +325,6 @@ def get_remarks(input_file, filter_=None):
 def gather_results(filenames, num_jobs, should_print_progress, filter_=None):
     if should_print_progress:
         print("Reading YAML files...")
-    if not Remark.demangler_proc:
-        Remark.set_demangler(Remark.default_demangler)
     remarks = optpmap.pmap(
         get_remarks, filenames, num_jobs, should_print_progress, filter_
     )

hroncok added a commit to hroncok/llvm-project that referenced this issue Mar 13, 2025
See https://bugzilla.redhat.com/2336915
See https://reviews.llvm.org/D41784?id=
See androm3da/optviewer-demo#4 (comment)

Fixes llvm#62403

The race condition happened when the demangler_proc was being set.
The locking mechanism itself happened too late.

This way, the lock always exists (to avoid a race when creating it)
and is always used when *creating* demangler_proc.

I don't have any prior experience with the codebase
and I cannot guarantee the behavior is correct.

It appears to get rid of the race (which I was seeing consistently).

    multiprocessing.pool.RemoteTraceback:
    """
    Traceback (most recent call last):
      File "/usr/lib64/python3.14/multiprocessing/pool.py", line 125, in worker
        result = (True, func(*args, **kwds))
                        ~~~~^^^^^^^^^^^^^^^
      File "/usr/lib64/python3.14/multiprocessing/pool.py", line 48, in mapstar
        return list(map(*args))
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/optpmap.py", line 25, in _wrapped_func
        return func(argument, filter_)
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/opt-viewer.py", line 293, in _render_file
        SourceFileRenderer(source_dir, output_dir, filename, no_highlight).render(remarks)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/opt-viewer.py", line 216, in render
        self.render_source_lines(self.source_stream, line_remarks)
        ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/opt-viewer.py", line 123, in render_source_lines
        self.render_inline_remarks(remark, html_line)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/opt-viewer.py", line 126, in render_inline_remarks
        inlining_context = r.DemangledFunctionName
                           ^^^^^^^^^^^^^^^^^^^^^^^
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/optrecord.py", line 153, in DemangledFunctionName
        return self.demangle(self.Function)
               ~~~~~~~~~~~~~^^^^^^^^^^^^^^^
      File "/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-19.1.6.src/llvm/tools/opt-viewer/optrecord.py", line 77, in demangle
        with cls.demangler_lock:
             ^^^^^^^^^^^^^^^^^^
    AttributeError: type object 'Passed' has no attribute 'demangler_lock'. Did you mean: 'demangler_proc'?
    """
@hroncok
Copy link
Contributor

hroncok commented Mar 13, 2025

It worked for me. #131214

@nikic nikic closed this as completed in e0f8898 Apr 2, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Apr 2, 2025
See https://bugzilla.redhat.com/2336915
See https://reviews.llvm.org/D41784?id=
See
androm3da/optviewer-demo#4 (comment)

Fixes llvm/llvm-project#62403.

The race condition happened when the demangler_proc was being set. The
locking mechanism itself happened too late.

This way, the lock always exists (to avoid a race when creating it) and
is always used when *creating* demangler_proc.
LucasSte pushed a commit to anza-xyz/llvm-project that referenced this issue Apr 8, 2025
These tests currently fail on some Macs for some versions of Python,
causing our CI to fail.

See, e.g., llvm#62403 and references
therein.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Apr 11, 2025
See https://bugzilla.redhat.com/2336915
See https://reviews.llvm.org/D41784?id=
See
androm3da/optviewer-demo#4 (comment)

Fixes llvm/llvm-project#62403.

The race condition happened when the demangler_proc was being set. The
locking mechanism itself happened too late.

This way, the lock always exists (to avoid a race when creating it) and
is always used when *creating* demangler_proc.

(cherry picked from commit e0f8898)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm-tools All llvm tools that do not have corresponding tag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants