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

Making mono_inst_name less misleading #83570

Closed

Conversation

sayeedkhannabil
Copy link
Contributor

Wraping both declaration and definition in #ifndef DISABLE_LOGGING.

Fix #83545

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Mar 17, 2023
@sayeedkhannabil
Copy link
Contributor Author

@dotnet-policy-service agree

@sayeedkhannabil
Copy link
Contributor Author

Do I have to add #ifndef DISABLE_LOGGING before all of the function call of mono_inst_name() to pass the tests?

Comment on lines 84 to 91
#else
g_error ("unknown opcode name for %d", op);
g_assert_not_reached ();
#endif
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This whole #else part can be removed

Comment on lines 2196 to 2198
#define mono_inst_name(op) _static_assert_disabled_logging(op)
void _static_assert_disabled_logging(int op) __attribute__((error("mono_inst_name is not available when DISABLE_LOGGING is defined.")));
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting idea. We don't only compile with gcc and clang, so we need to make some macros to make it workable. Also it's better to use __attribute__((unavailable)) when the compiler supports it, because then optimizations that remove a call won't remove the warning.

I did an example on godbolt that seems to work even with old versions of gcc and clang.

Add this to src/mono/mono/utils/mono-compiler.h

#if defined(__clang__)
#define MONO_FUNCTION_UNAVAILABLE(msg) __attribute__((unavailable(msg)))
#elif (__GNUC__ == 12 && __GNUC_MINOR__ >= 1)
#define MONO_FUNCTION_UNAVAILABLE(msg) __attribute__((unavailable(msg)))
#elif (__GNUC__ > 4) || (__GNUC__ >=4 && __GNUC_MINOR__ >= 4)
/* this might not warn if optimization removes a call, but it's better than nothing.
 * disable inlining to encourage GCC not to eliminate the call
 */
#define MONO_FUNCTION_UNAVAILABLE(msg) __attribute__((noinline,error(msg)))
#else
#define MONO_FUNCTION_UNAVAILABLE(msg) /* empty */
#endif

And then do this in this header (the implementation in helpers.c should be entirely within the #ifdef with no #else part):

#ifndef DISABLE_LOGGING
const char* mono_inst_name (int op);
#else
MONO_FUNCTION_UNAVAILABLE("mono_inst_name is not available when DISABLE_LOGGING is defined") const char *mono_inst_name (int op);
#endif

@lambdageek
Copy link
Member

lambdageek commented Mar 17, 2023

Do I have to add #ifndef DISABLE_LOGGING before all of the function call of mono_inst_name() to pass the tests?

Yes, you'll need to update very place that calls mono_inst_name. Some of them are already inside #ifdefs for logging (for example the entire src/mono/mono/mini/cfgdump.c file is in a giant ifdef)

@sayeedkhannabil
Copy link
Contributor Author

I could not figure out why some test cases are failing. Besides src/mono/mono/mini/cfgdump.c I have enclosed with #ifndef DISABLE_LOGGING in every places where mono_inst_name is being used. I did not do so in cfdump.c because it was already checking if DISABLE_LOGGING is enabled in the start of the code. Is that the case why some test cases are failing?

@SamMonoRT
Copy link
Member

@sayeedkhannabil - please resolve conflict. That will trigger a new CI run. We can help you investigate the failures once we have a newer CI check run.
cc @ivanpovazan

@ivanpovazan
Copy link
Member

@sayeedkhannabil is there anyway I could help you move forward with this PR?

@sayeedkhannabil
Copy link
Contributor Author

@sayeedkhannabil is there anyway I could help you move forward with this PR?

Hi. I am struggling with the CI/CD errors. Since I do not have any experience in that. If someone can help me figure out, how to work around with the CI/CD error, or give me some pointers how I can test this locally in my machine, that would be helpful for me. Thanks

@ivanpovazan
Copy link
Member

@sayeedkhannabil is there anyway I could help you move forward with this PR?

Hi. I am struggling with the CI/CD errors. Since I do not have any experience in that. If someone can help me figure out, how to work around with the CI/CD error, or give me some pointers how I can test this locally in my machine, that would be helpful for me. Thanks

Sure, I will gladly help you out with that.

  • The first thing that has to be done is to resolve conflicts that this PR has with the current tip of the main branch.
  • Once you resolve the conflicts please push those changes. That will trigger CI to do another round of testing.
  • After we get those results I can look into the failures to help you figure out whether your change introduced a regression or not.

@SamMonoRT SamMonoRT added the needs-author-action An issue or pull request that requires more info or actions from the author. label Aug 22, 2023
@SamMonoRT
Copy link
Member

@sayeedkhannabil - if the PR isn't ready, consider marking as Draft PR.

@sayeedkhannabil sayeedkhannabil force-pushed the disableLogin_mono_inst_name branch from 8d5e249 to 96c2e1d Compare August 23, 2023 05:05
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Aug 23, 2023
@sayeedkhannabil
Copy link
Contributor Author

sayeedkhannabil commented Aug 24, 2023 via email

@ghost ghost locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-meta-mono community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mono] Make mono_inst_name less misleading
4 participants