aa
com.cliffc.aa.type.TestApprox Class Reference

Public Member Functions

void testApprox1 ()
 
void testApprox2 ()
 
void testApprox3 ()
 
void testApprox4 ()
 
void testApprox5 ()
 
void testApprox6 ()
 
void testApprox7 ()
 
void testApprox8 ()
 
void testTSMeet ()
 
void testType ()
 

Private Member Functions

void check_leaf (TypeMemPtr p, int alias, TypeInt vt)
 

Detailed Description

Definition at line 11 of file TestApprox.java.

Member Function Documentation

◆ check_leaf()

void com.cliffc.aa.type.TestApprox.check_leaf ( TypeMemPtr  p,
int  alias,
TypeInt  vt 
)
private

Definition at line 483 of file TestApprox.java.

483  {
484  TypeStruct z = (TypeStruct)p._obj;
485  assertSame( vt, z.at(0));
486  Type x1 = z.at(1);
487  if( x1 != Type.NIL ) {
488  TypeMemPtr px = (TypeMemPtr)x1;
489  assertTrue(px._aliases.test(alias));
490  }
491  Type x2 = z.at(2);
492  if( x2 != Type.NIL ) {
493  TypeMemPtr px = (TypeMemPtr)x2;
494  assertTrue(px._aliases.test(alias));
495  }
496  }

References com.cliffc.aa.type.TypeMemPtr._aliases, com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.Type< T extends Type< T >.NIL, and com.cliffc.aa.type.Bits< B extends Bits< B >.test().

Referenced by com.cliffc.aa.type.TestApprox.testApprox4().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testApprox1()

void com.cliffc.aa.type.TestApprox.testApprox1 ( )

Definition at line 54 of file TestApprox.java.

54  {
55  final int CUTOFF = 3;
56  int alias0 = BitsAlias.new_alias(BitsAlias.REC);
57 
58  // Build a depth-CUTOFF linked list chain
59  TypeStruct t0 = TypeStruct.make(TypeFld.make("a",Type.XNIL ,0),
60  TypeFld.make("b",TypeInt.con(99),1));
61  TypeMemPtr p0 = TypeMemPtr.make(alias0,t0);
62  HashMap<Type,Integer> ds = p0.depth();
63  assertEquals(0,(int)ds.get(t0));
64 
65  TypeStruct t1 = TypeStruct.make(TypeFld.make("a",p0,0), TypeFld.make("b",TypeInt.con(98),1));
66  TypeMemPtr p1 = TypeMemPtr.make(alias0,t1);
67  ds = p1.depth();
68  assertEquals(1,(int)ds.get(t0));
69  assertEquals(0,(int)ds.get(t1));
70  assertEquals(0,(int)ds.get(p0));
71 
72  TypeStruct t2 = TypeStruct.make(TypeFld.make("a",p1,0), TypeFld.make("b",TypeInt.con(97),1));
73  TypeMemPtr p2 = TypeMemPtr.make(alias0,t2);
74  ds = p2.depth();
75  assertEquals(2,(int)ds.get(t0));
76 
77  TypeStruct t3 = TypeStruct.make(TypeFld.make("a",p2,0), TypeFld.make("b",TypeInt.con(96),1));
78  TypeMemPtr p3 = TypeMemPtr.make(alias0,t3);
79  ds = p3.depth();
80  assertEquals(CUTOFF ,(int)ds.get(t0));
81  assertEquals(CUTOFF-1,(int)ds.get(t1));
82  assertEquals(1,(int)ds.get(t2));
83  assertEquals(0,(int)ds.get(t3));
84  // No single depth is beyond cutoff
85  assertEquals(CUTOFF,TypeMemPtr.max(alias0,ds));
86 
87  // For all TypeStruct X at depth CUTOFF-1, make a clone of X and X's sub-
88  // graph, except every edge to a type at depth CUTOFF is replaced with the
89  // X clone.
90 
91  // original, too deep
92  // t3[,99] -> p2 -> t2[,99] -> p1 -> t1[,flt] -> p0 -> t0[,int] -> nil
93 
94  // replace ptrs to t0 with ptrs to t1
95  // t3[,99] -> p2 -> t2[,99] -> p1 -> t1[,flt] -> p0 -> t1*
96 
97  // collapse redundant ptrs to t1, and MEET t0-tail and t1-tail
98  // t3[,99] -> p2 -> t2[,99] -> {p0,p1} -> t1[,{flt&int}] -> {p0,p1}
99 
100  TypeStruct tax = t3.approx(CUTOFF,alias0);
101  TypeMemPtr pax = TypeMemPtr.make(alias0,tax);
102  HashMap<Type,Integer> ds2 = pax.depth();
103  assertEquals(CUTOFF,TypeMemPtr.max(alias0,ds2));
104  TypeMemPtr txp1 = (TypeMemPtr)tax.at(0);
105  assertEquals(0,(int)ds2.get(txp1));
106  TypeStruct txs1 = (TypeStruct)txp1._obj;
107  assertEquals(1,(int)ds2.get(txs1));
108  TypeMemPtr txp2 = (TypeMemPtr)txs1.at(0);
109  assertEquals(1,(int)ds2.get(txp2));
110  TypeStruct txs2 = (TypeStruct)txp2._obj;
111  assertEquals(2,(int)ds2.get(txs2));
112  assertEquals(TypeInt.NINT8,txs2.at(1));
113  TypeMemPtr txp3 = (TypeMemPtr)txs2.at(0);
114  assertEquals(2,(int)ds2.get(txp3));
115  // Weakened expected results after NIL expands to [0]->obj
116  assertEquals(txs2,txp3._obj);
117  //assertEquals(TypeObj.OBJ,txp3._obj);
118 
119  assertTrue(t3.isa(tax));
120  }

References com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TypeInt.con(), com.cliffc.aa.type.TypeMemPtr.depth(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMemPtr.max(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.TypeInt.NINT8, com.cliffc.aa.type.BitsAlias.REC, and com.cliffc.aa.type.Type< T extends Type< T >.XNIL.

Here is the call graph for this function:

◆ testApprox2()

void com.cliffc.aa.type.TestApprox.testApprox2 ( )

Definition at line 124 of file TestApprox.java.

124  {
125  final int CUTOFF = 3;
126  int alias0 = BitsAlias.new_alias(BitsAlias.REC);
127  BitsAlias alias = BitsAlias.make0(alias0);
128 
129  // p3 -> t3[,99] -> p2 -> t2[,99] -> p1 -> t1[,flt] -> p0 -> t0[,int] -> p1*
130 
131  // Build two structs pointing to each other
132  Object dummy0 = TypeStruct.TYPES;
133  Object dummy1 = TypeMemPtr.TYPES;
134  Type.RECURSIVE_MEET++;
135  TypeFld[] flds0 = TypeFlds.ts(TypeFld.malloc("a",null,0), TypeFld.malloc("b",null,1));
136  TypeFld[] flds1 = TypeFlds.ts(TypeFld.malloc("a",null,0), TypeFld.malloc("b",null,1));
137  TypeStruct t0 = TypeStruct.malloc("",false,flds0,true);
138  TypeStruct t1 = TypeStruct.malloc("",false,flds1,true);
139  t0._hash = t0.compute_hash(); t0._cyclic = true;
140  t1._hash = t1.compute_hash(); t1._cyclic = true;
141  TypeMemPtr p0 = TypeMemPtr.make(alias0,t0);
142  TypeMemPtr p1 = TypeMemPtr.make(alias0,t1);
143  t0.fld(0).setX(p1 );
144  t0.fld(1).setX(TypeInt.INT64);
145  t1.fld(0).setX(p0 );
146  t1.fld(1).setX(TypeFlt.FLT64);
147  Type.RECURSIVE_MEET--;
148  t0 = t0.install_cyclic(t0.reachable());
149  p1 = (TypeMemPtr)t0.at(0);
150 
151  HashMap<Type,Integer> ds = p1.depth();
152  assertEquals(1,(int)ds.get(t0));
153  assertEquals(0,(int)ds.get(t1));
154 
155  // Build a depth-CUTOFF linked list chain
156  TypeStruct t2 = TypeStruct.make(TypeFld.make("a",p1,0), TypeFld.make("b",TypeInt.con(99),1));
157  TypeMemPtr p2 = TypeMemPtr.make(alias0,t2);
158  ds = p2.depth();
159  assertEquals(2,(int)ds.get(t0));
160 
161  TypeStruct t3 = TypeStruct.make(TypeFld.make("a",p2,0), TypeFld.make("b",TypeInt.con(98),1));
162  TypeMemPtr p3 = TypeMemPtr.make(alias0,t3);
163  ds = p3.depth();
164  assertEquals(CUTOFF ,(int)ds.get(t0));
165  assertEquals(CUTOFF-1,(int)ds.get(t1));
166  assertEquals(1,(int)ds.get(t2));
167  assertEquals(0,(int)ds.get(t3));
168  // No single depth is beyond cutoff
169  assertEquals(CUTOFF,TypeMemPtr.max(alias0,ds));
170 
171  // For all TypeStruct X at depth CUTOFF-1, make a clone of X and X's sub-
172  // graph, except every edge to a type at depth CUTOFF is replaced with the
173  // X clone.
174 
175  // original, too deep
176  // t3[,98] -> p2 -> t2[,99] -> p1 -> t1[,flt] -> p0 -> t0[,int] -> p1*
177 
178  // replace ptrs to t0 with ptrs to t1
179  // t3[,98] -> p2 -> t2[,99] -> p1 -> t1[,flt] -> p0 -> t1*
180 
181  // collapse redundant ptrs to t1, and MEET t0-tail and t1-tail
182  // t3[,98] -> p2 -> t2[,99] -> {p0,p1} -> t1[,{flt&int}] -> {p0,p1}
183 
184  TypeStruct tax = t3.approx(CUTOFF,alias0);
185  TypeMemPtr pax = TypeMemPtr.make(alias0,tax);
186 
187  HashMap<Type,Integer> ds2 = pax.depth();
188  assertEquals(CUTOFF-1,TypeMemPtr.max(alias0,ds2));
189  TypeMemPtr txp1 = (TypeMemPtr)tax.at(0);
190  assertEquals(0,(int)ds2.get(txp1));
191  TypeStruct txs1 = (TypeStruct)txp1._obj;
192  assertEquals(1,(int)ds2.get(txs1));
193  TypeMemPtr txp2 = (TypeMemPtr)txs1.at(0);
194  assertEquals(1,(int)ds2.get(txp2));
195  TypeStruct txs2 = (TypeStruct)txp2._obj;
196  assertEquals(CUTOFF-1,(int)ds2.get(txs2));
197  assertEquals(Type.REAL,txs2.at(1));
198  TypeMemPtr txp3 = (TypeMemPtr)txs2.at(0);
199  // Pointer-equals; 'equals()' is not good enough
200  assertSame(txp2, txp3);
201  assertSame(txs2, txp3._obj);
202  assertTrue(t3.isa(tax));
203 
204  // Add another layer, and approx again
205  TypeStruct t4 = TypeStruct.make(TypeFld.make("a",pax,0), TypeFld.make("b",TypeInt.con(97),1));
206  TypeMemPtr p4 = TypeMemPtr.make(alias0,t4);
207  ds = p4.depth();
208  assertEquals(CUTOFF,(int)ds.get(txs2)); // Structure too deep
209  TypeStruct tax4 = t4.approx(CUTOFF,alias0);
210  TypeMemPtr pax4 = TypeMemPtr.make(alias0,tax4);
211 
212  ds2 = pax4.depth();
213  assertEquals(CUTOFF-1,TypeMemPtr.max(alias0,ds2));
214  TypeMemPtr t4p1 = (TypeMemPtr)tax4.at(0);
215  assertEquals(0,(int)ds2.get(t4p1));
216  TypeStruct t4s1 = (TypeStruct)t4p1._obj;
217  assertEquals(1,(int)ds2.get(t4s1));
218  TypeMemPtr t4p2 = (TypeMemPtr)t4s1.at(0);
219  assertEquals(1,(int)ds2.get(t4p2));
220  TypeStruct t4s2 = (TypeStruct)t4p2._obj;
221  assertEquals(CUTOFF-1,(int)ds2.get(t4s2));
222  assertEquals(Type.REAL,t4s2.at(1));
223  TypeMemPtr t4p3 = (TypeMemPtr)t4s2.at(0);
224  assertEquals(1,(int)ds2.get(t4p3));
225  assertEquals(t4s2,t4p3._obj);
226  assertTrue(t4.isa(tax4));
227  }

References com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TypeStruct.compute_hash(), com.cliffc.aa.type.TypeInt.con(), com.cliffc.aa.type.TypeMemPtr.depth(), com.cliffc.aa.type.TypeStruct.fld(), com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.BitsAlias.make0(), com.cliffc.aa.type.TypeFld.malloc(), com.cliffc.aa.type.TypeStruct.malloc(), com.cliffc.aa.type.TypeMemPtr.max(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.Type< T extends Type< T >.REAL, com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.Type< T extends Type< T >.RECURSIVE_MEET, com.cliffc.aa.type.TypeFld.setX(), com.cliffc.aa.type.TypeFlds.ts(), com.cliffc.aa.type.TypeMemPtr.TYPES, and com.cliffc.aa.type.TypeStruct.TYPES.

Here is the call graph for this function:

◆ testApprox3()

void com.cliffc.aa.type.TestApprox.testApprox3 ( )

Definition at line 233 of file TestApprox.java.

233  {
234  int alias0 = BitsAlias.new_alias(BitsAlias.REC);
235  int alias1 = BitsAlias.new_alias(BitsAlias.REC);
236 
237  // ......................................................... -> X5
238  Type str_x5 = TypeStr.con("X5");
239  TypeStruct x5 = TypeStruct.make(TypeFld.make("v",str_x5 ,0),
240  TypeFld.make("x",Type.XNIL,1),
241  TypeFld.make("a",Type.XNIL,2));
242  TypeMemPtr px5 = TypeMemPtr.make(alias1,x5);
243 
244  // ................................................... -> A3 -> X5
245  TypeStr str_a3 = TypeStr.con("A3");
246  TypeStruct a3 = TypeStruct.make(TypeFld.make("v",str_a3,0),
247  TypeFld.make("x",px5 ,1));
248  TypeMemPtr pa3 = TypeMemPtr.make(alias0,a3);
249 
250  // Build two structs pointing to each other
251  // ...................................... (X3 <-> X4 ) -> A3 -> X5
252  Type i13 = TypeStr.con("X3");
253  Type i14 = TypeStr.con("X4");
254  TypeFld fi13 = TypeFld.make("v",i13,0);
255  TypeFld fi14 = TypeFld.make("v",i14,0);
256  TypeFld fpa3 = TypeFld.make("a",pa3,2);
257  Type.RECURSIVE_MEET++;
258  TypeFld[] flds3 = TypeFlds.ts(fi13, TypeFld.malloc("x",null,1), fpa3);
259  TypeFld[] flds4 = TypeFlds.ts(fi14, TypeFld.malloc("x",null,1), fpa3);
260  TypeStruct x3 = TypeStruct.malloc("",false,flds3,true);
261  TypeStruct x4 = TypeStruct.malloc("",false,flds4,true);
262  x3._hash = x3.compute_hash(); x3._cyclic = true;
263  x4._hash = x4.compute_hash(); x4._cyclic = true;
264  TypeMemPtr px3 = TypeMemPtr.make(alias1,x3);
265  TypeMemPtr px4 = TypeMemPtr.make(alias1,x4);
266  x3.fld(1).setX(px4);
267  x4.fld(1).setX(px3);
268  Type.RECURSIVE_MEET--;
269  x3 = x3.install_cyclic(x3.reachable());
270  px3 = (TypeMemPtr)x4.at(1);
271 
272  // ................................ A2 -> (X3 <-> X4 ) -> A3 -> X5
273  TypeStr str_a2 = TypeStr.con("A2");
274  TypeStruct a2 = TypeStruct.make(TypeFld.make("v",str_a2,0),
275  TypeFld.make("x",px3 ,1));
276  TypeMemPtr pa2 = TypeMemPtr.make(alias0,a2);
277 
278  // Check sanity
279  HashMap<Type,Integer> depths = pa2.depth();
280  int maxd = TypeMemPtr.max(alias0,depths);
281  assertEquals(1,maxd);
282  assertEquals(1,(int)depths.get(a3));
283 
284  // .......................... X2 -> A2 -> (X3 <-> X4 ) -> A3 -> X5
285  TypeStruct x2 = TypeStruct.make(TypeFld.make("v",TypeStr.con("X2"),0),
286  TypeFld.make("x",Type.NIL,1),
287  TypeFld.make("a",pa2,2));
288  TypeMemPtr px2 = TypeMemPtr.make(alias1,x2);
289 
290  // .................... A1 -> X2 -> A2 -> (X3 <-> X4 ) -> A3 -> X5
291  TypeStruct a1 = TypeStruct.make(TypeFld.make("v",TypeStr.con("A1"),0),
292  TypeFld.make("x",px2,1));
293  TypeMemPtr pa1 = TypeMemPtr.make(alias0,a1);
294 
295  // Build two structs pointing to each other
296  // ..... (X0 <-> X1) -> A1 -> X2 -> A2 -> (X3 <-> X4 ) -> A3 -> X5
297  Type i10 = TypeStr.con("X0");
298  Type i11 = TypeStr.con("X1");
299  TypeFld fil0 = TypeFld.make("v",i10,0);
300  TypeFld fil1 = TypeFld.make("v",i11,0);
301  TypeFld fpa1 = TypeFld.make("a",pa1,2);
302  Type.RECURSIVE_MEET++;
303  TypeFld[] flds0 = TypeFlds.ts(fil0, TypeFld.malloc("x",null,1), fpa1);
304  TypeFld[] flds1 = TypeFlds.ts(fil1, TypeFld.malloc("x",null,1), fpa1);
305  TypeStruct x0 = TypeStruct.malloc("",false,flds0,true);
306  TypeStruct x1 = TypeStruct.malloc("",false,flds1,true);
307  x0._hash = x0.compute_hash(); x0._cyclic = true;
308  x1._hash = x1.compute_hash(); x1._cyclic = true;
309  TypeMemPtr px0 = TypeMemPtr.make(alias1,x0);
310  TypeMemPtr px1 = TypeMemPtr.make(alias1,x1);
311  x0.fld(1).setX(px1);
312  x1.fld(1).setX(px0);
313  Type.RECURSIVE_MEET--;
314  x0 = x0.install_cyclic(x0.reachable());
315  px0 = (TypeMemPtr)x1.at(1);
316 
317  // A0 -> (X0 <-> X1) -> A1 -> X2 -> A2 -> (X3 <-> X4 ) -> A3 -> X5
318  TypeStruct a0 = TypeStruct.make(TypeFld.make("v",TypeStr.con("A0"),0),
319  TypeFld.make("x",px0,1));
320  TypeMemPtr pa0 = TypeMemPtr.make(alias0,a0);
321 
322  // Check sanity
323  depths = pa0.depth();
324  assertEquals(0,(int)depths.get(a0));
325  assertEquals(1,(int)depths.get(a1));
326  assertEquals(2,(int)depths.get(a2));
327  assertEquals(3,(int)depths.get(a3));
328  assertEquals(3,TypeMemPtr.max(alias0,depths));
329 
330  // Approximate
331  TypeStruct zsa0 = a0.approx(3,alias0);
332  TypeMemPtr pzsa0 = TypeMemPtr.make(alias0,zsa0);
333 
334  // Check sanity!
335  // Was: A0 -> (X0 <-> X1) -> A1 -> X2 -> A2 -> (X3 <-> X4) -> A3 -> X5
336  // Apx: A0 -> (X0 <-> X1) -> A1 -> X2 -> A23-> X35 -> (X4 <-> X3) -> A23
337  assertSame(TypeStr.con("A0"), zsa0.at(0));
338  TypeMemPtr zpx0 = (TypeMemPtr)zsa0.at(1);
339 
340  TypeStruct zsx0 = (TypeStruct)zpx0._obj;
341  assertSame (i10 , zsx0.at(0));
342  TypeMemPtr zpx1 = (TypeMemPtr)zsx0.at(1);
343  TypeMemPtr zpa1 = (TypeMemPtr)zsx0.at(2);
344 
345  TypeStruct zsx1 = (TypeStruct)zpx1._obj;
346  assertSame (i11 , zsx1.at(0));
347  assertSame (zpx0, zsx1.at(1));
348  assertSame (zpa1, zsx1.at(2));
349 
350  TypeStruct zsa1 = (TypeStruct)zpa1._obj;
351  assertSame(TypeStr.con("A1"), zsa1.at(0));
352  TypeMemPtr zpx2 = (TypeMemPtr)zsa1.at(1);
353 
354  TypeStruct zsx2 = (TypeStruct)zpx2._obj;
355  assertSame(TypeStr.con("X2"), zsx2.at(0));
356  assertSame(Type.NIL, zsx2.at(1));
357  TypeMemPtr zpa23= (TypeMemPtr)zsx2.at(2);
358 
359  TypeStruct zsa23= (TypeStruct)zpa23._obj;
360  assertSame(str_a2.meet(str_a3), zsa23.at(0));
361  TypeMemPtr zpx35= (TypeMemPtr)zsa23.at(1);
362 
363  TypeStruct zsx35= (TypeStruct)zpx35._obj;
364  assertSame(str_x5.meet(i13), zsx35.at(0));
365  TypeMemPtr zpa4 = (TypeMemPtr)zsx35.at(1) ;
366  TypeMemPtr zpa23q=(TypeMemPtr)zsx35.at(2) ;
367  // Weakened expected results after NIL expands to [0]->obj
368  assertSame(zsa23, zpa23q._obj);
369  //assertSame(TypeObj.OBJ, zpa23q._obj);
370  TypeStruct zsx4 = (TypeStruct)zpa4._obj;
371  assertSame(i14, zsx4.at(0));
372  assertSame(zpx35, zsx4.at(1));
373  assertSame(zpa23, zsx4.at(2));
374 
375  depths = pzsa0.depth();
376  assertEquals(0,(int)depths.get(zsa0));
377  assertEquals(1,(int)depths.get(zsa1));
378  assertEquals(2,(int)depths.get(zsa23));
379  assertEquals(3,TypeMemPtr.max(alias0,depths));
380  assertTrue(a0.isa(zsa0));
381  }

References com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TypeStruct.compute_hash(), com.cliffc.aa.type.TypeStr.con(), com.cliffc.aa.type.TypeMemPtr.depth(), com.cliffc.aa.type.TypeStruct.fld(), com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeFld.malloc(), com.cliffc.aa.type.TypeStruct.malloc(), com.cliffc.aa.type.TypeMemPtr.max(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.Type< T extends Type< T >.NIL, com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.Type< T extends Type< T >.RECURSIVE_MEET, com.cliffc.aa.type.TypeFld.setX(), com.cliffc.aa.type.TypeFlds.ts(), and com.cliffc.aa.type.Type< T extends Type< T >.XNIL.

Here is the call graph for this function:

◆ testApprox4()

void com.cliffc.aa.type.TestApprox.testApprox4 ( )

Definition at line 401 of file TestApprox.java.

401  {
402  final int CUTOFF = 3;
403  int alias = BitsAlias.new_alias(BitsAlias.REC);
404  TypeFld lnil = TypeFld.make("l",Type.NIL,1);
405  TypeFld rnil = TypeFld.make("r",Type.NIL,2);
406 
407  TypeStruct x12= TypeStruct.make(TypeFld.make("v",TypeInt.con(12),0),lnil,rnil);
408  TypeMemPtr px12= TypeMemPtr.make(alias,x12);
409 
410  TypeStruct x10= TypeStruct.make(TypeFld.make("v",TypeInt.con(10),0),lnil,rnil);
411  TypeMemPtr px10= TypeMemPtr.make(alias,x10);
412 
413  TypeStruct x9 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 9),0),lnil,rnil);
414  TypeMemPtr px9 = TypeMemPtr.make(alias,x9 );
415 
416  TypeStruct x8 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 8),0),lnil,rnil);
417  TypeMemPtr px8 = TypeMemPtr.make(alias,x8 );
418 
419  TypeStruct x7 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 7),0),lnil,rnil);
420  TypeMemPtr px7 = TypeMemPtr.make(alias,x7 );
421 
422  TypeStruct x6 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 6),0),TypeFld.make("l",px12,1),rnil);
423  TypeMemPtr px6 = TypeMemPtr.make(alias,x6 );
424 
425  TypeStruct x5 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 5),0),TypeFld.make("l",px10,1),rnil);
426  TypeMemPtr px5 = TypeMemPtr.make(alias,x5 );
427 
428  TypeStruct x4 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 4),0),TypeFld.make("l",px8 ,1),TypeFld.make("r",px9,2) );
429  TypeMemPtr px4 = TypeMemPtr.make(alias,x4 );
430 
431  TypeStruct x3 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 3),0),TypeFld.make("l",px6 ,1),TypeFld.make("r",px7,2) );
432  TypeMemPtr px3 = TypeMemPtr.make(alias,x3 );
433 
434  TypeStruct x2 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 2),0),TypeFld.make("l",px4 ,1),TypeFld.make("r",px5,2) );
435  TypeMemPtr px2 = TypeMemPtr.make(alias,x2 );
436 
437  TypeStruct x1 = TypeStruct.make(TypeFld.make("v",TypeInt.con( 1),0),TypeFld.make("l",px2 ,1),TypeFld.make("r",px3,2) );
438  TypeMemPtr px1 = TypeMemPtr.make(alias,x1 );
439 
440  // Check sanity
441  HashMap<Type,Integer> depths = px1.depth();
442  assertEquals(0,(int)depths.get(x1));
443  assertEquals(1,(int)depths.get(x2));
444  assertEquals(1,(int)depths.get(x3));
445  assertEquals(2,(int)depths.get(x4));
446  assertEquals(2,(int)depths.get(x5));
447  assertEquals(2,(int)depths.get(x6));
448  assertEquals(2,(int)depths.get(x7));
449  assertEquals(3,(int)depths.get(x8));
450  assertEquals(3,(int)depths.get(x9));
451  assertEquals(3,(int)depths.get(x10));
452  assertEquals(3,(int)depths.get(x12));
453  assertEquals(3,TypeMemPtr.max(alias,depths));
454 
455  // Approximate
456  TypeStruct z1 = x1.approx(CUTOFF,alias);
457  TypeMemPtr pz1 = TypeMemPtr.make(alias,z1);
458  assertSame( TypeInt.con(1), z1.at(0));
459  TypeMemPtr p2 = (TypeMemPtr)z1.at(1) ;
460  TypeMemPtr p3 = (TypeMemPtr)z1.at(2) ;
461 
462  TypeStruct z2 = (TypeStruct)p2._obj ;
463  assertSame( TypeInt.con(2), z2.at(0));
464  TypeMemPtr p4 = (TypeMemPtr)z2.at(1) ;
465  TypeMemPtr p5 = (TypeMemPtr)z2.at(2) ;
466 
467  TypeStruct z3 = (TypeStruct)p3._obj ;
468  assertSame( TypeInt.con(3), z3.at(0));
469  TypeMemPtr p6 = (TypeMemPtr)z3.at(1) ;
470  TypeMemPtr p7 = (TypeMemPtr)z3.at(2) ;
471 
472  check_leaf(p4,alias,TypeInt.NINT8);
473  check_leaf(p5,alias,TypeInt.NINT8);
474  check_leaf(p6,alias,TypeInt.NINT8);
475  check_leaf(p7,alias,TypeInt.con(7));
476 
477  depths = pz1.depth();
478  assertEquals(3,TypeMemPtr.max(alias,depths));
479  }

References com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TestApprox.check_leaf(), com.cliffc.aa.type.TypeInt.con(), com.cliffc.aa.type.TypeMemPtr.depth(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMemPtr.max(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.Type< T extends Type< T >.NIL, com.cliffc.aa.type.TypeInt.NINT8, and com.cliffc.aa.type.BitsAlias.REC.

Here is the call graph for this function:

◆ testApprox5()

void com.cliffc.aa.type.TestApprox.testApprox5 ( )

Definition at line 505 of file TestApprox.java.

505  {
506  final int CUTOFF = 2;
507  int alias = BitsAlias.new_alias(BitsAlias.REC);
508 
509  TypeStruct x1= TypeStruct.make(TypeFld.make("l",Type.SCALAR,0),TypeFld.make("r",Type.SCALAR,0),TypeFld.make("v",Type.SCALAR,0));
510  TypeMemPtr px1= TypeMemPtr.make(alias,x1);
511  assertEquals(0,TypeMemPtr.max(alias,px1.depth()));
512 
513  TypeStruct x2= TypeStruct.make(TypeFld.make("l", px1 ,0),TypeFld.make("r",Type.SCALAR,0),TypeFld.make("v",Type.SCALAR,0));
514  TypeMemPtr px2= TypeMemPtr.make(alias,x2);
515  assertEquals(1,TypeMemPtr.max(alias,px2.depth()));
516 
517  TypeStruct x3= TypeStruct.make(TypeFld.make("l", px1 ,0),TypeFld.make("r", px1 ,0),TypeFld.make("v",Type.SCALAR,0));
518  TypeMemPtr px3= TypeMemPtr.make(alias,x3);
519  assertEquals(1,TypeMemPtr.max(alias,px3.depth()));
520 
521  TypeStruct x4= TypeStruct.make(TypeFld.make("l", px2 ,0),TypeFld.make("r", px3 ,0),TypeFld.make("v",Type.SCALAR,0));
522  TypeMemPtr px4= TypeMemPtr.make(alias,x4);
523  assertEquals(2,TypeMemPtr.max(alias,px4.depth()));
524 
525  // Approximate
526  TypeStruct z1 = x4.approx(CUTOFF,alias);
527  TypeMemPtr pz1 = TypeMemPtr.make(alias,z1);
528  assertEquals(1,TypeMemPtr.max(alias,pz1.depth()));
529  assertSame(x3,z1);
530  }

References com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeMemPtr.depth(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMemPtr.max(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.BitsAlias.REC, and com.cliffc.aa.type.Type< T extends Type< T >.SCALAR.

Here is the call graph for this function:

◆ testApprox6()

void com.cliffc.aa.type.TestApprox.testApprox6 ( )

Definition at line 539 of file TestApprox.java.

539  {
540  Object dummy0 = TypeStruct.TYPES;
541  Object dummy1 = TypeMemPtr.TYPES;
542  final int CUTOFF = 2;
543  int alias = BitsAlias.new_alias(BitsAlias.REC);
544 
545  Type.RECURSIVE_MEET++;
546  TypeFld[] flds1 = TypeFlds.ts(TypeFld.malloc("l",null,0), TypeFld.malloc("r",null,1), TypeFld.malloc("v",null,2));
547  TypeStruct x1 = TypeStruct.malloc("",false,flds1,true);
548  x1._hash = x1.compute_hash(); x1._cyclic = true;
549  TypeMemPtr px1 = TypeMemPtr.make_nil(alias,x1);
550  x1.fld(0).setX(Type.XNIL );
551  x1.fld(1).setX(px1 );
552  x1.fld(2).setX(Type.SCALAR);
553  Type.RECURSIVE_MEET--;
554  x1 = x1.install_cyclic(x1.reachable());
555  assertSame(px1,x1.at(1));
556 
557  TypeStruct x2= TypeStruct.make(TypeFld.make("l",px1,0),TypeFld.make("r",px1,1),TypeFld.make("v",Type.SCALAR,2));
558  TypeMemPtr px2= TypeMemPtr.make_nil(alias,x2);
559 
560  TypeStruct z0= TypeStruct.make(TypeFld.make("l",px1,0),TypeFld.make("r",px2,1),TypeFld.make("v",Type.SCALAR,2));
561  // Approximate
562  TypeStruct z1 = z0.approx(CUTOFF,alias);
563 
564  Type.RECURSIVE_MEET++;
565  TypeFld[] flds3 = TypeFlds.ts(TypeFld.malloc("l",null,0), TypeFld.malloc("r",null,1), TypeFld.malloc("v",null,2));
566  TypeStruct x3 = TypeStruct.malloc("",false,flds3,true);
567  x3._hash = x3.compute_hash(); x3._cyclic = true;
568  TypeMemPtr px3 = TypeMemPtr.make_nil(alias,x3);
569  x3.fld(0).setX(px3);//TypeMemPtr.make_nil(alias,TypeObj.OBJ);
570  x3.fld(1).setX(px3);
571  x3.fld(2).setX(Type.SCALAR);
572  Type.RECURSIVE_MEET--;
573  x3 = x3.install_cyclic(x3.reachable());
574  px3 = (TypeMemPtr)x3.at(1);
575 
576  TypeStruct x4= TypeStruct.make(TypeFld.make("l",px1,0),TypeFld.make("r",px3,1),TypeFld.make("v",Type.SCALAR,2));
577 
578  assertSame(x4,z1);
579  }

References com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TypeStruct.compute_hash(), com.cliffc.aa.type.TypeStruct.fld(), com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMemPtr.make_nil(), com.cliffc.aa.type.TypeFld.malloc(), com.cliffc.aa.type.TypeStruct.malloc(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.Type< T extends Type< T >.RECURSIVE_MEET, com.cliffc.aa.type.Type< T extends Type< T >.SCALAR, com.cliffc.aa.type.TypeFld.setX(), com.cliffc.aa.type.TypeFlds.ts(), com.cliffc.aa.type.TypeMemPtr.TYPES, com.cliffc.aa.type.TypeStruct.TYPES, and com.cliffc.aa.type.Type< T extends Type< T >.XNIL.

Here is the call graph for this function:

◆ testApprox7()

void com.cliffc.aa.type.TestApprox.testApprox7 ( )

Definition at line 586 of file TestApprox.java.

586  {
587 
588  // Make a short cycle using alias RECORD. Repeated add instances & approx,
589  // until fixed point.
590  final int CUTOFF=2;
591  TypeStruct ts0 = TypeStruct.make(TypeFld.NO_DISP);
592  TypeMemPtr tmp0 = TypeMemPtr.make(BitsAlias.RECORD_BITS0,ts0), tmp1=null;
593 
594  int cnt=0;
595  while( tmp0 != tmp1 && cnt < 100 ) {
596  TypeStruct ts1 = TypeStruct.make(TypeFld.make("^",tmp1=tmp0,0));
597  TypeStruct ts1x = ts1.approx(CUTOFF,BitsAlias.REC);
598  // Extend with nil-or-not endlessly.
599  tmp0 = TypeMemPtr.make(BitsAlias.RECORD_BITS0,ts1x);
600  cnt++;
601  }
602  // End result has no prefix, since NIL is allowed at every step. i.e., we
603  // added NIL-or-ptr-to-self 3 times, which is exactly approximated by a
604  // tight loop with no prefix.
605  assertEquals(CUTOFF+1,cnt);
606 
607 
608  // Make some child aliases.
609  final int alias6 = BitsAlias.new_alias(BitsAlias.REC);
610  final int alias7 = BitsAlias.new_alias(BitsAlias.REC);
611  final int alias8 = BitsAlias.new_alias(BitsAlias.REC);
612  final BitsAlias ba6 = BitsAlias.make0(alias6);
613  final BitsAlias ba7 = BitsAlias.make0(alias7);
614  final BitsAlias ba8 = BitsAlias.make0(alias8);
615  final BitsAlias ba60 = ba6.meet_nil();
616  final BitsAlias ba70 = ba7.meet_nil();
617  final BitsAlias ba80 = ba8.meet_nil();
618 
619  // Add a struct with alias6 & approx. Expect no change, despite alias6
620  // being a child of RECORD.
621  TypeStruct ts6 = TypeStruct.make(TypeFld.make("^",tmp0,0));
622  TypeStruct ts6x = ts6.approx(CUTOFF,alias6);
623  assertEquals(ts6,ts6x);
624  TypeMemPtr tmp6 = TypeMemPtr.make(ba60,ts6);
625  // Again with alias7
626  TypeStruct ts7 = TypeStruct.make(TypeFld.make("^",tmp6,0));
627  TypeStruct ts7x = ts7.approx(CUTOFF,alias7);
628  assertEquals(ts7,ts7x);
629  TypeMemPtr tmp7 = TypeMemPtr.make(ba70,ts7);
630  // Again with alias8
631  TypeStruct ts8 = TypeStruct.make(TypeFld.make("^",tmp7,0));
632  TypeStruct ts8x = ts8.approx(CUTOFF,alias8);
633  assertEquals(ts8,ts8x);
634 
635 
636  // Start with short cycle:
637  // 10_( 11_* ); 11#2 -> 10
638  // Add this on top (alias#4 and#3 are children of #2):
639  // 12#4 -> 13; 13_( 17_*, 14_* ); 14#3 -> 15; 15_( 16_*, 2.3 ); 16#4 -> 10; 17#5 -> 18; 18_(nil,1.2)
640  // Approx alias#4 should do nothing (only depth 2 for alias#4 till hit cycle).
641  // Then add it again & approx at depth 2 for alias#2.
642 
643 
644  // Start with: A -> A
645  // A is basic RECORD type, actually equal to TypeStruct.DISPLAY.
646  // B,C,D are child aliases of A and are alias6,7,8.
647  // D is a LHS end type: D -> (nil,88)
648  TypeStruct tsD = TypeStruct.make(TypeFld.fldBot,TypeInt.con(88));
649  TypeMemPtr tmpD = TypeMemPtr.make(ba8,tsD); // Note not nil
650  // Add (alternating the repeating field left and right):
651  // B1 = ( A , 99 )
652  TypeStruct tsB1 = TypeStruct.make(TypeFld.make("^",tmp0,0),TypeFld.make(TypeFld.fldBot,TypeInt.con(99),1));
653  assertEquals(tsB1,tsB1.approx(CUTOFF,alias6));
654  TypeMemPtr tmpB1= TypeMemPtr.make(ba6,tsB1); // Note not nil
655  // C1 = ( D , B1 )
656  TypeStruct tsC1 = TypeStruct.make(TypeFld.make("^",tmpD,0),TypeFld.make(TypeFld.fldBot,tmpB1,1));
657  assertEquals(tsC1,tsC1.approx(CUTOFF,alias7));
658  TypeMemPtr tmpC1= TypeMemPtr.make(ba7,tsC1); // Note not nil
659 
660  // Add repeatedly until stable:
661  // B2 = ( C1, 99 )
662  // C2 = ( D , B2 )
663  // This should approx by meeting a C with a A, which should drop off the
664  // RHS of the C. The C LHS is a D, which again meets with A to finish the
665  // collapse. Bug is that types flip-flop between 2 variants endlessly.
666  cnt = 0; tmp1 = null;
667  while( tmpC1 != tmp1 && cnt < 100 ) {
668  tmp1 = tmpC1;
669  // B2 = ( C1, 99 )
670  TypeStruct tsB2 = TypeStruct.make(TypeFld.make("^",tmpC1,0),TypeFld.make(TypeFld.fldBot,TypeInt.con(99),1));
671  TypeStruct tsB2x = tsB2.approx(CUTOFF,alias6);
672  TypeMemPtr tmpB2= TypeMemPtr.make(ba6,tsB2x); // Note not nil
673 
674  // C2 = ( D , B2 )
675  TypeStruct tsC2 = TypeStruct.make(TypeFld.make("^",tmpD,0),TypeFld.make(TypeFld.fldBot,tmpB2,1));
676  TypeStruct tsC2x = tsC2.approx(CUTOFF,alias7);
677  TypeMemPtr tmpC2= TypeMemPtr.make(ba7,tsC2x); // Note not nil
678  tmpC1 = tmpC2;
679  cnt++;
680  }
681  assertEquals(CUTOFF,cnt);
682 
683  }

References com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeInt.con(), com.cliffc.aa.type.TypeFld.fldBot, com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.BitsAlias.make0(), com.cliffc.aa.type.Bits< B extends Bits< B >.meet_nil(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.TypeFld.NO_DISP, com.cliffc.aa.type.BitsAlias.REC, and com.cliffc.aa.type.BitsAlias.RECORD_BITS0.

Here is the call graph for this function:

◆ testApprox8()

void com.cliffc.aa.type.TestApprox.testApprox8 ( )

Definition at line 685 of file TestApprox.java.

685  {
686  Object dummy0 = TypeStruct.TYPES;
687  Object dummy1 = TypeFunPtr.TYPES;
688  Object dummy2 = Env.GVN;
689  final int CUTOFF=2;
690  final int fidx = BitsFun.new_fidx(1), fidx0 = BitsFun.new_fidx(fidx), fidx1 = BitsFun.new_fidx(fidx);
691  final BitsFun fidxs = BitsFun.make0(fidx0,fidx1).dual();
692  final int alias = BitsAlias.new_alias(BitsAlias.REC);
693  Env.ALL_DISPLAYS = Env.ALL_DISPLAYS.set(alias); // Declare a display
694 
695  // Args for the forward-ref fib(^ ->Scalar). This has to start as hi-args
696  // for this test, as the cyclic approx is supposed to be low - and it has
697  // args known post-parse but not pre-parse.
698  TypeStruct tfp0_args = TypeStruct.make("", true, TypeFlds.ts(TypeMemPtr.DISP_FLD), false);
699 
700  TypeFunPtr tfp0 = TypeFunPtr.make(BitsFun.ANY,2,(TypeMemPtr)TypeFunPtr.DISP.simple_ptr()); // fib with generic display
701  TypeStruct dsp0 = TypeStruct.make(TypeMemPtr.DISP_FLD,TypeFld.make("fib",tfp0,1));// The display with weak fib-type
702  TypeMemPtr ptr0 = TypeMemPtr.make(alias,dsp0);
703  // Args for a strong fib: { ^:ptr0 x:int64 -> ~Scalar } // LOW
704  TypeStruct arg0 = TypeStruct.make(TypeFld.make("->",Type.SCALAR,0),
705  TypeFld.make("^",ptr0.simple_ptr(),1),
706  TypeFld.make("x",TypeInt.INT64,2));
707 
708  TypeFunPtr tfp1 = TypeFunPtr.make(fidxs,2,(TypeMemPtr)ptr0.simple_ptr()); // FIB with weak display
709  TypeStruct dsp1 = TypeStruct.make(TypeMemPtr.DISP_FLD,TypeFld.make("fib",tfp1,1)); // Display with stronger FIB-type
710  TypeMemPtr ptr1 = TypeMemPtr.make(alias,dsp1);
711  // Args for a strong fib: { ^:ptr x:int -> ~Scalar } // LOW. Display still not recursive.
712  TypeStruct arg1 = TypeStruct.make(TypeFld.make("->",Type.SCALAR,0),
713  TypeFld.make("^",ptr1.simple_ptr(),1),
714  TypeFld.make("x",TypeInt.INT64,2));
715 
716  TypeFunPtr tfp2 = TypeFunPtr.make(fidxs,2,(TypeMemPtr)ptr1.simple_ptr()); // fib2->dsp1->fib1->dsp0->fib0->generic_display
717  TypeStruct dsp2 = TypeStruct.make(TypeMemPtr.DISP_FLD,TypeFld.make("fib",tfp2,1)); // dsp2->fib2->dsp1->fib1->dsp0->fib0->generic_display
718 
719  // The approx that gets built: fib3->dsp3->fib3->dsp3->...
720  Type.RECURSIVE_MEET++;
721  TypeFld[] flds3 = TypeFlds.ts(TypeFld.malloc("^",null,0), TypeFld.malloc("fib",null,1));
722  TypeStruct dsp3 = TypeStruct.malloc("",false,flds3,false);
723  dsp3._hash = dsp3.compute_hash(); dsp3._cyclic = true;
724  TypeMemPtr ptr3 = TypeMemPtr.make(alias,dsp3);
725  TypeStruct arg3 = TypeStruct.make(TypeFld.make("->",Type.SCALAR,0),
726  TypeFld.make("^",ptr3.simple_ptr(),1),
727  TypeFld.make("x",TypeInt.INT64,2));
728  TypeFunPtr tfp3 = TypeFunPtr.make(fidxs,2,(TypeMemPtr)ptr3.simple_ptr());
729  dsp3.fld(0).setX(TypeMemPtr.DISPLAY_PTR);
730  dsp3.fld(1).setX(tfp3);
731  Type.RECURSIVE_MEET--;
732  dsp3 = dsp3.install_cyclic(dsp3.reachable());
733 
734  // This should pass an isa-test (was crashing)
735  Type mt0 = dsp0.meet(dsp3);
736 
737  // This should pass an isa-test (was crashing)
738  Type mt1 = dsp1.meet(dsp3);
739 
740  // Check the isa
741  Type mt = dsp2.meet(dsp3);
742  assertEquals(dsp3,mt);
743 
744  // Build the approx
745  TypeStruct rez = dsp2.approx(CUTOFF,alias);
746  assertEquals(dsp3,rez);
747  }

References com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.Env.ALL_DISPLAYS, com.cliffc.aa.type.BitsFun.ANY, com.cliffc.aa.type.TypeStruct.approx(), com.cliffc.aa.type.TypeStruct.compute_hash(), com.cliffc.aa.type.TypeFunPtr.DISP, com.cliffc.aa.type.TypeMemPtr.DISP_FLD, com.cliffc.aa.type.TypeMemPtr.DISPLAY_PTR, com.cliffc.aa.type.Bits< B extends Bits< B >.dual(), com.cliffc.aa.type.TypeStruct.fld(), com.cliffc.aa.Env.GVN, com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeFunPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.BitsFun.make0(), com.cliffc.aa.type.TypeFld.malloc(), com.cliffc.aa.type.TypeStruct.malloc(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.BitsFun.new_fidx(), com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.Type< T extends Type< T >.RECURSIVE_MEET, com.cliffc.aa.type.Type< T extends Type< T >.SCALAR, com.cliffc.aa.type.TypeFld.setX(), com.cliffc.aa.type.TypeMemPtr.simple_ptr(), com.cliffc.aa.type.TypeFlds.ts(), com.cliffc.aa.type.TypeFunPtr.TYPES, and com.cliffc.aa.type.TypeStruct.TYPES.

Here is the call graph for this function:

◆ testTSMeet()

void com.cliffc.aa.type.TestApprox.testTSMeet ( )

Definition at line 17 of file TestApprox.java.

17  {
18  Object dummy0 = TypeStruct.TYPES;
19  Object dummy1 = TypeMemPtr.TYPES;
20  int alias0 = BitsAlias.new_alias(BitsAlias.REC);
21 
22  // Build two structs pointing to each other.
23  // -> [,int] -> * -> [,flt] -> * ->
24  TypeFld fbint = TypeFld.make("b",TypeInt.INT64,1);
25  TypeFld fbflt = TypeFld.make("b",TypeFlt.FLT64,1);
26  Type.RECURSIVE_MEET++;
27  TypeFld[] flds0 = TypeFlds.ts(TypeFld.malloc("a",null,0), fbint);
28  TypeFld[] flds1 = TypeFlds.ts(TypeFld.malloc("a",null,0), fbflt);
29  TypeStruct t0 = TypeStruct.malloc("",false,flds0,true);
30  TypeStruct t1 = TypeStruct.malloc("",false,flds1,true);
31  t0._hash = t0.compute_hash(); t0._cyclic = true;
32  t1._hash = t1.compute_hash(); t1._cyclic = true;
33  TypeMemPtr p0 = TypeMemPtr.make(alias0,t0);
34  TypeMemPtr p1 = TypeMemPtr.make(alias0,t1);
35  t0.fld(0).setX(p1 );
36  t1.fld(0).setX(p0 );
37  Type.RECURSIVE_MEET--;
38  t0 = t0.install_cyclic(t0.reachable());
39 
40  // Meet them
41  TypeStruct mt = (TypeStruct)t0.meet(t1);
42 
43  // End result should be a cycle of length 1: [,real] -> * ->
44  // And NOT: [,real] -> * -> [,real] -> * ->
45  assertEquals(Type.REAL,mt.at(1));
46  TypeMemPtr pmt = (TypeMemPtr)mt.at(0);
47  assertSame(mt,pmt._obj);
48  TypeStruct head = mt.repeats_in_cycles();
49  assertNull(head);
50  }

References com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.type.TypeMemPtr._obj, com.cliffc.aa.type.TypeStruct.at(), com.cliffc.aa.type.TypeStruct.compute_hash(), com.cliffc.aa.type.TypeStruct.fld(), com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeFld.malloc(), com.cliffc.aa.type.TypeStruct.malloc(), com.cliffc.aa.type.BitsAlias.new_alias(), com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.Type< T extends Type< T >.REAL, com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.Type< T extends Type< T >.RECURSIVE_MEET, com.cliffc.aa.type.TypeStruct.repeats_in_cycles(), com.cliffc.aa.type.TypeFld.setX(), com.cliffc.aa.type.TypeFlds.ts(), com.cliffc.aa.type.TypeMemPtr.TYPES, and com.cliffc.aa.type.TypeStruct.TYPES.

Here is the call graph for this function:

◆ testType()

void com.cliffc.aa.type.TestApprox.testType ( )

Definition at line 13 of file TestApprox.java.

13  {
14  }

The documentation for this class was generated from the following file:
com.cliffc.aa.type.TestApprox.check_leaf
void check_leaf(TypeMemPtr p, int alias, TypeInt vt)
Definition: TestApprox.java:483