Skip to content

Commit edef69d

Browse files
committed
Remove redundant alias handling in JS compiler. NFC.
This change removes the redudant handling of aliases, leaving the simpler and more effecient one in place. The alternative PR is #17419. With this method the final output contains: var foo = target; Rather than: function foo(arg1, arg2) { return target(arg1, arg1); }
1 parent fb8375f commit edef69d

File tree

2 files changed

+6
-72
lines changed

2 files changed

+6
-72
lines changed

src/jsifier.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ function ${name}(${args}) {
349349
}
350350
}
351351

352-
if (redirectedIdent) {
353-
deps = deps.concat(LibraryManager.library[redirectedIdent + '__deps'] || []);
354-
}
355352
if (VERBOSE) {
356353
printErr(`adding ${finalName} and deps ${deps} : ` + (snippet + '').substr(0, 40));
357354
}

src/modules.js

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -237,75 +237,12 @@ global.LibraryManager = {
237237
}
238238
}
239239

240-
// apply synonyms. these are typically not speed-sensitive, and doing it
241-
// this way makes it possible to not include hacks in the compiler
242-
// (and makes it simpler to switch between SDL versions, fastcomp and non-fastcomp, etc.).
243-
const lib = this.library;
244-
libloop: for (const x in lib) {
245-
if (!Object.prototype.hasOwnProperty.call(lib, x)) {
246-
continue;
247-
}
248-
if (isJsLibraryConfigIdentifier(x)) {
249-
const index = x.lastIndexOf('__');
250-
const basename = x.slice(0, index);
251-
if (!(basename in lib)) {
252-
error(`Missing library element '${basename}' for library config '${x}'`);
253-
}
254-
continue;
255-
}
256-
if (typeof lib[x] == 'string') {
257-
let target = x;
258-
while (typeof lib[target] == 'string') {
259-
// ignore code and variable assignments, aliases are just simple names
260-
if (lib[target].search(/[=({; ]/) >= 0) continue libloop;
261-
target = lib[target];
262-
}
263-
if (!isNaN(target)) continue; // This is a number, and so cannot be an alias target.
264-
if (typeof lib[target] == 'undefined' || typeof lib[target] == 'function') {
265-
// When functions are aliased, a signature for the function must be
266-
// provided so that an efficient form of forwarding can be
267-
// implemented.
268-
function testStringType(sig) {
269-
if (typeof lib[sig] != 'undefined' && typeof typeof lib[sig] != 'string') {
270-
error(`${sig} should be a string! (was ${typeof lib[sig]})`);
271-
}
272-
}
273-
const aliasSig = x + '__sig';
274-
const targetSig = target + '__sig';
275-
testStringType(aliasSig);
276-
testStringType(targetSig);
277-
if (typeof lib[aliasSig] == 'string' && typeof lib[targetSig] == 'string' && lib[aliasSig] != lib[targetSig]) {
278-
error(`${aliasSig} (${lib[aliasSig]}) differs from ${targetSig} (${lib[targetSig]})`);
279-
}
280-
281-
const sig = lib[aliasSig] || lib[targetSig];
282-
if (typeof sig != 'string') {
283-
error(`Function ${x} aliases to target function ${target}, but neither the alias or the target provide a signature. Please add a ${targetSig}: 'vifj...' annotation or a ${aliasSig}: 'vifj...' annotation to describe the type of function forwarding that is needed!`);
284-
}
285-
286-
// If only one of the target or the alias specifies a sig then copy
287-
// this signature to the other.
288-
if (!lib[aliasSig]) {
289-
lib[aliasSig] = lib[targetSig];
290-
} else if (!lib[targetSig]) {
291-
lib[targetSig] = lib[aliasSig];
292-
}
293-
294-
if (typeof lib[target] != 'function') {
295-
error(`no alias found for ${x}`);
296-
}
297-
298-
const argCount = sig.length - 1;
299-
if (argCount !== lib[target].length) {
300-
error(`incorrect number of arguments in signature of ${x} (declared: ${argCount}, expected: ${lib[target].length})`);
301-
}
302-
const ret = sig == 'v' ? '' : 'return ';
303-
const args = genArgSequence(argCount).join(',');
304-
const mangledName = mangleCSymbolName(target);
305-
lib[x] = new Function(args, `${ret}${mangledName}(${args});`);
306-
307-
if (!lib[x + '__deps']) lib[x + '__deps'] = [];
308-
lib[x + '__deps'].push(target);
240+
for (const ident in this.library) {
241+
if (isJsLibraryConfigIdentifier(ident)) {
242+
const index = ident.lastIndexOf('__');
243+
const basename = ident.slice(0, index);
244+
if (!(basename in this.library)) {
245+
error(`Missing library element '${basename}' for library config '${ident}'`);
309246
}
310247
}
311248
}

0 commit comments

Comments
 (0)