Skip to content

Commit

Permalink
Simplify JIT diff names
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Sep 3, 2024
1 parent 03a72a5 commit 00f139f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Runner/Helpers/JitDiffUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static string GetCommentMarkdown(string[] diffs, int lengthLimit, bool re
JobBase job,
(string Description, string DasmFile, string Name)[] diffs,
Func<string, string?>? tryGetExtraInfo,
Func<string, string> replaceMethodName,
int maxCount)
{
if (diffs.Length == 0)
Expand Down Expand Up @@ -183,7 +184,7 @@ await Parallel.ForAsync(0, diffs.Length, async (i, _) =>
StringBuilder sb = new();

sb.AppendLine("<details>");
sb.AppendLine($"<summary>{diff.Description} - {diff.Name}</summary>");
sb.AppendLine($"<summary>{diff.Description} - {replaceMethodName(diff.Name)}</summary>");
sb.AppendLine();

if (tryGetExtraInfo?.Invoke(diff.Name) is { } extraInfo)
Expand Down
1 change: 1 addition & 0 deletions Runner/Jobs/JitDiffJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private async Task UploadJitDiffExamplesAsync(string diffAnalyzeSummary, bool re
this,
JitDiffUtils.ParseDiffAnalyzeEntries(diffAnalyzeSummary, regressions),
tryGetExtraInfo: null,
replaceMethodName: name => name,
maxCount: 20);

string changes = JitDiffUtils.GetCommentMarkdown(diffs, GitHubHelpers.CommentLengthLimit, regressions, out bool truncated);
Expand Down
32 changes: 29 additions & 3 deletions Runner/Jobs/RegexDiffJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ await Task.WhenAll(
$"{JitDiffJob.DiffsPrDirectory}/{JitDiffJob.DasmSubdirectory}",
count: 1_000);

await UploadJitDiffExamplesAsync(diffAnalyzeSummary, regressions: true, TryGetExtraInfo);
await UploadJitDiffExamplesAsync(diffAnalyzeSummary, regressions: false, TryGetExtraInfo);
await UploadJitDiffExamplesAsync(diffAnalyzeSummary, regressions: true, TryGetExtraInfo, ReplaceDiffName);
await UploadJitDiffExamplesAsync(diffAnalyzeSummary, regressions: false, TryGetExtraInfo, ReplaceDiffName);

async Task<string> GenerateRegexAssemblyAsync(bool baseline)
{
Expand Down Expand Up @@ -577,6 +577,31 @@ async Task<string> GenerateRegexAssemblyAsync(bool baseline)
return null;
}

string ReplaceDiffName(string name)
{
// Generated_11132.KnownRegex_11132_0+RunnerFactory+Runner:Scan(System.ReadOnlySpan`1[ushort]):this
// Generated_7625.KnownRegex_7625_0+RunnerFactory+Runner:TryMatchAtCurrentPosition(System.ReadOnlySpan`1[ushort]):ubyte:this
if (TryExtractKnownPatternIndex(name, out int index))
{
int offset = name.IndexOf("+Runner:", StringComparison.Ordinal);
if (offset >= 0)
{
name = name.Substring(offset + "+Runner:".Length);

offset = name.IndexOf('(');
if (offset >= 0)
{
name = name.Substring(0, offset);

// KnownRegex_7625_0:TryMatchAtCurrentPosition
return $"KnownRegex_{index}:{name}";
}
}
}

return name;
}

static bool TryExtractKnownPatternIndex(string text, out int index)
{
// sealed class KnownRegex_12323_0 : Regex
Expand All @@ -598,12 +623,13 @@ static bool TryExtractKnownPatternIndex(string text, out int index)
}
}

private async Task UploadJitDiffExamplesAsync(string diffAnalyzeSummary, bool regressions, Func<string, string?> tryGetExtraInfo)
private async Task UploadJitDiffExamplesAsync(string diffAnalyzeSummary, bool regressions, Func<string, string?> tryGetExtraInfo, Func<string, string> replaceName)
{
var (diffs, noisyDiffsRemoved) = await JitDiffUtils.GetDiffMarkdownAsync(
this,
JitDiffUtils.ParseDiffAnalyzeEntries(diffAnalyzeSummary, regressions),
tryGetExtraInfo,
replaceName,
maxCount: 1_000);

string changes = JitDiffUtils.GetCommentMarkdown(diffs, GitHubHelpers.GistLengthLimit, regressions, out bool truncated);
Expand Down

0 comments on commit 00f139f

Please sign in to comment.