From 4bbae113dc144f80ff4880c74c7068a9f7b14295 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Apr 2024 08:33:43 -0700 Subject: Precompute: Ignore mutable arrays in StringNew (#6522) All Struct/Array operations must ignore mutable fields in Precompute atm, which we did, but StringNew has an array variant that does an effective ArrayGet operation, which we didn't handle. --- src/passes/Precompute.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index 822b8ab16..4f9ad046d 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -195,6 +195,28 @@ public: return Literal(canonical, curr->type.getHeapType()); } + Flow visitStringNew(StringNew* curr) { + if (curr->op != StringNewWTF16Array) { + // TODO: handle other string ops. For now we focus on JS-like strings. + return Flow(NONCONSTANT_FLOW); + } + + // string.encode_wtf16_array is effectively an Array read operation, so + // just like ArrayGet above we must check for immutability. + auto ptrType = curr->ptr->type; + if (ptrType.isRef()) { + auto heapType = ptrType.getHeapType(); + if (heapType.isArray()) { + if (heapType.getArray().element.mutable_ == Immutable) { + return Super::visitStringNew(curr); + } + } + } + + // Otherwise, this is mutable or unreachable or otherwise uninteresting. + return Flow(NONCONSTANT_FLOW); + } + Flow visitStringEncode(StringEncode* curr) { // string.encode_wtf16_array is effectively an Array write operation, so // just like ArraySet and ArrayCopy above we must mark it as disallowed -- cgit v1.2.3