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

Allow signed line number deltas in the code object's line number table #61160

Closed
markshannon opened this issue Jan 13, 2013 · 6 comments
Closed
Labels
type-feature A feature request or enhancement

Comments

@markshannon
Copy link
Member

BPO 16956
Nosy @birkenfeld, @pitrou, @vstinner, @xdegaye, @markshannon
Superseder
  • bpo-26107: PEP 511: code.co_lnotab: use signed line number delta to support moving instructions in an optimizer
  • Files
  • dd04caae6647.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-01-20.11:36:19.420>
    created_at = <Date 2013-01-13.18:42:34.781>
    labels = ['type-feature']
    title = "Allow signed line number deltas in the code object's  line number table"
    updated_at = <Date 2016-01-20.11:36:19.419>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2016-01-20.11:36:19.419>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-01-20.11:36:19.420>
    closer = 'vstinner'
    components = []
    creation = <Date 2013-01-13.18:42:34.781>
    creator = 'Mark.Shannon'
    dependencies = []
    files = ['28718']
    hgrepos = ['172']
    issue_num = 16956
    keywords = ['patch']
    message_count = 6.0
    messages = ['179887', '179948', '180006', '181767', '181768', '258671']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'pitrou', 'vstinner', 'xdegaye', 'Mark.Shannon']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = '26107'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16956'
    versions = ['Python 3.4']

    @markshannon
    Copy link
    Member Author

    The restriction that line numbers must be monotonically increasing w.r.t bytecode offset in the co_lnotab array prevents a number of beneficial transformations in the bytecode compiler.

    This patch allows negative line number deltas and uses this capability to generate code for 'while' loops in standard text book fashion, putting the test *after* the body.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 14, 2013

    How does this interact with pdb?

    @pitrou pitrou added the type-feature A feature request or enhancement label Jan 14, 2013
    @markshannon
    Copy link
    Member Author

    The interaction between bdb/pdb and the line number table is via the frame.f_lineno attribute.

    Allowing signed offsets changes the one-to-one line muber => bytecode offset relation into a one-to-many relation.

    Reading frame.f_lineno is not an issue as each bytecode offset will always refer to exactly one line number.

    Setting frame.f_lineno requires some thought as each line number could potentially refer to several bytecode offsets. However, the proposed patch retains the one-to-one relation, as the test in the while statement is merely moved, not duplicated.

    I am reluctant to change frame_setlineno() until there really is a one-to-many relation as it will be untestable.
    Once a one-to-many relation exists (e.g. duplicating finally blocks to avoid 'pseudo excpetions') then frame_setlineno should be modified (and tests added)

    @xdegaye
    Copy link
    Mannequin

    xdegaye mannequin commented Feb 9, 2013

    How does this interact with pdb?

    Also, the findlinestarts() function from the dis module computes line
    numbers from lnotab. This function is used by pdb when displaying the
    lines of a traceback.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 9, 2013

    Your patch doesn't seem to work properly: a "while" loop doesn't generate negative line offsets. The reason seems to be that compiler_set_lineno() prevents it.
    (also, if I re-add the assert(d_lineno >= 0); in assemble_lnotab(), I don't get any crash)

    @vstinner
    Copy link
    Member

    Good news: this issue has been fixed in issue bpo-26107.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants