@@ -301,6 +301,88 @@ public void testCompiletimeObjectIdMigrationStress() {
301301 " testSuccess()" );
302302 }
303303
304+ @ Test
305+ public void testInterpreterIdRecyclingWithHashMap () {
306+ test ().withStdLib ()
307+ .executeProg (true )
308+ .runCompiletimeFunctions (true )
309+ .executeProgOnlyAfterTransforms ()
310+ .lines ("package Hello" ,
311+ "import HashMap" ,
312+ "class MyClass" ,
313+ " int payload" ,
314+ "" ,
315+ " construct(int payload)" ,
316+ " this.payload = payload" ,
317+ "" ,
318+ "function buildSequence(string label) returns string" ,
319+ " let map = new HashMap<int, MyClass>" ,
320+ "" ,
321+ " let a = new MyClass(11)" ,
322+ " let b = new MyClass(23)" ,
323+ " let c = new MyClass(37)" ,
324+ "" ,
325+ " let idA = a castTo int" ,
326+ " let idB = b castTo int" ,
327+ " let idC = c castTo int" ,
328+ "" ,
329+ " map.put(idA, a)" ,
330+ " map.put(idB, b)" ,
331+ " map.put(idC, c)" ,
332+ " print(label + \" create a id=\" + idA.toString() + \" payload=11\" )" ,
333+ " print(label + \" create b id=\" + idB.toString() + \" payload=23\" )" ,
334+ " print(label + \" create c id=\" + idC.toString() + \" payload=37\" )" ,
335+ "" ,
336+ " map.remove(idB)" ,
337+ " print(label + \" remove b-from-map id=\" + idB.toString())" ,
338+ " destroy b" ,
339+ " print(label + \" destroy b id=\" + idB.toString())" ,
340+ "" ,
341+ " let d = new MyClass(41)" ,
342+ " let idD = d castTo int" ,
343+ " map.put(idD, d)" ,
344+ " print(label + \" create d id=\" + idD.toString() + \" payload=41\" )" ,
345+ " print(label + \" recycled b->d = \" + (idB == idD).toString())" ,
346+ "" ,
347+ " var prev = new MyClass(100)" ,
348+ " var prevId = prev castTo int" ,
349+ " print(label + \" cycle seed id=\" + prevId.toString())" ,
350+ " for i = 1 to 4" ,
351+ " destroy prev" ,
352+ " print(label + \" cycle \" + i.toString() + \" destroy id=\" + prevId.toString())" ,
353+ " let next = new MyClass(100 + i)" ,
354+ " let nextId = next castTo int" ,
355+ " print(label + \" cycle \" + i.toString() + \" create id=\" + nextId.toString() + \" recycled=\" + (nextId == prevId).toString())" ,
356+ " prev = next" ,
357+ " prevId = nextId" ,
358+ " destroy prev" ,
359+ " print(label + \" final destroy id=\" + prevId.toString())" ,
360+ "" ,
361+ " map.get(idA).payload.assertEquals(11)" ,
362+ " map.get(idC).payload.assertEquals(37)" ,
363+ " map.get(idD).payload.assertEquals(41)" ,
364+ " map.size().assertEquals(3)" ,
365+ "" ,
366+ " let seqA = map.get(idA).payload * 100 + map.get(idC).payload" ,
367+ " let seqB = map.get(idD).payload * 10 + map.size()" ,
368+ " let recycled = (idB == idD).toInt()" ,
369+ "" ,
370+ " let sequence = seqA.toString() + \" :\" + seqB.toString() + \" :\" + recycled.toString()" ,
371+ " print(label + \" \" + sequence)" ,
372+ " return sequence" ,
373+ "" ,
374+ "init" ,
375+ " let sequence = buildSequence(\" RT\" )" ,
376+ " if sequence == \" 1137:413:1\" " ,
377+ " testSuccess()" ,
378+ "" ,
379+ "@compiletime" ,
380+ "function interpreterIdRecyclingCompiletime()" ,
381+ " let sequence = buildSequence(\" CT\" )" ,
382+ " print(\" CT-VERIFY \" + sequence)" ,
383+ " sequence.assertEquals(\" 1137:413:1\" )" );
384+ }
385+
304386 @ Test
305387 public void checkCompiletimeAnnotation1 () {
306388 testAssertErrorsLines (false , "Functions annotated '@compiletime' may not take parameters." ,
0 commit comments