Skip to content

Let's not generate #line directives in generated_cases.c.h #106656

@gvanrossum

Description

@gvanrossum

The cases generator has the ability (-l, --emit-line-directives) to emit C preprocessor #line directives so that the generated code is attributed to the proper line in the input (Python/bytecodes.c). Makefile.pre.in enables this option by default, because it helps debugging bugs in instruction implementations (i.e., bytecodes.c).

However, this option also has downsides -- because the code generator also makes up a lot of code that isn't sourced from bytecodes.c, it emits several #line directives for each instruction. The problem is that almost every time you edit bytecodes.c to insert or remove a line in an instruction, the #line directive for all following instructions must be adjusted, producing a humongous diff.

It is remarkable how often for various reasons I find myself looking at such a diff, and it's definitely a case of not seeing the forest for the trees.

I propose that we remove this flag from Makefile.pre.in. Diffs will be much smaller, and more useful. Devs who are faced with errors in the generated file that they would like to map back to the original file, can turn on the option manually. The easiest way is probably to run the tool like this:

python3 Tools/cases_generator/generate_cases.py -l

The defaults all match the explicit output filenames mentioned in Makefile.pre.in.

(If someone really would like to type some variant of make regen-cases to generate the #line directives, maybe we can define a new variable in Makefile.pre.in that you can pass on the command line, e.g. make regen-cases CASESFLAGS=-l.)

CC. @markshannon, @brandtbucher.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions