Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsc 4.5 hangs with unist-util-visit package (works fine with 4.4.4) #46900

Closed
stefanprobst opened this issue Nov 22, 2021 · 14 comments · Fixed by #47738
Closed

tsc 4.5 hangs with unist-util-visit package (works fine with 4.4.4) #46900

stefanprobst opened this issue Nov 22, 2021 · 14 comments · Fixed by #47738
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@stefanprobst
Copy link

Bug Report

the following example makes tsc hang indefinitely with version 4.5, but compiles fine with 4.4.4:

example: https://github.com/stefanprobst/issue-tsc

also see the discussion here: unifiedjs/unified#175

🔎 Search Terms

hangs

🕗 Version & Regression Information

  • This is a crash: tsc hangs, but does not give an error message
  • This changed between versions 4.4.4 and 4.5.2 (same behavior also in current @next version)

⏯ Playground Link

link to a reproduction repo above

💻 Code

🙁 Actual behavior

tsc hangs indefinitely without error message

🙂 Expected behavior

tsc finishing compilation, or giving indication what's wrong

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Nov 22, 2021

Sample call stack while stuck

isSimpleTypeRelatedTo (checker.ts:17773)
isRelatedTo (checker.ts:18270)
typeRelatedToSomeType (checker.ts:18585)
structuredTypeRelatedToWorker (checker.ts:18861)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getSimplifiedTypeOrConstraint (checker.ts:11730)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getEffectiveConstraintOfIntersection (checker.ts:11802)
isRelatedTo (checker.ts:18335)
typeRelatedToSomeType (checker.ts:18585)
structuredTypeRelatedToWorker (checker.ts:18861)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getSimplifiedTypeOrConstraint (checker.ts:11730)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getEffectiveConstraintOfIntersection (checker.ts:11802)
isRelatedTo (checker.ts:18335)
isRelatedTo (checker.ts:18339)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getSimplifiedTypeOrConstraint (checker.ts:11730)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getEffectiveConstraintOfIntersection (checker.ts:11802)
isRelatedTo (checker.ts:18335)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getSimplifiedTypeOrConstraint (checker.ts:11730)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getEffectiveConstraintOfIntersection (checker.ts:11802)
isRelatedTo (checker.ts:18335)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getSimplifiedTypeOrConstraint (checker.ts:11730)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getSimplifiedTypeOrConstraint (checker.ts:11731)
getConstraintFromIndexedAccess (checker.ts:11742)
getConstraintOfIndexedAccess (checker.ts:11726)
getConstraintOfType (checker.ts:11716)
getEffectiveConstraintOfIntersection (checker.ts:11802)
isRelatedTo (checker.ts:18335)
typeRelatedToSomeType (checker.ts:18585)
structuredTypeRelatedToWorker (checker.ts:18861)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18314)
isRelatedTo (checker.ts:18339)
isRelatedTo (checker.ts:18339)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
getSimplifiedConditionalType (checker.ts:15445)
getSimplifiedType (checker.ts:15357)
getNormalizedType (checker.ts:17851)
isRelatedTo (checker.ts:18233)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
instantiateTypeWorker (checker.ts:16828)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
instantiateList (checker.ts:16340)
instantiateTypes (checker.ts:16357)
instantiateTypeWorker (checker.ts:16794)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
getTrueTypeFromConditionalType (checker.ts:15730)
getSimplifiedConditionalType (checker.ts:15433)
getSimplifiedType (checker.ts:15357)
getImmediateBaseConstraint (checker.ts:11880)
getBaseConstraint (checker.ts:11901)
computeBaseConstraint (checker.ts:11917)
getImmediateBaseConstraint (checker.ts:11880)
getBaseConstraint (checker.ts:11901)
computeBaseConstraint (checker.ts:11955)
getImmediateBaseConstraint (checker.ts:11880)
getResolvedBaseConstraint (checker.ts:11864)
getBaseConstraintOfType (checker.ts:11836)
getApparentType (checker.ts:12036)
createUnionOrIntersectionProperty (checker.ts:12069)
getUnionOrIntersectionProperty (checker.ts:12221)
getPropertyOfUnionOrIntersectionType (checker.ts:12233)
getPropertiesOfUnionOrIntersectionType (checker.ts:11650)
getReducedType (checker.ts:12251)
getNormalizedType (checker.ts:17849)
isRelatedTo (checker.ts:18234)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
instantiateTypeWorker (checker.ts:16828)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
instantiateTypeWorker (checker.ts:16816)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
getConditionalType (checker.ts:15692)
getConditionalTypeInstantiation (checker.ts:16737)
instantiateTypeWorker (checker.ts:16819)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
getTrueTypeFromConditionalType (checker.ts:15730)
getSimplifiedConditionalType (checker.ts:15433)
getSimplifiedType (checker.ts:15357)
getConstraintOfDistributiveConditionalType (checker.ts:11775)
structuredTypeRelatedToWorker (checker.ts:19263)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
eachTypeRelatedToType (checker.ts:18655)
structuredTypeRelatedToWorker (checker.ts:18858)
structuredTypeRelatedTo (checker.ts:18842)
isRelatedTo (checker.ts:18311)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
structuredTypeRelatedToWorker (checker.ts:19265)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
structuredTypeRelatedToWorker (checker.ts:19276)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18317)
typeRelatedToEachType (checker.ts:18601)
structuredTypeRelatedToWorker (checker.ts:18864)
structuredTypeRelatedTo (checker.ts:18842)
recursiveTypeRelatedTo (checker.ts:18808)
isRelatedTo (checker.ts:18314)
checkTypeRelatedTo (checker.ts:17898)
isTypeRelatedTo (checker.ts:17836)
isTypeAssignableTo (checker.ts:16981)
instantiateTypeWorker (checker.ts:16828)
instantiateTypeWithAlias (checker.ts:16766)
instantiateType (checker.ts:16748)
getTrueTypeFromConditionalType (checker.ts:15730)
inferToConditionalType (checker.ts:22199)
invokeOnce (checker.ts:21988)
inferFromTypes (checker.ts:21920)
inferFromContravariantTypes (checker.ts:22037)
applyToParameterTypes (checker.ts:21318)
inferFromSignature (checker.ts:22345)
inferFromSignatures (checker.ts:22335)
inferFromObjectTypes (checker.ts:22311)
invokeOnce (checker.ts:21988)
inferFromTypes (checker.ts:21956)
inferTypes (checker.ts:21749)
inferTypeArguments (checker.ts:29330)
chooseOverload (checker.ts:30152)
resolveCall (checker.ts:29968)
resolveCallExpression (checker.ts:30409)
resolveSignature (checker.ts:30859)
getResolvedSignature (checker.ts:30891)
checkCallExpression (checker.ts:31022)
checkExpressionWorker (checker.ts:34070)
checkExpression (checker.ts:33968)
checkExpressionStatement (checker.ts:37036)
checkSourceElementWorker (checker.ts:40284)
checkSourceElement (checker.ts:40152)
forEach (core.ts:66)
checkBlock (checker.ts:36539)
checkSourceElementWorker (checker.ts:40280)
checkSourceElement (checker.ts:40152)
checkFunctionExpressionOrObjectLiteralMethodDeferred (checker.ts:32207)
checkDeferredNode (checker.ts:40462)
checkDeferredNodes (checker.ts:40438)
checkSourceFileWorker (checker.ts:40528)
checkSourceFile (checker.ts:40485)
getDiagnosticsWorker (checker.ts:40599)
getDiagnostics (checker.ts:40583)
(anonymous) (program.ts:2014)
runWithCancellationToken (program.ts:1966)
getBindAndCheckDiagnosticsForFileNoCache (program.ts:1999)
getAndCacheDiagnostics (program.ts:2305)
getBindAndCheckDiagnosticsForFile (program.ts:1995)
getSemanticDiagnosticsForFile (program.ts:1989)
(anonymous) (program.ts:1906)
flatMap (core.ts:412)
getDiagnosticsHelper (program.ts:1902)
getSemanticDiagnostics (program.ts:1915)
emitFilesAndReportErrors (watch.ts:329)
emitFilesAndReportErrorsAndGetExitStatus (watch.ts:372)
performCompilation (executeCommandLine.ts:776)
executeCommandLineWorker (executeCommandLine.ts:570)
executeCommandLine (executeCommandLine.ts:666)
(anonymous) (tsc.ts:21)
Module._compile (internal/modules/cjs/loader.js:1065)
Module._extensions..js (internal/modules/cjs/loader.js:1097)
Module.load (internal/modules/cjs/loader.js:933)
Module._load (internal/modules/cjs/loader.js:774)
executeUserEntryPoint (internal/modules/run_main.js:72)
(anonymous) (internal/main/run_main_module.js:17)

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Nov 22, 2021

We're trying to relate this source

(Parent<Node<Data>, Data> & Exclude<(Parent<Node<Data>, Data> & Exclude<(Parent<Node<Data>, Data> & Exclude<...>)["children"][number], void | ... 4 more ... | (Parent<...> & Exclude<...>)>)["children"][number], void | ... 5 more ... | (Parent<...> & Exclude<...>)>)["children"][number]

to this target

(Parent<Node<Data>, Data> & Exclude<(Parent<Node<Data>, Data> & Exclude<(Parent<Node<Data>, Data> & Exclude<...>)["children"][number], void | ... 4 more ... | (Parent<...> & Exclude<...>)>)["children"][number], void | ... 5 more ... | (Parent<...> & Exclude<...>)>)["children"][number]

originating (way up in the call stack at this call)

visit(tree, "element", function onElement(node, index, parent) {
      // noop
    })

After much preamble, we stack up an increasing number of frames here in isRelatedTo. I think tsc will eventually stack overflow but it'd probably take days:

                    const constraint = getEffectiveConstraintOfIntersection(source.flags & TypeFlags.Intersection ? (source as IntersectionType).types: [source], !!(target.flags & TypeFlags.Union));
                    if (constraint && (source.flags & TypeFlags.Intersection || target.flags & TypeFlags.Union)) {
                        if (everyType(constraint, c => c !== source)) { // Skip comparison if expansion contains the source itself
                            // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
                            if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
//     infinite recursion here           ^^^^^^^^^^^
                                resetErrorInfo(saveErrorInfo);
                            }
                        }
                    }

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 22, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.6.0 milestone Nov 22, 2021
@PabloSzx
Copy link

since this is a bug with 4.5 shouldn't this be targeted as a patch for 4.5?

@RyanCavanaugh
Copy link
Member

@PabloSzx depends on the fix. We can't backport every fix but if this is being commonly encountered we'll look into it

ntd added a commit to ntd/adg.entidi.com that referenced this issue Dec 14, 2021
ljcl added a commit to ljcl/website that referenced this issue Dec 17, 2021
ljcl added a commit to ljcl/website that referenced this issue Dec 17, 2021
@SilvaQ
Copy link

SilvaQ commented Dec 20, 2021

Excuse me, what is the current solution? I've looked at everything and I still can't find a solution.

I don't have a typescript project right now.
Pure JS projects do import {visit} from "unist-util-visit"; the CPU immediately overloads and vscode doesn't work properly

image

vscode issue

@cabljac
Copy link

cabljac commented Dec 20, 2021

In a similar situation to @SilvaQ here :/

Switched away from vscode and still hangs too

@SilvaQ
Copy link

SilvaQ commented Dec 22, 2021

Is there any progress? The whole business is on the verge of collapse, please tell me how to save this disaster!
@weswigham

@SilvaQ
Copy link

SilvaQ commented Dec 22, 2021

@cabljac

I think this could be a temporary solution。
The idea is to solve the problem by switching versions of typescript。
Modify the default typescript mode of vscode as shown in the documentation below:
using-the-workspace-version-of-typescript

steps:

  1. open vscode settings.json
  2. add typescript.tsdk filed
  3. specify the typescript path you want to use

I installed the specified version of the current project:

yarn add typescript@4.4.4

Modified the vscode configuration file:

       ... other fields here ....
"typescript.tsdk": "./node_modules/typescript/lib"

problem off for me now.

@cabljac
Copy link

cabljac commented Dec 22, 2021

@SilvaQ that seemed to work! Intellisense ain't working yet, but at least it isn't hanging. Thanks!!

@from-nibly
Copy link

from-nibly commented Jan 12, 2022

@SilvaQ This also worked for me. I'm not sure if I have the same dependency but I'm experiencing the same behavior with typescript version 4.5. It will just hang forever. Until I updated the tsdk property in my settings to be the local typescript in node_modules it would often never show linting errors or intellisense would lag indefinitely.

Question? Shouldn't using the local typescript version be the default? I would think that my editor should lint/etc with the version of typescript that matches the version I am using for compilation.

@NullVoxPopuli
Copy link

NullVoxPopuli commented Jan 13, 2022

I just ran in to this on my composite projects repo, https://github.com/NullVoxPopuli/ember-apply

I have no idea what it's getting stuck on though.

❯ yarn tsc --build --verbose 
yarn run v1.22.17
$ <repo>/node_modules/.bin/tsc --build --verbose
[12:19:27 AM] Projects in this build: 
    * packages/ember-apply/tsconfig.json
    * packages/ember/tailwind/tsconfig.json
    * tsconfig.json

[12:19:27 AM] Project 'packages/ember-apply/tsconfig.json' is out of date because oldest output 'packages/declarations/src/index.d.ts' is older than newest input 'packages/ember-apply/src/index.js'

[12:19:27 AM] Building project '<repo>/packages/ember-apply/tsconfig.json'...}

I'm using tsc to check JS, which I know (it seems) all of remark/rehype ecosystem projcets do as well 🙃

@theoludwig
Copy link

Friendly ping @weswigham & @RyanCavanaugh, as the TypeScript v4.6 is coming soon, and you recently released the beta release is there is any chance that this bug fix is included in v4.6. I can't upgrade (still on v4.4) because of this in one of my project.

Could we have some update on what is blocking for this, what are the issues and how can we help?

@lxcid
Copy link

lxcid commented Feb 5, 2022

Facing similar problem, bumping for visibility.

@erikdstock
Copy link

was banging my head against the wall with this one. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment