Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Ignore allocations inside Debug.Assert #52

Open
benaadams opened this issue Aug 5, 2018 · 2 comments
Open

Ignore allocations inside Debug.Assert #52

benaadams opened this issue Aug 5, 2018 · 2 comments

Comments

@benaadams
Copy link

As they are removed in release mode.

e.g. from SqlDataReader

Debug.Assert(SniContext.Snix_Read == stateObj.SniContext, string.Format((IFormatProvider)null, "The SniContext should be Snix_Read but it actually is {0}", stateObj.SniContext));

Produces

HAA0601	Value type to reference type conversion causes boxing at call site (here), and unboxing at the callee-site. Consider using generics if applicable
@edespong
Copy link
Contributor

edespong commented Nov 3, 2018

If we want to generalize it, anything marked with attribute [System.Diagnostics.Conditional("DEBUG")] should be ignored.

To solve this, my feeling is that it is needed to check every type of allocation, check if any of its parent syntax nodes is a InvocationExpression (or cannot possible have a parent who is) and then check its attributes or against a known list (e.g. "System.Diagnostics.Debug.Assert").

@mjsabby
Copy link
Contributor

mjsabby commented Nov 10, 2018

@edespong yeah. We do a lot of similar walks, so I don't think it should be that big of a perf hit.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants