Skip to content

Remove debugreturn.h and machinery around preventing returns - #116563

Merged
jkoritzinsky merged 8 commits into
dotnet:mainfrom
jkoritzinsky:no-debug-return
Jun 16, 2025
Merged

jkoritzinsky merged 8 commits into
dotnet:mainfrom
jkoritzinsky:no-debug-return

Conversation

@jkoritzinsky

Copy link
Copy Markdown
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 AI review requested due to automatic review settings June 11, 2025 23:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@janvorli

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread docs/design/coreclr/botr/exceptions.md Outdated

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

Comment thread src/coreclr/inc/contract.h Resolved
@jkoritzinsky
jkoritzinsky disabled auto-merge June 12, 2025 03:32
@jkoritzinsky
jkoritzinsky requested review from janvorli and jkotas June 12, 2025 17:46

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

@jkoritzinsky

Copy link
Copy Markdown
Member Author

/ba-g failures unrelated

@jkoritzinsky

Copy link
Copy Markdown
Member Author

/ba-g browser wam problem

@jkoritzinsky
jkoritzinsky merged commit abb26bc into dotnet:main Jun 16, 2025
@jkoritzinsky
jkoritzinsky deleted the no-debug-return branch June 16, 2025 22:56
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants