Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BuildScripts/MakeInternal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ForEach ($file in $inputFiles)
{
$content = Get-Content -path $file
$content = $content -creplace "public(?=\s+(((abstract|sealed|static|record)\s+)?(partial\s+)?class|delegate|enum|interface|struct|record))", "internal"
$content = $content -replace "^\s*#pragma warning.*$", "" # remove any #pragma directive that could be reactivating our global disable
$content = ,"#pragma warning disable" + $content # $content is a list of lines, insert at the top
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This generates the #pragma warning disable for each internal files.
This way the warnings are not ignored in your standard code, in case you want to see and handle them individually

$outputPath = Join-Path $outputFolder (Split-Path $file -Leaf)
Out-File $outputPath UTF8 -InputObject $content
}
Original file line number Diff line number Diff line change
Expand Up @@ -550,5 +550,3 @@ protected internal virtual Expression VisitRuntimeVariables(RuntimeVariablesExpr

protected internal virtual Expression VisitDebugInfo(DebugInfoExpression node) => node;
}

#nullable restore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not necessary at the end of files, these directives are per-file.

1 change: 0 additions & 1 deletion src/FastExpressionCompiler/FastExpressionCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11436,4 +11436,3 @@ namespace System.Diagnostics.CodeAnalysis
public sealed class UnscopedRefAttribute : Attribute { }
}
#endif
#nullable restore
27 changes: 14 additions & 13 deletions src/FastExpressionCompiler/ILReader.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable disable

#if DEBUG
// #define DEBUG_INTERNALS
#endif
Expand All @@ -7,6 +9,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
Expand Down Expand Up @@ -613,21 +616,21 @@ public DynamicMethodILProvider(DynamicMethod method)

public static class ILFormatter
{
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8"));
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4"));
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2"));
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.Append($"V_{ordinal}");
public static StringBuilder Label(StringBuilder sb, int offset) => sb.Append($"IL_{offset:D4}");
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8", CultureInfo.InvariantCulture));
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4", CultureInfo.InvariantCulture));
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2", CultureInfo.InvariantCulture));
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.AppendFormat(CultureInfo.InvariantCulture, "V_{0}", ordinal);
public static StringBuilder Label(StringBuilder sb, int offset) => sb.AppendFormat(CultureInfo.InvariantCulture, "IL_{0:D4}", offset);

public static StringBuilder MultipleLabels(StringBuilder sb, int[] offsets)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warnings could be ignored, but I think it's good to set the culture in case there is a side effect when rendered "technical" values like these.

{
var length = offsets.Length;
for (var i = 0; i < length; i++)
{
sb.AppendFormat(i == 0 ? "(" : ", ");
sb.Append(i == 0 ? "(" : ", ");
sb.Append(Label(sb, offsets[i]));
}
sb.AppendFormat(")");
sb.Append(')');
return sb;
}

Expand All @@ -648,9 +651,9 @@ public static StringBuilder EscapedString(StringBuilder sb, string str)
else if (ch == '\"')
sb.Append("\\\"");
else if (ch == '\\')
sb.Append("\\");
sb.Append('\\');
else if (ch < 0x20 || ch >= 0x7f)
sb.AppendFormat("\\u{0:x4}", (int)ch);
sb.AppendFormat(CultureInfo.InvariantCulture, "\\u{0:x4}", (int)ch);
else
sb.Append(ch);
}
Expand All @@ -663,10 +666,10 @@ public static StringBuilder SigByteArrayToString(StringBuilder sb, byte[] sig)
var length = sig.Length;
for (var i = 0; i < length; i++)
{
sb.AppendFormat(i == 0 ? "SIG [" : " ");
sb.Append(i == 0 ? "SIG [" : " ");
sb.Append(Int8ToHex(sb, sig[i]));
}
sb.AppendFormat("]");
sb.Append(']');
return sb;
}
}
Expand Down Expand Up @@ -820,5 +823,3 @@ public MemberInfo AsMember(int token)

public byte[] AsSignature(int token) => this[token] as byte[];
}

#pragma warning restore CS1591
2 changes: 0 additions & 2 deletions src/FastExpressionCompiler/ImTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,5 +1583,3 @@ public struct SmallSet16<K, TEq>() where TEq : struct, IEq<K>
/// <summary>Set with 16 keys on stack and entries baked by the single array</summary>
public SmallMap<K, SmallMap.Entry<K>, TEq, Size16, Stack16<int>, Stack16<SmallMap.Entry<K>>, SmallMap.SingleArrayEntries<K, SmallMap.Entry<K>, TEq>> Set;
}

#nullable restore
19 changes: 10 additions & 9 deletions src/FastExpressionCompiler/TestTools.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#nullable disable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added #nullable disable for every file, since this will be necessary for internal files, and you really don't use nullable types.


using System;
using System.Linq;
using System.Text;
using System.Reflection;
Expand All @@ -19,6 +21,7 @@ namespace FastExpressionCompiler;

using FastExpressionCompiler.ILDecoder;
using FastExpressionCompiler.ImTools;
using System.Globalization;
using System.Linq.Expressions;
#endif

Expand All @@ -27,10 +30,10 @@ namespace FastExpressionCompiler;
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")]
public static class TestTools
{
public static bool AllowPrintIL = false;
public static bool AllowPrintCS = false;
public static bool AllowPrintExpression = false;
public static bool DisableAssertOpCodes = false;
public static bool AllowPrintIL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were valid warnings appearing in my build. Though doesn't matter much in this case.

public static bool AllowPrintCS;
public static bool AllowPrintExpression;
public static bool DisableAssertOpCodes;

static TestTools()
{
Expand Down Expand Up @@ -628,9 +631,9 @@ class CallerMemberNameAttribute : Attribute { }
class CallerLineNumberAttribute : Attribute { }

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
class CallerArgumentExpression : Attribute
class CallerArgumentExpressionAttribute : Attribute
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There would be a conflict otherwise in internal files in some fwks, it would be conflicted between this and the real ones when it's used later in the code.

Copy link
Owner

Choose a reason for hiding this comment

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

Funny, that missed it.

{
public CallerArgumentExpression(string parameterName) { }
public CallerArgumentExpressionAttribute(string parameterName) { }
}
#endif

Expand Down Expand Up @@ -1060,5 +1063,3 @@ public void Run<T>(T test, TestFlags flags = TestFlags.Default) where T : ITestX
}
}
}

#pragma warning restore CS1591