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

Running type checker produces js out of memory error #59308

Closed
BKG01 opened this issue Jul 16, 2024 · 6 comments
Closed

Running type checker produces js out of memory error #59308

BKG01 opened this issue Jul 16, 2024 · 6 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@BKG01
Copy link

BKG01 commented Jul 16, 2024

πŸ”Ž Search Terms

out of memory
heap limit

πŸ•— Version & Regression Information

  • This is a crash
  • typescript version
npx tsc --version                                                                                                                                        
Version 5.5.3

⏯ Playground Link

No response

πŸ’» Code

Running type checker eg npx tsc

tsconfig

{
  "include": ["env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["remix.config.ts"],
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "target": "ES2022",
    "strict": true,
    "allowJs": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "skipLibCheck": true,
    "paths": {
      "~/*": ["./app/*"]
    },

    // Remix takes care of building everything in `remix build`.
    "noEmit": true
  }
}

πŸ™ Actual behavior

Out of memory error:


<--- Last few GCs --->

[15520:0x158008000]    58969 ms: Mark-sweep 4038.2 (4138.1) -> 4026.3 (4142.3) MB, 1964.9 / 0.0 ms  (average mu = 0.269, current mu = 0.015) allocation failure; scavenge might not succeed
[15520:0x158008000]    60669 ms: Mark-sweep 4042.3 (4142.3) -> 4032.1 (4147.8) MB, 1670.2 / 0.0 ms  (average mu = 0.156, current mu = 0.017) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x104fee598 node::Abort() [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 2: 0x104fee794 node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 3: 0x105142e70 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 4: 0x105142e20 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 5: 0x1052b85bc v8::internal::EmbedderStackStateScope::EmbedderStackStateScope(v8::internal::Heap*, v8::internal::EmbedderStackStateScope::Origin, cppgc::EmbedderStackState) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 6: 0x1052b7348 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 7: 0x1052aed00 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 8: 0x1052af4fc v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
 9: 0x105299ea8 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
10: 0x1055859e0 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
11: 0x10584510c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
12: 0x1057fc620 Builtins_CloneFastJSArray [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
13: 0x1058697c8 Builtins_ArrayPrototypeSlice [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
14: 0x10c5de948
15: 0x10cb1a3fc
16: 0x10cef0fb4
17: 0x10cba9f58
18: 0x10cbaa864
19: 0x10cbaa584
20: 0x10cbaa864
21: 0x10cee1c14
22: 0x10cbaa970
23: 0x10c76d780
24: 0x10cbe476c
25: 0x10cedcf08
26: 0x10c5e24a8
27: 0x10cbaa628
28: 0x10cbaa864
29: 0x10cbaa584
30: 0x10cbaa864
31: 0x10cee1c14
32: 0x10cbaa970
33: 0x10c76d780
34: 0x10cbe4518
35: 0x10cedcf08
36: 0x10c5e24a8
37: 0x10cbaa628
38: 0x10cbaa864
39: 0x10cbaa584
40: 0x10cbaa864
41: 0x10cee1c14
42: 0x10cbaa970
43: 0x10c76d780
44: 0x10cbe476c
45: 0x10cedcf08
46: 0x10c5e24a8
47: 0x10cbaa628
48: 0x10cbaa864
49: 0x10cbaa584
50: 0x10cbaa864
51: 0x10cee1c14
52: 0x10c9f45b4
53: 0x10c76d780
54: 0x10cbe4924
55: 0x10cedcf08
56: 0x10c5e24a8
57: 0x10c9f4f80
58: 0x10c9f47f8
59: 0x10c9f4eb8
60: 0x10cee1c14
61: 0x10cee9fb8
62: 0x10c5e24a8
63: 0x10c9f44d4
64: 0x10cee1c14
65: 0x10c9f45b4
66: 0x10cee1c14
67: 0x10cee9fb8
68: 0x10c5e24a8
69: 0x10c9f44d4
70: 0x10cee1c14
71: 0x10d131e24
72: 0x10cd91310
73: 0x10ce30fe8
74: 0x10ce39668
75: 0x10d12a854
76: 0x10c99ae98
77: 0x10c9b13e8
78: 0x10d108e48
79: 0x10c8eea58
80: 0x10d10ccd0
81: 0x10c909844
82: 0x10c8ee8a4
83: 0x10cba5e18
84: 0x10cb68488
85: 0x10c8eead8
86: 0x10cba5e18
87: 0x10c9570fc
88: 0x10cae3eb0
89: 0x10cd1e5f0
90: 0x10cd1cb10
91: 0x10c8eeb58
92: 0x10cba5e18
93: 0x10ce31090
94: 0x10ce396a4
95: 0x10d12a854
96: 0x10c99ae98
97: 0x10c9b13e8
98: 0x10d108e48
99: 0x10c8eea58
100: 0x10ce11d54
101: 0x10c8ee8e8
102: 0x10cba5e18
103: 0x10ccabef0
104: 0x10ccac294
105: 0x10c9ea834
106: 0x10cd9b604
107: 0x10cbb3944
108: 0x10cb0cd24
109: 0x10cbd8e2c
110: 0x10ca6a6a4
111: 0x10cb9d794
112: 0x10d118b44
113: 0x10cb79a38
114: 0x10c99c370
115: 0x10c991464
116: 0x10cb9d4fc
117: 0x10d118b44
118: 0x10cb79a38
119: 0x10c998514
120: 0x10d1234d8
121: 0x10cb9d730
122: 0x10d118b44
123: 0x10cb79a38
124: 0x10c99845c
125: 0x10cb9d89c
126: 0x10d118b44
127: 0x10c75070c
128: 0x10c44ced8
129: 0x10cbb5a80
130: 0x10c44d0e0
131: 0x10cb9d7c4
132: 0x10d118b44
133: 0x10cb79b5c
134: 0x10cb6a1a8
135: 0x10ceee5cc
136: 0x10cc926b0
137: 0x10d074ba0
138: 0x10cb68a34
139: 0x10c84f288
140: 0x10c85063c
141: 0x10c84f664
142: 0x10c84fd5c
143: 0x10c84f7c0
144: 0x10c84fa5c
145: 0x10c717a80
146: 0x10c45ea7c
147: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
148: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
149: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
150: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
151: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
152: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
153: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
154: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
155: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
156: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
157: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
158: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
159: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
160: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
161: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
162: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
163: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
164: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
165: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
166: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
167: 0x1057d0198 Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
168: 0x1057ce4d0 Builtins_JSEntryTrampoline [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
169: 0x1057ce164 Builtins_JSEntry [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
170: 0x10524fe60 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
171: 0x10524f558 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
172: 0x105157074 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
173: 0x104fd33a0 node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, node::Realm*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
174: 0x105061a88 node::Realm::ExecuteBootstrapper(char const*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
175: 0x104fb9604 node::StartExecution(node::Environment*, char const*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
176: 0x104fb95b4 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
177: 0x104f4400c node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
178: 0x105028dc4 node::NodeMainInstance::Run(int*, node::Environment*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
179: 0x105028b04 node::NodeMainInstance::Run() [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
180: 0x104fbbe58 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
181: 0x104fbc024 node::Start(int, char**) [/opt/homebrew/Cellar/node@18/18.20.3/bin/node]
182: 0x18f0260e0 start [/usr/lib/dyld]
fish: Job 1, 'npx tsc' terminated by signal SIGABRT (Abort)

πŸ™‚ Expected behavior

Type checker to run as expected

Additional information about the issue

Searched other issues and initially this looked similar, but out of date (version with fix is older) and details of error are not the same...
#56428

@jeremiewtd
Copy link

We face the same issue here.
It seems that the problems appear after v5.5.0-beta which worked fine, it starts crashing from v5.5.1-rc with this error :
RangeError: Maximum call stack size exceeded at getEffectiveTypeAnnotationNode

@RyanCavanaugh
Copy link
Member

We really need a codebase that reproduces the problem in order to investigate, unfortunately. Is anyone able to provide one?

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jul 17, 2024
@jeremiewtd
Copy link

You can use this codebase to reproduce the issue.

@BKG01
Copy link
Author

BKG01 commented Jul 23, 2024

I think there were two issues posted in this PR... as part of creating a repo to aid the Typescript team the issue was found to be an edgedb issue breaking the type checker... by having the wrong operand....

export async function checkDuplicateEmailParent(email: string) {
  try {
    // Query the Parent table to find a user with the given email
    const user = await e
      .select(e.User, (user) => ({
        email: true,
        filter_single: e.op(user.email, "ilike", email),
      }))
      .run(client)

    // Check if the user with the given email exists
    return !!user // Return true if user exists, otherwise false
  } catch (error) {
    console.error("Error checking for duplicate email:", error)
    throw error
  }
}

.. ilike should have been =

I'll raise an issue with the edgedb team.

closing as the original issue has been addressed. Feel free to reopen or create a new issue for the separate issue also posted in here.

@BKG01 BKG01 closed this as completed Jul 23, 2024
@jeremiewtd
Copy link

closing as the original issue has been addressed.

What do you mean by has been addressed ? Issue is solved ?

@scotttrinh
Copy link

@RyanCavanaugh

We really need a codebase that reproduces the problem in order to investigate, unfortunately. Is anyone able to provide one?

I'll try to get something minimal together for this


EdgeDB JS maintainer here with some context:

FWIW, the structure of this type is a single function with ~350 overloads where ilike is the second argument to a function, and this particular overload is the last overload that matches the first argument. This is an implementation of a type-safe "operator" function that defines explicit combinations of operands to operators with dependent return type based on operands.

Imagine something like this, but for 30 operators where some operators like = are defined for ~20 different operand combinations:

   function op<Opr1 extends TypeSet<$String>, Opr2 extends TypeSet<$String>>(
     opr1: Opr1,
     op: "=",
     opr2: Opr2
   ): TypeSet<$Boolean, cardUtils.multiplyCardinalities<Opr1, Opr2>>;
   function op<Opr1 extends TypeSet<$Number>, Opr2 extends TypeSet<$Number>>(
     opr1: Opr1,
     op: "=",
     opr2: Opr2
   ): TypeSet<$Boolean, cardUtils.multiplyCardinalities<Opr1, Opr2>>;
   function op<Opr1 extends TypeSet<$Boolean>, Opr2 extends TypeSet<$Boolean>>(
     opr1: Opr1,
     op: "=",
     opr2: Opr2
   ): TypeSet<$Boolean, cardUtils.multiplyCardinalities<Opr1, Opr2>>;

This worked poorly in TypeScript < 5.2, but it worked. After #54815, we started to get to a point where it was pretty easy to hit OOM or "too complex to represent" errors.

I've spent a lot of time refactoring this "simple" overload-per-operator-definition into something a little closer to constant-time for the inference engine, but in the end, the inference performance has gotten worse for some other operators as a result. A longer-term solution that we're exploring is to have separate functions (still with one overload per operator definition) for each operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

4 participants