Skip to content

[BUG] Cache fingerprinting ignores compiler_directives #7532

Closed

Description

@v01dXYZ

Describe the bug

The context is using Cython+coverage.py. To reproduce the bug:

  • Build the package without tracing compiler directives/macros
  • Build with cythonize.compiler_directives with linetrace=True + Extensions.define_macros with tracing macros
  • The cache outputs a code not taking into account linetrace, but the macros are defined and passed on to the C/C++ compiler.
  • No trace is generated at runtime and the Cython code is not part of the coverage report

I think the reason is because of the wrong assumption (compiler_directives does not influence code generation) that is written in a comment in Compiler/Options.py:get_fingerprint:

The fingerprinting function returns a string that will be fed to hash.update in Build/Cache.py:transitive_fingerprint

def get_fingerprint(self):
    data = {} 
    for key, value in self.__dict__.items():
       if key in SOMEVALUES:
           ... # many elif
       elif key in ['compiler_directives']:
           # directives passed on to the C compiler do not influence the generated code
           continue
       ... # many other elif

    str_data = convert_to_string(data)
    return data

But that is wrong, as Cython with linetrace=True generates instrumentation code (such as in Compiler/Code.py:write_trace_line()).

Code to reproduce the behaviour:

No response

Expected behaviour

I would expect Cython cache fingerprinting to take into account compiler_directives (or at least partially compiler_directive.linetrace).

OS

Linux (official docker image python:3.13-slim)

Python version

3.13.12

Cython version

3.2.4

Additional context

No response

Activity

  1. changed the title [-][BUG] Caching fingerprint doesn't take into account `compiler_directives`[/-] [+][BUG] Caching fingerprint ignore `compiler_directives`[/+] on Feb 17, 2026
  2. changed the title [-][BUG] Caching fingerprint ignore `compiler_directives`[/-] [+][BUG] Caching fingerprint ignores `compiler_directives`[/+] on Feb 17, 2026
  3. changed the title [-][BUG] Caching fingerprint ignores `compiler_directives`[/-] [+][BUG] Cache fingerprinting ignores `compiler_directives`[/+] on Feb 17, 2026
  4. scoder commented on Feb 17, 2026

    @scoder
    Contributor

    Thanks for the report. Yes, that looks like an incorrect assumption in the code. The compiler_directives instruct Cython itself to apply a certain behaviour, usually leading to different C code being generated. What might have been meant is the C macros etc., but the code is wrong as it stands.

    We might want to be a bit selective about directives that do not impact the generated result but should otherwise include the directives state in the fingerprint.

  5. scoder commented on Feb 18, 2026

    @scoder
    Contributor

    We'd be happy to receive a PR, BTW. :)

  6. v01dXYZ commented on Feb 18, 2026

    @v01dXYZ
    ContributorAuthor

    We'd be happy to receive a PR, BTW. :)

    Do you want me to first put back compiler_directives in the data dictionary? A finer grain approach would need to list all the compiler_directives option and to document exactly when they do not influence code generation.

  7. scoder commented on Feb 18, 2026

    @scoder
    Contributor

    I think we can start with the directives dict taken into account as a whole, then exclude what we can. Some exclusions are obvious, like the warning and test directives.

    The code above the _directive_defaults already has a few functions that copy the current directives with exclusions. I'd add a new one there.

  8. modified the milestones: 3.3.1, 3.2.10 on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions