File tree 5 files changed +31
-2
lines changed
5 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,8 @@ class FuncDeclaration : public Declaration
535
535
VarDeclaration *vresult; // result variable for out contracts
536
536
LabelDsymbol *returnLabel; // where the return goes
537
537
538
+ void *isTypeIsolatedCache; // An AA on the D side to cache an expensive check result
539
+
538
540
// used to prevent symbols in different
539
541
// scopes from having the same name
540
542
DsymbolTable *localsymtab;
Original file line number Diff line number Diff line change @@ -1957,6 +1957,7 @@ class Type : public ASTNode
1957
1957
bool equals (const RootObject* const o) const ;
1958
1958
bool equivalent (Type* t);
1959
1959
DYNCAST dyncast () const ;
1960
+ size_t getUniqueID () const ;
1960
1961
Covariant covariant (Type* t, uint64_t * pstc = nullptr );
1961
1962
const char * toChars () const ;
1962
1963
char * toPrettyChars (bool QualifyTypes = false );
@@ -2680,6 +2681,7 @@ class FuncDeclaration : public Declaration
2680
2681
const char * mangleString;
2681
2682
VarDeclaration* vresult;
2682
2683
LabelDsymbol* returnLabel;
2684
+ void * isTypeIsolatedCache;
2683
2685
DsymbolTable* localsymtab;
2684
2686
VarDeclaration* vthis;
2685
2687
bool isThis2;
Original file line number Diff line number Diff line change @@ -262,6 +262,8 @@ extern (C++) class FuncDeclaration : Declaration
262
262
VarDeclaration vresult; // / result variable for out contracts
263
263
LabelDsymbol returnLabel; // / where the return goes
264
264
265
+ bool [size_t ] isTypeIsolatedCache; // / cache for the potentially very expensive isTypeIsolated check
266
+
265
267
// used to prevent symbols in different
266
268
// scopes from having the same name
267
269
DsymbolTable localsymtab;
@@ -1530,8 +1532,23 @@ extern (C++) class FuncDeclaration : Declaration
1530
1532
extern (D ) final bool isTypeIsolated(Type t)
1531
1533
{
1532
1534
StringTable! Type parentTypes;
1533
- parentTypes._init();
1534
- return isTypeIsolated (t, parentTypes);
1535
+ const uniqueTypeID = t.getUniqueID();
1536
+ if (uniqueTypeID)
1537
+ {
1538
+ const cacheResultPtr = uniqueTypeID in isTypeIsolatedCache;
1539
+ if (cacheResultPtr ! is null )
1540
+ return * cacheResultPtr;
1541
+
1542
+ parentTypes._init();
1543
+ const isIsolated = isTypeIsolated(t, parentTypes);
1544
+ isTypeIsolatedCache[uniqueTypeID] = isIsolated;
1545
+ return isIsolated;
1546
+ }
1547
+ else
1548
+ {
1549
+ parentTypes._init();
1550
+ return isTypeIsolated (t, parentTypes);
1551
+ }
1535
1552
}
1536
1553
1537
1554
// /ditto
Original file line number Diff line number Diff line change @@ -426,6 +426,13 @@ extern (C++) abstract class Type : ASTNode
426
426
return DYNCAST .type;
427
427
}
428
428
429
+ // / Returns a non-zero unique ID for this Type, or returns 0 if the Type does not (yet) have a unique ID.
430
+ // / If `semantic()` has not been run, 0 is returned.
431
+ final size_t getUniqueID () const
432
+ {
433
+ return cast (size_t ) deco;
434
+ }
435
+
429
436
extern (D )
430
437
final Mcache* getMcache ()
431
438
{
Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ class Type : public ASTNode
224
224
bool equivalent (Type *t);
225
225
// kludge for template.isType()
226
226
DYNCAST dyncast () const { return DYNCAST_TYPE; }
227
+ size_t getUniqueID () const ;
227
228
Covariant covariant (Type *t, StorageClass *pstc = NULL );
228
229
const char *toChars () const ;
229
230
char *toPrettyChars (bool QualifyTypes = false );
You can’t perform that action at this time.
0 commit comments