!1741 Fix TSClassType Sequence Dependency in a file

Merge pull request !1741 from dingding/fix_ts_class_type_sequence_dependency
This commit is contained in:
openharmony_ci
2022-07-09 04:25:01 +00:00
committed by Gitee
8 changed files with 167 additions and 67 deletions
+8 -5
View File
@@ -2806,15 +2806,17 @@ void TSClassType::Dump(std::ostream &os) const
os << typeKind;
os << "\n";
os << " - ExtensionTypeGT: ";
JSTaggedValue extensionType = GetExtensionType();
if (extensionType.IsUndefined()) {
GlobalTSTypeRef extensionGT = GetExtensionGT();
if (extensionGT.IsDefault()) {
os << " (base class type) ";
} else {
uint64_t extensionTypeGT = TSType::Cast(extensionType.GetTaggedObject())->GetGTRef().GetType();
os << extensionTypeGT;
os << extensionGT.GetType();
}
os << "\n";
CString hasLinked = GetHasLinked() ? "true" : "false";
os << " - HasLinked: " << hasLinked << "\n";
os << " - InstanceType: " << "\n";
if (GetInstanceType().IsTSObjectType()) {
TSObjectType *instanceType = TSObjectType::Cast(GetInstanceType().GetTaggedObject());
@@ -4651,7 +4653,8 @@ void TSClassType::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>>
vec.push_back(std::make_pair(CString("InstanceType"), GetInstanceType()));
vec.push_back(std::make_pair(CString("ConstructorType"), GetConstructorType()));
vec.push_back(std::make_pair(CString("PrototypeType"), GetPrototypeType()));
vec.push_back(std::make_pair(CString("ExtensionType"), GetExtensionType()));
vec.push_back(std::make_pair(CString("ExtensionGTRawData"), JSTaggedValue(GetExtensionGTRawData())));
vec.push_back(std::make_pair(CString("HasLinked"), JSTaggedValue(GetHasLinked())));
}
void TSInterfaceType::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>> &vec) const
+2 -1
View File
@@ -2840,7 +2840,8 @@ JSHandle<TSClassType> ObjectFactory::NewTSClassType()
classType->SetInstanceType(thread_, JSTaggedValue::Undefined());
classType->SetConstructorType(thread_, JSTaggedValue::Undefined());
classType->SetPrototypeType(thread_, JSTaggedValue::Undefined());
classType->SetExtensionType(thread_, JSTaggedValue::Undefined());
classType->SetExtensionGTRawData(0);
classType->SetHasLinked(false);
return classType;
}
+11 -4
View File
@@ -49,13 +49,20 @@ enum class TSPrimitiveType : int {
class GlobalTSTypeRef {
public:
explicit GlobalTSTypeRef(uint32_t type = 0) : type_(type) {}
explicit GlobalTSTypeRef(int moduleId, int localId, int typeKind)
explicit GlobalTSTypeRef(int moduleId, int localId, int typeKind) : type_(0)
{
type_ = 0;
SetKind(typeKind);
SetLocalId(localId);
SetModuleId(moduleId);
}
explicit GlobalTSTypeRef(int moduleId, int localId, TSTypeKind typeKind) : type_(0)
{
SetKind(static_cast<int>(typeKind));
SetLocalId(localId);
SetModuleId(moduleId);
}
~GlobalTSTypeRef() = default;
static constexpr int TS_TYPE_RESERVED_COUNT = 50;
@@ -112,7 +119,7 @@ public:
void Dump() const
{
uint8_t kind = GetKind();
uint32_t kind = GetKind();
uint32_t gcType = GetGCType();
uint32_t moduleId = GetModuleId();
uint32_t localId = GetLocalId();
@@ -125,4 +132,4 @@ private:
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_TS_TYPES_GLOBAL_TS_TYPE_REF_H
#endif // ECMASCRIPT_TS_TYPES_GLOBAL_TS_TYPE_REF_H
+12
View File
@@ -511,6 +511,18 @@ void TSLoader::GenerateStaticHClass(JSHandle<TSTypeTable> tsTypeTable)
}
}
JSHandle<JSTaggedValue> TSLoader::GetType(const GlobalTSTypeRef &gt) const
{
JSThread *thread = vm_->GetJSThread();
uint32_t moduleId = gt.GetModuleId();
uint32_t localId = gt.GetLocalId();
JSHandle<TSModuleTable> mTable = GetTSModuleTable();
JSHandle<TSTypeTable> typeTable = mTable->GetTSTypeTable(thread, moduleId);
JSHandle<JSTaggedValue> type(thread, typeTable->Get(localId));
return type;
}
void TSModuleTable::Initialize(JSThread *thread, JSHandle<TSModuleTable> mTable)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
+2
View File
@@ -240,6 +240,8 @@ public:
void GenerateStaticHClass(JSHandle<TSTypeTable> tsTypeTable);
JSHandle<JSTaggedValue> GetType(const GlobalTSTypeRef &gt) const;
private:
NO_COPY_SEMANTIC(TSLoader);
+37 -4
View File
@@ -35,7 +35,8 @@ public:
return static_cast<TSType *>(const_cast<TaggedObject *>(object));
}
ACCESSORS_PRIMITIVE_FIELD(GT, uint64_t, BIT_FIELD_OFFSET, SIZE);
ACCESSORS_PRIMITIVE_FIELD(GT, uint32_t, BIT_FIELD_OFFSET, LAST_OFFSET);
DEFINE_ALIGN_SIZE(LAST_OFFSET);
GlobalTSTypeRef GetGTRef() const
{
@@ -81,12 +82,44 @@ public:
ACCESSORS(InstanceType, INSTANCE_TYPE_OFFSET, CONSTRUCTOR_TYPE_OFFSET);
ACCESSORS(ConstructorType, CONSTRUCTOR_TYPE_OFFSET, PROTOTYPE_TYPE_OFFSET);
ACCESSORS(PrototypeType, PROTOTYPE_TYPE_OFFSET, EXTENSION_TYPE_OFFSET);
ACCESSORS(ExtensionType, EXTENSION_TYPE_OFFSET, LAST_OFFSET);
ACCESSORS(PrototypeType, PROTOTYPE_TYPE_OFFSET, EXTENSION_GT_RAW_DATA_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(ExtensionGTRawData, uint32_t, EXTENSION_GT_RAW_DATA_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);
DECL_VISIT_OBJECT(INSTANCE_TYPE_OFFSET, LAST_OFFSET)
// define BitField
static constexpr size_t HAS_LINKED_BITS = 1;
FIRST_BIT_FIELD(BitField, HasLinked, bool, HAS_LINKED_BITS);
DECL_VISIT_OBJECT(INSTANCE_TYPE_OFFSET, EXTENSION_GT_RAW_DATA_OFFSET)
DECL_DUMP()
// Judgment base classType by extends typeId, ts2abc write 0 in base class type extends domain
inline static bool IsBaseClassType(int extendsTypeId)
{
const int baseClassTypeExtendsTypeId = 0;
return extendsTypeId == baseClassTypeExtendsTypeId;
}
GlobalTSTypeRef GetExtensionGT() const
{
uint32_t extensionGTRawData = GetExtensionGTRawData();
return GlobalTSTypeRef(extensionGTRawData);
}
void SetExtensionGT(GlobalTSTypeRef gt)
{
uint32_t extensionGTRawData = gt.GetType();
SetExtensionGTRawData(extensionGTRawData);
}
JSHandle<TSClassType> GetExtendClassType(JSThread *thread) const
{
GlobalTSTypeRef extensionGT = GetExtensionGT();
JSHandle<JSTaggedValue> extendClassType = thread->GetEcmaVM()->GetTSLoader()->GetType(extensionGT);
ASSERT(extendClassType->IsTSClassType());
return JSHandle<TSClassType>(extendClassType);
}
};
class TSClassInstanceType : public TSType {
+87 -46
View File
@@ -32,12 +32,14 @@ void TSTypeTable::Initialize(JSThread *thread, const JSPandaFile *jsPandaFile,
TSLoader *tsLoader = vm->GetTSLoader();
ObjectFactory *factory = vm->GetFactory();
JSHandle<TSTypeTable> tsTypetable = GenerateTypeTable(thread, jsPandaFile, recordImportModules);
JSHandle<TSTypeTable> tsTypeTable = GenerateTypeTable(thread, jsPandaFile, recordImportModules);
// Set TStypeTable -> GlobleModuleTable
JSHandle<EcmaString> fileName = factory->NewFromUtf8(jsPandaFile->GetJSPandaFileDesc());
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(tsTypetable), fileName);
tsLoader->GenerateStaticHClass(tsTypetable);
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(tsTypeTable), fileName);
TSTypeTable::LinkClassType(thread, tsTypeTable);
tsLoader->GenerateStaticHClass(tsTypeTable);
// management dependency module
while (recordImportModules.size() > 0) {
@@ -88,7 +90,7 @@ JSHandle<JSTaggedValue> TSTypeTable::ParseType(JSThread *thread, JSHandle<TSType
TSTypeKind kind = static_cast<TSTypeKind>(literal->Get(TYPE_KIND_INDEX_IN_LITERAL).GetInt());
switch (kind) {
case TSTypeKind::CLASS: {
JSHandle<TSClassType> classType = ParseClassType(thread, table, literal);
JSHandle<TSClassType> classType = ParseClassType(thread, literal);
return JSHandle<JSTaggedValue>(classType);
}
case TSTypeKind::CLASS_INSTANCE: {
@@ -251,16 +253,25 @@ JSHandle<TSImportType> TSTypeTable::ParseImportType(JSThread *thread, const JSHa
return importType;
}
JSHandle<TSClassType> TSTypeTable::ParseClassType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
const JSHandle<TaggedArray> &literal)
JSHandle<TSClassType> TSTypeTable::ParseClassType(JSThread *thread, const JSHandle<TaggedArray> &literal)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TSClassType> classType = factory->NewTSClassType();
int32_t index = 0;
ASSERT(static_cast<TSTypeKind>(literal->Get(index).GetInt()) == TSTypeKind::CLASS);
index = index + 2; // 2: ignore accessFlag and readonly
int32_t extendsTypeId = literal->Get(index++).GetInt();
const int32_t ignoreLength = 2; // 2: ignore accessFlag and readonly
index += ignoreLength;
int extendsTypeId = literal->Get(index++).GetInt();
if (TSClassType::IsBaseClassType(extendsTypeId)) {
classType->SetExtensionGT(GlobalTSTypeRef::Default());
classType->SetHasLinked(true);
} else {
int moduleId = thread->GetEcmaVM()->GetTSLoader()->GetNextModuleId();
GlobalTSTypeRef extensionGT = GlobalTSTypeRef(moduleId, extendsTypeId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT,
TSTypeKind::CLASS);
classType->SetExtensionGT(extensionGT);
}
// ignore implement
int32_t numImplement = literal->Get(index++).GetInt();
@@ -270,27 +281,17 @@ JSHandle<TSClassType> TSTypeTable::ParseClassType(JSThread *thread, JSHandle<TST
JSMutableHandle<JSTaggedValue> typeId(thread, JSTaggedValue::Undefined());
// resolve instance type
uint32_t numBaseFields = 0;
uint32_t numFields = static_cast<uint32_t>(literal->Get(index++).GetInt());
JSHandle<TSObjectType> instanceType;
if (extendsTypeId) { // base class is 0
uint32_t realExtendsTypeId = static_cast<uint32_t>(extendsTypeId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
JSHandle<TSClassType> extensionType(thread, typeTable->Get(realExtendsTypeId));
ASSERT(extensionType.GetTaggedValue().IsTSClassType());
classType->SetExtensionType(thread, extensionType);
instanceType = LinkSuper(thread, extensionType, &numBaseFields, numFields);
} else {
instanceType = factory->NewTSObjectType(numFields);
}
JSHandle<TSObjectType> instanceType = factory->NewTSObjectType(numFields);
JSHandle<TSObjLayoutInfo> instanceTypeInfo(thread, instanceType->GetObjLayoutInfo());
ASSERT(instanceTypeInfo->GetPropertiesCapacity() == numBaseFields + numFields);
ASSERT(instanceTypeInfo->GetPropertiesCapacity() == numFields);
for (uint32_t fieldIndex = 0; fieldIndex < numFields; ++fieldIndex) {
key.Update(literal->Get(index++));
typeId.Update(literal->Get(index++));
index += 2; // 2: ignore accessFlag and readonly
instanceTypeInfo->SetKey(thread, numBaseFields + fieldIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
instanceTypeInfo->SetKey(thread, fieldIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
}
classType->SetInstanceType(thread, instanceType);
@@ -374,30 +375,6 @@ JSHandle<TSInterfaceType> TSTypeTable::ParseInterfaceType(JSThread *thread, cons
return interfaceType;
}
JSHandle<TSObjectType> TSTypeTable::LinkSuper(JSThread *thread, JSHandle<TSClassType> &baseClassType,
uint32_t *numBaseFields, uint32_t numDerivedFields)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TSObjectType> baseInstanceType(thread, baseClassType->GetInstanceType());
JSHandle<TSObjLayoutInfo> baseInstanceTypeInfo(thread, baseInstanceType->GetObjLayoutInfo());
*numBaseFields = baseInstanceTypeInfo->NumberOfElements();
JSHandle<TSObjectType> derivedInstanceType = factory->NewTSObjectType(*numBaseFields + numDerivedFields);
JSHandle<TSObjLayoutInfo> derivedInstanceTypeInfo(thread, derivedInstanceType->GetObjLayoutInfo());
JSMutableHandle<JSTaggedValue> baseInstanceKey(thread, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> baseInstanceTypeId(thread, JSTaggedValue::Undefined());
for (uint32_t index = 0; index < baseInstanceTypeInfo->NumberOfElements(); ++index) {
baseInstanceKey.Update(baseInstanceTypeInfo->GetKey(index));
baseInstanceTypeId.Update(baseInstanceTypeInfo->GetTypeId(index));
derivedInstanceTypeInfo->SetKey(thread, index, baseInstanceKey.GetTaggedValue(),
baseInstanceTypeId.GetTaggedValue());
}
return derivedInstanceType;
}
JSHandle<TSUnionType> TSTypeTable::ParseUnionType(JSThread *thread, const JSPandaFile *jsPandaFile,
const JSHandle<TaggedArray> &literal)
{
@@ -570,4 +547,68 @@ JSHandle<TSTypeTable> TSTypeTable::PushBackTypeToInferTable(JSThread *thread, JS
return table;
}
void TSTypeTable::LinkClassType(JSThread *thread, JSHandle<TSTypeTable> table)
{
int numTypes = table->GetNumberOfTypes();
JSMutableHandle<JSTaggedValue> type(thread, JSTaggedValue::Undefined());
for (int i = 1; i <= numTypes; ++i) {
type.Update(table->Get(i));
if (!type->IsTSClassType()) {
continue;
}
JSHandle<TSClassType> classType(type);
if (classType->GetHasLinked()) { // has linked
continue;
}
JSHandle<TSClassType> extendClassType = classType->GetExtendClassType(thread);
MergeClassFiled(thread, classType, extendClassType);
}
}
void TSTypeTable::MergeClassFiled(JSThread *thread, JSHandle<TSClassType> classType,
JSHandle<TSClassType> extendClassType)
{
ASSERT(!classType->GetHasLinked());
if (!extendClassType->GetHasLinked()) {
MergeClassFiled(thread, extendClassType, extendClassType->GetExtendClassType(thread));
}
ASSERT(extendClassType->GetHasLinked());
JSHandle<TSObjectType> field(thread, classType->GetInstanceType());
JSHandle<TSObjLayoutInfo> layout(thread, field->GetObjLayoutInfo());
uint32_t numSelfTypes = layout->NumberOfElements();
JSHandle<TSObjectType> extendField(thread, extendClassType->GetInstanceType());
JSHandle<TSObjLayoutInfo> extendLayout(thread, extendField->GetObjLayoutInfo());
uint32_t numExtendTypes = extendLayout->NumberOfElements();
uint32_t numTypes = numSelfTypes + numExtendTypes;
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TSObjLayoutInfo> newLayout = factory->CreateTSObjLayoutInfo(numTypes);
uint32_t index = 0;
while (index < numExtendTypes) {
JSTaggedValue key = extendLayout->GetKey(index);
JSTaggedValue type = extendLayout->GetTypeId(index);
newLayout->SetKey(thread, index, key, type);
index++;
}
index = 0;
while (index < numSelfTypes) {
JSTaggedValue key = layout->GetKey(index);
JSTaggedValue type = layout->GetTypeId(index);
newLayout->SetKey(thread, numExtendTypes + index, key, type);
index++;
}
field->SetObjLayoutInfo(thread, newLayout);
classType->SetHasLinked(true);
}
} // namespace panda::ecmascript
+8 -7
View File
@@ -79,25 +79,21 @@ public:
private:
static JSHandle<TSTypeTable> GenerateTypeTable(JSThread *thread, const JSPandaFile *jsPandaFile,
CVector<JSHandle<EcmaString>> &recordImportModules);
CVector<JSHandle<EcmaString>> &recordImportModules);
static JSHandle<TaggedArray> GetExportTableFromPandFile(JSThread *thread, const panda_file::File &pf);
static panda_file::File::EntityId GetFileId(const panda_file::File &pf);
static JSHandle<TSClassType> ParseClassType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
const JSHandle<TaggedArray> &literal);
static JSHandle<TSClassType> ParseClassType(JSThread *thread, const JSHandle<TaggedArray> &literal);
static JSHandle<TSInterfaceType> ParseInterfaceType(JSThread *thread, const JSHandle<TaggedArray> &literal);
static JSHandle<TSUnionType> ParseUnionType(JSThread *thread, const JSPandaFile *jsPandaFile,
const JSHandle<TaggedArray> &literal);
static JSHandle<TSObjectType> LinkSuper(JSThread *thread, JSHandle<TSClassType> &baseClassType,
uint32_t *numBaseFields, uint32_t numDerivedFields);
static void CheckModule(JSThread *thread, const TSLoader* tsLoader, const JSHandle<EcmaString> target,
CVector<JSHandle<EcmaString>> &recordImportModules);
CVector<JSHandle<EcmaString>> &recordImportModules);
static JSHandle<EcmaString> GenerateVarNameAndPath(JSThread *thread, JSHandle<EcmaString> importPath,
JSHandle<EcmaString> fileName,
@@ -110,6 +106,11 @@ private:
static JSHandle<TSObjectType> ParseObjectType(JSThread *thread, const JSHandle<TaggedArray> &literal);
static int GetTypeKindFromFileByLocalId(JSThread *thread, const JSPandaFile *jsPandaFile, int localId);
static void LinkClassType(JSThread *thread, JSHandle<TSTypeTable> table);
static void MergeClassFiled(JSThread *thread, JSHandle<TSClassType> classType,
JSHandle<TSClassType> extendClassType);
};
} // namespace panda::ecmascript