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

Reduce boilerplate + avoid warning when overriding context for the current scope #521

Closed
eyalroz opened this issue May 19, 2023 · 0 comments

Comments

@eyalroz
Copy link
Owner

eyalroz commented May 19, 2023

There are several dozen places in our code where need to set a context for the scope (typically, the function body). We do so by defining a local CADRe variable :

cuda::context::current::detail_::scoped_override_t set_context_for_this_scope(expr);

with expr being some expression yielding a context handle. This is fine, but - it would not be a bad idea to mark this variable as const (various IDEs are all for it). Also, it's a lot of typing. Let's use a macro, then:

#define CAW_SET_SCOPE_CONTEXT(context_handle_expr_) \
const cuda::context::current::detail_::scoped_override_t caw_context_for_this_scope_(context_handle_expr_)

this might look a little ugly (WHO LIKES ALL CAPS?), but it conveys the intention even more clearly when reading the code, and it's 24 characters + the length of expr, vs. 78 characters + the length of expr, which is not just less typing, but less cognitive load when reading the code.

@eyalroz eyalroz added the task label May 19, 2023
@eyalroz eyalroz self-assigned this May 19, 2023
@eyalroz eyalroz changed the title Reduce boilerplate + avoid warning for context setting Reduce boilerplate May 20, 2023
@eyalroz eyalroz changed the title Reduce boilerplate Reduce boilerplate + avoid warning when overriding context for the current scope May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant