From 9e6f0a4abcd4b1578a35dca0720209ed5bbfeded Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 11 Nov 2026 16:17:41 +0000 Subject: [PATCH] One order of union members in every run; a literal of a @value type's fields merges into it; apt retries on CI - Union members were sorted by the address of their type, which differs between compiler runs: the default library's declarations (one run) and what lib.ts compiles to (another) had `string | RegExp` and `RegExp | string` - the flaky check_declarations failure of the alpha122 and alpha124 release runs. They are now sorted by their printed text (sortUnionMembers), the address only for members that print alike. - That order put `{at: s32}` before `Num` in `c ? n : { at: 6 }`, `n || { at: 6 }` and `num(5) ?? { at: 6 }`, and `.at` read 0: a field read from a union takes its first member's layout, and the two have one tag but not one layout. Right before only by the order of the addresses. An object literal whose fields convert to a @value type's, by name, without loss, now merges into that type (MLIRTypeHelper::literalConvertsToValueType). - CI: apt-get retries the whole install 5 times, 30 s apart. With public resolvers the Ubuntu mirrors still failed to resolve for a while on some runners. Co-Authored-By: Claude Opus 5.5 --- .../workflows/cmake-test-release-linux.yml | 9 +- .github/workflows/create-release.yml | 15 +++- .../TypeScript/MLIRLogic/MLIRTypeHelper.h | 86 ++++++++++++++++++- tslang/test/tester/value/value_missing_ops.ts | 5 ++ 4 files changed, 108 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake-test-release-linux.yml b/.github/workflows/cmake-test-release-linux.yml index 19f5cce52..7e8bb5c3b 100644 --- a/.github/workflows/cmake-test-release-linux.yml +++ b/.github/workflows/cmake-test-release-linux.yml @@ -92,10 +92,15 @@ jobs: continue-on-error: false shell: sh # Public resolvers: the runner's own DNS sometimes fails on the Ubuntu mirrors ("Temporary - # failure resolving 'azure.archive.ubuntu.com'") while every other host resolves. + # failure resolving 'azure.archive.ubuntu.com'") while every other host resolves. Even then a + # lookup can drop for a few seconds, longer than apt's own retries, so the whole step retries. run: | printf 'nameserver 8.8.8.8\nnameserver 1.1.1.1\n' | sudo tee /etc/resolv.conf > /dev/null - sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y ninja-build zlib1g-dev libzstd-dev libxml2-dev + for i in 1 2 3 4 5; do + sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y ninja-build zlib1g-dev libzstd-dev libxml2-dev && exit 0 + echo "apt-get failed (attempt $i), retrying in 30 s"; sleep 30 + done + exit 1 # - name: Install Clang 12 # continue-on-error: false diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index eec1e2cc6..584743abb 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -362,10 +362,15 @@ jobs: shell: sh # zlib, zstd and libxml2: the official LLVM package's CMake targets link against them. # Public resolvers: the runner's own DNS sometimes fails on the Ubuntu mirrors ("Temporary - # failure resolving 'azure.archive.ubuntu.com'") while every other host resolves. + # failure resolving 'azure.archive.ubuntu.com'") while every other host resolves. Even then a + # lookup can drop for a few seconds, longer than apt's own retries, so the whole step retries. run: | printf 'nameserver 8.8.8.8\nnameserver 1.1.1.1\n' | sudo tee /etc/resolv.conf > /dev/null - sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y ninja-build libcurl4-openssl-dev zlib1g-dev libzstd-dev libxml2-dev + for i in 1 2 3 4 5; do + sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y ninja-build libcurl4-openssl-dev zlib1g-dev libzstd-dev libxml2-dev && exit 0 + echo "apt-get failed (attempt $i), retrying in 30 s"; sleep 30 + done + exit 1 # - name: Install Clang 12 # continue-on-error: false @@ -561,7 +566,11 @@ jobs: # Public resolvers: see "Install Ninja" above. run: | printf 'nameserver 8.8.8.8\nnameserver 1.1.1.1\n' | sudo tee /etc/resolv.conf > /dev/null - sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y libcurl4-openssl-dev + for i in 1 2 3 4 5; do + sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install -y libcurl4-openssl-dev && exit 0 + echo "apt-get failed (attempt $i), retrying in 30 s"; sleep 30 + done + exit 1 - name: Clone Default Library shell: bash diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index fd4c98e4c..6390d1b56 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -250,10 +250,48 @@ class MLIRTypeHelper static mlir::Type getMissingValueType(mlir_ts::ValueType valueType) { mlir::SmallVector members{valueType, mlir_ts::NullType::get(valueType.getContext())}; - std::sort(members.begin(), members.end(), [](auto i, auto j) { return i.getAsOpaquePointer() < j.getAsOpaquePointer(); }); + sortUnionMembers(members); return mlir_ts::OptionalType::get(mlir_ts::UnionType::get(valueType.getContext(), members)); } + // The one order of a union's members, so `A | B` and `B | A` are one type. By the members' + // printed text, which is the same in every compiler run: a declaration written out by one run + // (the default library's) has to match the type another run makes of its source. The address + // of a type, used before, differs between runs. Members that print alike are ordered by + // address, as they cannot be told apart in text anyway. + static void sortUnionMembers(mlir::SmallVectorImpl &members) + { + if (members.size() < 2) + { + return; + } + + mlir::SmallVector> keyed; + keyed.reserve(members.size()); + for (auto member : members) + { + std::string text; + llvm::raw_string_ostream os(text); + member.print(os); + os.flush(); + keyed.emplace_back(std::move(text), member); + } + + std::sort(keyed.begin(), keyed.end(), [](const auto &a, const auto &b) { + if (a.first != b.first) + { + return a.first < b.first; + } + + return a.second.getAsOpaquePointer() < b.second.getAsOpaquePointer(); + }); + + for (size_t i = 0; i < members.size(); i++) + { + members[i] = keyed[i].second; + } + } + // Where null of a @value type T is in T itself: the index path, into T's storage, of a pointer no // value of T holds as null - the `this` of a field of an interface type (`{vtable, this}`, null // exactly when the interface is), or a field of a class type - so `T | null` needs no tag: null is @@ -3874,7 +3912,7 @@ class MLIRTypeHelper newTypes.push_back(type); } - std::sort (newTypes.begin(), newTypes.end(), [](auto i, auto j) { return (i.getAsOpaquePointer() < j.getAsOpaquePointer()); }); + sortUnionMembers(newTypes); return isUndefined ? mlir::Type(mlir_ts::OptionalType::get(mlir_ts::UnionType::get(context, newTypes))) @@ -4145,6 +4183,37 @@ class MLIRTypeHelper return false; } + // `valueType` when `literalType` is an object literal (a tuple) with its fields, by name and in + // order, each converting without loss (`{ at: 6 }`'s s32 to Num's number). Kept apart in a union, + // the two have one tag ("object") but not one layout, and a field read from the union takes + // the first member's: right or wrong by the members' order. + mlir_ts::ValueType literalConvertsToValueType(mlir::Type literalType, mlir::Type valueTypeIn) + { + auto valueType = dyn_cast_or_null(valueTypeIn); + if (!valueType) + { + return mlir_ts::ValueType(); + } + + auto storage = dyn_cast(stripValueType(valueType)); + auto literal = dyn_cast_or_null(convertConstTupleTypeToTupleType(literalType)); + if (!storage || !literal || storage.getFields().size() != literal.getFields().size()) + { + return mlir_ts::ValueType(); + } + + for (auto [from, to] : llvm::zip(literal.getFields(), storage.getFields())) + { + auto fromType = stripLiteralType(from.type); + if (from.id != to.id || !(fromType == to.type || canWideTypeWithoutDataLoss(fromType, to.type))) + { + return mlir_ts::ValueType(); + } + } + + return valueType; + } + mlir::Type mergeType(mlir::Location location, mlir::Type existType, mlir::Type currentType, bool& merged) { merged = false; @@ -4178,6 +4247,19 @@ class MLIRTypeHelper return currentType; } + // an object literal of a @value type's fields is that type: `n ?? { at: 6 }` is `Num` + if (auto valueType = literalConvertsToValueType(currentType, existType)) + { + merged = true; + return valueType; + } + + if (auto valueType = literalConvertsToValueType(existType, currentType)) + { + merged = true; + return valueType; + } + // in case of merging integer types with sign/no sign auto mergedInts = false; auto resNewIntType = mergeIntTypes(existType, currentType, mergedInts); diff --git a/tslang/test/tester/value/value_missing_ops.ts b/tslang/test/tester/value/value_missing_ops.ts index 23cb0bce1..556f5a0ac 100644 --- a/tslang/test/tester/value/value_missing_ops.ts +++ b/tslang/test/tester/value/value_missing_ops.ts @@ -56,6 +56,11 @@ function main() { const fallback: Mark = { at: 7, owner: new Owner(7) }; assert((mark(-1) ?? fallback).at == 7); assert((num(-1) ?? num(4)).at == 4 && (num(5) ?? { at: 6 }).at == 5); + // a literal of Num's fields beside a Num is a Num: kept as a union of the two, a field was read + // as the first member's layout, and got 0 when the literal (s32 fields) was ordered first + const five: Num = { at: 5 }; + const pick = five.at > 0; + assert((pick ? five : { at: 6 }).at == 5 && (five || { at: 6 }).at == 5, "a literal beside a Num"); const nothing: Mark | undefined = undefined; assert((nothing ?? fallback).at == 7);