aa
com.cliffc.aa.type.TestType Class Reference

Public Member Functions

void testBits ()
 
void testBits0 ()
 
void testCommuteSymmetricAssociative ()
 
void testCrush ()
 
void testFunction ()
 
void testLoad ()
 
void testNameCycle ()
 
void testNamesInts ()
 
void testOOPsNulls ()
 
void testRecursive ()
 
void testStructTuple ()
 
void testType ()
 

Private Member Functions

void testCrush0 (TypeObj ti, TypeObj tj)
 

Detailed Description

Definition at line 14 of file TestType.java.

Member Function Documentation

◆ testBits()

void com.cliffc.aa.type.TestType.testBits ( )

Definition at line 58 of file TestType.java.

58  {
59  // 1 - obj
60  // 2 - tuples & structs
61  // 3 - arrays
62  // 4 - strings
63  // 5 - "abc"
64 
65  // Distributivity
66  // t0 = *[5] -> "abc"
67  // t1 = *[4] -> str
68  // t2 = *[2] -> ()
69  // Since t0.isa(t1) then t0.join(t2) .isa( t1.join(t2) )
70  TypeMemPtr t0 = TypeMemPtr.ABCPTR;
71  TypeMemPtr t1 = TypeMemPtr.STRPTR;
72  TypeMemPtr t2 = TypeMemPtr.STRUCT;
73  assertTrue(t0.isa(t1));
74  Type t02,t12,mt;
75 
76  t02 = t0.join(t2); // join of unrelated bits2&5 []
77  t12 = t1.join(t2); // join of unrelated bits2&4 []
78  mt = t02.meet(t12);
79  assertEquals(t12,mt);
80  // also: (t0.meet(t1)).join(t2) == mt
81  // but since t0 isa t1,
82  // also: t1.join(t2) == mt
83  // [4] join [2] ==> [~2 + ~4]
84 
85  t1 = TypeMemPtr.STR0; // Same with nil
86  t02 = t0.join(t2); // join of unrelated bits2&5 []
87  t12 = t1.join(t2); // join of unrelated bits2&4 []
88  mt = t02.meet(t12);
89  assertEquals(t12,mt);
90  }

References com.cliffc.aa.type.TypeMemPtr.ABCPTR, com.cliffc.aa.type.Type< T extends Type< T >.isa(), com.cliffc.aa.type.Type< T extends Type< T >.join(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.type.TypeMemPtr.STR0, com.cliffc.aa.type.TypeMemPtr.STRPTR, and com.cliffc.aa.type.TypeMemPtr.STRUCT.

Here is the call graph for this function:

◆ testBits0()

void com.cliffc.aa.type.TestType.testBits0 ( )

Definition at line 26 of file TestType.java.

26  {
27 
28  // This looks like a crossing-nil bug, but it is not quite.
29  // What is "nil join *[4]->str"?
30  // Inverting, what is "nil meet *[~4]->str"?
31  // The issue is that 'nil' says nothing about what to do with the '->str'
32  // part of the structural meet breakdown. See testLattice14 & 15.
33  //
34  // Tested as Lattice: [0]-> obj ==> NIL ==> [~0]->~obj
35  //
36  // If NIL is 'signed', and effectively either '[0]->obj' or '[~0]->~obj'
37  // then this test works. Either [0]->obj:
38  // If "[0]-> obj is [0,2]->rec" Then A^C isa B^C. Fails, !A->B
39  // If "[0]->~obj is [0,2]->rec" Then A^C isa B^C. Works:
40  // [0 ]->~obj ^ [4]->str => [~0+4]->~obj
41  // [0,2]-> rec ^ [4]->str => [~0+4]->~obj
42  //
43  // nil.isa(*rec?) so nil.join(*str) isa (*rec?).join(*str)
44  Type t0 = Type.XNIL; // [0 ] -> obj
45  Type t1 = TypeMemPtr.STRUCT0;// [0,2] -> rec
46  assertTrue(t0.isa(t1)); // [0,2] -> obj -- meet is not t1
47  Type t2 = TypeMemPtr.OOP0; // [0,2] -> obj
48  assertTrue(t0.isa(t2)); //
49 
50  }

References com.cliffc.aa.type.Type< T extends Type< T >.isa(), com.cliffc.aa.type.TypeMemPtr.OOP0, com.cliffc.aa.type.TypeMemPtr.STRUCT0, and com.cliffc.aa.type.Type< T extends Type< T >.XNIL.

Here is the call graph for this function:

◆ testCommuteSymmetricAssociative()

void com.cliffc.aa.type.TestType.testCommuteSymmetricAssociative ( )

Definition at line 551 of file TestType.java.

551  {
552  assertTrue(Type.check_startup());
553  }

References com.cliffc.aa.type.Type< T extends Type< T >.check_startup().

Here is the call graph for this function:

◆ testCrush()

void com.cliffc.aa.type.TestType.testCrush ( )

Definition at line 515 of file TestType.java.

515  {
516  TypeObj[] objs = new TypeObj[]{
517  TypeObj.ISUSED,
518  TypeObj.OBJ,
519  TypeStr.STR,
520  TypeStr.ABC,
521  TypeStruct.ALLSTRUCT,
522  TypeStruct.INT64_INT64,
523  TypeStruct.NAMEPT,
524  TypeStruct.POINT,
525  TypeMemPtr.DISPLAY,
526  TypeStruct.A,
527  TypeStruct.ARW,
528  };
529 
530  for( int i=0; i<objs.length; i++ ) {
531  TypeObj toi = objs[i];
532  for( int j=i; j<objs.length; j++ ) {
533  TypeObj toj = objs[j];
534  testCrush0( toi , toj );
535  testCrush0((TypeObj)toi.dual(), toj );
536  testCrush0( toi ,(TypeObj)toj.dual());
537  testCrush0((TypeObj)toi.dual(),(TypeObj)toj.dual());
538  }
539  }
540  }

References com.cliffc.aa.type.TypeStruct.A, com.cliffc.aa.type.TypeStr.ABC, com.cliffc.aa.type.TypeStruct.ALLSTRUCT, com.cliffc.aa.type.TypeStruct.ARW, com.cliffc.aa.type.TypeMemPtr.DISPLAY, com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.TypeStruct.INT64_INT64, com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.ISUSED, com.cliffc.aa.type.TypeStruct.NAMEPT, com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.OBJ, com.cliffc.aa.type.TypeStruct.POINT, com.cliffc.aa.type.TypeStr.STR, and com.cliffc.aa.type.TestType.testCrush0().

Here is the call graph for this function:

◆ testCrush0()

void com.cliffc.aa.type.TestType.testCrush0 ( TypeObj  ti,
TypeObj  tj 
)
private

Definition at line 542 of file TestType.java.

542  {
543  if( ti.isa(tj) ) {
544  TypeObj tic = ti.crush();
545  TypeObj tjc = tj.crush();
546  assertTrue(tic.isa(tjc));
547  }
548  }

References com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.crush(), and com.cliffc.aa.type.Type< T extends Type< T >.isa().

Referenced by com.cliffc.aa.type.TestType.testCrush().

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

◆ testFunction()

void com.cliffc.aa.type.TestType.testFunction ( )

Definition at line 288 of file TestType.java.

288  {
289  PrimNode[] ignore2 = PrimNode.PRIMS(); // Force node
290 
291  TypeFunPtr gf = TypeFunPtr.GENERIC_FUNPTR;
292  // New functions fall squarely between +/- GENERIC_FUNPTR.
293 
294  // TypeTuple structure demands the shortest Tuple wins the "length
295  // war" (determines the length of the result based on short's any/all flag).
296  TypeFunPtr f1i2i = TypeFunPtr.make_new_fidx(BitsFun.ALL,2,NO_DISP);
297  // To be a GF result, GF has to be shorter and high; the isa does a meet of
298  // TypeFunPtrs which does a *join* of args, which duals the GF args down
299  // low. GF is zero length and low, and wins the meet.
300  assertTrue(f1i2i.isa(gf)); // To be long result, short must be high
301  // To have GF.dual() be anything else and short, GF.dual must be high and
302  // thus the result is a copy of F1I2I.
303  assertTrue(gf.dual().isa(f1i2i)); // To be short result, short must be low
304 
305  assertTrue(f1i2i.isa(gf));
306  TypeFunPtr f1f2f = TypeFunPtr.make_new_fidx(BitsFun.ALL,2,NO_DISP);
307  assertTrue(f1f2f.isa(gf));
308  TypeFunPtr mt = (TypeFunPtr)f1i2i.meet(f1f2f);
309  int fidx0 = f1i2i.fidx();
310  int fidx1 = f1f2f.fidx();
311  BitsFun funs = BitsFun.make0(fidx0).meet(BitsFun.make0(fidx1));
312  TypeFunPtr f3i2r = TypeFunPtr.make(funs,2,NO_DISP);
313  assertEquals(f3i2r,mt);
314  assertTrue(f3i2r.isa(gf));
315  assertTrue(f1i2i.isa(f3i2r));
316  assertTrue(f1f2f.isa(f3i2r));
317 
318  TypeFunPtr f2 = TypeFunPtr.make(BitsFun.make0(fidx1),2,NO_DISP); // Some generic function (happens to be #23, '&')
319  assertTrue(f2.isa(gf));
320  }

References com.cliffc.aa.type.BitsFun.ALL, com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.TypeFunPtr.fidx(), com.cliffc.aa.type.TypeFunPtr.GENERIC_FUNPTR, com.cliffc.aa.type.Type< T extends Type< T >.isa(), com.cliffc.aa.type.TypeFunPtr.make(), com.cliffc.aa.type.BitsFun.make0(), com.cliffc.aa.type.TypeFunPtr.make_new_fidx(), com.cliffc.aa.type.Bits< B extends Bits< B >.meet(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), and com.cliffc.aa.node.PrimNode.PRIMS.

Here is the call graph for this function:

◆ testLoad()

void com.cliffc.aa.type.TestType.testLoad ( )

Definition at line 473 of file TestType.java.

473  {
474  Object dummy0 = TypeStruct.TYPES;
475  // All are ISA
476  TypeMemPtr[] tmps = new TypeMemPtr[]{
477  TypeMemPtr.STRPTR.dual(),
478  TypeMemPtr.ABCPTR,
479  TypeMemPtr.STRPTR,
480  };
481  TypeMemPtr[] tmps1 = new TypeMemPtr[]{
482  TypeMemPtr.make(-4,TypeObj.XOBJ),
483  TypeMemPtr.make(-5,TypeObj.XOBJ),
484  TypeMemPtr.make(5,TypeObj. OBJ), // testing 5-obj & ISUSED [1....:use] vs MEM_ABC
485  TypeMemPtr.make(4,TypeObj. OBJ),
486  };
487  for( int i=0; i<tmps.length-1; i++ )
488  assertTrue(tmps[i].isa(tmps[i+1]));
489 
490  // All are ISA
491  TypeMem[] tmems = new TypeMem[]{
492  TypeMem.ANYMEM, // [1:~obj,3:~obj,5:~obj ]
493  TypeMem.MEM_ABC, // [1:~obj,3:~obj,5:"abc"]
494  TypeMem.MEM.dual(), // [1:~obj,3:~str,5:"abc"]
495  TypeMem.MEM, // [1: obj,3: str,5:"abc"]
496  TypeMem.MEM_ABC.dual(), // [1: obj,3: obj,5:"abc"]
497  TypeMem.ALLMEM, // [1: obj,3: obj,5: obj ]
498  };
499  for( int j=0; j<tmems.length-1; j++ )
500  assertTrue(tmems[j].isa(tmems[j+1]));
501 
502  TypeObj[][] rez = new TypeObj[tmps.length][tmems.length];
503  for( int i=0; i<tmps.length; i++ )
504  for( int j=0; j<tmems.length; j++ )
505  rez[i][j] = tmems[j].ld(tmps[i]);
506 
507  for( int i0=0; i0<tmps.length; i0++ )
508  for( int j0=0; j0<tmems.length; j0++ )
509  for( int i1=i0; i1<tmps.length; i1++ )
510  for( int j1=j0; j1<tmems.length; j1++ )
511  assertTrue( rez[i0][j0].isa(rez[i1][j1]) );
512  }

References com.cliffc.aa.type.TypeMemPtr.ABCPTR, com.cliffc.aa.type.TypeMem.ALLMEM, com.cliffc.aa.type.TypeMem.ANYMEM, com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeMem.MEM, com.cliffc.aa.type.TypeMem.MEM_ABC, com.cliffc.aa.type.TypeMemPtr.STRPTR, com.cliffc.aa.type.TypeStruct.TYPES, and com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.XOBJ.

Here is the call graph for this function:

◆ testNameCycle()

void com.cliffc.aa.type.TestType.testNameCycle ( )

Definition at line 433 of file TestType.java.

433  {
434  Object dummy0 = TypeStruct.TYPES;
435  Object dummy1 = TypeMemPtr.TYPES;
436  // Make a cycle: 0_A: -> 1_(n=*,v=i64) -> 2_TMP -> 3_B: -> 4_(n=*,v=f64) -> 5_TMP ->
437  // Dual; then meet ~4_() and ~0_A
438  final int alias = BitsAlias.REC;
439 
440  TypeFld fldvi = TypeFld.make("v",TypeInt.INT64,1);
441  TypeFld fldvf = TypeFld.make("v",TypeFlt.FLT64,1);
442  Type.RECURSIVE_MEET++;
443  TypeFld[] flds1 = TypeFlds.ts(TypeFld.malloc("n",null,0), fldvi);
444  TypeFld[] flds4 = TypeFlds.ts(TypeFld.malloc("n",null,0), fldvf);
445  TypeStruct as1 = TypeStruct.malloc("",false,flds1,true).set_name("A:");
446  TypeStruct bs4 = TypeStruct.malloc("",false,flds4,true).set_name("B:");
447  as1._hash = as1.compute_hash(); as1._cyclic = true;
448  bs4._hash = bs4.compute_hash(); bs4._cyclic = true;
449  TypeMemPtr ap5 = TypeMemPtr.make(alias,as1);
450  TypeMemPtr bp2 = TypeMemPtr.make(alias,bs4);
451  as1.fld(0).setX(bp2 );
452  bs4.fld(0).setX(ap5 );
453  Type.RECURSIVE_MEET--;
454  as1 = as1.install_cyclic(as1.reachable());
455  bp2 = (TypeMemPtr)as1.at(0);
456  bs4 = (TypeStruct)bp2._obj;
457  ap5 = (TypeMemPtr)bs4.at(0);
458 
459  Type das1 = as1.dual(); // ~A:@{b,int}
460  Type dbs4 = bs4.dual(); // ~B:@{a,flt}
461  // Since names mismatch, but both as1 and bs4 are high... must fall hard.
462  Type mt = das1.meet(dbs4); // ~ ~@{a join b, int join flt} ==> @{a join b, int32}
463  TypeStruct smt = (TypeStruct)mt;
464  assertEquals(TypeInt.INT32,smt.at(1));
465  TypeMemPtr smp = (TypeMemPtr)smt.at(0);
466  assertEquals(smt,smp._obj);
467  assertEquals(BitsAlias.RECORD_BITS,smp._aliases);
468 
469  Type mx = as1.dual().meet(dbs4);
470  assertEquals(smt,mx);
471  }

References com.cliffc.aa.type.TypeMemPtr._aliases, 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.INT32, 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.Type< T extends Type< T >.meet(), com.cliffc.aa.type.TypeStruct.reachable(), com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.BitsAlias.RECORD_BITS, 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:

◆ testNamesInts()

void com.cliffc.aa.type.TestType.testNamesInts ( )

Definition at line 92 of file TestType.java.

92  {
93 
94  // Lattice around int8 and 0 is well formed; exactly 3 edges, 3 nodes
95  // Confirm lattice: {~i16 -> ~i8 -> 0 -> i8 -> i16 }
96  // Confirm lattice: { ~i8 -> 1 -> i8 }
97  Type i16= TypeInt.INT16;
98  Type i8 = TypeInt.INT8;
99  Type xi8 = i8.dual();
100  Type xi16= i16.dual();
101  Type z = TypeInt.FALSE;
102  Type o = TypeInt.TRUE;
103  assertEquals(xi8,xi8.meet(xi16)); // ~i16-> ~i8
104  assertEquals( z ,z .meet(xi8 )); // ~i8 -> 0
105  assertEquals(i8 ,i8 .meet(z )); // 0 -> i8
106  assertEquals(i16,i16.meet(xi8 )); // i8 -> i16
107  assertEquals( o ,o .meet(xi8 )); // ~i8 -> 1
108  assertEquals(i8 ,i8 .meet(o )); // 1 -> i8
109 
110  // Lattice around n:int8 and n:0 is well formed; exactly 2 edges, 3 nodes
111  // Confirm lattice: {N:~i8 -> N:1 -> N:i8}
112  // Confirm lattice: {N:~i8 -> N:0 -> N:i8}
113  Type ni8 = TypeInt.INT8.set_name("__test_enum:");
114  Type xni8= ni8.dual(); // dual name:int8
115  Type no = o.set_name("__test_enum:");
116  Type nz = z.set_name("__test_enum:");
117  assertEquals(no ,no .meet(xni8)); // N:~i8 -> N: 1
118  assertEquals(ni8,ni8.meet(no )); // N: 1 -> N:i8
119  assertEquals(nz ,nz .meet(xni8)); // N:~i8 -> N:0
120  assertEquals(ni8,ni8.meet(nz )); // N:0 -> N:i8
121  assertEquals(no ,no .meet(xni8)); // n:1 & n:~i8 -> mixing 0 and 1
122 
123  // Crossing lattice between named and unnamed ints
124  // Confirm lattice: {~i8 -> N:~i8 -> 0 -> N:i8 -> i8; N:0 -> 0 }
125  // NOT: Confirm lattice: {N:~i8 -> ~i8; N:i8 -> i8 }
126  assertEquals(xni8,xni8.meet( xi8));// ~i8 -> N:~i8
127  assertEquals( z, z .meet(xni8));// N:~i8 -> {0,1}??? When falling off from a Named Int, must fall below ANY constant to keep a true lattice
128  assertEquals( i8, ni8.meet( z));// 0 -> N:i8
129  assertEquals( i8, i8.meet( ni8));// N: i8 -> i8
130  assertEquals( z, z.meet( nz));// N: 0 -> 0
131 
132  assertEquals(xni8,xi8.meet(xni8)); // N:~i8 <- ~i8
133  assertEquals(o, o .meet(xni8)); // 1 & N:~i8
134  }

References com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.TypeInt.FALSE, com.cliffc.aa.type.TypeInt.INT16, com.cliffc.aa.type.TypeInt.INT8, com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.type.Type< T extends Type< T >.set_name(), and com.cliffc.aa.type.TypeInt.TRUE.

Here is the call graph for this function:

◆ testOOPsNulls()

void com.cliffc.aa.type.TestType.testOOPsNulls ( )

Definition at line 142 of file TestType.java.

142  {
143  Type bot = Type .ALL;
144 
145  Type mem = TypeMem .MEM; // All memory
146  Type str = TypeStr .STR; // All Strings
147  Type tup = TypeStruct.ALLSTRUCT; // All Structs
148 
149  Type abc = TypeStr .ABC; // String constant
150  Type zer = TypeInt .FALSE;
151  Type tp0 = TypeStruct.make(zer); // tuple of a '0'
152 
153  Type tupX= tup.dual();
154  Type strX= str.dual();
155  Type memX= mem.dual();
156 
157  Type top = Type.ANY;
158 
159  assertTrue( top.isa(memX));
160 
161  //assertTrue(memX.isa(strX)); // mem is a CONTAINER for memory objects, e.g. Struct,Str
162  //assertTrue(memX.isa(tupX));
163 
164  assertTrue( strX.isa(abc));
165  assertTrue( tupX.isa(tp0));
166  assertTrue(!strX.isa(zer));
167  assertTrue(!tupX.isa(zer));
168 
169  assertTrue( abc .isa(str));
170  assertTrue( tp0 .isa(tup));
171  assertTrue(!zer .isa(str));
172  assertTrue(!zer .isa(tup));
173 
174  //assertTrue( str .isa(mem)); // mem is a CONTAINER for memory objects, e.g. Struct,Str
175  //assertTrue( tup .isa(mem));
176 
177  assertTrue( mem .isa(bot));
178 
179  // ---
180  Type pmem0= TypeMemPtr.OOP0; // *[ALL]?
181  Type pmem = TypeMemPtr.OOP ; // *[ALL]
182  Type pstr0= TypeMemPtr.STR0; // *[str]?
183  TypeMemPtr pstr = TypeMemPtr.STRPTR; // *[str]
184  Type ptup0= TypeMemPtr.STRUCT0; // *[tup]?
185  Type ptup = TypeMemPtr.STRUCT; // *[tup]
186 
187  Type pabc0= TypeMemPtr.ABC0; // *["abc"]?
188  TypeMemPtr pabc = TypeMemPtr.ABCPTR; // *["abc"]
189  TypeMemPtr pzer = TypeMemPtr.make(BitsAlias.type_alias(BitsAlias.REC),TypeStruct.ALLSTRUCT);// *[(0)]
190  TypeMemPtr pzer0= TypeMemPtr.make(pzer._aliases.meet_nil(),TypeStruct.ALLSTRUCT); // *[(0)]?
191  Type nil = Type.NIL, xnil=Type.XNIL;
192 
193  Type xtup = ptup .dual();
194  Type xtup0= ptup0.dual();
195  TypeMemPtr xstr = pstr.dual();
196  Type xstr0= pstr0.dual();
197  Type xmem = pmem .dual();
198  Type xmem0= pmem0.dual();
199 
200  assertTrue( top .isa(xmem0));
201  assertTrue(xmem0.isa(xmem ));
202 
203  assertTrue(xmem0.isa(xstr0));
204  assertTrue(xmem .isa(xstr ));
205  assertTrue(xmem0.isa(xtup0));
206  assertTrue(xmem .isa(xtup ));
207 
208  // "~str?" or "*[~0+4+]~str?" includes a nil, but nothing can fall to a nil
209  // (breaks lattice)... instead they fall to their appropriate nil-type.
210  assertEquals(Type.NIL,xstr0.meet( nil ));
211 
212  // This is a choice ptr-to-alias#1, vs a nil-able ptr-to-alias#2. Since
213  // they are from different alias classes, they are NEVER equal (unless both
214  // nil). We cannot tell what they point-to, so we do not know if the
215  // memory pointed-at is compatible or not.
216  assertTrue (xstr0.isa(pabc0)); // ~*[1]+0 vs ~*[2]?
217  assertTrue (xstr .isa(pabc ));
218  // We can instead assert that values loaded are compatible:
219  assertTrue (TypeMem.MEM.dual().ld(xstr).isa(TypeMem.MEM_ABC.ld(pabc)));
220 
221  // "~@{}?" or "*[~0+2+]~@{}?" includes a nil, but nothing can fall to a nil
222  // (breaks lattice)... instead they fall to their appropriate nil-type.
223  assertEquals(TypeMemPtr.NIL,xtup0.meet( nil ));
224  assertTrue (xtup0.isa(pzer0));
225  assertTrue (xtup .isa(pzer ));
226  //assertTrue(TypeMem.MEM_TUP.dual().ld(xstr).isa(TypeMem.MEM_ZER.ld(pabc)));
227 
228  assertTrue(xnil .isa(pabc0)); // nil expands as [0]->obj so !isa [2]->"abc"
229  assertTrue(xnil .isa(pstr0)); // nil expands as [0]->obj so !isa [4]->str
230  assertTrue(xnil .isa(ptup0)); // nil expands as [0]->obj so !isa [2]->()
231  assertTrue(xnil .isa(pzer0)); // nil expands as [0]->obj so !isa [2]->@{}
232 
233  assertTrue (pabc0.isa(pstr0));
234  assertTrue (pabc .isa(pstr ));
235  assertTrue (TypeMem.MEM_ABC.ld(pabc).isa(TypeMem.MEM.ld(pstr)));
236  assertTrue (pzer0.isa(ptup0));
237  assertTrue (pzer .isa(ptup ));
238  assertTrue (ptup0.isa(pmem0));
239  assertTrue (ptup .isa(pmem ));
240 
241  assertTrue (pmem .isa(pmem0));
242  assertTrue (pmem0.isa( bot ));
243 
244 
245  // Crossing ints and *[ALL]+null
246  Type i8 = TypeInt.INT8;
247  Type xi8 = i8.dual();
248  assertEquals( Type.NSCALR, xi8.meet(xmem0)); // ~OOP+0 & ~i8 -> 0
249  }

References com.cliffc.aa.type.TypeMemPtr._aliases, com.cliffc.aa.type.TypeStr.ABC, com.cliffc.aa.type.TypeMemPtr.ABC0, com.cliffc.aa.type.TypeMemPtr.ABCPTR, com.cliffc.aa.type.Type< T extends Type< T >.ALL, com.cliffc.aa.type.TypeStruct.ALLSTRUCT, com.cliffc.aa.type.Type< T extends Type< T >.ANY, com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.TypeInt.FALSE, com.cliffc.aa.type.TypeInt.INT8, com.cliffc.aa.type.Type< T extends Type< T >.isa(), com.cliffc.aa.type.TypeMem.ld(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.type.Bits< B extends Bits< B >.meet_nil(), com.cliffc.aa.type.TypeMem.MEM, com.cliffc.aa.type.TypeMem.MEM_ABC, com.cliffc.aa.type.Type< T extends Type< T >.NIL, com.cliffc.aa.type.Type< T extends Type< T >.NSCALR, com.cliffc.aa.type.TypeMemPtr.OOP, com.cliffc.aa.type.TypeMemPtr.OOP0, com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.type.TypeStr.STR, com.cliffc.aa.type.TypeMemPtr.STR0, com.cliffc.aa.type.TypeMemPtr.STRPTR, com.cliffc.aa.type.TypeMemPtr.STRUCT, com.cliffc.aa.type.TypeMemPtr.STRUCT0, com.cliffc.aa.type.BitsAlias.type_alias(), and com.cliffc.aa.type.Type< T extends Type< T >.XNIL.

Here is the call graph for this function:

◆ testRecursive()

void com.cliffc.aa.type.TestType.testRecursive ( )

Definition at line 324 of file TestType.java.

324  {
325 
326  // Recursive types no longer cyclic in the concrete definition? Because
327  // TypeObj can contain TypeMemPtrs but not another nested TypeObj...
328  final int alias1 = BitsAlias.new_alias(BitsAlias.REC);
329  final TypeMemPtr ts0ptr = TypeMemPtr.make (alias1,TypeStruct.ALLSTRUCT);
330  final TypeMemPtr ts0ptr0= TypeMemPtr.make_nil(alias1,TypeStruct.ALLSTRUCT);
331 
332  // Anonymous recursive structs -
333  // - struct with pointer to self
334  TypeFld fldv = TypeFld.make("v",TypeInt.INT64,1);
335  TypeStruct ts0 = TypeStruct.malloc("",false,TypeFlds.ts(TypeFld.malloc("n",null,0),fldv),true);
336  ts0._hash = ts0.compute_hash();
337  ts0.fld(0).setX(ts0ptr); ts0._cyclic = true;
338  ts0 = ts0.install_cyclic(ts0.reachable());
339  TypeMem ts0mem = TypeMem.make(alias1,ts0); // {1:@{n:*[1],v:int} }
340 
341  // - struct with pointer to self or nil
342  TypeStruct ts1 = TypeStruct.malloc("",false,TypeFlds.ts(TypeFld.malloc("n",null,0),fldv),true);
343  ts1._hash = ts1.compute_hash();
344  ts1.fld(0).setX(ts0ptr0); ts1._cyclic = true;
345  ts1 = ts1.install_cyclic(ts1.reachable());
346  TypeMem ts1mem = TypeMem.make(alias1,ts1); // {1:@{n:*[0,1],v:int} }
347 
348  Type tsmt = ts0.meet(ts1);
349  assertEquals(ts1,tsmt);
350  Type tsmemmt = ts0mem.meet(ts1mem);
351  assertEquals(ts1mem,tsmemmt);
352 
353  // Cyclic named struct: Memory#2 :A:@{n:*[0,2],v:int}
354  // If we unrolled this (and used S for Struct and 0 for Nil) we'd get:
355  // AS0AS0AS0AS0AS0AS0...
356  final int alias2 = BitsAlias.new_alias(BitsAlias.REC);
357  TypeMemPtr tptr2= TypeMemPtr.make_nil(alias2,TypeObj.OBJ); // *[0,2]
358  TypeStruct ts2 = TypeStruct.make(TypeFld.make("n",tptr2,0),fldv); // @{n:*[0,2],v:int}
359  TypeStruct ta2 = ts2.set_name("A:");
360 
361  // Peel A once without the nil: Memory#3: A:@{n:*[2],v:int}
362  // ASAS0AS0AS0AS0AS0AS0...
363  final int alias3 = BitsAlias.new_alias(BitsAlias.REC);
364  TypeMemPtr tptr3= TypeMemPtr.make(alias3,TypeObj.OBJ); // *[3]
365  TypeStruct ts3 = TypeStruct.make(TypeFld.make("n",tptr2,0),fldv); // @{n:*[0,2],v:int}
366  TypeStruct ta3 = ts3.set_name("A:");
367 
368  // Peel A twice without the nil: Memory#4: A:@{n:*[3],v:int}
369  // ASASAS0AS0AS0AS0AS0AS0...
370  final int alias4 = BitsAlias.new_alias(BitsAlias.REC);
371  TypeStruct ts4 = TypeStruct.make(TypeFld.make("n",tptr3,0),fldv); // @{n:*[3],v:int}
372  TypeStruct ta4 = ts4.set_name("A:");
373 
374  // Then make a MemPtr{3,4}, and ld - should be a PeelOnce
375  // Starting with the Struct not the A we get:
376  // Once: SAS0AS0AS0AS0AS0AS0...
377  // Twice: SAS AS0AS0AS0AS0AS0...
378  // Meet: SAS0AS0AS0AS0AS0AS0...
379  // which is the Once yet again
380  TypeObj[] tos = new TypeObj[alias4+1];
381  tos[1]=TypeObj.XOBJ;
382  tos[alias2]=ta2;
383  tos[alias3]=ta3;
384  tos[alias4]=ta4;
385  TypeMem mem234 = TypeMem.make0(tos);
386  TypeMemPtr ptr34 = (TypeMemPtr)TypeMemPtr.make(alias3,TypeObj.OBJ).meet(TypeMemPtr.make(alias4,TypeObj.OBJ));
387 
388  // Since hacking ptrs about from mem values, no cycles so instead...
389  Type mta = mem234.ld(ptr34);
390  //assertEquals(ta3,mta);
391  TypeMemPtr ptr023 = (TypeMemPtr)TypeMemPtr.make_nil(alias2,TypeObj.OBJ).meet(TypeMemPtr.make(alias3,TypeObj.OBJ));
392  TypeStruct xts = TypeStruct.make(TypeFld.make("n",ptr023,0),fldv);
393  Type xta = xts.set_name("A:");
394  assertEquals(xta,mta);
395 
396  // Mismatched Names in a cycle; force a new cyclic type to appear
397  final int alias5 = BitsAlias.new_alias(BitsAlias.REC);
398  TypeStruct tsnb = TypeStruct.make(TypeFld.make("n",TypeMemPtr.make_nil(alias5,TypeObj.OBJ),0),TypeFld.make("v",TypeFlt.FLT64,1));
399  TypeStruct tfb = tsnb.set_name("B:");
400  Type mtab = ta2.meet(tfb);
401 
402  // TODO: Needs a way to easily test simple recursive types
403  TypeStruct mtab0 = (TypeStruct)mtab;
404  assertEquals("n",mtab0.fld(0)._fld);
405  assertEquals("v",mtab0.fld(1)._fld);
406  TypeMemPtr mtab1 = (TypeMemPtr)mtab0.at(0);
407  assertTrue(mtab1._aliases.test(alias2)&& mtab1._aliases.test(alias5));
408  assertEquals(Type.REAL,mtab0.at(1));
409 
410 
411  // In the ptr/mem model, all Objs from the same NewNode are immediately
412  // approximated by a single Alias#. This stops any looping type growth.
413  // The only way to get precision back is to inline the NewNode and get new
414  // Alias#s.
415 
416  // Nest a linked-list style tuple 10 deep; verify actual depth is capped at
417  // less than 5. Any data loop must contain a Phi; if structures are
418  // nesting infinitely deep, then it must contain a NewNode also.
419  int alias = BitsAlias.new_alias(BitsAlias.REC);
420  TypeStruct ts = TypeStruct.make(TypeFld.make(TypeFld.fldBot,Type.NIL,0),TypeFld.make(TypeFld.fldBot,TypeInt.con(0),1));
421  TypeMemPtr phi = TypeMemPtr.make(alias,ts);
422  for( int i=1; i<20; i++ ) {
423  TypeStruct newt = TypeStruct.make(TypeFld.make(TypeFld.fldBot,phi,0),TypeFld.make(TypeFld.fldBot,TypeInt.con(i),1));
424  TypeStruct approx = newt.approx(2/*CUTOFF*/,alias);
425  phi = TypeMemPtr.make(alias,approx);
426  }
427  HashMap<Type,Integer> ds = phi.depth();
428  int d = TypeMemPtr.max(alias,ds);
429  assertTrue(0 <= d && d <10);
430  }

References com.cliffc.aa.type.TypeMemPtr._aliases, com.cliffc.aa.type.TypeStruct._cyclic, com.cliffc.aa.type.TypeFld._fld, com.cliffc.aa.type.TypeStruct.ALLSTRUCT, 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.TypeFld.fldBot, com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.type.TypeStruct.install_cyclic(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.type.TypeMem.ld(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeMem.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMem.make0(), com.cliffc.aa.type.TypeMemPtr.make_nil(), 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.TypeObj< O extends TypeObj< O >.OBJ, 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.TypeFld.setX(), com.cliffc.aa.type.Bits< B extends Bits< B >.test(), com.cliffc.aa.type.TypeFlds.ts(), and com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.XOBJ.

Here is the call graph for this function:

◆ testStructTuple()

void com.cliffc.aa.type.TestType.testStructTuple ( )

Definition at line 251 of file TestType.java.

251  {
252  Type nil = Type.NIL;
253  // Tuple is more general that Struct
254  Type tf = TypeStruct.TFLT64; // ( flt64); choice leading field name
255  Type tsx= TypeStruct. FLT64; // @{x:flt64}; fixed leading field name
256  Type tff = tsx.meet(tf); //
257  assertEquals(tf,tff); // tsx.isa(tf)
258  TypeStruct t0 = TypeStruct.make(Types.ts(nil)); // (nil)
259  TypeStruct ts0= TypeStruct.make(TypeFld.NO_DISP,TypeFld.make("x",nil,1)); // @{x:nil}
260  Type tss = ts0.meet(t0);
261  assertEquals(t0,tss); // t0.isa(ts0)
262 
263  // meet @{c:0}? and @{c:@{x:1}?,}
264  int alias0 = BitsAlias.type_alias(BitsAlias.REC);
265  int alias1 = BitsAlias.type_alias(alias0);
266  int alias2 = BitsAlias.type_alias(BitsAlias.REC);
267  int alias3 = BitsAlias.type_alias(alias0);
268  TypeObj a1 = TypeStruct.make(TypeFld.make("c",Type.NIL,0)); // @{c:nil}
269  TypeObj a3 = TypeStruct.make(TypeFld.make("x",TypeInt.TRUE,0)); // @{x: 1 }
270  TypeObj a2 = TypeStruct.make(TypeFld.make("c",TypeMemPtr.make_nil(alias3,a3),0)); // @{c:*{3#}?}
271  Ary<TypeObj> tos = new Ary<>(TypeObj.class);
272  tos.setX(BitsAlias.ALL,TypeObj.OBJ);
273  tos.setX(alias1,a1);
274  tos.setX(alias2,a2);
275  tos.setX(alias3,a3);
276  TypeMem mem = TypeMem.make0(tos.asAry()); // [7:@{c==nil},8:{c=*[0,9]},9:@{x==1}]
277  // *[1]? join *[2] ==> *[1+2]?
278  // {~0+7+8} -> @{ c== [~0] -> @{x==1}} // Retain precision after nil
279  Type ptr12 = Type.NIL.join(TypeMemPtr.make(-alias1,(TypeObj)a1.dual())).join( TypeMemPtr.make(-alias2,(TypeObj)a2.dual()));
280  // mem.ld(*[1+2]?) ==> @{c:0}
281  // Currently retaining precision after nil: [~0] -> @{ x==1}
282  Type ld = mem.ld((TypeMemPtr)ptr12);
283  TypeObj ax = TypeStruct.make(TypeFld.make("c",Type.NIL,0)); // @{c:nil}
284  assertTrue(ld.isa(ax));
285  }

References com.cliffc.aa.type.BitsAlias.ALL, com.cliffc.aa.util.Ary< E >.asAry(), com.cliffc.aa.type.Type< T extends Type< T >.dual(), com.cliffc.aa.type.Type< T extends Type< T >.isa(), com.cliffc.aa.type.Type< T extends Type< T >.join(), com.cliffc.aa.type.TypeMem.ld(), com.cliffc.aa.type.TypeFld.make(), com.cliffc.aa.type.TypeMemPtr.make(), com.cliffc.aa.type.TypeStruct.make(), com.cliffc.aa.type.TypeMem.make0(), com.cliffc.aa.type.TypeMemPtr.make_nil(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.type.Type< T extends Type< T >.NIL, com.cliffc.aa.type.TypeFld.NO_DISP, com.cliffc.aa.type.TypeObj< O extends TypeObj< O >.OBJ, com.cliffc.aa.type.BitsAlias.REC, com.cliffc.aa.util.Ary< E >.setX(), com.cliffc.aa.type.TypeStruct.TFLT64, com.cliffc.aa.type.TypeInt.TRUE, com.cliffc.aa.type.Types.ts(), and com.cliffc.aa.type.BitsAlias.type_alias().

Here is the call graph for this function:

◆ testType()

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

Definition at line 16 of file TestType.java.

16  {
17 
18  TypeFld vi = TypeFld.make("v",TypeInt.INT64,2);
19  TypeStruct a0 = TypeStruct.make(TypeFld.NO_DISP,TypeFld.make("n",Type.XSCALAR, 1),vi);
20  TypeStruct a1 = TypeStruct.make(TypeFld.NO_DISP,TypeFld.make("n",TypeMemPtr.make(9,a0),1),vi);
21  TypeStruct a2 = a1.approx(1,9);
22 
23  System.out.println(a1);
24  }

References com.cliffc.aa.type.TypeStruct.approx(), 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.TypeFld.NO_DISP, and com.cliffc.aa.type.Type< T extends Type< T >.XSCALAR.

Here is the call graph for this function:

The documentation for this class was generated from the following file:
com.cliffc.aa.type.TestType.testCrush0
void testCrush0(TypeObj ti, TypeObj tj)
Definition: TestType.java:542