-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-139922: Tail calling for MSVC (VS 2026) #139962
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
Changes from 1 commit
82d1259
3248658
9ac430d
085c1d7
0b12f2e
acf48f5
35e96c1
d7737e9
86f19cf
40013cc
48db59e
bc9d23c
19e02c2
66ec774
50f8ff7
5d908b4
0786133
e699d40
66d6c39
5584fec
7eeeaa8
6f3d525
81618e2
2008d1d
7c84388
68b41cf
c7316fc
9214d5b
52c6f9c
34d98d3
7ec626e
ad1c5a2
4155337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -391,7 +391,7 @@ _PyForIter_VirtualIteratorNext(PyThreadState* tstate, struct _PyInterpreterFrame | |
| #define SPECIAL___AEXIT__ 3 | ||
| #define SPECIAL_MAX 3 | ||
|
|
||
| /* Special counterparts of ceval functions for performance reasons */ | ||
| // Special counterparts of ceval functions for performance reasons | ||
| PyAPI_FUNC(int) _PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result); | ||
|
|
||
| #if defined(_MSC_VER) && !defined(__clang__) && _Py_TAIL_CALL_INTERP | ||
|
|
@@ -400,17 +400,18 @@ PyAPI_FUNC(int) _PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, Py | |
| # define Py_NO_INLINE_MSVC_TAILCALL | ||
| #endif | ||
|
|
||
| // Tells the compiler that this variable cannot be alised. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar nit, but "cannot be aliased" is ambiguous (because it's not clear whether we are choosing not to alias it, or telling the compiler that it cannot choose to alias it). I think we're promising that it won't be aliased? So "Tells the compiler to trust that we haven't aliased this variable" better explains what it's doing. Or just "... this variable is not going to be aliased". Alternatively, "Tells the compiler not to alias the variable" (but I don't think that even makes sense, let alone being correct here). |
||
| #if defined(_MSC_VER) && !defined(__clang__) | ||
| # define Py_MSVC_RESTRICT restrict | ||
| # define Py_UNALIASED(var) restrict var | ||
| #else | ||
| # define Py_MSVC_RESTRICT | ||
| # define Py_UNALIASED(var) var | ||
| #endif | ||
|
|
||
| // Just a scope. Hints to the programmer | ||
| // Just a scope. Hints to the programmer and compiler | ||
| // That any local variable defined within this block MUST | ||
| // not escape from the current definition. | ||
| # define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE() { | ||
| # define Py_END_LOCALS_MUST_NOT_ESCAPE() } | ||
| # define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE { | ||
| # define Py_END_LOCALS_MUST_NOT_ESCAPE } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Is the only difference the restrict annotation?
We could just add the annotation to
PyMapping_GetOptionalItemtheresultpointer can never alias the other parameters.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.
Yes. We can't because
PyMapping_GetOptionalItemis part of the public API, and we can't change the signature of it.Uh oh!
There was an error while loading. Please reload this page.
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.
We aren't changing the signature, just telling the compiler than one of its parameters can't alias the others.
I'm surprised we need to do this anyway. I would have thought that strict aliasing already tells MSVC that they can't alias.
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.
My understanding is, that strict aliasing can't help here, since in
all parameters are of type
PyObject. And by usingrestrictwe tell the compiler that "we assure you, that none of thesePyObjects point to the same memory", and if we brake that contract, UB kicks in.