Skip to content

Remove debugreturn.h and machinery around preventing returns #116563

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

Merged
merged 8 commits into from
Jun 16, 2025

Conversation

jkoritzinsky
Copy link
Member

Remove last usages of our debug return macros and add a comment in our coding guidelines about returns shouldn't be used.

…r coding guidelines about returns shouldn't be used.
@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 23:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

The PR removes the legacy debugreturn machinery from VM and interpreter code, deletes the debugreturn.h file, and adds a cautionary note in the exceptions documentation about not returning inside EX_CATCH blocks.

  • Remove all #include "debugreturn.h" and related #undef return hacks
  • Delete debugreturn.h and purge DEBUG_ASSURE_NO_RETURN_* macros from exception macros
  • Add a reminder in docs/design/coreclr/botr/exceptions.md about avoiding returns between EX_CATCH and EX_END_CATCH

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/vm/interpexec.cpp Removed hack around debugreturn.h that broke constexpr usage
src/coreclr/vm/fcall.h Dropped include of debugreturn.h
src/coreclr/vm/clrex.h Removed SetupFinally() declaration
src/coreclr/vm/clrex.cpp Deleted long explanatory comments about unwind behavior
src/coreclr/interpreter/stackmap.cpp Removed hack undef for return from debugreturn.h
src/coreclr/interpreter/compiler.cpp Same removal of debugreturn.h hack
src/coreclr/inc/gcinfotypes.h Removed #undef return hack from header
src/coreclr/inc/ex.h Cleared out DEBUG_ASSURE_NO_RETURN_* invocations in macros
src/coreclr/inc/debugreturn.h Deleted entire file
src/coreclr/inc/contract.h Dropped include of debugreturn.h
src/coreclr/inc/clrhost.h Dropped include of debugreturn.h
docs/design/coreclr/botr/exceptions.md Added note cautioning against returns inside EX_CATCH blocks
Comments suppressed due to low confidence (2)

src/coreclr/vm/clrex.h:184

  • The declaration of SetupFinally() was removed, but any calls or references to this method in implementation files will now break. Please ensure that its usages are also deleted or updated accordingly to avoid build errors.
void SetupFinally();

docs/design/coreclr/botr/exceptions.md:47

  • [nitpick] Consider relocating this guidance into the official coding guidelines document for exception macros, ensuring it’s discoverable alongside related style rules and preventing it from becoming overlooked in implementation-specific docs.
A function should not return from between an `EX_CATCH` usage and an `EX_END_CATCH` usage. Doing so will effectively swallow the exception.

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@janvorli
Copy link
Member

@jkoritzinsky I can see the DEBUG_ASSURE_NO_RETURN_XXX macros used at more places than your PR touches. exceptmacros.h, frames.h and olevariant.cpp.

@jkoritzinsky
Copy link
Member Author

I can't find them (at least in olevariant.cpp with full-text search and a build succeeds on my local machine). Where are you seeing them?

@janvorli
Copy link
Member

Oh, I am sorry, I was looking at a local checkout of the repo and haven't realized it was for v9.0.5.

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) June 11, 2025 23:42
@@ -44,6 +44,8 @@ And here is the big difference from C++ exceptions: the CLR developer doesn't ge

It bears repeating that the EX_CATCH macro catches everything. This behaviour is frequently not what a function needs. The next two sections discuss more about how to deal with exceptions that shouldn't have been caught.

A function should not return from between an `EX_CATCH` usage and an `EX_END_CATCH` usage. Doing so will effectively swallow the exception.
Copy link
Member

Choose a reason for hiding this comment

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

Doing so will effectively swallow the exception.

Why is it a problem? For example, if I write the following:

bool DoStuffNoThrow()
{
    EX_TRY
    {
        DoStuff();
    }
    EX_CATCH
    {
        return false;
    }
    EX_END_CATCH(SwallowAllExceptions);

     return true;
}

I naturally expect the method to swallow the exception and return false if there is one. SwallowAllExceptions is redundant in this case, but it should not affect correctness.

Or are there other negative side-effects if I do that?

Copy link
Member Author

Choose a reason for hiding this comment

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

My main concern here was I wanted docs to point to in case someone uses a something like RethrowTransientExceptions but has an early return.

Copy link
Member

Choose a reason for hiding this comment

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

Should we get rid of the argument for EX_END_CATCH macro and make rethrowing a statement to make it more obvious that it is part of the regular flow and returning before that won't execute it?

    EX_CATCH
    {
        return false;
        RethrowTransientExceptions;
    }
    EX_END_CATCH;

Some existing places do it like that already, For example:

RethrowTerminalExceptions;

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea. I'll do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the usage. Looks a lot cleaner to me (and easier to understand in my opinion).

@jkoritzinsky jkoritzinsky disabled auto-merge June 12, 2025 03:32
@jkoritzinsky jkoritzinsky requested review from janvorli and jkotas June 12, 2025 17:46
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@jkoritzinsky
Copy link
Member Author

/ba-g failures unrelated

@jkoritzinsky
Copy link
Member Author

/ba-g browser wam problem

@jkoritzinsky jkoritzinsky merged commit abb26bc into dotnet:main Jun 16, 2025
95 of 97 checks passed
@jkoritzinsky jkoritzinsky deleted the no-debug-return branch June 16, 2025 22:56
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.

3 participants