aa
Type.java
Go to the documentation of this file.
1 package com.cliffc.aa.type;
2 
3 import com.cliffc.aa.util.*;
4 
5 import java.util.HashMap;
6 import java.util.concurrent.ConcurrentHashMap;
7 import java.util.function.Predicate;
8 
12 // C2-style type system, with Meet & Dual.
13 
14 // This is a symmetric complete bounded (ranked) lattice.
15 // Also the meet is commutative and associative.
16 // The lattice has a dual (symmetric), and join is ~(~x meet ~y).
17 // See https://en.wikipedia.org/wiki/Lattice_(order).
18 
19 // Symmetric around the centerline of constants. Fixed height, so a finite
20 // count of Meet stabilizes; a unique All (Bottom; no known value) and due to
21 // symmetry a unique Any (Top, all values simultaneously). Supports function
22 // types, various kinds of numeric ranges, nil, tuples and structs, objects,
23 // memory and named subtypes of the above.
24 //
25 // During program typing, always keeping the "loosest" possible program and if
26 // this program still types as 'Any' then the program is ambiguous. 'All'
27 // represents a type conflict.
28 //
29 // ASCII-Grams of Type Lattices
30 //
31 // Ints: ~int64 -> ~int32 -> ~int16 -> ~int8 -> ~int1 -> {...-3,-2,-1,0,1,2,3,...} -> int1 -> int8 -> int16 -> int32 -> int64
32 // /---^ /--^ \------v \---v
33 // Floats: ~flt64 -> ~flt32 ----------------------------> {... -pi,-0.1,0,0.1,pi, ... } ----------------------> flt32 -> flt64
34 // int{1,8,16} all inject in flt32; int32 injects in flt64. Small integer
35 // constants as floats inject into the integers.
36 //
37 // Named ints and flts "subtype", except for 0 which is canonically the same
38 // everywhere. Example assuming a name "gal:flt32"
39 // ~flt64 -> ~flt32 -> gal:~flt32 -> {... gal:-pi, gal:-0.1, 0, gal:0.1, gal:pi, ... } -> gal:flt32 -> flt32 -> flt64
40 //
41 // OOPs are everywhere nullable; they always support a {oop+null, oop, null,
42 // oop&null} set of choices, where oop+null and oop&null are duals.
43 // Tuples are OOPS with an infinite list of values; the values are dualed
44 // structurally.
45 // Structs are tuples with a set of named fields; the fields can be top, a
46 // field name, or bottom.
47 // Strings are OOPs which again can be top, a constant, or bottom.
48 //
49 // Because the meet is commutative, associative, distributive, the following holds:
50 //
51 // (forall X, join X) === ~(forall X, meet ~X)
52 //
53 // ===========================================================================
54 //
55 // A Treatise on NIL
56 //
57 // I want to have a distinguished NIL-type in the language - too obvious, too
58 // useful. Hence "i=0" or "ptr=0" or "ptr ? s1 : s2" all use the concept of
59 // nil. However, having a single type which can be both an integer and a
60 // pointer breaks the major Type Lattice property. Basically if nil can be
61 // used to "cross" between Integers and Pointers (or Fun Pointers, Floats, etc)
62 // then the Type system is no longer a Lattice and all sorts of havoc ensues.
63 //
64 // Over the past 1.5yrs I've tried every possible combination of things I can
65 // do with nil that also lets me keep it in the language and used in both
66 // integer and pointer contexts, but also in the Lattice. The Type code is
67 // full of train-wreck leftovers from various attempts.
68 //
69 // Example:
70 // ~int == int.dual() (the high ints)
71 // *str? == a nil-able pointer to a string
72 // A "NIL" such that ~int.meet(NIL) == NIL, but also NIL.meet(*str?) == (*str?)
73 // seems highly desirable... and crosses between ints and string-pointers.
74 
75 // Cast-not-nil (after a if-test for nil) in dying (not dead) code often sees
76 // nil inputs. Casts do a JOIN on their input - so we might see e.g.
77 // nil.join(*str). The problem is, the nil can drop to an int before the Cast
78 // goes dead. Thus the Cast computes int.join(*str). Since nil.isa(int) the
79 // Cast inputs drop monotonically... so the output should also. Thus
80 // nil.join(*str).isa(int.join(*str)). This is a standard symmetry
81 // property and is one of the major Type system asserts... and it doesn't hold.
82 
83 // nil.isa(int) == TRUE ; the nil is treated as a TypeInt.ZERO
84 // nil.join(*str) == *[0+4+]str? ; the nil is treated as a TypeMemPtr.NIL.
85 // int.join(*str) == nScalar ; Nothing in common
86 // *[0+4+]str?.isa(nScalar) == FALSE!!!!! ; Crossing-nil has failed again...
87 
88 // Tried a nil is in the Type system, but OUT of the Lattice. At any given use
89 // point the nil collapses exactly one of the more refined nils (TypeInt.ZERO,
90 // TypeMemPtr.NIL, etc) but until then it is an undistinguished nil.
91 
92 // Current solution is that nil is signed: XNIL and NIL.
93 
94 public class Type<T extends Type<T>> implements Cloneable {
95  static private int CNT=1;
96  public int _uid; // Unique ID, will have gaps, used to uniquely order Types
97  public int _hash; // Hash for this Type; built recursively
98  byte _type; // Simple types use a simple enum
99  public String _name; // All types can be named
100  T _dual; // All types support a dual notion, eagerly computed and cached here
101 
102  protected Type() { _uid = _uid(); }
103  private int _uid() { return CNT++; }
104  @SuppressWarnings("unchecked")
105  protected T init(byte type, String name) { _type=type; _name=name; return (T)this; }
106  @Override public final int hashCode( ) { assert _hash!=0; return _hash; }
107  // Compute the hash and return it, with all child types already having their
108  // hash computed. Subclasses override this.
109  int compute_hash() { return (_type<<1)|1|_name.hashCode(); }
110 
111  // Is anything equals to this?
112  @Override public boolean equals( Object o ) {
113  if( this == o ) return true;
114  if( !(o instanceof Type) ) return false;
115  Type t = (Type)o;
116  return _type==t._type && Util.eq(_name,t._name);
117  }
118  public boolean cycle_equals( Type t ) {
119  assert is_simple(); // Overridden in subclasses
120  return _type==t._type && Util.eq(_name,t._name);
121  }
122 
123  // In order to handle recursive printing, this is the only toString call in
124  // the Type hierarchy. Instead, subtypes override 'str(...)' where the extra
125  // args stop cycles (VBitSet) or sharpen pointers (TypeMem), or optimize
126  // printing strings (SB).
127  @Override public final String toString() { return str(new SB(),new VBitSet(),null,true).toString(); }
128  // Nice, REPL-friendly and error-friendly dump.
129  // Debug flag dumps, e.g. raw aliases and raw fidxs.
130  // This is the 'base' printer, as changing this changes behavior.
131  public SB str( SB sb, VBitSet dups, TypeMem mem, boolean debug ) { return sb.p(_name).p(STRS[_type]); }
132 
133  // Shallow array compare, using '==' instead of 'equals'. Since elements are
134  // interned, this is the same as 'equals' except asymptotically faster unless
135  // there is a type-cycle, then infinitely faster.
136  public static boolean eq( Type[] t0, Type[] t1 ) {
137  if( t0==t1 ) return true;
138  if( t0==null || t1==null ) return false;
139  if( t0.length != t1.length ) return false;
140  for( int i=0; i<t0.length; i++ )
141  if( t0[i] != t1[i] )
142  return false;
143  return true;
144  }
145 
146  // Construct a simple type, possibly from a pool
147  static Type make(byte type) {
148  Pool P = POOLS[type];
149  Type t1 = P.malloc();
150  return t1.init(type,"").hashcons_free();
151  }
152  @SuppressWarnings("unchecked")
153  final T hashcons_free() {
154  T t2 = hashcons();
155  return this==t2 ? t2 : (T)POOLS[_type].free(this,t2);
156  }
157 
158  // ----------------------------------------------------------
159  // Hash-Cons - all Types are interned in this hash table. Thus an equality
160  // check of a (possibly very large) Type is always a simple pointer-equality
161  // check, except during construction and intern'ing.
162  private static final ConcurrentHashMap<Type,Type> INTERN = new ConcurrentHashMap<>();
163  public static int RECURSIVE_MEET; // Count of recursive meet depth
164  @SuppressWarnings("unchecked")
165  private T hashcons() {
166  _hash = compute_hash(); // Set hash
167  T t2 = (T)INTERN.get(this); // Lookup
168  if( t2!=null ) { // Found prior
169  assert t2._dual != null; // Prior is complete with dual
170  assert this != t2; // Do not hashcons twice, should not get self back
171  return t2; // Return prior
172  }
173  if( RECURSIVE_MEET > 0 ) // Mid-building recursive types; do not intern
174  return (T)this;
175  // Not in type table
176  _dual = null; // No dual yet
177  INTERN.put(this,this); // Put in table without dual
178  T d = xdual(); // Compute dual without requiring table lookup, and not setting name
179  d._name = _name; // xdual does not set name either
180  d._hash = d.compute_hash(); // Set dual hash
181  _dual = d;
182  if( this==d ) return d; // Self-symmetric? Dual is self
183  assert !equals(d); // Self-symmetric is handled by caller
184  assert d._dual==null; // Else dual-dual not computed yet
185  assert INTERN.get(d)==null;
186  d._dual = (T)this;
187  INTERN.put(d,d);
188  return (T)this;
189  }
190  // Remove a forward-ref type from the interning dictionary, prior to
191  // interning it again - as a self-recursive type
192  @SuppressWarnings("unchecked")
193  final T untern( ) {
194  assert _hash != 0;
195  assert INTERN.get(this)==this;
196  Type rez = INTERN.remove(this);
197  assert rez == this;
198  return (T)this;
199  }
200  @SuppressWarnings("unchecked")
201  final T retern( ) {
202  assert _dual._dual == this;
203  assert _hash != 0;
204  assert INTERN.get(this)==null;
205  INTERN.put(this,this);
206  assert INTERN.get(this)==this;
207  return (T)this;
208  }
209  boolean interned() { return INTERN.get(this)==this; }
210  Type intern_lookup() { return INTERN.get(this); }
211  static int intern_size() { return INTERN.size(); }
212  public static boolean intern_check() {
213  int errs=0;
214  for( Type k : INTERN.keySet() ) {
215  Type v = INTERN.get(k);
216  if( !k.intern_check0(v) ) {
217  System.out.println("INTERN_CHECK FAIL: "+k._uid+":"+k+" vs "+v._uid+":"+v);
218  errs++;
219  }
220  }
221  return errs==0;
222  }
223  private boolean intern_check0(Type v) {
224  if( this != v || _dual==null || _dual._dual!=this || compute_hash()!=_hash ) return false;
225  return intern_check1();
226  }
227  boolean intern_check1() { return true; }
228  // Debugging helper
229  static Type intern_find(int uid) {
230  for( Type k : INTERN.keySet() )
231  if( k._uid==uid )
232  return k;
233  return null;
234  }
235 
236  // ----------------------------------------------------------
237  // Simple types are implemented fully here. "Simple" means: the code and
238  // type hierarchy are simple, not that the Type is conceptually simple.
239  static final byte TALL = 0; // Bottom
240  static final byte TANY = 1; // Top
241  static final byte TCTRL = 2; // Ctrl flow bottom
242  static final byte TXCTRL = 3; // Ctrl flow top (mini-lattice: any-xctrl-ctrl-all)
243  // Scalars; all possible finite types that fit in a machine register;
244  // includes pointers (functions, structs), ints, floats; excludes state of
245  // Memory and Ctrl. Scalars are stateless and "free" to make copies.
246  static final byte TSCALAR = 4; // Scalars
247  static final byte TXSCALAR= 5; // Invert scalars
248  // Not-nil Scalars. Same as Scalars above but excludes nil/0. Note that I
249  // have a doubly represented type: TypeNil.make(SCALAR) would add a nil to a
250  // SCALAR except SCALAR already has a nil. This means if I define SCALAR as
251  // not having a nil, I could drop TNSCALR and TXNSCALR... but that makes
252  // TypeNil.make(SCALAR) below SCALAR in the lattice, which gets ugly.
253  static final byte TNSCALR = 6; // Scalars-not-nil
254  static final byte TXNSCALR= 7; // Invert Scalars-not-nil
255  static final byte TREAL = 8; // All Real Numbers
256  static final byte TXREAL = 9; // Any Real Numbers; dual of REAL
257  static final byte TNREAL =10; // Numbers-not-nil
258  static final byte TXNREAL =11; // Invert Numbers-not-nil
259  static final byte TNIL =12; // The Nil-type
260  static final byte TXNIL =13; // NIL.dual
261  static final byte TSIMPLE =14; // End of the Simple Types
262  private static final String[] STRS = new String[]{"all","any","Ctrl","~Ctrl","Scalar","~Scalar","nScalar","~nScalar","Real","~Real","nReal","~nReal","nil","0"};
263  static final byte TINT =15; // All Integers, including signed/unsigned and various sizes; see TypeInt
264  static final byte TFLT =16; // All IEEE754 Float Numbers; 32- & 64-bit, and constants and duals; see TypeFlt
265  static final byte TRPC =17; // Return PCs; Continuations; call-site return points; see TypeRPC
266  static final byte TTUPLE =18; // Tuples; finite collections of unrelated Types, kept in parallel
267  static final byte TOBJ =19; // Memory objects; arrays and structs and strings
268  static final byte TSTRUCT =20; // Memory Structs; tuples with named fields
269  static final byte TARY =21; // Memory Array type
270  static final byte TSTR =22; // Memory String type; an array of chars
271  static final byte TFLD =23; // Fields in structs
272  static final byte TMEM =24; // Memory type; a map of Alias#s to TOBJs
273  static final byte TMEMPTR =25; // Memory pointer type; a collection of Alias#s
274  static final byte TFUNPTR =26; // Function pointer, refers to a collection of concrete functions
275  static final byte TFUNSIG =27; // Function signature; formals & ret. Not any concrete function.
276  static final byte TLIVE =28; // Liveness; backwards flow of TypeObj
277  static final byte TLAST =29; // Type check
278 
279  // Object Pooling to handle frequent (re)construction of temp objects being
280  // interned.
281  static final Pool[] POOLS = new Pool[TLAST];
282  @SuppressWarnings("unchecked")
283  static class Pool {
284  private int _malloc, _free, _pool, _clone;
285  private final Ary<Type> _frees;
286  private final Type _gold;
287  Pool(byte t, Type gold) {
288  gold._type = t;
289  _gold=gold;
290  _frees= new Ary<>(new Type[1],0);
291  POOLS[t] = this;
292  }
293  <T extends Type> T malloc() {
294  if( _frees.isEmpty() ) { _malloc++; _clone--; return (T)_gold.clone(); }
295  else { _pool ++; return (T)_frees.pop(); }
296  }
297  <T extends Type> T free(T t1, T t2) {
298  _frees.push(t1);
299  _free++;
300  return t2;
301  }
302  }
303  @SuppressWarnings("unchecked")
304  protected Type clone() {
305  try {
306  POOLS[_type]._clone++;
307  Type t = (Type)super.clone();
308  t._uid = _uid();
309  t._dual = null;
310  t._hash = 0;
311  if( t instanceof TypeStruct )
312  ((TypeStruct)t)._cyclic = false;
313  return t;
314  }
315  catch( CloneNotSupportedException cns ) { throw new RuntimeException(cns); }
316  }
317 
318  // All the simple types share the same pool
319  static {
320  Pool P = new Pool(TALL,new Type());
321  for( int i=0; i<TSIMPLE; i++ ) POOLS[i]=P;
322  }
323 
324  public static final Type ALL = make( TALL ); // Bottom
325  public static final Type ANY = make( TANY ); // Top
326  public static final Type CTRL = make( TCTRL ); // Ctrl
327  public static final Type XCTRL = make(TXCTRL ); // Ctrl
328  public static final Type SCALAR= make( TSCALAR); // ptrs, ints, flts; things that fit in a machine register
329  public static final Type XSCALAR= make(TXSCALAR); // ptrs, ints, flts; things that fit in a machine register
330  public static final Type NSCALR= make( TNSCALR); // Scalars-not-nil
331  public static final Type XNSCALR= make(TXNSCALR); // Scalars-not-nil
332  public static final Type NIL = make( TNIL ); // The Nil.
333  public static final Type XNIL = make(TXNIL ); // The ~Nil.
334  public static final Type REAL = make( TREAL );
335  private static final Type XREAL = make(TXREAL );
336  static final Type NREAL = make( TNREAL );
337  private static final Type XNREAL = make(TXNREAL );
338 
339  // Collection of sample types for checking type lattice properties.
340  private static final Type[] TYPES = new Type[]{ALL,CTRL,SCALAR,NSCALR,REAL,NREAL};
341 
342  // The complete list of primitive types that are disjoint and also is-a
343  // SCALAR; nothing else is a SCALAR except what is on this list (or
344  // subtypes). Useful when type-specializing functions to break SCALAR args
345  // into a concrete list of specific types. Specifically excludes e.g.
346  // TypeTuple - these may be passed as a scalar reference type in the future
347  // but for now Tuples explicitly refer to multiple values, and a SCALAR is
348  // exactly 1 value.
349  private static /*final*/ Type[] SCALAR_PRIMS;
350 
351  private boolean is_simple() { return _type < TSIMPLE; }
352  private boolean is_ptr() { byte t = _type; return t == TFUNPTR || t == TMEMPTR; }
353  private boolean is_num() { byte t = _type; return t == TREAL || t == TXREAL || t == TNREAL || t == TXNREAL || t == TINT || t == TFLT; }
354  // True if 'this' isa SCALAR, without the cost of a full 'meet()'
355  private static final byte[] ISA_SCALAR = new byte[]{/*ALL-0*/0,0,0,0,1,1,1,1,1,1,/*TNREAL-10*/1,1,1,1,/*TSIMPLE-14*/0, 1,1,1,0,0,0,0,0,0,0,1,1,/*TFUNSIG-27*/0,/*TLIVE-28*/0}/*TLAST=29*/;
356  public final boolean isa_scalar() { assert ISA_SCALAR.length==TLAST; return ISA_SCALAR[_type]!=0; }
357  // Simplify pointers (lose what they point at).
358  public Type simple_ptr() { return this; }
359 
360  // Return cached dual
361  public final T dual() { return _dual; }
362 
363  // Compute dual right now. Overridden in subclasses.
364  @SuppressWarnings("unchecked")
365  T xdual() { return (T)new Type().init((byte)(_type^1),""); }
366  T rdual() { assert _dual!=null; return _dual; }
367 
368  // ----------------------------------------------------------
369  // Memoize meet results
370  private static class Key {
371  static Key K = new Key(null,null);
373  Key(Type a, Type b) { _a=a; _b=b; }
375  @Override public int hashCode() { return ((_a._hash<<17)|(_a._hash>>>15))^_b._hash; }
376  @Override public boolean equals(Object o) { return _a==((Key)o)._a && _b==((Key)o)._b; }
377  static Type get(Type a, Type b) {
378  K._a=a;
379  K._b=b;
380  return INTERN_MEET.get(K);
381  }
382  static void put(Type a, Type b, Type mt) {
383  INTERN_MEET.put(new Key(a,b),mt);
384  // Uncomment to check hash quality.
385  //Util.hash_quality_check_per(INTERN_MEET);
386  }
389  for( Key k : INTERN_MEET.keySet() ) {
390  int hash = k.hashCode();
391  Integer ii = hashs.get(hash);
392  hashs.put(hash,ii==null ? 1 : ii+1);
393  }
394  int[] hist = new int[16];
395  int maxval=0;
396  long maxkey=-1;
397  for( long l : hashs.keySet() ) {
398  int reps = hashs.get(l);
399  if( reps > maxval ) { maxval=reps; maxkey=l; }
400  if( reps < hist.length ) hist[reps]++;
401  else System.out.println("hash "+l+" repeats "+reps);
402  }
403  for( int i=0; i<hist.length; i++ )
404  if( hist[i] > 0 )
405  System.out.println("Number of hashes with "+i+" repeats: "+hist[i]);
406  System.out.println("Max repeat key "+maxkey+" repeats: "+maxval);
407  }
408 
409  }
410 
411  // Compute the meet
412  public final Type meet( Type t ) {
413  // Short cut for the self case
414  if( t == this ) return this;
415  // Short-cut for seeing this meet before
416  Type mt = Key.get(this,t);
417  if( mt != null ) return mt;
418 
419  // "Triangulate" the matrix and cut in half the number of cases.
420  // Reverse; xmeet 2nd arg is never "is_simple" and never equal to "this".
421  // This meet ignores the _name field, and can return any-old name it wants.
422  mt = !is_simple() && t.is_simple() ? t.xmeet(this) : xmeet(t);
423 
424  // Meet the names. Subclasses basically ignore the names as they have
425  // their own complicated meets to perform, so we meet them here for all.
426  Type nmt = xmt_name(t,mt);
427 
428  // Quick check on NIL: if either argument is NIL the result is allowed to
429  // be NIL... but nobody in the lattice can make a NIL from whole cloth, or
430  // we get the crossing-nil bug.
431  assert (nmt != NIL && nmt!=XNIL) || this==NIL || this==XNIL || t==NIL || t==XNIL;
432 
433  // Record this meet, to short-cut next time
434  if( RECURSIVE_MEET == 0 ) // Only not mid-building recursive types;
435  Key.put(this,t,nmt);
436  return nmt;
437  }
438 
439  // Meet the names. Subclasses basically ignore the names as they have
440  // their own complicated meets to perform, so we meet them here for all.
441  private Type xmt_name(Type t, Type mt) {
442  String n = mtname(t,mt); // Meet name strings
443  // If the names are incompatible and the meet remained high then the
444  // mismatched names force a drop.
445  if( n.length() < _name.length() && n.length() < t._name.length() && mt.above_center() ) {
446  if( mt.interned() ) // recursive type creation?
447  mt = mt.dual(); // Force low
448  }
449  if( mt.is_simple() ) n=""; // No named simple types
450  if( mt._type==TOBJ ) n=""; // OBJ splits into strings (arrays) and structs, which can keep their names
451 
452  // Inject the name
453  if( !Util.eq(mt._name,n) ) // Fast path cutout
454  mt = mt.set_name(n);
455  return mt;
456  }
457 
458  // Compute meet right now. Overridden in subclasses.
459  // Handles cases where 'this.is_simple()' and unequal to 't'.
460  // Subclassed xmeet calls can assert that '!t.is_simple()'.
461  protected Type xmeet(Type t) {
462  assert is_simple(); // Should be overridden in subclass
463  // ANY meet anything is thing; thing meet ALL is ALL
464  if( _type==TALL || t._type==TANY ) return this;
465  if( _type==TANY || t._type==TALL ) return t;
466 
467  // Ctrl can only meet Ctrl, XCtrl or Top
468  byte type = (byte)(_type|t._type); // the OR is low if both are low
469  if( type <= TXCTRL ) return _type==TXCTRL && t._type==TXCTRL ? XCTRL : CTRL;
470  if( _type <= TXCTRL || t._type <= TXCTRL ) return ALL;
471 
472  // Meeting scalar and non-scalar falls to ALL. Includes most Memory shapes.
473  if( isa_scalar() ^ t.isa_scalar() ) return ALL;
474 
475  // Memory does something complex with memory
476  if( t._type==TMEM ) return t.xmeet(this);
477 
478  // Scalar is close to bottom: nearly everything falls to SCALAR, except
479  // Bottom (already handled) and Control (error; already handled).
480  if( _type == TSCALAR || t._type == TSCALAR ) return SCALAR;
481 
482  // ~Scalar is close to Top: it falls to nearly anything.
483  if( _type == TXSCALAR ) return t ;
484  if( t._type == TXSCALAR ) return this;
485 
486  // Not-nil variants
487  if( _type == TNSCALR ) return t.must_nil() ? SCALAR : NSCALR;
488  if( t._type == TNSCALR ) return must_nil() ? SCALAR : NSCALR;
489  if( _type == TXNSCALR) return t.not_nil();
490  if( t._type == TXNSCALR) return not_nil();
491 
492  if( _type == TNIL || _type == TXNIL ) return t.meet_nil(this);
493 
494  // Scalar values break out into: nums(reals (int,flt)), GC-ptrs (structs(tuples), arrays(strings)), fun-ptrs, RPC
495  if( t._type == TFUNPTR ||
496  t._type == TMEMPTR ||
497  t._type == TRPC )
498  return cross_nil(t);
499 
500  boolean that_oop = t.is_ptr();
501  boolean that_num = t.is_num();
502  assert !(that_oop&&that_num);
503 
504  // Down to just nums and GC-ptrs
505  if( is_num() ) {
506  // May be OOP0 or STR or STRUCT or TUPLE
507  if( that_oop ) return (must_nil() || t.must_nil()) ? SCALAR : NSCALR;
508  if( that_num || t==NIL || t==XNIL ) {
509  // Real; same pattern as ANY/ALL, or SCALAR/XSCALAR
510  if( _type == TREAL || t._type == TREAL ) return REAL;
511  if( _type == TXREAL ) return t ;
512  if( t._type == TXREAL ) return this;
513 
514  // Not-nil variants
515  if( _type == TNREAL ) return t.must_nil() ? REAL : NREAL;
516  if( t._type == TNREAL ) return must_nil() ? REAL : NREAL;
517  if( _type == TXNREAL) return t.not_nil();
518  if( t._type == TXNREAL) return not_nil();
519  }
520  }
521  throw typerr(t);
522  }
523 
524  // Named types are essentially a subclass of any type.
525  // Examples:
526  // B:A:int << B:int << int // Subtypes
527  // B:int.isa (int)
528  // B:A:int.isa (B:int)
529  // C:int.meet(B:int) == int
530  // B:A:int.meet(C:int) == int
531  //
532  // B:A:~int.join(B:~int) == B:A:~int
533  // C:~int.join(B:~int) == ~int
534  //
535  // B: int.meet( ~int) == B: int.meet(B:~int) == B:int
536  // B:~int.meet( int) == int
537  // B:~int.meet(C: int) == int
538  // B:~int.meet(B: int) == B: int
539  // B:~int.meet(C:~int) == int // Nothing in common, fall to int
540  // B:~int.meet( ~int) == B: ~int
541  // B:A:~int.meet(B:~int) == B:A:~int // both high, keep long; short guy high, keep long
542  // B:A:~int.meet(B: int) == B: int // one low, keep low ; short guy low, keep short
543  // B:A: int.meet(B:~int) == B:A: int // one low, keep low ; short guy high, keep long
544  // B:A: int.meet(B: int) == B: int // both low, keep short; short guy low, keep short
545  //
546  // B:A:~int.meet(B:D:~int) == B:int // Nothing in common, fall to int
547 
548  static boolean check_name( String n ) { return n.isEmpty() || n.charAt(n.length()-1)==':'; }
549  public boolean has_name() { return !_name.isEmpty(); }
550  // Make a named variant of any type, by just adding a name.
551  public final T set_name(String name) {
552  assert check_name(name);
553  return _set_name(name);
554  }
555  @SuppressWarnings("unchecked")
556  public final T remove_name() { return has_name() ? _set_name("") : (T)this; }
557  @SuppressWarnings("unchecked")
558  private T _set_name(String name) {
559  POOLS[_type]._clone++;
560  T t1 = (T)clone();
561  t1._name = name;
562  return t1.hashcons_free();
563  }
564 
565  // TODO: will also need a unique lexical numbering, not just a name, to
566  // handle the case of the same name used in two different scopes.
567  final String mtname(Type t, Type mt) {
568  Type t0 = this, t1 = t;
569  String s0 = t0._name, s1 = t1._name;
570  assert check_name(s0) && check_name(s1);
571  if( Util.eq(s0,s1) ) return s0;
572  // Sort by name length
573  if( s0.length() > s1.length() ) { t1=this; t0=t; s0=t0._name; s1=t1._name; }
574  int x = 0, i; char c; // Last colon separator index
575  // Find split point
576  for( i = 0; i < s0.length(); i++ ) {
577  if( (c=s0.charAt(i)) != s1.charAt(i) )
578  break;
579  if( c==':' ) x=i;
580  }
581  // If s0 is a prefix of s1, and s0 is high then it can cover s1.
582  if( i==s0.length() && t0.above_center() && (!t1.above_center() || mt.above_center()) )
583  return s1;
584  // Keep the common prefix, which might be all of s0
585  String s2 = i==s0.length() ? s0 : s0.substring(0, x).intern();
586  assert check_name(s2);
587  return s2;
588  }
589 
590  // By design in meet, args are already flipped to order _type, which forces
591  // symmetry for things with badly ordered _type fields. The question is
592  // still interesting for other orders.
593  private boolean check_commute( Type t, Type mt ) {
594  if( t==this ) return true;
595  if( is_simple() && !t.is_simple() ) return true; // By design, flipped the only allowed order
596  Type mt2 = t.xmeet(this); // Reverse args and try again
597 
598  // Also reverse names.
599  Type nmt2 = t.xmt_name(this,mt2);
600 
601  if( mt==nmt2 ) return true;
602  System.out.println("Meet not commutative: "+this+".meet("+t+")="+mt+",\n but "+t+".meet("+this+")="+nmt2);
603  return false;
604  }
605  // A & B = MT
606  // Expect: ~A & ~MT == ~A
607  // Expect: ~B & ~MT == ~B
608  private boolean check_symmetric( Type t, Type mt ) {
609  if( t==this ) return true;
610  Type ta = mt._dual.meet(t._dual);
611  Type tb = mt._dual.meet( _dual);
612  if( ta==t._dual && tb==_dual ) return true;
613  System.err.print("("+this+" & "+t+")=="+mt+" but \n("+mt._dual+" & ");
614  if( ta!=t._dual ) System.err.println(t._dual+")=="+ta+" \nwhich is not "+t._dual);
615  else System.err.println( _dual+")=="+tb+" \nwhich is not "+ _dual);
616  return false;
617  }
618 
619  public Type join( Type t ) { return dual().meet(t.dual()).dual(); }
620 
621  // True if 'this' isa/subtypes 't'. E.g. Int32-isa-Int64, but not vice-versa
622  // E.g. ANY-isa-XSCALAR; XSCALAR-isa-XREAL; XREAL-isa-Int(Any); Int(Any)-isa-Int(3)
623  public boolean isa( Type t ) { return meet(t)==t; }
624  // True if 'this' isa 't' but is not equal to 't'
625  public boolean above( Type t ) { return t != this && meet(t)==t; }
626 
627  // MEET at a Loop; optimize no-final-updates on backedges.
628  public Type meet_loop(Type t2) { return meet(t2); }
629 
630 
631  // Report OOB based on shallowest OOB component.
632  public Type oob_deep( Type t ) { return oop_deep_impl(t); }
633  // Report OOB based on shallowest OOB component.
634  public Type oop_deep_impl(Type t) { return oob(); }
635  public Type oob( ) { return oob(ALL); }
636  public Type oob(Type e) { return above_center() ? e.dual() : e; }
637  public TypeObj oob(TypeObj e) { return above_center() ? (TypeObj)e.dual() : e; }
638  public TypeStruct oob(TypeStruct e) { return above_center() ? e.dual() : e; }
639  public TypeMem oob(TypeMem e) { return above_center() ? e.dual() : e; }
640  public TypeMemPtr oob(TypeMemPtr e) { return above_center() ? e.dual() : e; }
641 
642  public static void init0( HashMap<String,Type> types ) {
643  types.put("real",REAL);
644  types.put("scalar",SCALAR);
645  TypeInt.init1(types);
646  TypeFlt.init1(types);
647  TypeStr.init1(types);
648  }
649 
650  private static Ary<Type> ALL_TYPES; // Used for tests
651  public static Ary<Type> ALL_TYPES() {
652  if( ALL_TYPES != null ) return ALL_TYPES;
653  Ary<Type> ts = new Ary<>(new Type[1],0);
654  concat(ts,Type .TYPES);
655  concat(ts,TypeFlt .TYPES);
656  concat(ts,TypeFunPtr.TYPES);
657  concat(ts,TypeFunSig.TYPES);
658  concat(ts,TypeInt .TYPES);
659  concat(ts,TypeLive .TYPES);
660  concat(ts,TypeMem .TYPES);
661  concat(ts,TypeMemPtr.TYPES);
662  concat(ts,TypeObj .TYPES);
663  concat(ts,TypeRPC .TYPES);
664  concat(ts,TypeStr .TYPES);
665  concat(ts,TypeStruct.TYPES);
666  concat(ts,TypeTuple .TYPES);
667  concat(ts,TypeAry .TYPES);
668  // Partial order Sort, makes for easier tests later. Arrays.sort requires
669  // a total order (i.e., the obvious Comparator breaks the sort contract),
670  // so we hand-roll a simple bubble sort.
671  for( int i=0; i<ts._len; i++ )
672  for( int j=i+1; j<ts._len; j++ )
673  if( ts._es[j].isa(ts._es[i]) ) { Type tmp = ts._es[i]; ts._es[i] = ts._es[j]; ts._es[j] = tmp; }
674  return (ALL_TYPES = ts); // Preserve for tests
675  }
676  static void concat( Ary<Type> ts, Type[] ts1 ) {
677  for( Type t1 : ts1 ) {
678  assert !t1.above_center(); // Always below-center or equal, because we'll dual anyways
679  ts.push(t1);
680  if( t1!=t1.dual() ) ts.push(t1.dual());
681  }
682  }
683 
684  static boolean check_startup() {
685  Type[] ts = ALL_TYPES().asAry();
686 
687  // Confirm commutative & complete
688  for( Type t0 : ts )
689  for( Type t1 : ts ) {
690  Type mt = t0.meet(t1);
691  assert t0.check_commute (t1,mt);
692  assert t0.check_symmetric(t1,mt);
693  }
694 
695  // Confirm associative
696  int errs=0;
697  for( Type t0 : ts )
698  for( Type t1 : ts )
699  for( Type t2 : ts ) {
700  Type t01 = t0 .meet(t1 );
701  Type t12 = t1 .meet(t2 );
702  Type t01_2 = t01.meet(t2 );
703  Type t0_12 = t0 .meet(t12);
704  if( t01_2 != t0_12 && errs++ < 10 )
705  System.err.println("("+t0+"&"+t1+") & "+t2+" == "+t0+" & ("+t1+" & "+t2+"); "+
706  "("+t01 +") & "+t2+" == "+t0+" & ("+t12 +"); "+
707  t01_2 +" == "+t0_12);
708  }
709  assert errs==0 : "Found "+errs+" associative errors";
710 
711 
712  // Confirm symmetry. If A isa B, then A.join(C) isa B.join(C)
713  for( Type t0 : ts )
714  for( Type t1 : ts ) {
715  if( t0.isa(t1) ) {
716  for( Type t2 : ts ) {
717  Type t02 = t0.join(t2);
718  Type t12 = t1.join(t2);
719  Type mt = t02.meet(t12);
720  if( mt != t12 && errs++ < 10 ) {
721  System.err.println("("+t0+" ^ "+t2+") = "+t02+"; "+
722  "("+t1+" ^ "+t2+") = "+t12+"; "+
723  "their meet = "+mt+" which is not "+t12);
724  }
725  }
726  }
727  }
728  assert errs==0 : "Found "+errs+" non-join-type errors";
729 
730  // Check scalar primitives; all are SCALARS and none sub-type each other.
732  for( Type t : SCALAR_PRIMS ) assert t.isa(SCALAR);
733  for( int i=0; i<SCALAR_PRIMS.length; i++ )
734  for( int j=i+1; j<SCALAR_PRIMS.length; j++ )
735  assert !SCALAR_PRIMS[i].isa(SCALAR_PRIMS[j]);
736 
737  return true;
738  }
739 
740  // True if value is above the centerline (no definite value, ambiguous)
741  public boolean above_center() {
742  switch( _type ) {
743  case TALL:
744  case TCTRL:
745  case TREAL: case TNREAL:
746  case TSCALAR: case TNSCALR:
747  case TNIL:
748  return false; // These are all below center
749  case TANY:
750  case TXCTRL:
751  case TXREAL: case TXNREAL:
752  case TXSCALAR: case TXNSCALR:
753  case TXNIL:
754  return true; // These are all above center
755  default: throw typerr(null);// Overridden in subclass
756  }
757  }
758  // True if value is higher-equal to SOME constant.
759  public boolean may_be_con() {
760  switch( _type ) {
761  case TALL:
762  case TSCALAR: case TNSCALR:
763  case TREAL: case TNREAL:
764  case TXCTRL:
765  case TCTRL:
766  return false; // These all include not-constant things
767  case TANY:
768  case TXREAL: case TXNREAL:
769  case TXSCALAR: case TXNSCALR:
770  case TNIL: case TXNIL:
771  return true; // These all include some constants
772  default: throw typerr(null);
773  }
774  }
775  // True if exactly a constant (not higher, not lower)
776  public boolean is_con() {
777  switch( _type ) {
778  case TALL:
779  case TCTRL:
780  case TNREAL:
781  case TREAL:
782  case TNSCALR:
783  case TSCALAR:
784  case TANY:
785  case TXCTRL:
786  case TXNREAL:
787  case TXREAL:
788  case TXNSCALR:
789  case TXSCALAR:
790  return false; // Not exactly a constant
791  case TNIL: case TXNIL:
792  return true;
793  default: throw typerr(null);// Overridden in subclass
794  }
795  }
796  public Type high() { return above_center() ? this : dual(); }
797 
798  // Return true if this is a forward-ref function pointer (return type from EpilogNode)
799  public boolean is_forward_ref() { return false; }
800 
801  // Return a long from a TypeInt constant; assert otherwise.
802  public long getl() { if( _type==TNIL || _type==TXNIL ) return 0; throw typerr(null); }
803  // Return a double from a TypeFlt constant; assert otherwise.
804  public double getd() { if( _type==TNIL || _type==TXNIL ) return 0.0; throw typerr(null); }
805  // Return a String from a TypeStr constant; assert otherwise.
806  public String getstr() { throw typerr(null); }
807 
808  // Lattice of conversions:
809  // -1 unknown; top; might fail, might be free (Scalar->Int); Scalar might lift
810  // to e.g. Float and require a user-provided rounding conversion from F64->Int.
811  // 0 requires no/free conversion (Int8->Int64, F32->F64)
812  // +1 requires a bit-changing conversion (Int->Flt)
813  // 99 Bottom; No free converts; e.g. Flt->Int requires explicit rounding
814  public byte isBitShape(Type t) {
815  if( has_name() || t.has_name() ) throw com.cliffc.aa.AA.unimpl();
816  if( _type == TNIL || _type==TXNIL ) return 0; // Nil is free to convert always
817  if( above_center() && isa(t) ) return 0; // Can choose compatible format
818  if( _type == t._type ) return 0; // Same type is OK
819  if( t._type==TSCALAR ) return 0; // Generic function arg never requires a conversion
820  if( _type == TALL || t._type==TALL || _type == TSCALAR || _type == TNSCALR ) return -1; // Scalar has to resolve
821  if( (_type == TREAL || _type == TNREAL) && t.is_num() ) return -1; // Real->Int/Flt has to resolve
822  if( t._type == TNIL || t._type == TXNIL ) return (byte)(may_nil() ? -1 : 99); // Must resolve to a NIL first
823 
824  throw typerr(t); // Overridden in subtypes
825  }
826  // "widen" a narrow type for primitive type-specialization and H-M
827  // unification. e.g. "3" becomes "int64".
828  public Type widen() {
829  switch( _type ) {
830  case TREAL: case TXREAL:
831  case TSCALAR: case TXSCALAR:
832  case TNSCALR: case TXNSCALR:
833  case TNIL: case TXNIL:
834  return SCALAR;
835  case TANY : case TALL :
836  return this;
837  case TCTRL: case TXCTRL:
838  return Type.CTRL;
839  default: throw typerr(null); // Overridden in subclass
840  }
841  }
842 
843  // True if type must include a nil (as opposed to may-nil, which means the
844  // type can choose something other than nil).
845  public boolean must_nil() {
846  switch( _type ) {
847  case TALL:
848  case TREAL:
849  case TSCALAR:
850  case TNIL: case TXNIL:
851  case TCTRL: // Nonsense, only for IfNode.value test
852  case TXCTRL: // Nonsense, only for IfNode.value test
853  case TMEM: // Nonsense, only for IfNode.value test
854  return true; // These all must include a nil
855  case TANY: // All above-center types are not required to include a nil
856  case TXREAL:
857  case TXSCALAR:
858  case TXNSCALR: case TNSCALR:
859  case TXNREAL: case TNREAL:
860  return false; // These all may be non-nil
861  default: throw typerr(null); // Overridden in subclass
862  }
863  }
864  // Mismatched scalar types that can only cross-nils
865  final Type cross_nil(Type t) { return must_nil() || t.must_nil() ? SCALAR : NSCALR; }
866 
867  // True if type may include a nil (as opposed to must-nil).
868  // True for many above-center or zero values.
869  public boolean may_nil() {
870  switch(_type) {
871  case TALL:
872  case TREAL:
873  case TSCALAR:
874  case TXNSCALR: case TNSCALR:
875  case TXNREAL: case TNREAL:
876  case TTUPLE:
877  return false;
878  case TANY:
879  case TXREAL:
880  case TXSCALAR:
881  case TCTRL: // Nonsense, only for IfNode.value test
882  case TXCTRL: // Nonsense, only for IfNode.value test
883  case TMEM: // Nonsense, only for IfNode.value test
884  return true;
885  default: throw typerr(null); // Overridden in subclass
886  }
887  }
888 
889  // Return the type without a nil-choice. Only applies to above_center types,
890  // as these are the only types with a nil-choice. Only called during meets
891  // with above-center types. If called with below-center, there is no
892  // nil-choice (might be a must-nil but not a choice-nil), so can return this.
894  switch( _type ) {
895  case TXSCALAR: return XNSCALR;
896  case TXREAL : return XNREAL ;
897  case TSCALAR: case TNSCALR: case TXNSCALR:
898  case TREAL: case TNREAL: case TXNREAL:
899  case TNIL: case TXNIL:
900  return this;
901  default: throw typerr(null); // Overridden in subclass
902  }
903  }
904  public Type meet_nil(Type nil) {
905  assert nil==NIL || nil==XNIL;
906  switch( _type ) {
907  case TANY:
908  case TXREAL:
909  case TXSCALAR:
910  case TXNIL: return nil; // Preserve high/low flavor
911  case TNIL: return NIL;
912  case TXNREAL:
913  case TXNSCALR: return TypeInt.BOOL;
914  case TREAL: case TNREAL: return REAL;
915  case TSCALAR: case TNSCALR: return SCALAR;
916  case TCTRL: case TXCTRL:
917  case TOBJ:
918  case TSTR:
919  case TSTRUCT:
920  case TMEM: return ALL;
921  default: throw typerr(null); // Overridden in subclass
922  }
923  }
924 
925  // Is t type contained within this? Short-circuits on a true
926  public final boolean contains( Type t ) { return contains(t,null); }
927  boolean contains( Type t, VBitSet bs ) { return this==t; }
928 
929  // Sharpen pointer with memory
930  public Type sharptr( Type ptr ) { return this==ANY ? TypeMem.ANYMEM.sharptr(ptr) : ptr; }
931 
932  // Apply the test(); if it returns true iterate over all nested child types.
933  // If the test returns false, short-circuit the walk. No attempt to guard
934  // against recursive structure walks, so the 'test' must return false when
935  // visiting the same Type again.
936  public void walk( Predicate<Type> p ) { assert is_simple(); p.test(this); }
937 
938  TypeStruct repeats_in_cycles(TypeStruct head, VBitSet bs) { return null; }
939 
940  // Display might be Scalar or ~Scalar at GVN start
941  public boolean is_display_ptr() { return _type==TSCALAR || _type==TXSCALAR || _type==TNIL || _type==TXNIL || _type==TANY || _type==TALL; }
942  boolean is_display() { return false; }
943 
944  // Make from existing type, replacing TMPs with alias from the map
945  public Type make_from(Type head, TypeMem map, VBitSet visit) { return this; }
946 
947  RuntimeException typerr(Type t) {
948  throw new RuntimeException("Should not reach here: internal type system error with "+this+(t==null?"":(" and "+t)));
949  }
950 }
com.cliffc.aa.type.Type.xdual
T xdual()
Definition: Type.java:365
com.cliffc.aa.type.TypeMemPtr.TYPES
static final Type[] TYPES
Definition: TypeMemPtr.java:106
com.cliffc.aa.type.Type.Key._a
Type _a
Definition: Type.java:374
com.cliffc.aa.type.Type.NSCALR
static final Type NSCALR
Definition: Type.java:330
com.cliffc.aa.type.Type.TLIVE
static final byte TLIVE
Definition: Type.java:276
com.cliffc.aa.type.Type.intern_check1
boolean intern_check1()
Definition: Type.java:227
com.cliffc.aa.type.Type.retern
final T retern()
Definition: Type.java:201
com.cliffc.aa.type.Type.intern_check0
boolean intern_check0(Type v)
Definition: Type.java:223
com.cliffc.aa.type.Type.TMEMPTR
static final byte TMEMPTR
Definition: Type.java:273
com.cliffc.aa.type.TypeFlt.init1
static void init1(HashMap< String, Type > types)
Definition: TypeFlt.java:43
com.cliffc.aa.type.TypeFunPtr
Definition: TypeFunPtr.java:23
com.cliffc.aa.type.Type.NREAL
static final Type NREAL
Definition: Type.java:336
com.cliffc.aa.type.Type.clone
Type clone()
Definition: Type.java:304
com.cliffc.aa.util.Ary.push
E push(E e)
Add element in amortized constant time.
Definition: Ary.java:58
com.cliffc.aa.util.NonBlockingHashMap
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with better scaling pr...
Definition: NonBlockingHashMap.java:75
com.cliffc.aa.type.Type.Pool.free
< T extends Type > T free(T t1, T t2)
Definition: Type.java:297
com.cliffc.aa.type.Type.TREAL
static final byte TREAL
Definition: Type.java:255
com.cliffc.aa.type.Type.not_nil
Type not_nil()
Definition: Type.java:893
com.cliffc.aa.util.Ary.isEmpty
boolean isEmpty()
Definition: Ary.java:20
com.cliffc.aa.type.Type.isa
boolean isa(Type t)
Definition: Type.java:623
com.cliffc.aa.type.Type.typerr
RuntimeException typerr(Type t)
Definition: Type.java:947
com.cliffc.aa.type.Type._set_name
T _set_name(String name)
Definition: Type.java:558
com.cliffc.aa.type.TypeMem
Memory type; the state of all of memory; memory edges order memory ops.
Definition: TypeMem.java:53
com.cliffc.aa.util.Util.eq
static boolean eq(String s0, String s1)
Definition: Util.java:16
com.cliffc.aa.type.Type.join
Type join(Type t)
Definition: Type.java:619
com.cliffc.aa.type.Type.interned
boolean interned()
Definition: Type.java:209
com.cliffc.aa.type.Type.SCALAR
static final Type SCALAR
Definition: Type.java:328
com.cliffc
com.cliffc.aa.type.Type._hash
int _hash
Definition: Type.java:97
com.cliffc.aa.type.Type.intern_size
static int intern_size()
Definition: Type.java:211
com.cliffc.aa.type.Type.toString
final String toString()
Definition: Type.java:127
com.cliffc.aa.type.Type.widen
Type widen()
Definition: Type.java:828
com.cliffc.aa.util.Ary.pop
E pop()
Definition: Ary.java:41
com.cliffc.aa.type.Type.oob_deep
Type oob_deep(Type t)
Definition: Type.java:632
com.cliffc.aa.type.Type.may_nil
boolean may_nil()
Definition: Type.java:869
com.cliffc.aa.type.Type.XSCALAR
static final Type XSCALAR
Definition: Type.java:329
com.cliffc.aa.type.TypeRPC.ALL_CALL
static final TypeRPC ALL_CALL
Definition: TypeRPC.java:31
com.cliffc.aa.type.Type.Type
Type()
Definition: Type.java:102
com.cliffc.aa.util
Definition: AbstractEntry.java:1
com.cliffc.aa.type.Type.check_commute
boolean check_commute(Type t, Type mt)
Definition: Type.java:593
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.type.TypeFunPtr.GENERIC_FUNPTR
static final TypeFunPtr GENERIC_FUNPTR
Definition: TypeFunPtr.java:80
com.cliffc.aa.type.TypeStr.init1
static void init1(HashMap< String, Type > types)
Definition: TypeStr.java:50
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.type.Type.contains
boolean contains(Type t, VBitSet bs)
Definition: Type.java:927
com.cliffc.aa.type.Type.oob
TypeObj oob(TypeObj e)
Definition: Type.java:637
com.cliffc.aa.type.Type.Key.intern_meet_quality_check
static void intern_meet_quality_check()
Definition: Type.java:387
com.cliffc.aa.type.Type.hashCode
final int hashCode()
Definition: Type.java:106
com.cliffc.aa.type.TypeFlt
Definition: TypeFlt.java:9
com.cliffc.aa.type.Type.CNT
static int CNT
Definition: Type.java:95
com.cliffc.aa.util.Ary
Definition: Ary.java:11
com.cliffc.aa.type.Type.compute_hash
int compute_hash()
Definition: Type.java:109
com.cliffc.aa.type.Type.TSTR
static final byte TSTR
Definition: Type.java:270
com.cliffc.aa.type.Type.meet_nil
Type meet_nil(Type nil)
Definition: Type.java:904
com.cliffc.aa.type.Type.Pool._gold
final Type _gold
Definition: Type.java:286
com.cliffc.aa.type.TypeTuple
Definition: TypeTuple.java:11
com.cliffc.aa.type.Type._type
byte _type
Definition: Type.java:98
com.cliffc.aa.type.Type.repeats_in_cycles
TypeStruct repeats_in_cycles(TypeStruct head, VBitSet bs)
Definition: Type.java:938
com.cliffc.aa.type.Type.xmt_name
Type xmt_name(Type t, Type mt)
Definition: Type.java:441
com.cliffc.aa.util.Ary._len
int _len
Definition: Ary.java:13
com.cliffc.aa.type.Type.Key.equals
boolean equals(Object o)
Definition: Type.java:376
com.cliffc.aa.type.Type.above
boolean above(Type t)
Definition: Type.java:625
com.cliffc.aa.util.Ary._es
E[] _es
Definition: Ary.java:12
com.cliffc.aa.type.Type.Key.INTERN_MEET
static NonBlockingHashMap< Key, Type > INTERN_MEET
Definition: Type.java:372
com.cliffc.aa.type.Type.TXNIL
static final byte TXNIL
Definition: Type.java:260
com.cliffc.aa.type.Type.TLAST
static final byte TLAST
Definition: Type.java:277
com.cliffc.aa.type.Type.ANY
static final Type ANY
Definition: Type.java:325
com.cliffc.aa.type.Type.untern
final T untern()
Definition: Type.java:193
com.cliffc.aa.type.Type.check_name
static boolean check_name(String n)
Definition: Type.java:548
com.cliffc.aa.type.TypeFunPtr.TYPES
static final TypeFunPtr[] TYPES
Definition: TypeFunPtr.java:82
com.cliffc.aa.type.TypeAry
Definition: TypeAry.java:7
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.type.TypeStruct
A memory-based collection of optionally named fields.
Definition: TypeStruct.java:50
com.cliffc.aa.type.Type.TANY
static final byte TANY
Definition: Type.java:240
com.cliffc.aa.AA.unimpl
static RuntimeException unimpl()
Definition: AA.java:10
com.cliffc.aa.type.Type.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: Type.java:131
com.cliffc.aa.type.Type.TFUNPTR
static final byte TFUNPTR
Definition: Type.java:274
com.cliffc.aa.type.Type.TINT
static final byte TINT
Definition: Type.java:263
com.cliffc.aa.type.Type.intern_check
static boolean intern_check()
Definition: Type.java:212
com.cliffc.aa.type.TypeMem.ANYMEM
static final TypeMem ANYMEM
Definition: TypeMem.java:228
com.cliffc.aa.type.Type.remove_name
final T remove_name()
Definition: Type.java:556
com.cliffc.aa.type.Type.ISA_SCALAR
static final byte[] ISA_SCALAR
Definition: Type.java:355
com.cliffc.aa.type.Type.getd
double getd()
Definition: Type.java:804
com.cliffc.aa.type.Type.ALL
static final Type ALL
Definition: Type.java:324
com.cliffc.aa.type.Type.Key._b
Type _b
Definition: Type.java:374
com.cliffc.aa.type.Type.cycle_equals
boolean cycle_equals(Type t)
Definition: Type.java:118
com.cliffc.aa.type.Type.ALL_TYPES
static Ary< Type > ALL_TYPES
Definition: Type.java:650
com.cliffc.aa.type.Type.TMEM
static final byte TMEM
Definition: Type.java:272
com.cliffc.aa.util.NonBlockingHashMapLong.keySet
Set< Long > keySet()
Returns a Set view of the keys contained in this map; with care the keys may be iterated over without...
Definition: NonBlockingHashMapLong.java:1168
com.cliffc.aa.type.Type.Pool._clone
int _clone
Definition: Type.java:284
com.cliffc.aa.type.Type.TXNREAL
static final byte TXNREAL
Definition: Type.java:258
com.cliffc.aa.type.Type.TTUPLE
static final byte TTUPLE
Definition: Type.java:266
com.cliffc.aa.type.TypeInt.INT64
static final TypeInt INT64
Definition: TypeInt.java:39
com.cliffc.aa.type.Type._uid
int _uid()
Definition: Type.java:103
com.cliffc.aa.type.Type.set_name
final T set_name(String name)
Definition: Type.java:551
com.cliffc.aa.type.Type.rdual
T rdual()
Definition: Type.java:366
com.cliffc.aa.type.TypeObj
Definition: TypeObj.java:15
com.cliffc.aa.type.Type.isBitShape
byte isBitShape(Type t)
Definition: Type.java:814
com.cliffc.aa.type.Type.TFLD
static final byte TFLD
Definition: Type.java:271
com.cliffc.aa.type.Type.is_con
boolean is_con()
Definition: Type.java:776
com.cliffc.aa.type.Type._dual
T _dual
Definition: Type.java:100
com.cliffc.aa.type.Type.above_center
boolean above_center()
Definition: Type.java:741
com.cliffc.aa.util.NonBlockingHashMapLong.get
final TypeV get(long key)
Returns the value to which the specified key is mapped, or.
Definition: NonBlockingHashMapLong.java:368
com.cliffc.aa.type.Type.TSTRUCT
static final byte TSTRUCT
Definition: Type.java:268
com.cliffc.aa.type.Type.TALL
static final byte TALL
Definition: Type.java:239
com.cliffc.aa.type.Type.meet_loop
Type meet_loop(Type t2)
Definition: Type.java:628
com.cliffc.aa.type.Type.Key.K
static Key K
Definition: Type.java:371
com.cliffc.aa.type.Type.init0
static void init0(HashMap< String, Type > types)
Definition: Type.java:642
com.cliffc.aa.type.Type.RECURSIVE_MEET
static int RECURSIVE_MEET
Definition: Type.java:163
com.cliffc.aa.type.Type.XNSCALR
static final Type XNSCALR
Definition: Type.java:331
com.cliffc.aa.type.Type.has_name
boolean has_name()
Definition: Type.java:549
com.cliffc.aa.type.Type.contains
final boolean contains(Type t)
Definition: Type.java:926
com.cliffc.aa.type.Type.is_num
boolean is_num()
Definition: Type.java:353
com.cliffc.aa.util.Util
Definition: Util.java:5
com.cliffc.aa.type.Type.CTRL
static final Type CTRL
Definition: Type.java:326
com.cliffc.aa.type.Type.cross_nil
final Type cross_nil(Type t)
Definition: Type.java:865
com.cliffc.aa.type.Type.make_from
Type make_from(Type head, TypeMem map, VBitSet visit)
Definition: Type.java:945
com.cliffc.aa.type.Type.xmeet
Type xmeet(Type t)
Definition: Type.java:461
com.cliffc.aa.type.Type.must_nil
boolean must_nil()
Definition: Type.java:845
com.cliffc.aa.type.Type.INTERN
static final ConcurrentHashMap< Type, Type > INTERN
Definition: Type.java:162
com.cliffc.aa.type.Type.may_be_con
boolean may_be_con()
Definition: Type.java:759
com.cliffc.aa.type.Type.mtname
final String mtname(Type t, Type mt)
Definition: Type.java:567
com.cliffc.aa.type.Type.XCTRL
static final Type XCTRL
Definition: Type.java:327
com.cliffc.aa.type.Type.sharptr
Type sharptr(Type ptr)
Definition: Type.java:930
com.cliffc.aa.type.Type.init
T init(byte type, String name)
Definition: Type.java:105
com.cliffc.aa.type.TypeMem.sharptr
Type sharptr(Type ptr)
Definition: TypeMem.java:419
com.cliffc.aa.type.Type.simple_ptr
Type simple_ptr()
Definition: Type.java:358
com.cliffc.aa.type.Type.check_symmetric
boolean check_symmetric(Type t, Type mt)
Definition: Type.java:608
com.cliffc.aa.type.Type.TSCALAR
static final byte TSCALAR
Definition: Type.java:246
com.cliffc.aa.type.Type.TYPES
static final Type[] TYPES
Definition: Type.java:340
com.cliffc.aa.type.Type.high
Type high()
Definition: Type.java:796
com.cliffc.aa.type.Type.TXSCALAR
static final byte TXSCALAR
Definition: Type.java:247
com.cliffc.aa.type.TypeStr
Definition: TypeStr.java:14
com.cliffc.aa.type.Type.intern_find
static Type intern_find(int uid)
Definition: Type.java:229
com.cliffc.aa.type.Type.Pool.Pool
Pool(byte t, Type gold)
Definition: Type.java:287
com.cliffc.aa.type.Type.Key.put
static void put(Type a, Type b, Type mt)
Definition: Type.java:382
com.cliffc.aa.type.Type.TNIL
static final byte TNIL
Definition: Type.java:259
com.cliffc.aa.type.Type.Pool
Definition: Type.java:283
com.cliffc.aa.type.Type.TRPC
static final byte TRPC
Definition: Type.java:265
HashMap
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.type.Type.is_ptr
boolean is_ptr()
Definition: Type.java:352
com.cliffc.aa.type.Type.is_simple
boolean is_simple()
Definition: Type.java:351
com.cliffc.aa.type.Type.check_startup
static boolean check_startup()
Definition: Type.java:684
com.cliffc.aa.type.Type.hashcons_free
final T hashcons_free()
Definition: Type.java:153
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.type.Type.NIL
static final Type NIL
Definition: Type.java:332
com.cliffc.aa.type.Type.TSIMPLE
static final byte TSIMPLE
Definition: Type.java:261
com.cliffc.aa.type.Type.XREAL
static final Type XREAL
Definition: Type.java:335
com.cliffc.aa.AA
an implementation of language AA
Definition: AA.java:9
com.cliffc.aa.type.Type.ALL_TYPES
static Ary< Type > ALL_TYPES()
Definition: Type.java:651
com.cliffc.aa.type.Type.oob
Type oob(Type e)
Definition: Type.java:636
com.cliffc.aa.type.Type.oop_deep_impl
Type oop_deep_impl(Type t)
Definition: Type.java:634
com.cliffc.aa.type.Type.equals
boolean equals(Object o)
Definition: Type.java:112
com.cliffc.aa.type.Type.XNREAL
static final Type XNREAL
Definition: Type.java:337
com.cliffc.aa.type.Type.SCALAR_PRIMS
static Type[] SCALAR_PRIMS
Definition: Type.java:349
com.cliffc.aa.type.Type.is_display_ptr
boolean is_display_ptr()
Definition: Type.java:941
com.cliffc.aa
Definition: AA.java:1
com.cliffc.aa.type.TypeLive
Definition: TypeLive.java:19
com.cliffc.aa.type.Type.TCTRL
static final byte TCTRL
Definition: Type.java:241
com.cliffc.aa.type.Type.Key.Key
Key(Type a, Type b)
Definition: Type.java:373
com.cliffc.aa.type.Type.oob
TypeMemPtr oob(TypeMemPtr e)
Definition: Type.java:640
com.cliffc.aa.type.Type.TNREAL
static final byte TNREAL
Definition: Type.java:257
com.cliffc.aa.type.Type._uid
int _uid
Definition: Type.java:96
com.cliffc.aa.type.Type.oob
TypeMem oob(TypeMem e)
Definition: Type.java:639
com.cliffc.aa.type.Type.Key.hashCode
int hashCode()
Definition: Type.java:375
Cloneable
com.cliffc.aa.type.TypeStruct.TYPES
static final TypeStruct[] TYPES
Definition: TypeStruct.java:242
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.type.Type.make
static Type make(byte type)
Definition: Type.java:147
com.cliffc.aa.type.Type.Pool._pool
int _pool
Definition: Type.java:284
com.cliffc.aa.type.Type._name
String _name
Definition: Type.java:99
com.cliffc.aa.type.TypeFunSig
Definition: TypeFunSig.java:10
com.cliffc.aa.type.Type.walk
void walk(Predicate< Type > p)
Definition: Type.java:936
com.cliffc.aa.type.TypeFunSig.TYPES
static final TypeFunSig[] TYPES
Definition: TypeFunSig.java:85
com.cliffc.aa.type.Type.dual
final T dual()
Definition: Type.java:361
com.cliffc.aa.type.Type.REAL
static final Type REAL
Definition: Type.java:334
com.cliffc.aa.type.Type.isa_scalar
final boolean isa_scalar()
Definition: Type.java:356
com.cliffc.aa.type.Type.STRS
static final String[] STRS
Definition: Type.java:262
com.cliffc.aa.util.NonBlockingHashMapLong
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with primitive long ke...
Definition: NonBlockingHashMapLong.java:91
com.cliffc.aa.type.Type.oob
TypeStruct oob(TypeStruct e)
Definition: Type.java:638
com.cliffc.aa.type.TypeRPC
Definition: TypeRPC.java:7
com.cliffc.aa.type.Type.oob
Type oob()
Definition: Type.java:635
com.cliffc.aa.type.Type.XNIL
static final Type XNIL
Definition: Type.java:333
com.cliffc.aa.type.Type.POOLS
static final Pool[] POOLS
Definition: Type.java:281
com.cliffc.aa.util.NonBlockingHashMapLong.put
TypeV put(long key, TypeV val)
Maps the specified key to the specified value in the table.
Definition: NonBlockingHashMapLong.java:278
com.cliffc.aa.type.Type.TOBJ
static final byte TOBJ
Definition: Type.java:267
com.cliffc.aa.type.Type.Pool._frees
final Ary< Type > _frees
Definition: Type.java:285
com.cliffc.aa.type.Type.concat
static void concat(Ary< Type > ts, Type[] ts1)
Definition: Type.java:676
com.cliffc.aa.type.Type.intern_lookup
Type intern_lookup()
Definition: Type.java:210
com.cliffc.aa.type.Type.TNSCALR
static final byte TNSCALR
Definition: Type.java:253
com.cliffc.aa.type.TypeMemPtr.OOP0
static final TypeMemPtr OOP0
Definition: TypeMemPtr.java:93
com.cliffc.aa.type.Type.Pool.malloc
< T extends Type > T malloc()
Definition: Type.java:293
com.cliffc.aa.type.Type.getl
long getl()
Definition: Type.java:802
com.cliffc.aa.type.Type.Key
Definition: Type.java:370
com.cliffc.aa.type.Type.eq
static boolean eq(Type[] t0, Type[] t1)
Definition: Type.java:136
com
com.cliffc.aa.type.TypeInt.init1
static void init1(HashMap< String, Type > types)
Definition: TypeInt.java:51
com.cliffc.aa.type.Type.getstr
String getstr()
Definition: Type.java:806
com.cliffc.aa.type.TypeInt.BOOL
static final TypeInt BOOL
Definition: TypeInt.java:43
com.cliffc.aa.util.SB.toString
String toString()
Definition: SB.java:62
com.cliffc.aa.type.Type.TXNSCALR
static final byte TXNSCALR
Definition: Type.java:254
com.cliffc.aa.type.Type.hashcons
T hashcons()
Definition: Type.java:165
com.cliffc.aa.type.Type.TXCTRL
static final byte TXCTRL
Definition: Type.java:242
com.cliffc.aa.type.TypeMemPtr
Definition: TypeMemPtr.java:14
com.cliffc.aa.type.Type.TXREAL
static final byte TXREAL
Definition: Type.java:256
com.cliffc.aa.type.Type.is_display
boolean is_display()
Definition: Type.java:942
com.cliffc.aa.type.Type.TFUNSIG
static final byte TFUNSIG
Definition: Type.java:275
com.cliffc.aa.type.Type.is_forward_ref
boolean is_forward_ref()
Definition: Type.java:799
com.cliffc.aa.type.Type.TARY
static final byte TARY
Definition: Type.java:269
com.cliffc.aa.type.TypeFlt.FLT64
static final TypeFlt FLT64
Definition: TypeFlt.java:38
com.cliffc.aa.type.Type.TFLT
static final byte TFLT
Definition: Type.java:264