Skip to content

Commit 9cedbce

Browse files
paldepindCopilot
andcommitted
JavaScript: Remove TypeScript parser memory limits
Remove extractor-imposed Node heap limits and obsolete TypeScript RAM configuration. Stop interpreting CODEQL_RAM in the JavaScript autobuild launchers, and retain --typescript-ram as an ignored compatibility option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7f45b794-38b9-4abc-b652-03279c8dba77
1 parent 81a1deb commit 9cedbce

5 files changed

Lines changed: 3 additions & 77 deletions

File tree

‎javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ public Set<String> getPredefinedGlobals() {
224224
/** Should textual information be extracted into the lines/4 relation? */
225225
private boolean extractLines;
226226

227-
/** Override amount of RAM to allocate to the TypeScript compiler. */
228-
private int typescriptRam;
229-
230227
/** The default character encoding to use for parsing source files. */
231228
private String defaultEncoding;
232229

@@ -267,7 +264,6 @@ public ExtractorConfig(ExtractorConfig that) {
267264
this.sourceType = that.sourceType;
268265
this.htmlHandling = that.htmlHandling;
269266
this.extractLines = that.extractLines;
270-
this.typescriptRam = that.typescriptRam;
271267
this.defaultEncoding = that.defaultEncoding;
272268
this.virtualSourceRoot = that.virtualSourceRoot;
273269
}
@@ -426,16 +422,6 @@ public ExtractorConfig withExtractLines(boolean extractLines) {
426422
return res;
427423
}
428424

429-
public int getTypeScriptRam() {
430-
return typescriptRam;
431-
}
432-
433-
public ExtractorConfig withTypeScriptRam(int ram) {
434-
ExtractorConfig res = new ExtractorConfig(this);
435-
res.typescriptRam = ram;
436-
return res;
437-
}
438-
439425
public String getDefaultEncoding() {
440426
return defaultEncoding;
441427
}

‎javascript/extractor/src/com/semmle/js/extractor/Main.java‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.semmle.js.parser.ParsedProject;
2121
import com.semmle.ts.extractor.TypeScriptParser;
2222
import com.semmle.util.data.StringUtil;
23-
import com.semmle.util.data.UnitParser;
2423
import com.semmle.util.exception.ResourceError;
2524
import com.semmle.util.exception.UserError;
2625
import com.semmle.util.extraction.ExtractorOutputConfig;
@@ -60,9 +59,9 @@ public class Main {
6059
private static final String P_SOURCE_TYPE = "--source-type";
6160
private static final String P_TYPESCRIPT = "--typescript";
6261
private static final String P_TYPESCRIPT_FULL = "--typescript-full";
63-
private static final String P_TYPESCRIPT_RAM = "--typescript-ram";
6462

6563
// symbolic constants for deprecated command line parameter names
64+
private static final String P_TYPESCRIPT_RAM = "--typescript-ram";
6665
private static final String P_EXCLUDE_PATH = "--exclude-path";
6766
private static final String P_TOLERATE_PARSE_ERRORS = "--tolerate-parse-errors";
6867
private static final String P_NODEJS = "--nodejs";
@@ -130,7 +129,6 @@ public void run(String[] args) {
130129
}
131130

132131
TypeScriptParser tsParser = extractorState.getTypeScriptParser();
133-
tsParser.setTypescriptRam(extractorConfig.getTypeScriptRam());
134132
if (containsTypeScriptFiles()) {
135133
tsParser.verifyInstallation(!ap.has(P_QUIET));
136134
}
@@ -373,10 +371,7 @@ private ArgsParser addArgs(ArgsParser argsParser) {
373371
argsParser.addFlag(P_TYPESCRIPT, 0, "Enable basic TypesScript support.");
374372
argsParser.addFlag(
375373
P_TYPESCRIPT_FULL, 0, "Enable full TypeScript support with static type information.");
376-
argsParser.addFlag(
377-
P_TYPESCRIPT_RAM,
378-
1,
379-
"Amount of memory allocated to the TypeScript compiler process. The default is 1G.");
374+
argsParser.addToleratedFlag(P_TYPESCRIPT_RAM, 1);
380375
argsParser.addToleratedFlag(P_DEBUG_EXCLUSIONS, 0);
381376
argsParser.addTrailingParam("files", "Files and directories to extract.");
382377
return argsParser;
@@ -415,11 +410,7 @@ private ExtractorConfig parseJSOptions(ArgsParser ap) {
415410
ap.has(P_EXPERIMENTAL) ? HtmlPopulator.Config.ALL : HtmlPopulator.Config.ELEMENTS))
416411
.withFileType(getFileType(ap))
417412
.withSourceType(ap.getEnum(P_SOURCE_TYPE, SourceType.class, SourceType.AUTO))
418-
.withExtractLines(ap.has(P_EXTRACT_PROGRAM_TEXT))
419-
.withTypeScriptRam(
420-
ap.has(P_TYPESCRIPT_RAM)
421-
? UnitParser.parseOpt(ap.getString(P_TYPESCRIPT_RAM), UnitParser.MEGABYTES)
422-
: 0);
413+
.withExtractLines(ap.has(P_EXTRACT_PROGRAM_TEXT));
423414
if (ap.has(P_DEFAULT_ENCODING)) cfg = cfg.withDefaultEncoding(ap.getString(P_DEFAULT_ENCODING));
424415

425416
// Make a usable virtual source root mapping.

‎javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.semmle.js.parser.ParsedProject;
3737
import com.semmle.js.parser.JSParser.Result;
3838
import com.semmle.util.data.StringUtil;
39-
import com.semmle.util.data.UnitParser;
4039
import com.semmle.util.exception.CatastrophicError;
4140
import com.semmle.util.exception.Exceptions;
4241
import com.semmle.util.exception.InterruptedError;
@@ -96,24 +95,6 @@ public class TypeScriptParser {
9695
*/
9796
public static final String TYPESCRIPT_RETRIES_VAR = "SEMMLE_TYPESCRIPT_RETRIES";
9897

99-
/**
100-
* An environment variable (without the <code>SEMMLE_</code> or <code>LGTM_</code> prefix), that can be
101-
* set to indicate the maximum heap space usable by the Node.js process, in addition to its
102-
* "reserve memory".
103-
*
104-
* <p>Defaults to 2000 MB (for a total heap space of 2400 MB by default).
105-
*/
106-
public static final String TYPESCRIPT_RAM_SUFFIX = "TYPESCRIPT_RAM";
107-
108-
/**
109-
* An environment variable (without the <code>SEMMLE_</code> or <code>LGTM_</code> prefix), that can be
110-
* set to indicate the additional heap space added to <code>TYPESCRIPT_RAM</code> when setting the
111-
* Node.js heap limit.
112-
*
113-
* <p>Defaults to 400 MB (for a total heap space of 2400 MB by default).
114-
*/
115-
public static final String TYPESCRIPT_RAM_RESERVE_SUFFIX = "TYPESCRIPT_RAM_RESERVE";
116-
11798
/**
11899
* An environment variable with additional VM arguments to pass to the Node process.
119100
*
@@ -154,17 +135,9 @@ public class TypeScriptParser {
154135
*/
155136
private List<String> nodeJsRuntimeExtraArgs = Collections.emptyList();
156137

157-
/** If non-zero, we use this instead of relying on the corresponding environment variable. */
158-
private int typescriptRam = 0;
159-
160138
/** Metadata requested immediately after starting the TypeScript parser. */
161139
private TypeScriptParserMetadata metadata;
162140

163-
/** Sets the amount of RAM to allocate to the TypeScript compiler.s */
164-
public void setTypescriptRam(int megabytes) {
165-
this.typescriptRam = megabytes;
166-
}
167-
168141
/**
169142
* Verifies that Node.js and TypeScript are installed and throws an exception otherwise.
170143
*
@@ -274,14 +247,6 @@ private List<String> getNodeJsRuntimeInvocation(String... args) {
274247
private void setupParserWrapper() {
275248
verifyNodeInstallation();
276249

277-
int mainMemoryMb =
278-
typescriptRam != 0
279-
? typescriptRam
280-
: EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_SUFFIX, 2000);
281-
int reserveMemoryMb = EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_RESERVE_SUFFIX, 400);
282-
283-
System.out.println("Memory for TypeScript process: " + mainMemoryMb + " MB, and " + reserveMemoryMb + " MB reserve");
284-
285250
File parserWrapper = getParserWrapper();
286251

287252
String debugFlagString = Env.systemEnv().getNonEmpty(TYPESCRIPT_NODE_FLAGS);
@@ -297,7 +262,6 @@ private void setupParserWrapper() {
297262
}
298263

299264
List<String> cmd = getNodeJsRuntimeInvocation();
300-
cmd.add("--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb));
301265
cmd.addAll(debugFlags);
302266
cmd.add(parserWrapper.getAbsolutePath());
303267

‎javascript/resources/tools/autobuild.cmd‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ SETLOCAL EnableDelayedExpansion
33

44
set jvm_args=-Xss16m
55

6-
rem If CODEQL_RAM is set, use half for Java and half for TS.
7-
if NOT [%CODEQL_RAM%] == [] (
8-
set /a "half_ram=CODEQL_RAM/2"
9-
set LGTM_TYPESCRIPT_RAM=!half_ram!
10-
set jvm_args=!jvm_args! -Xmx!half_ram!m
11-
)
12-
136
rem If CODEQL_THREADS is set, propagate via LGTM_THREADS.
147
if NOT [%CODEQL_THREADS%] == [] (
158
set LGTM_THREADS=%CODEQL_THREADS%

‎javascript/resources/tools/autobuild.sh‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ set -eu
44

55
jvm_args=-Xss16m
66

7-
# If CODEQL_RAM is set, use half for Java and half for TS.
8-
if [ -n "${CODEQL_RAM:-}" ] ; then
9-
half_ram="$(( CODEQL_RAM / 2 ))"
10-
LGTM_TYPESCRIPT_RAM="$half_ram"
11-
export LGTM_TYPESCRIPT_RAM
12-
jvm_args="$jvm_args -Xmx${half_ram}m"
13-
fi
14-
157
# If CODEQL_THREADS is set, propagate via LGTM_THREADS.
168
if [ -n "${CODEQL_THREADS:-}" ] ; then
179
LGTM_THREADS="$CODEQL_THREADS"

0 commit comments

Comments
 (0)