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

[experiment] services monomorphization + tsc using public API #58080

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 13 additions & 12 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,6 @@ function entrypointBuildTask(options) {
return { build, bundle, shim, main, watch };
}

const { main: tsc, watch: watchTsc } = entrypointBuildTask({
name: "tsc",
description: "Builds the command-line compiler",
buildDeps: [generateDiagnostics],
project: "src/tsc",
srcEntrypoint: "./src/tsc/tsc.ts",
builtEntrypoint: "./built/local/tsc/tsc.js",
output: "./built/local/tsc.js",
mainDeps: [generateLibs],
});
export { tsc, watchTsc };

const { main: services, build: buildServices, watch: watchServices } = entrypointBuildTask({
name: "services",
description: "Builds the typescript.js library",
Expand All @@ -408,6 +396,19 @@ const { main: services, build: buildServices, watch: watchServices } = entrypoin
});
export { services, watchServices };

const { main: tsc, watch: watchTsc } = entrypointBuildTask({
name: "tsc",
description: "Builds the command-line compiler",
buildDeps: [generateDiagnostics],
project: "src/tsc",
srcEntrypoint: "./src/tsc/tsc.ts",
builtEntrypoint: "./built/local/tsc/tsc.js",
output: "./built/local/tsc.js",
mainDeps: [generateLibs, services],
bundlerOptions: { usePublicAPI: true },
});
export { tsc, watchTsc };

export const dtsServices = task({
name: "dts-services",
description: "Bundles typescript.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from "../factory/nodeFactory";
export * from "../factory/emitNode";
export * from "../factory/emitHelpers";
export * from "../factory/nodeTests";
export * from "../factory/nodeChildren";
export * from "../factory/utilities";
export * from "../factory/utilitiesPublic";
export * from "../parser";
Expand Down
19 changes: 19 additions & 0 deletions src/compiler/factory/nodeChildren.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Node } from "../_namespaces/ts";

const nodeChildren = new WeakMap<Node, Node[] | undefined>();

/** @internal */
export function getNodeChildren(node: Node): Node[] | undefined {
return nodeChildren.get(node);
}

/** @internal */
export function setNodeChildren(node: Node, children: Node[]): Node[] {
nodeChildren.set(node, children);
return children;
}

/** @internal */
export function unsetNodeChildren(node: Node) {
nodeChildren.delete(node);
}
3 changes: 2 additions & 1 deletion src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ import {
setEmitFlags,
setIdentifierAutoGenerate,
setIdentifierTypeArguments,
setNodeChildren,
setParent,
setTextRange,
ShorthandPropertyAssignment,
Expand Down Expand Up @@ -6210,7 +6211,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
// @api
function createSyntaxList(children: Node[]) {
const node = createBaseNode<SyntaxList>(SyntaxKind.SyntaxList);
node._children = children;
setNodeChildren(node, children);
return node;
}

Expand Down
8 changes: 3 additions & 5 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ import {
unescapeLeadingUnderscores,
UnionOrIntersectionTypeNode,
UnionTypeNode,
unsetNodeChildren,
UpdateExpression,
VariableDeclaration,
VariableDeclarationList,
Expand Down Expand Up @@ -10002,9 +10003,7 @@ namespace IncrementalParser {

// Ditch any existing LS children we may have created. This way we can avoid
// moving them forward.
if (node._children) {
node._children = undefined;
}
unsetNodeChildren(node);

setTextRangePosEnd(node, node.pos + delta, node.end + delta);

Expand Down Expand Up @@ -10160,7 +10159,7 @@ namespace IncrementalParser {
const fullEnd = child.end;
if (fullEnd >= changeStart) {
child.intersectsChange = true;
child._children = undefined;
unsetNodeChildren(child);

// Adjust the pos or end (or both) of the intersecting element accordingly.
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
Expand Down Expand Up @@ -10349,7 +10348,6 @@ namespace IncrementalParser {

export interface IncrementalNode extends Node, IncrementalElement {
hasBeenIncrementallyParsed: boolean;
_children: Node[] | undefined;
}

interface IncrementalNodeArray extends NodeArray<IncrementalNode>, IncrementalElement {
Expand Down
1 change: 0 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9674,7 +9674,6 @@ export interface DiagnosticCollection {
// SyntaxKind.SyntaxList
export interface SyntaxList extends Node {
kind: SyntaxKind.SyntaxList;
_children: Node[];
}

// dprint-ignore
Expand Down
16 changes: 13 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ import {
getLineStarts,
getModeForUsageLocation,
getNameOfDeclaration,
getNodeChildren,
getNormalizedAbsolutePath,
getNormalizedPathComponents,
getOwnKeys,
Expand Down Expand Up @@ -511,7 +512,6 @@ import {
SymbolFlags,
SymbolTable,
SyntaxKind,
SyntaxList,
TaggedTemplateExpression,
TemplateExpression,
TemplateLiteral,
Expand Down Expand Up @@ -1162,8 +1162,11 @@ export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, inclu
// the syntax list itself considers them as normal trivia. Therefore if we simply skip
// trivia for the list, we may have skipped the JSDocComment as well. So we should process its
// first child to determine the actual position of its first token.
if (node.kind === SyntaxKind.SyntaxList && (node as SyntaxList)._children.length > 0) {
return getTokenPosOfNode((node as SyntaxList)._children[0], sourceFile, includeJsDoc);
if (node.kind === SyntaxKind.SyntaxList) {
const first = firstOrUndefined(getNodeChildren(node));
if (first) {
return getTokenPosOfNode(first, sourceFile, includeJsDoc);
}
}

return skipTrivia(
Expand Down Expand Up @@ -8155,6 +8158,7 @@ export interface ObjectAllocator {
}

function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
// Note: if modifying this, be sure to update SymbolObject in src/services/services.ts
this.flags = flags;
this.escapedName = name;
this.declarations = undefined;
Expand All @@ -8172,20 +8176,23 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
}

function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
// Note: if modifying this, be sure to update TypeObject in src/services/services.ts
this.flags = flags;
if (Debug.isDebugging || tracing) {
this.checker = checker;
}
}

function Signature(this: Signature, checker: TypeChecker, flags: SignatureFlags) {
// Note: if modifying this, be sure to update SignatureObject in src/services/services.ts
this.flags = flags;
if (Debug.isDebugging) {
this.checker = checker;
}
}

function Node(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
// Note: if modifying this, be sure to update NodeObject in src/services/services.ts
this.pos = pos;
this.end = end;
this.kind = kind;
Expand All @@ -8199,6 +8206,7 @@ function Node(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
}

function Token(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
// Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts
this.pos = pos;
this.end = end;
this.kind = kind;
Expand All @@ -8210,6 +8218,7 @@ function Token(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number)
}

function Identifier(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
// Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts
this.pos = pos;
this.end = end;
this.kind = kind;
Expand All @@ -8222,6 +8231,7 @@ function Identifier(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: num
}

function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) {
// Note: if modifying this, be sure to update SourceMapSourceObject in src/services/services.ts
this.fileName = fileName;
this.text = text;
this.skipTrivia = skipTrivia || (pos => pos);
Expand Down
7 changes: 6 additions & 1 deletion src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
validateLocaleAndSetLanguage,
version,
WatchCompilerHost,
WatchOfConfigFile,
WatchOptions,
} from "./_namespaces/ts";

Expand All @@ -94,6 +95,7 @@ interface Statistic {
type: StatisticType;
}

/** @internal */
export enum StatisticType {
time,
count,
Expand Down Expand Up @@ -730,6 +732,7 @@ function executeCommandLineWorker(
}
}

/** @internal */
export function isBuild(commandLineArgs: readonly string[]) {
if (commandLineArgs.length > 0 && commandLineArgs[0].charCodeAt(0) === CharacterCodes.minus) {
const firstOption = commandLineArgs[0].slice(commandLineArgs[0].charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
Expand All @@ -738,12 +741,14 @@ export function isBuild(commandLineArgs: readonly string[]) {
return false;
}

/** @internal */
export type ExecuteCommandLineCallbacks = (program: Program | BuilderProgram | ParsedCommandLine) => void;
/** @internal */
export function executeCommandLine(
system: System,
cb: ExecuteCommandLineCallbacks,
commandLineArgs: readonly string[],
) {
): void | SolutionBuilder<EmitAndSemanticDiagnosticsBuilderProgram> | WatchOfConfigFile<EmitAndSemanticDiagnosticsBuilderProgram> {
if (isBuild(commandLineArgs)) {
const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(commandLineArgs.slice(1));
if (buildOptions.generateCpuProfile && system.enableCPUProfiler) {
Expand Down
Loading