From e028a6de1f00c6c417ab73bddbf196f0581c40fd Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 15 Jul 2026 22:50:07 +0000 Subject: [PATCH 1/3] Fix llvm_unreachable abort when resolving non-data-field names on array types getFieldTypeByFieldName's ArrayType case only special-cased "length" and the synthetic index-access field names, then hit llvm_unreachable for any other field name -- including legitimate extension-method names like "push"/"pop"/"entries" on the array. This aborts whenever --export=all forces eager instantiation of a generic class whose body calls array extension methods (e.g. the default lib's Array/TypedArray, which Uint8Array/Int32Array alias), as seen when compiling a .d.ts with `declare function` signatures that reference typed arrays (#231). Return an empty type instead, matching the "field not found" convention already used by the tuple/const-tuple cases in the same function, whose callers (the `in` operator check and extendsType) already treat a null type as "not present" correctly. --- tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index cd54ccffa..9de993d0f 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -2372,8 +2372,9 @@ class MLIRTypeHelper return mlir_ts::AnyType::get(context); } - llvm_unreachable("not implemented"); - } + // any other field (e.g. an extension method name like "push"/"pop") is not a data field of the array + return mlir::Type(); + } // TODO: read fields info from class Array if (auto constArrayType = dyn_cast(srcType)) From 036868ccd3d22ce53889abe0df9c4043fc40e969 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 15 Jul 2026 22:55:04 +0000 Subject: [PATCH 2/3] Fix remaining llvm_unreachable aborts in getFieldTypeByFieldName Same defect as the ArrayType case fixed in the previous commit, present in four more branches of the same function: - InterfaceType/ClassType: aborted when a string field name matched neither a field nor a method, instead of returning "not found" so the caller can keep looking (e.g. via extension functions). - ConstArrayType/StringType: only special-cased "length" (and, for ConstArrayType, the synthetic index-access field), then aborted for any other field/method name -- e.g. String.fromCharCode. All five branches now return an empty type for an unresolved field name, matching the convention already used by the ConstTupleType/TupleType branches earlier in the same function. This matters in particular for the UnionType branch (right below), which calls this function per member and treats a falsy result as "this member doesn't have the field" -- before this fix, a union containing a class/interface/array/string member would abort the process instead. --- .../TypeScript/MLIRLogic/MLIRTypeHelper.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index 9de993d0f..d5ed6c3de 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -2314,10 +2314,6 @@ class MLIRTypeHelper { return methodInfo->funcType; } - else - { - llvm_unreachable("not implemented"); - } } } @@ -2341,10 +2337,6 @@ class MLIRTypeHelper { return methodInfo->funcType; } - else - { - llvm_unreachable("not implemented"); - } } } @@ -2390,8 +2382,9 @@ class MLIRTypeHelper return mlir_ts::AnyType::get(context); } - llvm_unreachable("not implemented"); - } + // any other field (e.g. an extension method name like "push"/"pop") is not a data field of the array + return mlir::Type(); + } // TODO: read data from String class if (auto stringType = dyn_cast(srcType)) @@ -2401,8 +2394,9 @@ class MLIRTypeHelper return mlir_ts::NumberType::get(context); } - llvm_unreachable("not implemented"); - } + // any other field (e.g. a method name like "fromCharCode"/"charAt") is not a data field of String + return mlir::Type(); + } if (auto unionType = dyn_cast(srcType)) { From c6b99ebe7b15004d110c7980a399123d857ab59f Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 15 Jul 2026 23:22:55 +0000 Subject: [PATCH 3/3] Fix getFieldTypeByFieldName looking up ClassType in the interfaces table The ClassType branch called getInterfaceInfoByFullName() with a class's full name instead of getClassInfoByFullName(), so it was looking up class field/method info in the wrong registry. Since classes and interfaces are registered in separate tables, this lookup essentially never succeeded for a real class, silently returning "field not found" for every field/method access on a class type -- affecting the `in` operator on class instances and extendsType's structural matching of classes against tuple-shaped constraints (e.g. `T extends { length: number }`). ClassInfo's findField/findMethod have a different signature than InterfaceInfo's (findField takes a bool& out-param and returns a value rather than a pointer), so the fix updates the call site accordingly rather than just swapping the lookup function. Verified against the full tester/tests suite (365 files): no crashes, no new failures compared to the pre-fix baseline. --- tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index d5ed6c3de..37f23d2cf 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -2322,12 +2322,13 @@ class MLIRTypeHelper if (auto srcClassType = dyn_cast(srcType)) { - if (auto srcClassInfo = getInterfaceInfoByFullName(srcClassType.getName().getValue())) + if (auto srcClassInfo = getClassInfoByFullName(srcClassType.getName().getValue())) { - auto fieldInfo = srcClassInfo->findField(fieldName); - if (fieldInfo) + auto foundField = false; + auto fieldInfo = srcClassInfo->findField(fieldName, foundField); + if (foundField) { - return fieldInfo->type; + return fieldInfo.type; } if (auto strName = dyn_cast(fieldName))