Skip to content

Push anonymous namespace into codegen, not template#49498

Closed
ezyang wants to merge 6 commits intogh/ezyang/897/basefrom
gh/ezyang/897/head
Closed

Push anonymous namespace into codegen, not template#49498
ezyang wants to merge 6 commits intogh/ezyang/897/basefrom
gh/ezyang/897/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented Dec 16, 2020

Stack from ghstack:

In the near future, I want to code generate some functions that are
visible externally to this compilation unit. I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang ezyang@fb.com

Differential Revision: D25616104

In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Dec 16, 2020

💊 CI failures summary and remediations

As of commit 23d2a76 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

This comment has been revised 50 times.

ezyang added a commit that referenced this pull request Dec 16, 2020
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

ghstack-source-id: 3254eac
Pull Request resolved: #49498
@ezyang ezyang requested a review from smessmer December 16, 2020 21:23
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D25616104](https://our.internmc.facebook.com/intern/diff/D25616104)

[ghstack-poisoned]
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D25616104](https://our.internmc.facebook.com/intern/diff/D25616104)

[ghstack-poisoned]
In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D25616104](https://our.internmc.facebook.com/intern/diff/D25616104)

[ghstack-poisoned]

namespace {

${dispatch_definitions}
Copy link
Copy Markdown
Collaborator

@bdhirsh bdhirsh Jan 5, 2021

Choose a reason for hiding this comment

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

Do you plan on potentially generating functions with different namespaces in the same Register{DispatchKey}.cpp file? If it'll always be uniform per file, it might be cleaner to code-template the name of the namespace directly. So you can look at something like RegisterCPU.cpp and easily say "oh yeah these functions are all in the same namespace"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, they'll either be anonymous, or in the cpu namespace (for example).

Copy link
Copy Markdown
Contributor

@smessmer smessmer left a comment

Choose a reason for hiding this comment

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

What's your reason for putting it in codegen? As long as it unconditionally applies to the whole file, it'd be easier to have it in the template.

Copy link
Copy Markdown
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

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

Makes sense. As an aside, making wrapper names more unique would've been a nice improvement in greppability of the generated code, so I'm kind of sad you didn't wind up doing this but I imagine it would've been a substantially bigger undertaking.

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Jan 6, 2021

What's your reason for putting it in codegen? As long as it unconditionally applies to the whole file, it'd be easier to have it in the template.

In the next PR this invariant is violated!

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Jan 6, 2021

As an aside, making wrapper names more unique would've been a nice improvement in greppability of the generated code, so I'm kind of sad you didn't wind up doing this but I imagine it would've been a substantially bigger undertaking.

It's not that hard. I'll put it on the cleanup list.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@ezyang merged this pull request in 68a6e46.

hwangdeyu pushed a commit to hwangdeyu/pytorch that referenced this pull request Jan 14, 2021
Summary:
Pull Request resolved: pytorch#49498

In the near future, I want to code generate some functions that are
visible externally to this compilation unit.  I cannot easily do this
if all the codegen code is wrapped in a global anonymous namespace,
so push the namespace in.

Registration has to stay in an anonymous namespace to avoid name conflicts.
This could also have been solved by making the wrapper functions have
more unique names but I didn't do this in the end.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Test Plan: Imported from OSS

Reviewed By: albanD, smessmer

Differential Revision: D25616104

Pulled By: ezyang

fbshipit-source-id: 323c0dda05a081502aab702f359a08dfac8c41a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants