Skip to content

Commit 05331f9

Browse files
[MERGE #5246 @Penguinwizzard] Clean-up auxptr typing
Merge pull request #5246 from Penguinwizzard:strict_auxptr Add a type table for function auxptr types instead of having casts everywhere.
2 parents b326495 + d366529 commit 05331f9

File tree

2 files changed

+146
-85
lines changed

2 files changed

+146
-85
lines changed

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ namespace Js
988988
Var
989989
FunctionBody::GetFormalsPropIdArrayOrNullObj()
990990
{
991-
Var formalsPropIdArray = this->GetAuxPtrWithLock(AuxPointerType::FormalsPropIdArray);
991+
Var formalsPropIdArray = this->GetAuxPtrWithLock<AuxPointerType::FormalsPropIdArray>();
992992
if (formalsPropIdArray == nullptr)
993993
{
994994
return GetScriptContext()->GetLibrary()->GetNull();
@@ -1001,16 +1001,16 @@ namespace Js
10011001
{
10021002
if (checkForNull)
10031003
{
1004-
Assert(this->GetAuxPtrWithLock(AuxPointerType::FormalsPropIdArray));
1004+
Assert(this->GetAuxPtrWithLock<AuxPointerType::FormalsPropIdArray>());
10051005
}
1006-
return static_cast<PropertyIdArray*>(this->GetAuxPtrWithLock(AuxPointerType::FormalsPropIdArray));
1006+
return this->GetAuxPtrWithLock<AuxPointerType::FormalsPropIdArray>();
10071007
}
10081008

10091009
void
10101010
FunctionBody::SetFormalsPropIdArray(PropertyIdArray * propIdArray)
10111011
{
1012-
AssertMsg(propIdArray == nullptr || this->GetAuxPtrWithLock(AuxPointerType::FormalsPropIdArray) == nullptr, "Already set?");
1013-
this->SetAuxPtr(AuxPointerType::FormalsPropIdArray, propIdArray);
1012+
AssertMsg(propIdArray == nullptr || this->GetAuxPtrWithLock<AuxPointerType::FormalsPropIdArray>() == nullptr, "Already set?");
1013+
this->SetAuxPtr<AuxPointerType::FormalsPropIdArray>(propIdArray);
10141014
}
10151015

10161016
ByteBlock*
@@ -1907,7 +1907,7 @@ namespace Js
19071907
{
19081908
return string;
19091909
}
1910-
this->SetAuxPtr(AuxPointerType::CachedSourceString, nullptr);
1910+
this->SetAuxPtr<AuxPointerType::CachedSourceString>(nullptr);
19111911
}
19121912
return nullptr;
19131913
}
@@ -1923,13 +1923,13 @@ namespace Js
19231923

19241924
RecyclerWeakReference<JavascriptString> * ParseableFunctionInfo::GetCachedSourceStringWeakRef()
19251925
{
1926-
return static_cast<RecyclerWeakReference<JavascriptString> *>(this->GetAuxPtr(AuxPointerType::CachedSourceString));
1926+
return this->GetAuxPtr<AuxPointerType::CachedSourceString>();
19271927
}
19281928

19291929
void ParseableFunctionInfo::SetCachedSourceStringWeakRef(RecyclerWeakReference<JavascriptString> * weakRef)
19301930
{
19311931
Assert(this->GetCachedSourceString() == nullptr);
1932-
this->SetAuxPtr(AuxPointerType::CachedSourceString, weakRef);
1932+
this->SetAuxPtr<AuxPointerType::CachedSourceString>(weakRef);
19331933
}
19341934

19351935
FunctionInfoArray ParseableFunctionInfo::GetNestedFuncArray()
@@ -2053,12 +2053,12 @@ namespace Js
20532053
// Function object type list methods
20542054
FunctionProxy::FunctionTypeWeakRefList* FunctionProxy::GetFunctionObjectTypeList() const
20552055
{
2056-
return static_cast<FunctionTypeWeakRefList*>(this->GetAuxPtr(AuxPointerType::FunctionObjectTypeList));
2056+
return this->GetAuxPtr<AuxPointerType::FunctionObjectTypeList>();
20572057
}
20582058

20592059
void FunctionProxy::SetFunctionObjectTypeList(FunctionProxy::FunctionTypeWeakRefList* list)
20602060
{
2061-
this->SetAuxPtr(AuxPointerType::FunctionObjectTypeList, list);
2061+
this->SetAuxPtr<AuxPointerType::FunctionObjectTypeList>(list);
20622062
}
20632063

20642064
template <typename Fn>
@@ -4036,7 +4036,7 @@ namespace Js
40364036
// Assert(CanDoStackNestedFunc());
40374037
Assert(parentFunctionBody->DoStackNestedFunc());
40384038

4039-
this->SetAuxPtr(AuxPointerType::StackNestedFuncParent, this->GetScriptContext()->GetRecycler()->CreateWeakReferenceHandle(parentFunctionInfo));
4039+
this->SetAuxPtr<AuxPointerType::StackNestedFuncParent>(this->GetScriptContext()->GetRecycler()->CreateWeakReferenceHandle(parentFunctionInfo));
40404040
}
40414041

40424042
FunctionInfo * FunctionBody::GetStackNestedFuncParentStrongRef()
@@ -4047,12 +4047,12 @@ namespace Js
40474047

40484048
RecyclerWeakReference<FunctionInfo> * FunctionBody::GetStackNestedFuncParent()
40494049
{
4050-
return static_cast<RecyclerWeakReference<FunctionInfo>*>(this->GetAuxPtr(AuxPointerType::StackNestedFuncParent));
4050+
return this->GetAuxPtr<AuxPointerType::StackNestedFuncParent>();
40514051
}
40524052

40534053
FunctionInfo * FunctionBody::GetAndClearStackNestedFuncParent()
40544054
{
4055-
if (this->GetAuxPtr(AuxPointerType::StackNestedFuncParent))
4055+
if (this->GetAuxPtr<AuxPointerType::StackNestedFuncParent>())
40564056
{
40574057
FunctionInfo * parentFunctionInfo = GetStackNestedFuncParentStrongRef();
40584058
ClearStackNestedFuncParent();
@@ -4063,7 +4063,7 @@ namespace Js
40634063

40644064
void FunctionBody::ClearStackNestedFuncParent()
40654065
{
4066-
this->SetAuxPtr(AuxPointerType::StackNestedFuncParent, nullptr);
4066+
this->SetAuxPtr<AuxPointerType::StackNestedFuncParent>(nullptr);
40674067
}
40684068

40694069
void FunctionBody::CreateCacheIdToPropertyIdMap(uint rootObjectLoadInlineCacheStart, uint rootObjectLoadMethodInlineCacheStart,
@@ -5157,7 +5157,7 @@ namespace Js
51575157

51585158
// Set other state back to before parse as well
51595159
this->SetStackNestedFunc(false);
5160-
this->SetAuxPtr(AuxPointerType::StackNestedFuncParent, nullptr);
5160+
this->SetAuxPtr<AuxPointerType::StackNestedFuncParent>(nullptr);
51615161
this->SetReparsed(true);
51625162
#if DBG
51635163
char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
@@ -6053,18 +6053,18 @@ namespace Js
60536053
{
60546054
return;
60556055
}
6056-
this->SetAuxPtr(AuxPointerType::ForInCacheArray, AllocatorNewArrayZ(CacheAllocator, this->GetScriptContext()->GetEnumeratorAllocator(), EnumeratorCache, profiledForInLoopCount));
6056+
this->SetAuxPtr<AuxPointerType::ForInCacheArray>(AllocatorNewArrayZ(CacheAllocator, this->GetScriptContext()->GetEnumeratorAllocator(), EnumeratorCache, profiledForInLoopCount));
60576057
}
60586058

60596059
EnumeratorCache * FunctionBody::GetForInCache(uint index)
60606060
{
60616061
Assert(index < this->GetProfiledForInLoopCount());
6062-
return &((EnumeratorCache *)this->GetAuxPtr(AuxPointerType::ForInCacheArray))[index];
6062+
return &this->GetAuxPtr<AuxPointerType::ForInCacheArray>()[index];
60636063
}
60646064

60656065
EnumeratorCache * FunctionBody::GetForInCacheArray()
60666066
{
6067-
return ((EnumeratorCache *)this->GetAuxPtrWithLock(AuxPointerType::ForInCacheArray));
6067+
return this->GetAuxPtrWithLock<AuxPointerType::ForInCacheArray>();
60686068
}
60696069

60706070
void FunctionBody::CleanUpForInCache(bool isShutdown)
@@ -6074,7 +6074,7 @@ namespace Js
60746074
{
60756075
return;
60766076
}
6077-
EnumeratorCache * forInCacheArray = (EnumeratorCache *)this->GetAuxPtr(AuxPointerType::ForInCacheArray);
6077+
EnumeratorCache * forInCacheArray = this->GetAuxPtr<AuxPointerType::ForInCacheArray>();
60786078
if (forInCacheArray)
60796079
{
60806080
if (isShutdown)
@@ -6084,7 +6084,7 @@ namespace Js
60846084
else
60856085
{
60866086
AllocatorDeleteArray(CacheAllocator, this->GetScriptContext()->GetEnumeratorAllocator(), profiledForInLoopCount, forInCacheArray);
6087-
this->SetAuxPtr(AuxPointerType::ForInCacheArray, nullptr);
6087+
this->SetAuxPtr<AuxPointerType::ForInCacheArray>(nullptr);
60886088
}
60896089
}
60906090
}
@@ -6360,15 +6360,15 @@ namespace Js
63606360
AsmJsFunctionInfo* FunctionBody::AllocateAsmJsFunctionInfo()
63616361
{
63626362
Assert( !this->GetAsmJsFunctionInfo() );
6363-
this->SetAuxPtr(AuxPointerType::AsmJsFunctionInfo, RecyclerNew( m_scriptContext->GetRecycler(), AsmJsFunctionInfo));
6363+
this->SetAuxPtr<AuxPointerType::AsmJsFunctionInfo>(RecyclerNew( m_scriptContext->GetRecycler(), AsmJsFunctionInfo));
63646364
return this->GetAsmJsFunctionInfo();
63656365
}
63666366

63676367
AsmJsModuleInfo* FunctionBody::AllocateAsmJsModuleInfo()
63686368
{
63696369
Assert( !this->GetAsmJsModuleInfo() );
63706370
Recycler* rec = m_scriptContext->GetRecycler();
6371-
this->SetAuxPtr(AuxPointerType::AsmJsModuleInfo, RecyclerNew(rec, AsmJsModuleInfo, rec));
6371+
this->SetAuxPtr<AuxPointerType::AsmJsModuleInfo>(RecyclerNew(rec, AsmJsModuleInfo, rec));
63726372
return this->GetAsmJsModuleInfo();
63736373
}
63746374
#endif
@@ -6528,11 +6528,11 @@ namespace Js
65286528
return runtimeData;
65296529
}
65306530

6531+
template<Js::FunctionProxy::AuxPointerType auxType>
65316532
FunctionCodeGenRuntimeData * FunctionBody::EnsureCodeGenRuntimeDataCommon(
65326533
Recycler *const recycler,
65336534
__in_range(0, profiledCallSiteCount - 1) const ProfileId profiledCallSiteId,
6534-
FunctionBody *const inlinee,
6535-
AuxPointerType auxType)
6535+
FunctionBody *const inlinee)
65366536
{
65376537
Assert(recycler);
65386538
Assert(profiledCallSiteId < profiledCallSiteCount);
@@ -6544,7 +6544,7 @@ namespace Js
65446544
this->SetAuxPtr(auxType, codeGenRuntimeData);
65456545
}
65466546

6547-
Field(FunctionCodeGenRuntimeData *)* codeGenRuntimeData = static_cast<Field(FunctionCodeGenRuntimeData *)*>(this->GetAuxPtr(auxType));
6547+
Field(FunctionCodeGenRuntimeData *)* codeGenRuntimeData = this->GetAuxPtr<auxType>();
65486548
Field(FunctionCodeGenRuntimeData *) const inlineeData = codeGenRuntimeData[profiledCallSiteId];
65496549
if (inlineeData == nullptr)
65506550
{
@@ -6577,15 +6577,15 @@ namespace Js
65776577
__in_range(0, profiledCallSiteCount - 1) const ProfileId profiledCallSiteId,
65786578
FunctionBody *const inlinee)
65796579
{
6580-
return EnsureCodeGenRuntimeDataCommon(recycler, profiledCallSiteId, inlinee, AuxPointerType::CodeGenRuntimeData);
6580+
return EnsureCodeGenRuntimeDataCommon<AuxPointerType::CodeGenRuntimeData>(recycler, profiledCallSiteId, inlinee);
65816581
}
65826582

65836583
FunctionCodeGenRuntimeData * FunctionBody::EnsureCallbackInlineeCodeGenRuntimeData(
65846584
Recycler *const recycler,
65856585
__in_range(0, profiledCallSiteCount - 1) const ProfileId profiledCallSiteId,
65866586
FunctionBody *const inlinee)
65876587
{
6588-
return EnsureCodeGenRuntimeDataCommon(recycler, profiledCallSiteId, inlinee, AuxPointerType::CodeGenCallbackRuntimeData);
6588+
return EnsureCodeGenRuntimeDataCommon<AuxPointerType::CodeGenCallbackRuntimeData>(recycler, profiledCallSiteId, inlinee);
65896589
}
65906590

65916591
const FunctionCodeGenRuntimeData *FunctionBody::GetLdFldInlineeCodeGenRuntimeData(const InlineCacheIndex inlineCacheIndex) const
@@ -6740,12 +6740,12 @@ namespace Js
67406740
}
67416741
FunctionEntryPointInfo *FunctionBody::GetSimpleJitEntryPointInfo() const
67426742
{
6743-
return static_cast<FunctionEntryPointInfo *>(this->GetAuxPtr(AuxPointerType::SimpleJitEntryPointInfo));
6743+
return this->GetAuxPtr<AuxPointerType::SimpleJitEntryPointInfo>();
67446744
}
67456745

67466746
void FunctionBody::SetSimpleJitEntryPointInfo(FunctionEntryPointInfo *const entryPointInfo)
67476747
{
6748-
this->SetAuxPtr(AuxPointerType::SimpleJitEntryPointInfo, entryPointInfo);
6748+
this->SetAuxPtr<AuxPointerType::SimpleJitEntryPointInfo>(entryPointInfo);
67496749
}
67506750

67516751

0 commit comments

Comments
 (0)