Skip to content

Commit b1f0dc5

Browse files
committed
Turn this into a proper flag
1 parent 23e28c9 commit b1f0dc5

8 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/compiler/checker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ import {
10831083
tryGetModuleSpecifierFromDeclaration,
10841084
tryGetPropertyAccessOrIdentifierToString,
10851085
TryStatement,
1086-
TSGO_COMPAT,
10871086
TupleType,
10881087
TupleTypeNode,
10891088
TupleTypeReference,
@@ -1543,6 +1542,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
15431542
var useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
15441543
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
15451544
var noUncheckedSideEffectImports = compilerOptions.noUncheckedSideEffectImports !== false;
1545+
var stableTypeOrdering = compilerOptions.stableTypeOrdering !== false;
15461546

15471547
var checkBinaryExpression = createCheckBinaryExpression();
15481548
var emitResolver = createResolver();
@@ -5559,7 +5559,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55595559
}
55605560

55615561
function createTypeofType() {
5562-
return getUnionType(map(TSGO_COMPAT ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys()), getStringLiteralType));
5562+
return getUnionType(map(stableTypeOrdering ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys()), getStringLiteralType));
55635563
}
55645564

55655565
function createTypeParameter(symbol?: Symbol) {
@@ -5579,7 +5579,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55795579
}
55805580

55815581
function getNamedMembers(members: SymbolTable, container: Symbol | undefined): Symbol[] {
5582-
if (!TSGO_COMPAT) {
5582+
if (!stableTypeOrdering) {
55835583
let result: Symbol[] | undefined;
55845584
members.forEach((symbol, id) => {
55855585
if (isNamedMember(symbol, id)) {
@@ -18072,11 +18072,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1807218072
}
1807318073

1807418074
function containsType(types: readonly Type[], type: Type): boolean {
18075-
return TSGO_COMPAT ? binarySearch(types, type, identity, compareTypes) >= 0 : binarySearch(types, type, getTypeId, compareValues) >= 0;
18075+
return stableTypeOrdering ? binarySearch(types, type, identity, compareTypes) >= 0 : binarySearch(types, type, getTypeId, compareValues) >= 0;
1807618076
}
1807718077

1807818078
function insertType(types: Type[], type: Type): boolean {
18079-
const index = TSGO_COMPAT ? binarySearch(types, type, identity, compareTypes) : binarySearch(types, type, getTypeId, compareValues);
18079+
const index = stableTypeOrdering ? binarySearch(types, type, identity, compareTypes) : binarySearch(types, type, getTypeId, compareValues);
1808018080
if (index < 0) {
1808118081
types.splice(~index, 0, type);
1808218082
return true;
@@ -18098,7 +18098,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1809818098
}
1809918099
else {
1810018100
const len = typeSet.length;
18101-
const index = TSGO_COMPAT ? binarySearch(typeSet, type, identity, compareTypes) : (len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues));
18101+
const index = stableTypeOrdering ? binarySearch(typeSet, type, identity, compareTypes) : (len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues));
1810218102
if (index < 0) {
1810318103
typeSet.splice(~index, 0, type);
1810418104
}
@@ -53787,7 +53787,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5378753787
function sortSymbolsIfTSGoCompat(array: Symbol[]): Symbol[];
5378853788
function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined;
5378953789
function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined {
53790-
if (TSGO_COMPAT && array) {
53790+
if (stableTypeOrdering && array) {
5379153791
return array.sort(compareSymbols); // eslint-disable-line local/no-array-mutating-method-expressions
5379253792
}
5379353793
return array;

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
961961
description: Diagnostics.Built_in_iterators_are_instantiated_with_a_TReturn_type_of_undefined_instead_of_any,
962962
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
963963
},
964+
{
965+
name: "stableTypeOrdering",
966+
type: "boolean",
967+
affectsSemanticDiagnostics: true,
968+
affectsBuildInfo: true,
969+
category: Diagnostics.Type_Checking,
970+
description: Diagnostics.Ensure_types_are_ordered_stably_and_deterministically_across_compilations,
971+
defaultValueDescription: true,
972+
},
964973
{
965974
name: "noImplicitThis",
966975
type: "boolean",

src/compiler/corePublic.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ export const versionMajorMinor = "6.0";
55
/** The version of the TypeScript compiler release */
66
export const version: string = `${versionMajorMinor}.0-dev`;
77

8-
const tsgoCompatEnv = typeof process !== "undefined" && process.env ? process.env.TSGO_COMPAT : undefined;
9-
10-
/** @internal */
11-
export const TSGO_COMPAT: boolean = tsgoCompatEnv ? tsgoCompatEnv === "true" : true;
12-
138
/**
149
* Type of objects whose values are all of the same type.
1510
* The `in` and `for-in` operators can *not* be safely used,

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6589,6 +6589,10 @@
65896589
"category": "Message",
65906590
"code": 6808
65916591
},
6592+
"Ensure types are ordered stably and deterministically across compilations.": {
6593+
"category": "Message",
6594+
"code": 6809
6595+
},
65926596

65936597
"one of:": {
65946598
"category": "Message",

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7541,6 +7541,7 @@ export interface CompilerOptions {
75417541
strictNullChecks?: boolean; // Always combine with strict property
75427542
strictPropertyInitialization?: boolean; // Always combine with strict property
75437543
strictBuiltinIteratorReturn?: boolean; // Always combine with strict property
7544+
stableTypeOrdering?: boolean;
75447545
stripInternal?: boolean;
75457546
/** @deprecated */
75467547
suppressExcessPropertyErrors?: boolean;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,6 +7114,7 @@ declare namespace ts {
71147114
strictNullChecks?: boolean;
71157115
strictPropertyInitialization?: boolean;
71167116
strictBuiltinIteratorReturn?: boolean;
7117+
stableTypeOrdering?: boolean;
71177118
stripInternal?: boolean;
71187119
/** @deprecated */
71197120
suppressExcessPropertyErrors?: boolean;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"stableTypeOrdering": true
4+
}
5+
}

tests/baselines/reference/tsc/commandLine/help-all.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ Raise an error when a function parameter isn't read.
271271
type: boolean
272272
default: false
273273

274+
--stableTypeOrdering
275+
Ensure types are ordered stably and deterministically across compilations.
276+
type: boolean
277+
default: true
278+
274279
--strict
275280
Enable all strict type-checking options.
276281
type: boolean

0 commit comments

Comments
 (0)