Skip to content

Conversation

@gvanrossum
Copy link
Member

@gvanrossumgvanrossum commented Nov 16, 2022

This refactor also fixes code generation for cache effects that aren't unused and removes check_overlaps(). It shows it all off for the BINARY_SUBSCR family. (I had an earlier PR (GH-99408) for this, but it got a bit stale and I decided to delete the history.)

@gvanrossumgvanrossum marked this pull request as ready for review November 16, 2022 23:28
@gvanrossum
Copy link
MemberAuthor

I have a newer version of the same code in GH-99495 (which adds macros and ops) but that's not fully baked and I figured I'd release this in stages so it's easier on the reviewer. If you'd rather review the tooling in even larger chunks let me know. (I think the changes to the instruction definitions are pretty mild in this one.)

Copy link
Member

@brandtbucherbrandtbucher left a comment

Choose a reason for hiding this comment

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

Looks good. A few comments:

PyObject*container=SECOND();
_PyBinarySubscrCache*cache= (_PyBinarySubscrCache*)next_instr;
uint32_ttype_version=read_u32(cache->type_version);
inst(BINARY_SUBSCR_GETITEM, (container, sub, unused/1, type_version/2, func_version/1--unused)){
Copy link
Member

Choose a reason for hiding this comment

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

Super cool to see the cache reads in action!

}
PyObject*arg=TOP();
PyObject*res=_PyCFunction_TrampolineCall(cfunc, PyCFunction_GET_SELF(callable), arg);
PyObject*res=cfunc(PyCFunction_GET_SELF(callable), arg);
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to change this (also the two instances below)?

returnself.header.inputs

@property
defoutputs(self) ->list[StackEffect]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defoutputs(self) ->list[StackEffect]:
defoutputs(self) ->list[OutputEffect]:

Comment on lines +73 to +75
ifceffect.name!="unused":
# TODO: if name is 'descr' use PyObject *descr = read_obj(...)
bits=ceffect.size*16
Copy link
Member

Choose a reason for hiding this comment

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

I had suggestions on these from the other PR, not sure if you saw (I like _ more than unused, and both "unused" and 16 might benefit from constant names in this file).

Unless you just disagreed, in which case, feel free to ignore this. :)

# Write output stack effect assignments
input_names= [seffect.nameforseffectinself.input_effects]
fori, outputinenumerate(reversed(self.output_effects), 1):
ifoutput.namenotininput_namesandoutput.name!="unused":
Copy link
Member

Choose a reason for hiding this comment

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

For output.name not in input_names, don't we need to check that they occur at the same (stack-adjusted) position, and write them out if not?

Comment on lines +179 to +183
whiletkn:=psr.next(raw=True):
iftkn.text==BEGIN_MARKER:
break
else:
raisepsr.make_syntax_error(f"Unexpected token")
returninstrs, supers, families
raisepsr.make_syntax_error(f"Couldn't find {BEGIN_MARKER!r} in {psr.filename}")
Copy link
Member

Choose a reason for hiding this comment

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

Wild, I've never seen while/else before...

Comment on lines +222 to +226
print(
f"Unknown instruction {target!r} predicted in {instr.name!r}",
file=sys.stderr,
)
self.errors+=1
Copy link
Member

Choose a reason for hiding this comment

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

You do this move in lots of places... maybe add a method?

deferror(self, e: str) ->None: print(e, file=sys.stderr) self.errors+=1

Comment on lines +257 to +258
iflen(members) <2:
continue
Copy link
Member

Choose a reason for hiding this comment

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

This should be an error, yeah?

gvanrossum added a commit to gvanrossum/cpython that referenced this pull request Nov 18, 2022
@gvanrossumgvanrossum merged commit 4f5e1cb into python:mainNov 18, 2022
@gvanrossumgvanrossum deleted the cases-refactor branch November 18, 2022 01:06
gvanrossum added a commit to gvanrossum/cpython that referenced this pull request Nov 18, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@gvanrossum@brandtbucher@bedevere-bot