GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-93691: Compiler's code-gen passes location around instead of holding it on the global compiler state by iritkatriel · Pull Request #98001 · python/cpython

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Oct 6, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This implements #93691 (comment).

The line numbers are almost identical to those we calculated before (see the individual commits if you're interested in the process I followed). There were a few place (around annotations, for instance) where the line number was not set so it remained whatever it was before. I didn't bother going through hoops to make this backwards compatible because it's obviously wrong. I just take the line number from the current AST node.

In a few places (like pattern matching) I pass around a pointer to the location which can be updated deep in the recursion. This is not how it should be, but it's how it was until now (the global was updated in the recursion and impacted further nodes). So I used pointers to emulate this and get similar results, but my intention is to get rid of these pointers in the future, and just take locations from the relevant, current, AST node.

  • Issue: Bytecode positions seem way too broad #93691

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel added 5 commits September 29, 2022 23:22
@iritkatriel
pass location into the various ADDOPs
ecfa12e
@iritkatriel
Pass locations around instead of using the one on the compiler state.…
082625c
… Assert they are the same as on the compiler state, except a few places where the location is currently wrong/random.
@iritkatriel
find last loc in finally body
c50ff36
@iritkatriel
remove scaffold
091266f
@iritkatriel
remove u_loc from compiler_unit
8fd667d
@iritkatriel
iritkatriel requested a review from markshannon as a code owner October 6, 2022 23:14
@bedevere-bot bedevere-bot added the awaiting core review label Oct 6, 2022
@iritkatriel iritkatriel added the skip news label Oct 6, 2022
@iritkatriel
iritkatriel requested review from brandtbucher and sweeneyde October 6, 2022 23:19
@iritkatriel
Merge remote-tracking branch 'upstream/main' into linenos
c7764ce
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 6, 2022
@bedevere-bot

bedevere-bot commented Oct 6, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit c7764ce 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 6, 2022
@iritkatriel
Merge remote-tracking branch 'upstream/main' into linenos
498e98b
@iritkatriel iritkatriel mentioned this pull request Oct 7, 2022
gh-91052: Add C API for watching dictionaries #31787
Merged
@JelleZijlstra
Merge branch 'main' into linenos
f8d061b
@JelleZijlstra

JelleZijlstra commented Oct 7, 2022

Copy link
Copy Markdown
Member

Going to retrigger buildbots after merging the refleak fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 7, 2022
@bedevere-bot

bedevere-bot commented Oct 7, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @JelleZijlstra for commit f8d061b 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 7, 2022
@markshannon

markshannon commented Oct 7, 2022

Copy link
Copy Markdown
Member

I notice that some function take a location, and others take a pointer to a location. Why?
A typedef might help readability as well.

typedef struct location { ... } Location;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Oct 7, 2022

Copy link
Copy Markdown
Member Author

I notice that some function take a location, and others take a pointer to a location. Why?

See above (#98001 (comment)).

A typedef might help readability as well.

typedef struct location { ... } Location;

Yeah could do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel and others added 2 commits October 7, 2022 23:28
@iritkatriel
typedef of the location struct
0df1e0c
@iritkatriel
Merge branch 'main' into linenos
e09f741
@iritkatriel iritkatriel self-assigned this Oct 8, 2022
markshannon
markshannon requested changes Oct 10, 2022
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement.

A few comments, but no major issues.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/compile.c Outdated
static location
last_location_in_body(asdl_stmt_seq *stmts)
{
for (int i = asdl_seq_LEN(stmts) - 1; i >= 0; i++) {

@markshannon markshannon Oct 10, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIndows warning. Use Py_ssize_t instead of int.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Oct 17, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this? There are a few other for loops with int variable in this file, I don't know if they need to change too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/compile.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/compile.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/compile.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/compile.c
@@ -4015,8 +4066,10 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
n++;
}
}
ADDOP_I(c, RAISE_VARARGS, (int)n);
location loc = LOC(s);

@markshannon markshannon Oct 10, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few cases of this pattern:

    location loc = LOC(s);
    ADDOP...(..., loc, ...);

Any reason not to shorten this to:

    ADDOP...(..., LOC(S), ...);

?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Oct 17, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll land this and do this and other cleanup in followup PRs. (There are still the SET_LOC and UNSET_LOC to remove - they do nothing now).

Thanks for the review!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Oct 10, 2022
@bedevere-bot

bedevere-bot commented Oct 10, 2022

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be put in the comfy chair!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel and others added 3 commits October 16, 2022 20:26
@iritkatriel
Merge branch 'main' into linenos
80393a3
@iritkatriel
int --> Py_ssize_t. renamed last_location_in_body --> location_of_las…
8e7acf6
…t_executing_statement
@iritkatriel
removed CHANGED comment indicating where line numbers were not perfec…
5418bb5
…tly preserved
markshannon
markshannon approved these changes Oct 17, 2022
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting changes labels Oct 17, 2022
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 17, 2022
@bedevere-bot

bedevere-bot commented Oct 17, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 5418bb5 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 17, 2022
@iritkatriel
iritkatriel merged commit 6da1a2e into python:main Oct 17, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Oct 17, 2022
carljm added a commit to carljm/cpython that referenced this pull request Oct 17, 2022
@carljm
Merge branch 'main' into typewatch
cdbe93b
* main: (31 commits)
  pythongh-95913: Move subinterpreter exper removal to 3.11 WhatsNew (pythonGH-98345)
  pythongh-95914: Add What's New item describing PEP 670 changes (python#98315)
  Remove unused arrange_output_buffer function from zlibmodule.c. (pythonGH-98358)
  pythongh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (python#98316)
  pythonGH-98327: Reduce scope of catch_warnings() in _make_subprocess_transport (python#98333)
  pythongh-93691: Compiler's code-gen passes location around instead of holding it on the global compiler state (pythonGH-98001)
  pythongh-97669: Create Tools/build/ directory (python#97963)
  pythongh-95534: Improve gzip reading speed by 10% (python#97664)
  pythongh-95913: Forward-port int/str security change to 3.11 What's New in main (python#98344)
  pythonGH-91415: Mention alphabetical sort ordering in the Sorting HOWTO (pythonGH-98336)
  pythongh-97930: Merge with importlib_resources 5.9 (pythonGH-97929)
  pythongh-85525: Remove extra row in doc (python#98337)
  pythongh-85299: Add note warning about entry point guard for asyncio example (python#93457)
  pythongh-97527: IDLE - fix buggy macosx patch (python#98313)
  pythongh-98307: Add docstring and documentation for SysLogHandler.createSocket (pythonGH-98319)
  pythongh-94808: Cover `PyFunction_GetCode`, `PyFunction_GetGlobals`, `PyFunction_GetModule` (python#98158)
  pythonGH-94597: Deprecate child watcher getters and setters (python#98215)
  pythongh-98254: Include stdlib module names in error messages for NameErrors (python#98255)
  Improve speed. Reduce auxiliary memory to 16.6% of the main array. (pythonGH-98294)
  [doc] Update logging cookbook with an example of custom handling of levels. (pythonGH-98290)
  ...
@iritkatriel
iritkatriel deleted the linenos branch October 18, 2022 14:23
@Eclips4 Eclips4 mentioned this pull request Jun 11, 2023
3.12 tracing regression: a conditional in a finally block will revisit the condition before exiting the block. #105658
Closed
@gvanrossum gvanrossum mentioned this pull request Aug 8, 2023
Bytecode documentation issues for Python 3.12 #107457
Closed
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon approved these changes
@sweeneyde sweeneyde Awaiting requested review from sweeneyde
@brandtbucher brandtbucher Awaiting requested review from brandtbucher

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@iritkatriel iritkatriel

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@iritkatriel @bedevere-bot @JelleZijlstra @markshannon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.