-
Notifications
You must be signed in to change notification settings - Fork 263
try_as casts should not store COM error context; consume method cast checking should use return codes directly #1450
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
Conversation
…instead for consume methods
|
Is try_as_reason a new public API? Would try_as_with_reason be a better name? |
I like that name better. I renamed it everywhere. |
…ref/release that is increasing binary size
|
Is there a specific reason for using |
Yes, the goal is to have the throw statement inside a |
|
Yeah, you're right. I didn't originally use that because it wouldn't have worked right before the This seems to split the difference on binary size. It is larger than Edit: I did some binary size analysis. The growth is from compiler inlining decision differences. In the before (commit d296af6) there were function calls to consume_X methods. In the after many of those were inlined. I'm inclined to accept this as-is and then once PGO counts are updated it will pick and choose the best approach on a case-by-case basis. |
This reverts commit 96f637e.
|
/AzurePipelines help |
Supported commands
See additional documentation. |
|
/azp list |
|
CI/CD Pipelines for this repository: |
|
@microsoft-github-policy-service rerun |
…d classes dont see it
Why is this change being made?
I have been trying to ingest the HEAD of cppwinrt for some large internal projects and one of them had some test failures with the new version. The failures are because there is a
try_ascast in their code that fails and is handled fine, but it leaves a COM error context floating around on that thread. Subsequent code fails to originate an error because it sees a context already active on the thread and NOOP'ed.What this boils down to is that
try_asshould not have a behavioral change to store context when the cast fails.Briefly summarize what changed
To address this problem I am taking a PR suggestion from @oldnewthing to have a new
try_as_with_reasonmethod that returns both the cast result as well as the HRESULT. The error context logic was only there to smuggle the HRESULT out of a call without an HRESULT return value, so if it is a direct return we don't need that anymore. The new method directly returns the HRESULT so there is no ambiguity.The previous approach relied on a cast operator to call try_as (or just addref when the type is already a match). Thanks to the recent
if constexprcode gen change those cases are now separated out. We have a code block where we know a cast is needed sotry_as_with_reasoncan be called unconditionally. The code path where no cast is needed already circumvents this and is nicely unaffected.This also made
check_cast_resultequiavelnt tocheck_hresultso it was deleted in favor of just callingcheck_hresult.How was this change tested?
I did local builds of cppwinrt (both Debug and Release) and ran the tests. I am also compiling some large internal projects with it to ensure that there are no obvious breaks or regressions. I am expecting minimal to no binary size impact from this change.
Here is what the latest code gen is for IStringable::ToString()