@@ -151,23 +151,17 @@ class HeapType {
151151 HeapTypeKind getKind () const ;
152152
153153 constexpr bool isBasic () const { return id <= _last_basic_type; }
154- bool isFunction () const {
155- return isMaybeShared (func) || getKind () == HeapTypeKind::Func;
156- }
157- bool isData () const {
158- auto kind = getKind ();
159- return isMaybeShared (string) || kind == HeapTypeKind::Struct ||
160- kind == HeapTypeKind::Array;
161- }
162- bool isSignature () const { return getKind () == HeapTypeKind::Func; }
163- bool isContinuation () const { return getKind () == HeapTypeKind::Cont; }
164- bool isStruct () const { return getKind () == HeapTypeKind::Struct; }
165- bool isArray () const { return getKind () == HeapTypeKind::Array; }
154+ bool isFunction () const ;
155+ bool isData () const ;
156+ bool isSignature () const ;
157+ bool isContinuation () const ;
158+ bool isStruct () const ;
159+ bool isArray () const ;
166160 bool isExn () const { return isMaybeShared (HeapType::exn); }
167161 bool isString () const { return isMaybeShared (HeapType::string); }
168162 bool isBottom () const ;
169163 bool isOpen () const ;
170- bool isShared () const { return getShared () == Shared; }
164+ bool isShared () const ;
171165
172166 Shareability getShared () const ;
173167
@@ -1117,6 +1111,97 @@ std::ostream& operator<<(std::ostream&, const TypeBuilder::ErrorReason&);
11171111
11181112// Inline some nontrivial methods here for performance reasons.
11191113
1114+ using RecGroupInfo = std::vector<HeapType>;
1115+
1116+ struct HeapTypeInfo {
1117+ using type_t = HeapType;
1118+ bool isTemp = false ;
1119+ bool isOpen = false ;
1120+ Shareability share = Unshared;
1121+ HeapTypeInfo* supertype = nullptr ;
1122+ HeapTypeInfo* descriptor = nullptr ;
1123+ HeapTypeInfo* described = nullptr ;
1124+ RecGroupInfo* recGroup = nullptr ;
1125+ size_t recGroupIndex = 0 ;
1126+ HeapTypeKind kind;
1127+ union {
1128+ Signature signature;
1129+ Continuation continuation;
1130+ Struct struct_;
1131+ Array array;
1132+ };
1133+
1134+ HeapTypeInfo (Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
1135+ HeapTypeInfo (Continuation continuation)
1136+ : kind(HeapTypeKind::Cont), continuation(continuation) {}
1137+ HeapTypeInfo (const Struct& struct_)
1138+ : kind(HeapTypeKind::Struct), struct_(struct_) {}
1139+ HeapTypeInfo (Struct&& struct_)
1140+ : kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
1141+ HeapTypeInfo (Array array) : kind(HeapTypeKind::Array), array(array) {}
1142+ ~HeapTypeInfo ();
1143+
1144+ constexpr bool isSignature () const { return kind == HeapTypeKind::Func; }
1145+ constexpr bool isContinuation () const { return kind == HeapTypeKind::Cont; }
1146+ constexpr bool isStruct () const { return kind == HeapTypeKind::Struct; }
1147+ constexpr bool isArray () const { return kind == HeapTypeKind::Array; }
1148+ constexpr bool isData () const { return isStruct () || isArray (); }
1149+ };
1150+
1151+ inline HeapTypeInfo* getHeapTypeInfo (HeapType ht) {
1152+ assert (!ht.isBasic ());
1153+ return (HeapTypeInfo*)ht.getID ();
1154+ }
1155+
1156+ inline HeapTypeKind HeapType::getKind () const {
1157+ if (isBasic ()) {
1158+ return HeapTypeKind::Basic;
1159+ }
1160+ return getHeapTypeInfo (*this )->kind ;
1161+ }
1162+
1163+ inline bool HeapType::isFunction () const {
1164+ return isMaybeShared (func) || getKind () == HeapTypeKind::Func;
1165+ }
1166+
1167+ inline bool HeapType::isData () const {
1168+ auto kind = getKind ();
1169+ return isMaybeShared (string) || kind == HeapTypeKind::Struct ||
1170+ kind == HeapTypeKind::Array;
1171+ }
1172+
1173+ inline bool HeapType::isSignature () const {
1174+ return getKind () == HeapTypeKind::Func;
1175+ }
1176+
1177+ inline bool HeapType::isContinuation () const {
1178+ return getKind () == HeapTypeKind::Cont;
1179+ }
1180+
1181+ inline bool HeapType::isStruct () const {
1182+ return getKind () == HeapTypeKind::Struct;
1183+ }
1184+
1185+ inline bool HeapType::isArray () const {
1186+ return getKind () == HeapTypeKind::Array;
1187+ }
1188+
1189+ inline bool HeapType::isOpen () const {
1190+ if (isBasic ()) {
1191+ return false ;
1192+ }
1193+ return getHeapTypeInfo (*this )->isOpen ;
1194+ }
1195+
1196+ inline bool HeapType::isShared () const { return getShared () == Shared; }
1197+
1198+ inline Shareability HeapType::getShared () const {
1199+ if (isBasic ()) {
1200+ return (getID () & SharedMask) != 0 ? Shared : Unshared;
1201+ }
1202+ return getHeapTypeInfo (*this )->share ;
1203+ }
1204+
11201205inline bool HeapType::isBottom () const {
11211206 if (isBasic ()) {
11221207 switch (getBasic (Unshared)) {
0 commit comments