Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Oct 17, 2023
1 parent bf8fe01 commit 560137c
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim lambdaId As DebugId
Dim previousLambdaId As DebugId = Nothing
Dim runtimeRudeEdit As String = Nothing
If SlotAllocatorOpt?.TryGetPreviousLambda(lambdaOrLambdaBodySyntax, isLambdaBody, previousLambdaId, runtimeRudeEdit) = True Then
If SlotAllocatorOpt?.TryGetPreviousLambda(lambdaOrLambdaBodySyntax, isLambdaBody, previousLambdaId, runtimeRudeEdit) = True AndAlso runtimeRudeEdit Is Nothing Then
lambdaId = previousLambdaId
Else
lambdaId = New DebugId(_lambdaDebugInfoBuilder.Count, CompilationState.ModuleBuilderOpt.CurrentGenerationOrdinal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

Imports System.Collections.Immutable
Imports System.Reflection.Metadata.Ecma335
Imports Microsoft.CodeAnalysis.EditAndContinue.UnitTests
Imports Microsoft.CodeAnalysis.Emit
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.VisualBasic.EditAndContinue.UnitTests
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Roslyn.Test.Utilities

Expand Down Expand Up @@ -2219,5 +2221,119 @@ End Class

diff2.VerifyIL("C.F", expectedIL.Replace("<<VALUE>>", "2"))
End Sub

<Fact>
Public Sub LambdaWithRudeEdit()
Using test = New EditAndContinueTest()
test.AddBaseline(
source:="
Imports System
Class C
<N:0>Sub F()</N:0>
Dim <N:1>x = 1</N:1>
Dim a1 = new Action(<N:2>Sub() Console.WriteLine(0)</N:2>)
Dim a2 = new Action(<N:3>Sub() Console.WriteLine(1)</N:3>)
End Sub
End Class
",
validator:=
Sub(g)
End Sub).
AddGeneration(
source:="
Imports System
Class C
<N:0>Sub F()</N:0>
Dim <N:1>x = 1</N:1>
Dim a1 = new Action(<N:2>Sub() Console.WriteLine(x)</N:2>)
Dim a2 = new Action(<N:3>Sub() Console.WriteLine(1)</N:3>)
End Sub
End Class
",
edits:=
Function(source)
Return {
Edit(
SemanticEditKind.Update,
Function(c) c.GetMember("C.F"),
rudeEdits:=Function(n) If(ReferenceEquals(n, source.GetNode("N", 2)), "Rude edit!", Nothing),
preserveLocalVariables:=True)
}
End Function,
validator:=
Sub(g)
' Static lambda is reused.
' A new display class and method is generated for lambda that captures x.
g.VerifySynthesizedMembers(
"C: {_Closure$__, _Closure$__1-0#1}",
"C._Closure$__: {$I1-1, _Lambda$__1-1}",
"C._Closure$__1-0#1: {_Lambda$__0#1}")

g.VerifyMethodDefNames("F", "_Lambda$__1-0", "_Lambda$__1-1", ".ctor", "_Lambda$__0#1")

g.VerifyIL("
{
// Code size 67 (0x43)
.maxstack 2
IL_0000: nop
IL_0001: newobj 0x06000007
IL_0006: stloc.3
IL_0007: ldloc.3
IL_0008: ldc.i4.1
IL_0009: stfld 0x04000004
IL_000e: ldloc.3
IL_000f: ldftn 0x06000008
IL_0015: newobj 0x0A000009
IL_001a: stloc.s V_4
IL_001c: ldsfld 0x04000003
IL_0021: brfalse.s IL_002a
IL_0023: ldsfld 0x04000003
IL_0028: br.s IL_0040
IL_002a: ldsfld 0x04000001
IL_002f: ldftn 0x06000006
IL_0035: newobj 0x0A000009
IL_003a: dup
IL_003b: stsfld 0x04000003
IL_0040: stloc.s V_5
IL_0042: ret
}
{
// Code size 11 (0xb)
.maxstack 8
IL_0000: ldstr 0x70000005
IL_0005: newobj 0x0A00000A
IL_000a: throw
}
{
// Code size 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: ldc.i4.1
IL_0002: call 0x0A00000B
IL_0007: nop
IL_0008: ret
}
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call 0x0A00000C
IL_0006: ret
}
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld 0x04000004
IL_0007: call 0x0A00000B
IL_000c: nop
IL_000d: ret
}
")
End Sub).
Verify()
End Using
End Sub
End Class
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
kind As SemanticEditKind,
symbolProvider As Func(Of Compilation, ISymbol),
Optional newSymbolProvider As Func(Of Compilation, ISymbol) = Nothing,
Optional rudeEdits As Func(Of SyntaxNode, String) = Nothing,
Optional preserveLocalVariables As Boolean = False) As SemanticEditDescription
Return New SemanticEditDescription(kind, symbolProvider, newSymbolProvider, rudeEdits:=Nothing, preserveLocalVariables)
Return New SemanticEditDescription(kind, symbolProvider, newSymbolProvider, rudeEdits, preserveLocalVariables)
End Function

Friend Function ToLocalInfo(local As Cci.ILocalDefinition) As ILVisualizer.LocalInfo
Expand Down

0 comments on commit 560137c

Please sign in to comment.