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

Validation Performance: File level providedSymbols and requiredSymbols #944

Merged
merged 17 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Lightning
markwpearce committed Nov 15, 2023
commit a4c84677f3f7358b4155a7fd0e2db8b0323929ca
40 changes: 20 additions & 20 deletions benchmarks/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 12 additions & 34 deletions src/AstValidationSegmenter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { DottedGetExpression, TypeExpression, VariableExpression } from './parser/Expression';
import { SymbolTypeFlag } from './SymbolTable';
import { UnresolvedNodeSet } from './UnresolvedNodeSet';
import { isBody, isClassStatement, isCommentStatement, isInterfaceStatement, isNamespaceStatement, isVariableExpression } from './astUtils/reflection';
import { ChildrenSkipper, WalkMode, createVisitor } from './astUtils/visitors';
import type { ExtraSymbolData, GetTypeOptions, TypeChainEntry } from './interfaces';
import type { GetTypeOptions, TypeChainEntry } from './interfaces';
import type { AstNode } from './parser/AstNode';
import { util } from './util';
import type { NamespaceStatement } from '.';
@@ -14,21 +13,19 @@ export const InsideSegmentWalkMode = WalkMode.visitStatements | WalkMode.visitEx
export interface UnresolvedSymbol {
typeChain: TypeChainEntry[];
flags: SymbolTypeFlag;
endChainFlags: SymbolTypeFlag;
containingNamespaces: string[];
}

export class AstValidationSegmenter {

public unresolvedSegments = new Map<AstNode, UnresolvedNodeSet>();
public validatedSegments = new Map<AstNode, boolean>();
public segmentsForValidation = new Array<AstNode>();
public singleValidationSegments = new Set<AstNode>();
public unresolvedSegmentsSymbols = new Map<AstNode, Set<UnresolvedSymbol>>();
public ast: AstNode;


reset() {
this.unresolvedSegments.clear();
this.validatedSegments.clear();
this.singleValidationSegments.clear();
this.unresolvedSegmentsSymbols.clear();
@@ -59,15 +56,7 @@ export class AstValidationSegmenter {

const nodeType = expression.getType(options);
if (!nodeType.isResolvable()) {
let nodeSet: UnresolvedNodeSet;
let symbolsSet: Set<UnresolvedSymbol>;
if (!this.unresolvedSegments.has(segment)) {
nodeSet = new UnresolvedNodeSet(segment);
this.unresolvedSegments.set(segment, nodeSet);
} else {
nodeSet = this.unresolvedSegments.get(segment);
}
nodeSet.addExpression(expression, options);
if (!assignedSymbols?.has(typeChain[0].name.toLowerCase())) {
if (!this.unresolvedSegmentsSymbols.has(segment)) {
symbolsSet = new Set<UnresolvedSymbol>();
@@ -76,7 +65,7 @@ export class AstValidationSegmenter {
symbolsSet = this.unresolvedSegmentsSymbols.get(segment);
}

symbolsSet.add({ typeChain: typeChain, flags: flag, containingNamespaces: this.currentNamespaceStatement?.getNameParts()?.map(t => t.text) });
symbolsSet.add({ typeChain: typeChain, flags: typeChain[0].flags, endChainFlags: flag, containingNamespaces: this.currentNamespaceStatement?.getNameParts()?.map(t => t.text) });
}
return true;
}
@@ -142,9 +131,6 @@ export class AstValidationSegmenter {
const expressionIsUnresolved = this.checkExpressionForUnresolved(segment, expr, assignedSymbols);
foundUnresolvedInSegment = expressionIsUnresolved || foundUnresolvedInSegment;
skipper.skip();
},
InterfaceFieldStatement: (stmt) => {
console.log(stmt);
}
}), {
walkMode: InsideSegmentWalkMode,
@@ -156,31 +142,23 @@ export class AstValidationSegmenter {
}


getSegments(): AstNode[] {
getSegments(changedSymbols: Map<SymbolTypeFlag, Set<string>>): AstNode[] {
const segmentsToWalkForValidation: AstNode[] = [];
for (const segment of this.segmentsForValidation) {
const unresolvedNodeSet = this.unresolvedSegments.get(segment);
const symbolsRequired = this.unresolvedSegmentsSymbols.get(segment);

const isSingleValidationSegment = this.singleValidationSegments.has(segment);
const singleValidationSegmentAlreadyValidated = isSingleValidationSegment ? this.validatedSegments.get(segment) : false;
let segmentNeedsRevalidation = !singleValidationSegmentAlreadyValidated;
if (unresolvedNodeSet) {
for (let node of unresolvedNodeSet.nodes) {
const data: ExtraSymbolData = {};
const options: GetTypeOptions = { flags: util.isInTypeExpression(node) ? SymbolTypeFlag.typetime : SymbolTypeFlag.runtime, data: data };
const type = node.getType(options);
if (!type || !type.isResolvable()) {
// the type that we're checking here is not found - force validation
segmentNeedsRevalidation = true;

if (symbolsRequired) {
for (const requiredSymbol of symbolsRequired.values()) {
const changeSymbolSetForFlag = changedSymbols.get(requiredSymbol.flags);
if (util.setContainsUnresolvedSymbol(changeSymbolSetForFlag, requiredSymbol)) {
segmentsToWalkForValidation.push(segment);
break;
} else {
const newTypeToCheck = unresolvedNodeSet.addTypeForExpression(node, options, type);
segmentNeedsRevalidation = segmentNeedsRevalidation || newTypeToCheck;
}
}
if (segmentNeedsRevalidation) {
segmentsToWalkForValidation.push(segment);
continue;
}
} else if (segmentNeedsRevalidation) {
segmentsToWalkForValidation.push(segment);
}
5 changes: 5 additions & 0 deletions src/DiagnosticMessages.ts
Original file line number Diff line number Diff line change
@@ -753,6 +753,11 @@ export let DiagnosticMessages = {
message: `Operator '${operatorString}' cannot be applied to type${secondType ? 's' : ''} '${firstType}'${secondType ? ` and '${secondType}'` : ''}`,
code: 1144,
severity: DiagnosticSeverity.Error
}),
incompatibleSymbolDefinition: (symbol: string, scopeName: string) => ({
message: `'${symbol}' is incompatible across scope group (${scopeName})`, // TODO: Add scopes where it was defined
code: 1145,
severity: DiagnosticSeverity.Error
})
};
export const defaultMaximumTruncationLength = 160;
Loading