@@ -37,20 +37,28 @@ class UEmptyHeap<Field, ArrayType>(private val ctx: UContext) : UReadOnlySymboli
3737
3838interface UHeap <Ref , Value , SizeT , Field , ArrayType , Guard > : UReadOnlyHeap <Ref , Value , SizeT , Field , ArrayType , Guard > {
3939 fun <Sort : USort > writeField (ref : Ref , field : Field , sort : Sort , value : Value , guard : Guard )
40- fun <Sort : USort > writeArrayIndex (ref : Ref , index : SizeT , type : ArrayType , elementSort : Sort , value : Value , guard : Guard )
40+ fun <Sort : USort > writeArrayIndex (
41+ ref : Ref ,
42+ index : SizeT ,
43+ type : ArrayType ,
44+ elementSort : Sort ,
45+ value : Value ,
46+ guard : Guard
47+ )
4148
4249 fun writeArrayLength (ref : Ref , size : SizeT , arrayType : ArrayType )
4350
4451 fun <Sort : USort > memset (ref : Ref , type : ArrayType , sort : Sort , contents : Sequence <Value >)
45- fun <Sort : USort > memcpy (
52+ fun <Sort : USort > memcpy (
4653 srcRef : Ref ,
4754 dstRef : Ref ,
4855 type : ArrayType ,
49- sort : Sort ,
56+ elementSort : Sort ,
5057 fromSrcIdx : SizeT ,
5158 fromDstIdx : SizeT ,
5259 toDstIdx : SizeT ,
53- guard : Guard )
60+ guard : Guard
61+ )
5462
5563 fun allocate (): UConcreteHeapAddress
5664 fun allocateArray (count : SizeT ): UConcreteHeapAddress
@@ -143,20 +151,28 @@ data class URegionHeap<Field, ArrayType>(
143151 }
144152
145153 // TODO: Either prohibit merging concrete and symbolic heap addresses, or fork state by ite-refs here
146- override fun <Sort : USort > writeField (ref : UHeapRef , field : Field , sort : Sort , value : UExpr <out USort >, guard : UBoolExpr ) {
147- if (guard == = ctx.falseExpr)
148- return
154+ override fun <Sort : USort > writeField (
155+ ref : UHeapRef ,
156+ field : Field ,
157+ sort : Sort ,
158+ value : UExpr <out USort >,
159+ guard : UBoolExpr
160+ ) {
161+ // A write operation that never succeeds
162+ if (guard.isFalse) return
149163
150164 val valueToWrite = value.asExpr(sort)
151165
152166 when (ref) {
153167 is UConcreteHeapRef -> {
154- if (guard == = guard.ctx.trueExpr) {
155- allocatedFields = allocatedFields.put(Pair (ref.address, field), valueToWrite)
168+ val key = ref.address to field
169+ val allocatedFieldValue = if (guard.isTrue) {
170+ valueToWrite
156171 } else {
157- val iteValue = ctx.mkIte(guard, valueToWrite, readField(ref, field, sort))
158- allocatedFields = allocatedFields.put(ref.address to field, iteValue)
172+ ctx.mkIte(guard, valueToWrite, readField(ref, field, sort))
159173 }
174+
175+ allocatedFields = allocatedFields.put(key, allocatedFieldValue)
160176 }
161177
162178 else -> {
@@ -175,8 +191,8 @@ data class URegionHeap<Field, ArrayType>(
175191 value : UExpr <out USort >,
176192 guard : UBoolExpr
177193 ) {
178- if (guard == = ctx.falseExpr)
179- return
194+ // A write operation that never succeeds
195+ if (guard.isFalse) return
180196
181197 val valueToWrite = value.asExpr(elementSort)
182198
@@ -189,7 +205,7 @@ data class URegionHeap<Field, ArrayType>(
189205
190206 else -> {
191207 val region = inputArrayRegion(type, elementSort)
192- val newRegion = region.write(Pair ( ref, index) , valueToWrite, guard)
208+ val newRegion = region.write(ref to index, valueToWrite, guard)
193209 inputArrays = inputArrays.put(type, newRegion)
194210 }
195211 }
@@ -215,34 +231,37 @@ data class URegionHeap<Field, ArrayType>(
215231 TODO (" Not yet implemented" )
216232 }
217233
218- override fun <Sort : USort > memcpy (
234+ override fun <Sort : USort > memcpy (
219235 srcRef : UHeapRef ,
220236 dstRef : UHeapRef ,
221237 type : ArrayType ,
222- sort : Sort ,
238+ elementSort : Sort ,
223239 fromSrcIdx : USizeExpr ,
224240 fromDstIdx : USizeExpr ,
225241 toDstIdx : USizeExpr ,
226242 guard : UBoolExpr
227243 ) {
228- if (guard == = guard.ctx.falseExpr)
229- return
244+ // A copy operation that never succeeds
245+ if (guard.isFalse) return
230246
231247 val src = srcRef to fromSrcIdx
232248 val dst = dstRef to fromDstIdx
233- when (srcRef) {
249+
250+ when (srcRef) {
234251 is UConcreteHeapRef -> {
235- val srcRegion = allocatedArrayRegion(type, srcRef.address, sort)
252+ val srcRegion = allocatedArrayRegion(type, srcRef.address, elementSort)
253+
236254 when (dstRef) {
237255 is UConcreteHeapRef -> {
238- val dstRegion = allocatedArrayRegion(type, dstRef.address, sort )
256+ val dstRegion = allocatedArrayRegion(type, dstRef.address, elementSort )
239257 val keyConverter = UAllocatedToAllocatedKeyConverter (src, dst, toDstIdx)
240258 val newDstRegion = dstRegion.memcpy(srcRegion, fromDstIdx, toDstIdx, keyConverter, guard)
241259 allocatedArrays = allocatedArrays.put(dstRef.address, newDstRegion)
242260 }
261+
243262 is UIteExpr -> TODO ()
244263 else -> {
245- val dstRegion = inputArrayRegion(type, sort )
264+ val dstRegion = inputArrayRegion(type, elementSort )
246265 val keyConverter = UAllocatedToInputKeyConverter (src, dst, toDstIdx)
247266 val newDstRegion = dstRegion.memcpy(srcRegion, dst, dstRef to toDstIdx, keyConverter, guard)
248267 inputArrays = inputArrays.put(type, newDstRegion)
@@ -253,17 +272,19 @@ data class URegionHeap<Field, ArrayType>(
253272 is UIteExpr -> TODO ()
254273
255274 else -> {
256- val srcRegion = inputArrayRegion(type, sort)
275+ val srcRegion = inputArrayRegion(type, elementSort)
276+
257277 when (dstRef) {
258278 is UConcreteHeapRef -> {
259- val dstRegion = allocatedArrayRegion(type, dstRef.address, sort )
279+ val dstRegion = allocatedArrayRegion(type, dstRef.address, elementSort )
260280 val keyConverter = UInputToAllocatedKeyConverter (src, dst, toDstIdx)
261281 val newDstRegion = dstRegion.memcpy(srcRegion, fromDstIdx, toDstIdx, keyConverter, guard)
262282 allocatedArrays = allocatedArrays.put(dstRef.address, newDstRegion)
263283 }
284+
264285 is UIteExpr -> TODO ()
265286 else -> {
266- val dstRegion = inputArrayRegion(type, sort )
287+ val dstRegion = inputArrayRegion(type, elementSort )
267288 val keyConverter = UInputToInputKeyConverter (src, dst, toDstIdx)
268289 val newDstRegion = dstRegion.memcpy(srcRegion, dst, dstRef to toDstIdx, keyConverter, guard)
269290 inputArrays = inputArrays.put(type, newDstRegion)
0 commit comments