Skip to content

Commit

Permalink
Merge branch 'main' into check-pr-55445
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Sep 28, 2023
2 parents de53a32 + 284cd45 commit 9d8809c
Show file tree
Hide file tree
Showing 61 changed files with 2,199 additions and 418 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/new-release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 5
- uses: actions/setup-node@v3
- run: |
npm --version
# corepack enable npm
npm install -g $(jq -r '.packageManager' < package.json)
npm --version
- uses: actions/checkout@v3
with:
fetch-depth: 5
- run: |
git checkout -b ${{ github.event.client_payload.branch_name }}
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/set-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
contents: write

steps:
- uses: actions/setup-node@v3
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.branch_name }}
- uses: actions/setup-node@v3
- run: |
npm --version
# corepack enable npm
Expand Down
472 changes: 239 additions & 233 deletions package-lock.json

Large diffs are not rendered by default.

56 changes: 35 additions & 21 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20780,6 +20780,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let skipParentCounter = 0; // How many errors should be skipped 'above' in the elaboration pyramid
let lastSkippedInfo: [Type, Type] | undefined;
let incompatibleStack: DiagnosticAndArguments[] | undefined;
// In Node.js, the maximum number of elements in a map is 2^24. We limit the number of entries an invocation
// of checkTypeRelatedTo can add to a relation to 1/8th of its remaining capacity.
let relationCount = (16_000_000 - relation.size) >> 3;

Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");

Expand All @@ -20788,8 +20791,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
reportIncompatibleStack();
}
if (overflow) {
// Record this relation as having failed such that we don't attempt the overflowing operation again.
const id = getRelationKey(source, target, /*intersectionState*/ IntersectionState.None, relation, /*ignoreConstraints*/ false);
relation.set(id, RelationComparisonResult.Reported | RelationComparisonResult.Failed);
tracing?.instant(tracing.Phase.CheckTypes, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth: sourceDepth, targetDepth });
const diag = error(errorNode || currentNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
const message = relationCount <= 0 ?
Diagnostics.Excessive_complexity_comparing_types_0_and_1 :
Diagnostics.Excessive_stack_depth_comparing_types_0_and_1;
const diag = error(errorNode || currentNode, message, typeToString(source), typeToString(target));
if (errorOutputContainer) {
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
}
Expand Down Expand Up @@ -21422,6 +21431,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// we need to deconstruct unions before intersections (because unions are always at the top),
// and we need to handle "each" relations before "some" relations for the same kind of type.
if (source.flags & TypeFlags.Union) {
if (target.flags & TypeFlags.Union) {
// Intersections of union types are normalized into unions of intersection types, and such normalized
// unions can get very large and expensive to relate. The following fast path checks if the source union
// originated in an intersection. If so, and if that intersection contains the target type, then we know
// the result to be true (for any two types A and B, A & B is related to both A and B).
const sourceOrigin = (source as UnionType).origin;
if (sourceOrigin && sourceOrigin.flags & TypeFlags.Intersection && target.aliasSymbol && contains((sourceOrigin as IntersectionType).types, target)) {
return Ternary.True;
}
// Similarly, in unions of unions the we preserve the original list of unions. This original list is often
// much shorter than the normalized result, so we scan it in the following fast path.
const targetOrigin = (target as UnionType).origin;
if (targetOrigin && targetOrigin.flags & TypeFlags.Union && source.aliasSymbol && contains((targetOrigin as UnionType).types, source)) {
return Ternary.True;
}
}
return relation === comparableRelation ?
someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState) :
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState);
Expand Down Expand Up @@ -21673,6 +21698,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return entry & RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
}
}
if (relationCount <= 0) {
overflow = true;
return Ternary.False;
}
if (!maybeKeys) {
maybeKeys = [];
maybeKeysSet = new Set();
Expand Down Expand Up @@ -21770,6 +21799,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// A false result goes straight into global cache (when something is false under
// assumptions it will also be false without assumptions)
relation.set(id, (reportErrors ? RelationComparisonResult.Reported : 0) | RelationComparisonResult.Failed | propagatingVarianceFlags);
relationCount--;
resetMaybeStack(/*markAllAsSucceeded*/ false);
}
return result;
Expand All @@ -21779,6 +21809,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
maybeKeysSet.delete(maybeKeys[i]);
if (markAllAsSucceeded) {
relation.set(maybeKeys[i], RelationComparisonResult.Succeeded | propagatingVarianceFlags);
relationCount--;
}
}
maybeCount = maybeStart;
Expand Down Expand Up @@ -39768,16 +39799,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkSourceElement(node.argument);

if (node.attributes) {
const override = getResolutionModeOverride(node.attributes, grammarErrorOnNode);
const errorNode = node.attributes;
if (override && errorNode && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) {
grammarErrorOnNode(
errorNode,
node.attributes.token === SyntaxKind.WithKeyword
? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext
: Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext,
);
}
getResolutionModeOverride(node.attributes, grammarErrorOnNode);
}
checkTypeReferenceOrImport(node);
}
Expand Down Expand Up @@ -45248,25 +45270,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const override = getResolutionModeOverride(node, validForTypeAttributes ? grammarErrorOnNode : undefined);
const isImportAttributes = declaration.attributes.token === SyntaxKind.WithKeyword;
if (validForTypeAttributes && override) {
if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) {
return grammarErrorOnNode(
node,
isImportAttributes
? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext
: Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext,
);
}
return; // Other grammar checks do not apply to type-only imports with resolution mode assertions
}

const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
if (mode !== ModuleKind.ESNext && moduleKind !== ModuleKind.ESNext) {
const message = isImportAttributes
? moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_transpile_to_CommonJS_require_calls
? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls
: Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext
: moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_CommonJS_require_calls
? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls
: Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext;
return grammarErrorOnNode(node, message);
}
Expand Down
18 changes: 7 additions & 11 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,6 @@
"category": "Error",
"code": 1451
},
"'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.": {
"category": "Error",
"code": 1452
},
"`resolution-mode` should be either `require` or `import`.": {
"category": "Error",
"code": 1453
Expand Down Expand Up @@ -1520,10 +1516,6 @@
"category": "Message",
"code": 1461
},
"The 'resolution-mode' attribute is only supported when 'moduleResolution' is 'node16' or 'nodenext'.": {
"category": "Error",
"code": 1462
},
"'resolution-mode' is the only valid key for type import attributes.": {
"category": "Error",
"code": 1463
Expand Down Expand Up @@ -3611,7 +3603,7 @@
"category": "Error",
"code": 2835
},
"Import assertions are not allowed on statements that transpile to CommonJS 'require' calls.": {
"Import assertions are not allowed on statements that compile to CommonJS 'require' calls.": {
"category": "Error",
"code": 2836
},
Expand Down Expand Up @@ -3683,7 +3675,7 @@
"category": "Error",
"code": 2855
},
"Import attributes are not allowed on statements that transpile to CommonJS 'require' calls.": {
"Import attributes are not allowed on statements that compile to CommonJS 'require' calls.": {
"category": "Error",
"code": 2856
},
Expand All @@ -3695,10 +3687,14 @@
"category": "Error",
"code": 2858
},
"The type of this declaration is ambiguous and may be observed as either '{0}' or '{1}'.": {
"Excessive complexity comparing types '{0}' and '{1}'.": {
"category": "Error",
"code": 2859
},
"The type of this declaration is ambiguous and may be observed as either '{0}' or '{1}'.": {
"category": "Error",
"code": 2860
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
Loading

0 comments on commit 9d8809c

Please sign in to comment.