Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c47e0a1
Add performance hooks
GlassBricks Jul 13, 2022
665dec2
Ignore v8 profile logs
GlassBricks Jul 14, 2022
fa24f0c
Optimize TransformationContext
GlassBricks Jul 14, 2022
450b22b
Remove WeakMap<TransformationContext, ...>
GlassBricks Jul 15, 2022
7528726
Change language extension declaration method
GlassBricks Jul 15, 2022
953ecc4
Significantly improve performance of language extensions
GlassBricks Jul 15, 2022
200851d
Separate iterable language extensions
GlassBricks Jul 15, 2022
4b3eeab
Unify language extension call transformers
GlassBricks Jul 15, 2022
82d1f11
Fix getExtensionsKindForType and error reporting for TableNew type
GlassBricks Jul 15, 2022
a506a68
Merge lua-set additions
GlassBricks Jul 15, 2022
e8bc49a
Cache function context
GlassBricks Jul 15, 2022
d45644d
Fix crash on incorrect language extension use
GlassBricks Jul 15, 2022
03d58c0
Optimize and cleanup builtins
GlassBricks Jul 15, 2022
cabedc4
Optimize and cleanup annotations
GlassBricks Jul 15, 2022
3b9d607
Remove deprecated annotations
GlassBricks Jul 15, 2022
f427976
Optimize assignment-validation
GlassBricks Jul 16, 2022
3796067
Optimize language extensions again
GlassBricks Jul 16, 2022
9702525
Optimize getEmitPlan
GlassBricks Jul 16, 2022
3017f04
Flatten visitor map
GlassBricks Jul 16, 2022
c3c3279
Ignore v8 cpu profiles
GlassBricks Jul 16, 2022
b289a30
Fix prettier
GlassBricks Jul 16, 2022
34cea8b
PR feedback
GlassBricks Jul 16, 2022
b8fe76e
Optimize isExplicitArrayType
GlassBricks Jul 16, 2022
a8f7aff
PR feedback
GlassBricks Jul 17, 2022
3e453ab
Revert changes to createReturnStatement
GlassBricks Jul 17, 2022
c01a6da
PR feedback
GlassBricks Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ yarn.lock

benchmark/data/*
benchmark/dist/*

# v8 cpu profiles
*-.log
*.cpuprofile
146 changes: 72 additions & 74 deletions language-extensions/index.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/CompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface TypeScriptToLuaOptions {
sourceMapTraceback?: boolean;
tstlVerbose?: boolean;
lua51AllowTryCatchInAsyncAwait?: boolean;
measurePerformance?: boolean;
}

export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> &
Expand Down
5 changes: 5 additions & 0 deletions src/cli/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export const optionDeclarations: CommandLineOption[] = [
description: "Always allow try/catch in async/await functions for Lua 5.1.",
type: "boolean",
},
{
name: "measurePerformance",
description: "Measure performance of the tstl compiler.",
type: "boolean",
},
];

export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine): ParsedCommandLine {
Expand Down
3 changes: 1 addition & 2 deletions src/lualib-build/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SourceNode } from "source-map";
import * as ts from "typescript";
import * as tstl from "..";
import * as path from "path";
import { getUsedLuaLibFeatures } from "../transformation/utils/lualib";
import { LuaLibFeature, LuaLibModulesInfo, luaLibModulesInfoFileName, resolveRecursiveLualibFeatures } from "../LuaLib";
import { EmitHost, ProcessedFile } from "../transpilation/utils";
import {
Expand Down Expand Up @@ -72,7 +71,7 @@ class LuaLibPlugin implements tstl.Plugin {
// Transpile file as normal with tstl
const fileResult = context.superTransformNode(file)[0] as tstl.File;

const usedFeatures = new Set<tstl.LuaLibFeature>(getUsedLuaLibFeatures(context));
const usedFeatures = new Set<tstl.LuaLibFeature>(context.usedLuaLibFeatures);

// Get all imports in file
const importNames = new Set<string>();
Expand Down
83 changes: 83 additions & 0 deletions src/measure-performance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { performance } from "perf_hooks";

// We use our own performance hooks implementation for easier use, but also call node's performance hooks, so it shows up in the profiler.

let enabled = false;
const marks = new Map<string, number>();
const durations = new Map<string, number>();

function timestamp() {
return performance.now();
}

/**
* Marks a performance event, with the given markName.
*/
function mark(markName: string) {
if (enabled) {
marks.set(markName, timestamp());
performance.mark(markName);
}
}

/**
* Adds a performance measurement with the specified name.
*
* @param measureName The name of the performance measurement.
* @param startMarkName The name of the starting mark
* @param endMarkName The name of the ending mark
*/
function measure(measureName: string, startMarkName: string, endMarkName: string) {
if (enabled) {
const end = marks.get(endMarkName) ?? timestamp();
const start = marks.get(startMarkName) ?? performance.timeOrigin;
const previousDuration = durations.get(measureName) ?? 0;
durations.set(measureName, previousDuration + (end - start));
performance.measure(measureName, startMarkName, endMarkName);
}
}

/**
* Starts a performance measurement section.
* @param name name of the measurement
*/
export function startSection(name: string) {
mark("start " + name);
}

/**
* Ends a performance measurement section.
* @param name name of the measurement
*/
export function endSection(name: string) {
mark("end " + name);
measure(name, "start " + name, "end " + name);
}

export function isMeasurementEnabled() {
return enabled;
}

export function enableMeasurement() {
if (!enabled) {
enabled = true;
}
}

export function disableMeasurement() {
if (enabled) {
enabled = false;
marks.clear();
durations.clear();
}
}

export function forEachMeasure(callback: (measureName: string, duration: number) => void) {
durations.forEach((duration, measureName) => callback(measureName, duration));
}

export function getTotalDuration() {
let total = 0;
forEachMeasure((_, duration) => (total += duration));
return total;
}
7 changes: 5 additions & 2 deletions src/transformation/builtins/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TransformationContext } from "../context";
import { unsupportedProperty } from "../utils/diagnostics";
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
import { transformArguments, transformCallAndArguments } from "../visitors/call";
import { isStringType, isNumberType, findFirstNonOuterParent } from "../utils/typescript";
import { findFirstNonOuterParent, typeAlwaysHasSomeOfFlags } from "../utils/typescript";
import { moveToPrecedingTemp } from "../visitors/expression-list";
import { isUnpackCall, wrapInTable } from "../utils/lua-ast";

Expand Down Expand Up @@ -145,7 +145,10 @@ export function transformArrayPrototypeCall(
case "join":
const callerType = context.checker.getTypeAtLocation(calledMethod.expression);
const elementType = context.checker.getElementTypeOfArrayType(callerType);
if (elementType && (isStringType(context, elementType) || isNumberType(context, elementType))) {
if (
elementType &&
typeAlwaysHasSomeOfFlags(context, elementType, ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)
) {
const defaultSeparatorLiteral = lua.createStringLiteral(",");
const param = params[0];
const parameters = [
Expand Down
25 changes: 14 additions & 11 deletions src/transformation/builtins/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
import { isNumberType } from "../utils/typescript";
import { transformArguments } from "../visitors/call";

export function transformGlobalCall(
export function tryTransformBuiltinGlobalCall(
context: TransformationContext,
node: ts.CallExpression
node: ts.CallExpression,
expressionType: ts.Type
): lua.Expression | undefined {
const signature = context.checker.getResolvedSignature(node);
const parameters = transformArguments(context, node.arguments, signature);
const expressionType = context.checker.getTypeAtLocation(node.expression);
function getParameters() {
const signature = context.checker.getResolvedSignature(node);
return transformArguments(context, node.arguments, signature);
}

const name = expressionType.symbol.name;
switch (name) {
case "SymbolConstructor":
return transformLuaLibFunction(context, LuaLibFeature.Symbol, node, ...parameters);
return transformLuaLibFunction(context, LuaLibFeature.Symbol, node, ...getParameters());
case "NumberConstructor":
return transformLuaLibFunction(context, LuaLibFeature.Number, node, ...parameters);
return transformLuaLibFunction(context, LuaLibFeature.Number, node, ...getParameters());
case "isNaN":
case "isFinite":
const numberParameters = isNumberType(context, expressionType)
? parameters
: [transformLuaLibFunction(context, LuaLibFeature.Number, undefined, ...parameters)];
? getParameters()
: [transformLuaLibFunction(context, LuaLibFeature.Number, undefined, ...getParameters())];

return transformLuaLibFunction(
context,
Expand All @@ -31,8 +34,8 @@ export function transformGlobalCall(
...numberParameters
);
case "parseFloat":
return transformLuaLibFunction(context, LuaLibFeature.ParseFloat, node, ...parameters);
return transformLuaLibFunction(context, LuaLibFeature.ParseFloat, node, ...getParameters());
case "parseInt":
return transformLuaLibFunction(context, LuaLibFeature.ParseInt, node, ...parameters);
return transformLuaLibFunction(context, LuaLibFeature.ParseInt, node, ...getParameters());
}
}
Loading