Skip to content

Takes a while with high memory to calculate highly recursive types with intersections #20558

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

Open
dead-claudia opened this issue Dec 8, 2017 · 3 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@dead-claudia
Copy link

TypeScript Version: 2.6.2

Code

Apologies for the length - I can't really make the repro any smaller than this without it taking a fraction of the time and about half the memory. Also, note: this does not require a config.

interface Context<P, O> {
    createV(this: this & Context<P, O & {raw: true}>, attrs: P): Context<P, O>;
    createRC(this: this & Context<P, O & {raw: true}>, attrs: P, ref: (elem: P) => any): Context<P, O>;

    simpleV(this: this & Context<P, O & {raw: true}>, attrs: P): void;
    simpleRC(this: this & Context<P, O & {raw: true}>, attrs: P, ref: (elem: P) => any): void;

    add(this: this & Context<P, O & {text: true}>): void;
    raw(this: this & Context<P, O & {raw: true}>, elem: P): void;

    invokeC<C>(
        tag: Component<object, P, O>,
        children: (r: Context<P, O>, context: C) => void,
        context: C
    ): void;
    invokeAC<A extends object, C>(
        tag: Component<A, P, O>, attrs: A,
        children: (r: Context<P, O>, context: C) => void,
        context: C
    ): void;
}

interface TopContext<P, O> extends Context<P, O> {
    hasOption<K extends keyof O>(key: K): this is (this & TopContext<P, {[P in K]: O[P]}>);
}

type Component<A extends object, P, O> = <C>(
    attrs: A, r: TopContext<P, O>,
    children: (r: Context<P, O>, context: C) => void,
    context: C
) => void

interface ContextWrap<P, O> {
    instance: Context<P, O>;
}

interface TopContextWrap<P, O> extends ContextWrap<P, O> {
    instance: TopContext<P, O>;
}

Expected behavior: It to take maybe a few seconds. Remove any one function or property out of that, and that's the compilation time I would normally expect.

Actual behavior: It takes ~15-20 seconds to check, and requires ~180-200 MB of memory in the process.

@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 2, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Feb 2, 2018

this is what i am seeing on latest in master:

RangeError: Maximum call stack size exceeded
    at getAnonymousTypeInstantiation (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:1:1)
    at instantiateType (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26419:32)
    at C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26261:42
    at Object.map (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:477:29)
    at getAnonymousTypeInstantiation (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26344:40)
    at instantiateType (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26419:32)
    at C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26261:42
    at Object.map (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:477:29)
    at getAnonymousTypeInstantiation (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26344:40)
    at instantiateType (C:\Users\mhegazy\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:26419:32)

@mhegazy mhegazy added this to the TypeScript 2.8 milestone Feb 2, 2018
@dead-claudia
Copy link
Author

@mhegazy That's odd. I ran it on Mac, which from a quick Google search, has a higher default stack space limit, though - 8MB instead of 1MB. (In the release when I tested it, it did manage to eventually succeed.)

Note that the above example should validate as successful.

@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 3.0, Future Jul 2, 2018
@sandersn sandersn removed their assignment Jan 7, 2020
@jakebailey
Copy link
Member

This old issue was fixed by the surprisingly new #52392; likely this deserves a test, if anything; its compile perf is not that bad post-fix (.7s on my machine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants