Skip to content

Commit 27e7ff8

Browse files
committed
[fix] splitting fixes, optimizations
1 parent e616b05 commit 27e7ff8

File tree

11 files changed

+343
-280
lines changed

11 files changed

+343
-280
lines changed

VSharp.SILI.Core/API.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ module API =
556556
| Ite iteType ->
557557
let filtered = iteType.filter (fun r -> Pointers.isBadRef r |> isTrue |> not)
558558
filtered.ToDisjunctiveGvs()
559-
|> List.iter (fun (g, r) -> state.memory.GuardedWriteClassField (Some g) (extractAddress r) field value)
560-
| _ -> state.memory.WriteClassField (extractAddress reference) field value
559+
|> List.iter (fun (g, r) -> state.memory.WriteClassField (Some g) (extractAddress r) field value)
560+
| _ -> state.memory.WriteClassField None (extractAddress reference) field value
561561

562562
let WriteClassField state reference field value =
563563
WriteClassFieldUnsafe emptyReporter state reference field value
@@ -733,7 +733,7 @@ module API =
733733
let symbolicCase address =
734734
let address, arrayType = memory.StringArrayInfo address (Some length)
735735
Copying.fillArray state address arrayType (makeNumber 0) length char
736-
memory.WriteClassField address Reflection.stringLengthField length
736+
memory.WriteClassField None address Reflection.stringLengthField length
737737
match string.term, concreteChar, concreteLen with
738738
| HeapRef({term = ConcreteHeapAddress a} as address, sightType), Some (:? char as c), Some (:? int as len)
739739
when cm.Contains a ->

VSharp.SILI.Core/Copying.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module internal Copying =
7575
let stringAddress = ConcreteHeapAddress stringConcreteAddress
7676
let stringAddress, arrayType = memory.StringArrayInfo stringAddress (Some arrayLength)
7777
copyArray state arrayAddress startIndex arrayType stringAddress (makeNumber 0) arrayType arrayLength
78-
memory.WriteClassField stringAddress Reflection.stringLengthField arrayLength
78+
memory.WriteClassField None stringAddress Reflection.stringLengthField arrayLength
7979

8080
let copyCharArrayToString (state : state) arrayAddress stringConcreteAddress startIndex length =
8181
let memory = state.memory

VSharp.SILI.Core/Memory.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,9 +2040,7 @@ module internal Memory =
20402040
self.CommonWriteArrayIndex None address indices arrayType value
20412041
member self.WriteArrayRange address fromIndices toIndices arrayType value =
20422042
self.CommonWriteArrayRange None address fromIndices toIndices arrayType value
2043-
member self.WriteClassField address field value =
2044-
self.CommonWriteClassField None address field value
2045-
member self.GuardedWriteClassField guard address field value =
2043+
member self.WriteClassField guard address field value =
20462044
self.CommonWriteClassField guard address field value
20472045

20482046
member self.WriteStackLocation key value = writeStackLocation key value

VSharp.SILI.Core/MemoryRegion.fs

Lines changed: 129 additions & 125 deletions
Large diffs are not rendered by default.

VSharp.SILI.Core/State.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ and IMemory =
257257

258258
abstract WriteStackLocation : stackKey -> term -> unit
259259

260-
abstract WriteClassField : term -> fieldId -> term -> unit
261-
abstract GuardedWriteClassField : term option -> term -> fieldId -> term -> unit
262-
260+
abstract WriteClassField : term option -> term -> fieldId -> term -> unit
263261
abstract Write : IErrorReporter -> term -> term -> unit
264262
abstract AllocateOnStack : stackKey -> term -> unit
265263

VSharp.SILI.Core/Terms.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,22 @@ and iteType = genericIteType<term>
220220
and genericIteType<'a> = {branches: (term * 'a) list; elseValue : 'a}
221221
with
222222
static member FromGvs gvs =
223-
if List.length gvs < 2 then internalfail "Empty and one-element unions are forbidden!"
223+
if List.length gvs < 2 then internalfail "Empty and one-element ite's are forbidden!"
224224
let branches, e = List.splitAt (List.length gvs - 1) gvs
225225
{branches = branches; elseValue = e |> List.head |> snd}
226+
226227
member x.mapValues mapper =
227228
{branches = List.map (fun (g, v) -> (g, mapper v)) x.branches; elseValue = mapper x.elseValue}
229+
228230
member x.filter predicate =
229231
if predicate x.elseValue then
230232
{branches = List.filter (snd >> predicate) x.branches; elseValue = x.elseValue}
231233
else
232234
List.filter (snd >> predicate) x.branches |> genericIteType<'a>.FromGvs
235+
236+
member x.exists predicate =
237+
predicate x.elseValue || List.exists (fun (g, v) -> predicate v) x.branches
238+
233239
member x.choose mapper =
234240
let chooser (g, v) = Option.bind (fun w -> Some(g, w)) (mapper v)
235241
match mapper x.elseValue with

VSharp.Test/Tests/Lists.cs

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -532,59 +532,6 @@ public static int TestOverlappingCopy1(int[] a, int i)
532532
return 3;
533533
}
534534

535-
[TestSvm(94)]
536-
public static int TestSolvingCopyOverwrittenValueUnreachable1(string[] a, string[] b)
537-
{
538-
if (a != null && b != null && a.Length > b.Length)
539-
{
540-
a[0] = "42";
541-
b[0] = "4";
542-
Array.Copy(a, 0, b, 0, b.Length);
543-
if (b[0] != "42") // unreachable
544-
{
545-
return -1;
546-
}
547-
548-
return 0;
549-
}
550-
551-
return 3;
552-
}
553-
554-
[TestSvm(95)]
555-
public static int TestSolvingCopyOverwrittenValueUnreachable2(string[] a, int i, string[] b)
556-
{
557-
if (a != null && b != null && a.Length > b.Length)
558-
{
559-
b[i] = "500";
560-
Array.Copy(a, 0, b, 0, b.Length);
561-
if (b.Length > 0 && a[i] != "500" && b[i] == "500") // unreachable
562-
{
563-
return -1;
564-
}
565-
566-
return 0;
567-
}
568-
569-
return 3;
570-
}
571-
572-
[TestSvm(94)]
573-
public static int TestSolvingCopy8(object[] a, object[] b, int i)
574-
{
575-
if (a.Length > b.Length && 0 <= i && i < b.Length)
576-
{
577-
Array.Fill(a, "abc");
578-
Array.Copy(a, b, b.Length);
579-
580-
if (b[i] == b[i + 1])
581-
return 42;
582-
return 10;
583-
}
584-
585-
return 3;
586-
}
587-
588535
[TestSvm(97)]
589536
public static int TestSolvingCopy9(object[] a, int i, object[] b)
590537
{
@@ -785,20 +732,6 @@ public class MyClass
785732
public int x;
786733
}
787734

788-
[TestSvm(88)]
789-
public static int LastRecordReachability(string[] a, string[] b, int i, string s)
790-
{
791-
a[i] = "1";
792-
b[1] = s;
793-
if (b[1] != s)
794-
{
795-
// unreachable
796-
return -1;
797-
}
798-
799-
return 0;
800-
}
801-
802735
[TestSvm(90)]
803736
public static int ArrayElementsAreReferences(MyClass[] a, int i, int j)
804737
{
@@ -924,44 +857,6 @@ public static int ConcreteDictionaryTest(int v)
924857
return 0;
925858
}
926859

927-
[TestSvm(100)]
928-
public static int ConcreteDictionaryTest1(int a, string b)
929-
{
930-
var d = new Dictionary<int, List<string>>();
931-
d.Add(1, new List<string> { "2", "3" });
932-
d.Add(4, new List<string> { "5", "6" });
933-
if (d.TryGetValue(a, out var res))
934-
{
935-
if (res.Contains(b))
936-
return 1;
937-
return 0;
938-
}
939-
940-
return 2;
941-
}
942-
943-
public class Person
944-
{
945-
public string FirstName { get; set; }
946-
public string LastName { get; init; }
947-
};
948-
949-
[TestSvm(95)]
950-
public static int IteKeyWrite(int i)
951-
{
952-
var a = new Person[4];
953-
a[0] = new Person() {FirstName = "asd", LastName = "qwe"};
954-
a[3] = new Person() {FirstName = "zxc", LastName = "vbn"};
955-
var p = a[i];
956-
p.FirstName = "323";
957-
if (i == 0 && a[3].FirstName == "323")
958-
{
959-
return -1;
960-
}
961-
962-
return 1;
963-
}
964-
965860
[TestSvm(100)]
966861
public static int ListContains(int a, int b)
967862
{
@@ -1413,33 +1308,6 @@ public static int ConcurrentDict(int a, int b)
14131308
return -1;
14141309
return 0;
14151310
}
1416-
[TestSvm(95)]
1417-
public static int TestSplittingWithCopy(int srcI, int dstI, int len)
1418-
{
1419-
string[] arr = {"a", "b", "c", "d", "e"};
1420-
var a = new string[5];
1421-
Array.Copy(arr, srcI, a, dstI, len);
1422-
if (a[2].Length == 3)
1423-
return -1;
1424-
return 1;
1425-
}
1426-
[TestSvm(91)]
1427-
public static int TestSplittingWithCopyRegionsImportance(string[] a, int i)
1428-
{
1429-
a[i] = "a";
1430-
a[1] = "b";
1431-
var b = new string[a.Length];
1432-
Array.Copy(a, 0, b, 0, a.Length);
1433-
if (i == 1 && b[i] == "a") // unreachable
1434-
// record b[i], "a" exists only if i != 1
1435-
return -1;
1436-
if (i != 1 && b[i] != "a") // unreachable
1437-
{
1438-
return -2;
1439-
}
1440-
1441-
return 1;
1442-
}
14431311

14441312
[TestSvm(83)]
14451313
public static int VolatileWrite()

0 commit comments

Comments
 (0)