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

importlib.h should be regenerated when the marshaling code changes #59557

Closed
meadori opened this issue Jul 14, 2012 · 17 comments
Closed

importlib.h should be regenerated when the marshaling code changes #59557

meadori opened this issue Jul 14, 2012 · 17 comments
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error

Comments

@meadori
Copy link
Member

meadori commented Jul 14, 2012

BPO 15352
Nosy @pitrou, @meadori, @ericsnowcurrently
Files
  • issue15352-v0.patch: Patch against tip
  • 442723
  • 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-09-08.01:51:44.566>
    created_at = <Date 2012-07-14.19:41:05.168>
    labels = ['type-bug', 'build']
    title = 'importlib.h should be regenerated when the marshaling code changes'
    updated_at = <Date 2021-03-23.14:35:14.528>
    user = 'https://github.com/meadori'

    bugs.python.org fields:

    activity = <Date 2021-03-23.14:35:14.528>
    actor = 'aaadsghsu'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-08.01:51:44.566>
    closer = 'eric.snow'
    components = ['Build']
    creation = <Date 2012-07-14.19:41:05.168>
    creator = 'meador.inge'
    dependencies = []
    files = ['26382', '49901']
    hgrepos = []
    issue_num = 15352
    keywords = ['patch']
    message_count = 17.0
    messages = ['165464', '165465', '165468', '165501', '165503', '165544', '165571', '165583', '165592', '165595', '165597', '167395', '167538', '168973', '274949', '274950', '275145']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'Arfrever', 'meador.inge', 'python-dev', 'eric.snow']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue15352'
    versions = ['Python 3.6']

    @meadori
    Copy link
    Member Author

    meadori commented Jul 14, 2012

    Today I was hacking on a patch that changes the marshaling format for Code objects. When building the patch I was met with:

    ValueError: bad marshal data (unknown type code)
    make: *** [Lib/_sysconfigdata.py] Abort trap: 6

    This is because the frozen importlib was not rebuilt with the new marshaling format.

    @meadori meadori added build The build process and cross-build type-bug An unexpected behavior, bug, or error labels Jul 14, 2012
    @meadori
    Copy link
    Member Author

    meadori commented Jul 14, 2012

    Patch attached.

    @pitrou
    Copy link
    Member

    pitrou commented Jul 14, 2012

    Looks good to me. It probably won't cover all cases (such as e.g. changing the bytecode format), but it's a good step forward.

    @ericsnowcurrently
    Copy link
    Member

    FYI: the .pyc magic number is now built/kept in Lib/importlib/_bootstrap.py, so updates to it will trigger a rebuild of frozen importlib during make.

    @ericsnowcurrently
    Copy link
    Member

    What I mean is, shouldn't changes to marshal have an accompanying bump to the pyc magic number?

    @meadori
    Copy link
    Member Author

    meadori commented Jul 15, 2012

    Eric, that is a good point, but if someone forgets (like I did) or just hasn't gotten around to bumping the number yet, then the build breaks because the interpreter crashes. I think we should always try to avoid building an interpreter that is in an inconsistent state.

    Anyway, I am hitting another problem now -- _freeze_importlib is *not* idempotent. Thus adding this rule might cause some noise in the builds because importlib.h is different when nothing has actually changed. I am still investigating that problem.

    Assuming I can fix the idempotency problem, then maybe _freeze_importlib should just be always run.

    @meadori
    Copy link
    Member Author

    meadori commented Jul 16, 2012

    Hmmm, I guess the idempotency issue is no worse than it already is -- the
    same thing can still happen with trivial changes to the other prerequisites
    for importlib.h.

    Consider this small example (you might have to run sample program multiple
    times to see a difference):

    $ cat dis-closure.py
    import dis
    def adder(a, b):
        def add():
            return a + b
        return add

    print(dis.dis(adder(1, 2).__code__))

    $  ./python.exe dis-closure.py
      5           0 LOAD_DEREF               0 (a) 
                  3 LOAD_DEREF               1 (b) 
                  6 BINARY_ADD           
                  7 RETURN_VALUE         
    None
    $  ./python.exe dis-closure.py
      5           0 LOAD_DEREF               1 (a) 
                  3 LOAD_DEREF               0 (b) 
                  6 BINARY_ADD           
                  7 RETURN_VALUE         
    None

    The order of 'co_cellvars', 'co_varnames', and 'co_freevars' can be
    different from compile to compile, thus the bytecode can be different
    from compile to compile (I am not sure if this is worth fixing).

    Thus there may be times where importlib.h is regenerated, but the changes
    in the bytecode aren't significant.

    I will just commit this patch as is.

    @pitrou
    Copy link
    Member

    pitrou commented Jul 16, 2012

    Anyway, I am hitting another problem now -- _freeze_importlib is *not* idempotent.

    What do you mean with "idempotent"? Deterministic?

    @pitrou
    Copy link
    Member

    pitrou commented Jul 16, 2012

    Le lundi 16 juillet 2012 à 05:42 +0000, Meador Inge a écrit :

    The order of 'co_cellvars', 'co_varnames', and 'co_freevars' can be
    different from compile to compile, thus the bytecode can be different
    from compile to compile (I am not sure if this is worth fixing).

    I don't know, but you could open an issue just for the record.
    People may be surprised if bytecode generation isn't deterministic.

    @meadori
    Copy link
    Member Author

    meadori commented Jul 16, 2012

    On Mon, Jul 16, 2012 at 5:20 AM, Antoine Pitrou <report@bugs.python.org> wrote:

    > Anyway, I am hitting another problem now -- _freeze_importlib is *not* idempotent.

    What do you mean with "idempotent"? Deterministic?

    Whoops, yeah, deterministic. I got mixed up with my terminology.

    @meadori
    Copy link
    Member Author

    meadori commented Jul 16, 2012

    On Mon, Jul 16, 2012 at 7:13 AM, Antoine Pitrou <report@bugs.python.org> wrote:

    I don't know, but you could open an issue just for the record.
    People may be surprised if bytecode generation isn't deterministic.

    Yeah, I was somewhat surprised and it took some digging to figure
    out exactly what was changing. Opened bpo-15368 to track this.

    @ericsnowcurrently
    Copy link
    Member

    Meador, is this still a problem? There was a flurry of activity in this area.

    @meadori
    Copy link
    Member Author

    meadori commented Aug 6, 2012

    Yup, it is still an issue. The recent activity was mostly related to Windows builds (bpo-15431).

    @ericsnowcurrently
    Copy link
    Member

    FWIW, the patch looks good to me. This is probably the last week to get this in for 3.3.0.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 8, 2016

    New changeset 344f44bd793f by Eric Snow in branch 'default':
    Issue bpo-15352: Rebuild frozen modules when marshal.c is changed.
    https://hg.python.org/cpython/rev/344f44bd793f

    @ericsnowcurrently
    Copy link
    Member

    Thanks for the patch Meador.

    @meadori
    Copy link
    Member Author

    meadori commented Sep 8, 2016

    Hmmm, not sure why I forgot to apply this myself. Thanks for committing it Eric.

    @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
    build The build process and cross-build type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants