From 4b2a80d3154c0427075d30a5364b0899cbc4a5a2 Mon Sep 17 00:00:00 2001 From: verytactical <186486509+verytactical@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:44:16 +0400 Subject: [PATCH] refactor: move `errors.ts` (#1316) --- src/abi/global.ts | 2 +- src/abi/map.ts | 2 +- src/abi/struct.ts | 2 +- src/bindings/typescript/serializers.ts | 2 +- src/bindings/typescript/writeStruct.ts | 2 +- src/bindings/writeTypescript.ts | 2 +- src/constEval.ts | 2 +- src/error/display-to-json.ts | 2 +- src/error/display-to-string.ts | 2 +- src/{ => error}/errors.ts | 4 ++-- src/generator/writers/writeExpression.ts | 2 +- src/generator/writers/writeFunction.ts | 2 +- src/generator/writers/writeSerialization.ts | 2 +- src/grammar/ast.ts | 2 +- src/grammar/clone.ts | 2 +- src/grammar/compare.ts | 2 +- src/grammar/hash.ts | 2 +- src/grammar/next/index.ts | 5 ++++- src/grammar/prev/grammar.ts | 2 +- src/grammar/prev/parser-error.ts | 2 +- src/grammar/sort.ts | 2 +- src/grammar/src-info.ts | 2 +- src/grammar/store.ts | 2 +- src/imports/resolveImports.ts | 2 +- src/index.ts | 2 +- src/interpreter.ts | 2 +- src/main.ts | 2 +- src/node.ts | 2 +- src/optimizer/test/partial-eval.spec.ts | 2 +- src/pipeline/build.ts | 2 +- src/storage/allocator.ts | 2 +- src/storage/resolveAllocation.ts | 2 +- src/types/resolveABITypeRef.ts | 2 +- src/types/resolveDescriptors.ts | 2 +- src/types/resolveErrors.ts | 2 +- src/types/resolveExpression.ts | 4 ++-- src/types/resolveSignatures.ts | 4 ++-- src/types/resolveStatements.ts | 2 +- src/types/types.ts | 2 +- src/utils/tricks.ts | 2 +- src/utils/utils.ts | 2 +- 41 files changed, 47 insertions(+), 44 deletions(-) rename src/{ => error}/errors.ts (96%) diff --git a/src/abi/global.ts b/src/abi/global.ts index 4bd5ff988..7691c326a 100644 --- a/src/abi/global.ts +++ b/src/abi/global.ts @@ -7,7 +7,7 @@ import { writeString, } from "../generator/writers/writeConstant"; import { writeExpression } from "../generator/writers/writeExpression"; -import { throwCompilationError } from "../errors"; +import { throwCompilationError } from "../error/errors"; import { getErrorId } from "../types/resolveErrors"; import { AbiFunction } from "./AbiFunction"; import { sha256_sync } from "@ton/crypto"; diff --git a/src/abi/map.ts b/src/abi/map.ts index d2c52c783..f17d5cb90 100644 --- a/src/abi/map.ts +++ b/src/abi/map.ts @@ -4,7 +4,7 @@ import { TypeRef } from "../types/types"; import { WriterContext } from "../generator/Writer"; import { ops } from "../generator/writers/ops"; import { writeExpression } from "../generator/writers/writeExpression"; -import { throwCompilationError } from "../errors"; +import { throwCompilationError } from "../error/errors"; import { getType } from "../types/resolveDescriptors"; import { AbiFunction } from "./AbiFunction"; import { AstExpression } from "../grammar/ast"; diff --git a/src/abi/struct.ts b/src/abi/struct.ts index 48a24a135..541dba8ac 100644 --- a/src/abi/struct.ts +++ b/src/abi/struct.ts @@ -1,6 +1,6 @@ import { ops } from "../generator/writers/ops"; import { writeExpression } from "../generator/writers/writeExpression"; -import { throwCompilationError } from "../errors"; +import { throwCompilationError } from "../error/errors"; import { getType } from "../types/resolveDescriptors"; import { AbiFunction } from "./AbiFunction"; diff --git a/src/bindings/typescript/serializers.ts b/src/bindings/typescript/serializers.ts index 7e45c326f..cc7fdea4d 100644 --- a/src/bindings/typescript/serializers.ts +++ b/src/bindings/typescript/serializers.ts @@ -1,6 +1,6 @@ import { ABITypeRef } from "@ton/core"; import { Writer } from "../../utils/Writer"; -import { throwInternalCompilerError } from "../../errors"; +import { throwInternalCompilerError } from "../../error/errors"; const primitiveTypes = [ "int", diff --git a/src/bindings/typescript/writeStruct.ts b/src/bindings/typescript/writeStruct.ts index 2235e0efe..003f3577f 100644 --- a/src/bindings/typescript/writeStruct.ts +++ b/src/bindings/typescript/writeStruct.ts @@ -1,7 +1,7 @@ import { ABIType, ABITypeRef } from "@ton/core"; import { serializers } from "./serializers"; import { AllocationCell, AllocationOperation } from "../../storage/operation"; -import { throwInternalCompilerError } from "../../errors"; +import { throwInternalCompilerError } from "../../error/errors"; import { Writer } from "../../utils/Writer"; export const maxTupleSize = 15; diff --git a/src/bindings/writeTypescript.ts b/src/bindings/writeTypescript.ts index c534ff71e..57d6029e2 100644 --- a/src/bindings/writeTypescript.ts +++ b/src/bindings/writeTypescript.ts @@ -14,7 +14,7 @@ import { writeTupleSerializer, } from "./typescript/writeStruct"; import { AllocationCell } from "../storage/operation"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { topologicalSort } from "../utils/utils"; import { allocate, diff --git a/src/constEval.ts b/src/constEval.ts index 37914006e..332d7d0d5 100644 --- a/src/constEval.ts +++ b/src/constEval.ts @@ -6,7 +6,7 @@ import { isLiteral, AstLiteral, } from "./grammar/ast"; -import { TactConstEvalError, throwInternalCompilerError } from "./errors"; +import { TactConstEvalError, throwInternalCompilerError } from "./error/errors"; import { AstUtil } from "./optimizer/util"; import { ExpressionTransformer } from "./optimizer/types"; import { StandardOptimizer } from "./optimizer/standardOptimizer"; diff --git a/src/error/display-to-json.ts b/src/error/display-to-json.ts index 6c7e55daa..65138c2da 100644 --- a/src/error/display-to-json.ts +++ b/src/error/display-to-json.ts @@ -2,7 +2,7 @@ * Render error message to JSON for tests */ -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "./errors"; import { SrcInfo } from "../grammar"; import { srcInfoEqual } from "../grammar/src-info"; import { ErrorDisplay } from "./display"; diff --git a/src/error/display-to-string.ts b/src/error/display-to-string.ts index e93d1a06a..f0d406cb7 100644 --- a/src/error/display-to-string.ts +++ b/src/error/display-to-string.ts @@ -3,7 +3,7 @@ */ import { ErrorDisplay } from "./display"; -import { locationStr } from "../errors"; +import { locationStr } from "./errors"; export const displayToString: ErrorDisplay = { text: (text) => text, diff --git a/src/errors.ts b/src/error/errors.ts similarity index 96% rename from src/errors.ts rename to src/error/errors.ts index 0b2cac041..f12c0b4c8 100644 --- a/src/errors.ts +++ b/src/error/errors.ts @@ -1,7 +1,7 @@ import path from "path"; import { cwd } from "process"; -import { AstFuncId, AstId, AstTypeId } from "./grammar/ast"; -import { SrcInfo } from "./grammar"; +import { AstFuncId, AstId, AstTypeId } from "../grammar/ast"; +import { SrcInfo } from "../grammar"; export class TactError extends Error { readonly loc?: SrcInfo; diff --git a/src/generator/writers/writeExpression.ts b/src/generator/writers/writeExpression.ts index 193ac03d8..61a159220 100644 --- a/src/generator/writers/writeExpression.ts +++ b/src/generator/writers/writeExpression.ts @@ -12,7 +12,7 @@ import { TactConstEvalError, throwCompilationError, throwInternalCompilerError, -} from "../../errors"; +} from "../../error/errors"; import { getExpType } from "../../types/resolveExpression"; import { getStaticConstant, diff --git a/src/generator/writers/writeFunction.ts b/src/generator/writers/writeFunction.ts index f897bd258..41143612b 100644 --- a/src/generator/writers/writeFunction.ts +++ b/src/generator/writers/writeFunction.ts @@ -22,7 +22,7 @@ import { cast } from "./cast"; import { resolveFuncTupleType } from "./resolveFuncTupleType"; import { ops } from "./ops"; import { freshIdentifier } from "./freshIdentifier"; -import { idTextErr, throwInternalCompilerError } from "../../errors"; +import { idTextErr, throwInternalCompilerError } from "../../error/errors"; import { ppAsmShuffle } from "../../prettyPrinter"; export function writeCastedExpression( diff --git a/src/generator/writers/writeSerialization.ts b/src/generator/writers/writeSerialization.ts index a9b593a80..592345cea 100644 --- a/src/generator/writers/writeSerialization.ts +++ b/src/generator/writers/writeSerialization.ts @@ -1,5 +1,5 @@ import { contractErrors } from "../../abi/errors"; -import { throwInternalCompilerError } from "../../errors"; +import { throwInternalCompilerError } from "../../error/errors"; import { dummySrcInfo, ItemOrigin } from "../../grammar"; import { AllocationCell, AllocationOperation } from "../../storage/operation"; import { StorageAllocation } from "../../storage/StorageAllocation"; diff --git a/src/grammar/ast.ts b/src/grammar/ast.ts index bfd460576..2b3ed020d 100644 --- a/src/grammar/ast.ts +++ b/src/grammar/ast.ts @@ -1,5 +1,5 @@ import { Address, Cell, Slice } from "@ton/core"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { dummySrcInfo, SrcInfo } from "./src-info"; export type AstModule = { diff --git a/src/grammar/clone.ts b/src/grammar/clone.ts index 48e8a8a79..31b92d1fe 100644 --- a/src/grammar/clone.ts +++ b/src/grammar/clone.ts @@ -1,5 +1,5 @@ import { AstNode, FactoryAst } from "./ast"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; export function cloneNode( src: T, diff --git a/src/grammar/compare.ts b/src/grammar/compare.ts index d744caecc..918d3bd95 100644 --- a/src/grammar/compare.ts +++ b/src/grammar/compare.ts @@ -56,7 +56,7 @@ import { AstStatementDestruct, } from "./ast"; import { AstRenamer } from "./rename"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import JSONbig from "json-bigint"; /** diff --git a/src/grammar/hash.ts b/src/grammar/hash.ts index a4ac5c616..354f22431 100644 --- a/src/grammar/hash.ts +++ b/src/grammar/hash.ts @@ -26,7 +26,7 @@ import { AstAsmInstruction, } from "./ast"; import { createHash } from "crypto"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import JSONbig from "json-bigint"; export type AstHash = string; diff --git a/src/grammar/next/index.ts b/src/grammar/next/index.ts index 6a1341c7e..5afda6e1d 100644 --- a/src/grammar/next/index.ts +++ b/src/grammar/next/index.ts @@ -2,7 +2,10 @@ import * as $ from "@tonstudio/parser-runtime"; import * as A from "../ast"; import * as G from "./grammar"; import type { $ast } from "./grammar"; -import { TactCompilationError, throwInternalCompilerError } from "../../errors"; +import { + TactCompilationError, + throwInternalCompilerError, +} from "../../error/errors"; import { SyntaxErrors, syntaxErrorSchema } from "../parser-error"; import { AstSchema, getAstSchema } from "../ast-typed"; import { getSrcInfo, ItemOrigin } from "../src-info"; diff --git a/src/grammar/prev/grammar.ts b/src/grammar/prev/grammar.ts index 4964f03ce..4951d5c62 100644 --- a/src/grammar/prev/grammar.ts +++ b/src/grammar/prev/grammar.ts @@ -1,6 +1,6 @@ import { Node, IterationNode, NonterminalNode } from "ohm-js"; import tactGrammar from "./grammar.ohm-bundle"; -import { throwInternalCompilerError } from "../../errors"; +import { throwInternalCompilerError } from "../../error/errors"; import { AstAugmentedAssignOperation, AstConstantAttribute, diff --git a/src/grammar/prev/parser-error.ts b/src/grammar/prev/parser-error.ts index b5cf31015..fd40d493a 100644 --- a/src/grammar/prev/parser-error.ts +++ b/src/grammar/prev/parser-error.ts @@ -1,6 +1,6 @@ import { MatchResult } from "ohm-js"; import { ErrorDisplay } from "../../error/display"; -import { TactCompilationError } from "../../errors"; +import { TactCompilationError } from "../../error/errors"; import { syntaxErrorSchema } from "../parser-error"; import { ItemOrigin, SrcInfo } from "../src-info"; import { getSrcInfoFromOhm } from "./src-info"; diff --git a/src/grammar/sort.ts b/src/grammar/sort.ts index 41af072eb..a924702c6 100644 --- a/src/grammar/sort.ts +++ b/src/grammar/sort.ts @@ -5,7 +5,7 @@ import { AstContractAttribute, AstNode, } from "./ast"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; /** * Provides utilities to sort lists of AST nodes. diff --git a/src/grammar/src-info.ts b/src/grammar/src-info.ts index 296a29d3f..feb3941a2 100644 --- a/src/grammar/src-info.ts +++ b/src/grammar/src-info.ts @@ -1,4 +1,4 @@ -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; export type ItemOrigin = "stdlib" | "user"; diff --git a/src/grammar/store.ts b/src/grammar/store.ts index 651a13e4c..21092e297 100644 --- a/src/grammar/store.ts +++ b/src/grammar/store.ts @@ -6,7 +6,7 @@ import { AstTypeDecl, AstAsmFunctionDef, } from "./ast"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { CompilerContext, createContextStore } from "../context"; import { ItemOrigin } from "./src-info"; import { Parser } from "./grammar"; diff --git a/src/imports/resolveImports.ts b/src/imports/resolveImports.ts index b88c066cf..5e7994030 100644 --- a/src/imports/resolveImports.ts +++ b/src/imports/resolveImports.ts @@ -1,6 +1,6 @@ import { ItemOrigin, Parser } from "../grammar"; import { VirtualFileSystem } from "../vfs/VirtualFileSystem"; -import { throwCompilationError } from "../errors"; +import { throwCompilationError } from "../error/errors"; import { resolveLibrary } from "./resolveLibrary"; export function resolveImports(args: { diff --git a/src/index.ts b/src/index.ts index 15ec85cf7..4ffc2787f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export { TactInternalCompilerError, TactConstEvalError, TactErrorCollection, -} from "./errors"; +} from "./error/errors"; export { optionsSchema, projectSchema, diff --git a/src/interpreter.ts b/src/interpreter.ts index ebc366d88..7b1573445 100644 --- a/src/interpreter.ts +++ b/src/interpreter.ts @@ -9,7 +9,7 @@ import { idTextErr, throwConstEvalError, throwInternalCompilerError, -} from "./errors"; +} from "./error/errors"; import { AstAddress, AstBinaryOperation, diff --git a/src/main.ts b/src/main.ts index 76cc91a1b..abfb5a5af 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,4 +16,4 @@ export { createVirtualFileSystem } from "./vfs/createVirtualFileSystem"; export * from "./browser"; export * from "./verify"; export * from "./logger"; -export * from "./errors"; +export * from "./error/errors"; diff --git a/src/node.ts b/src/node.ts index 218533d09..1af679d9c 100644 --- a/src/node.ts +++ b/src/node.ts @@ -4,7 +4,7 @@ import { ConfigProject, Config, parseConfig } from "./config/parseConfig"; import { createNodeFileSystem } from "./vfs/createNodeFileSystem"; import { build } from "./pipeline/build"; import { LogLevel, Logger } from "./logger"; -import { TactErrorCollection } from "./errors"; +import { TactErrorCollection } from "./error/errors"; type AdditionalCliOptions = { mode?: ConfigProject["mode"]; diff --git a/src/optimizer/test/partial-eval.spec.ts b/src/optimizer/test/partial-eval.spec.ts index 34cb418b5..c31650e23 100644 --- a/src/optimizer/test/partial-eval.spec.ts +++ b/src/optimizer/test/partial-eval.spec.ts @@ -13,7 +13,7 @@ import { AssociativeRule3 } from "../associative"; import { evalBinaryOp, evalUnaryOp } from "../../interpreter"; import { getParser } from "../../grammar"; import { defaultParser } from "../../grammar/grammar"; -import { throwInternalCompilerError } from "../../errors"; +import { throwInternalCompilerError } from "../../error/errors"; const MAX: string = "115792089237316195423570985008687907853269984665640564039457584007913129639935"; diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index d13216484..ea5b70a78 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -20,7 +20,7 @@ import { compile } from "./compile"; import { precompile } from "./precompile"; import { getCompilerVersion } from "./version"; import { FactoryAst, getAstFactory, idText } from "../grammar/ast"; -import { TactErrorCollection } from "../errors"; +import { TactErrorCollection } from "../error/errors"; import { getParser, Parser } from "../grammar"; import { defaultParser } from "../grammar/grammar"; diff --git a/src/storage/allocator.ts b/src/storage/allocator.ts index d12374389..2d388073e 100644 --- a/src/storage/allocator.ts +++ b/src/storage/allocator.ts @@ -4,7 +4,7 @@ import { AllocationOperation, AllocationOperationType, } from "./operation"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; const ALLOCATOR_RESERVE_BIT = 1; const ALLOCATOR_RESERVE_REF = 1; diff --git a/src/storage/resolveAllocation.ts b/src/storage/resolveAllocation.ts index 483b98b51..cacea64d9 100644 --- a/src/storage/resolveAllocation.ts +++ b/src/storage/resolveAllocation.ts @@ -7,7 +7,7 @@ import { AllocationOperation } from "./operation"; import { allocate, getAllocationOperationFromField } from "./allocator"; import { createABITypeRefFromTypeRef } from "../types/resolveABITypeRef"; import { funcInitIdOf } from "../generator/writers/id"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { idText } from "../grammar/ast"; const store = createContextStore(); diff --git a/src/types/resolveABITypeRef.ts b/src/types/resolveABITypeRef.ts index b2cf8e731..3f5390a3b 100644 --- a/src/types/resolveABITypeRef.ts +++ b/src/types/resolveABITypeRef.ts @@ -17,7 +17,7 @@ import { idTextErr, throwCompilationError, throwInternalCompilerError, -} from "../errors"; +} from "../error/errors"; import { TypeRef } from "./types"; import { CompilerContext } from "../context"; import { getType } from "./resolveDescriptors"; diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index e63624fca..42b422719 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -24,7 +24,7 @@ import { idTextErr, throwCompilationError, throwInternalCompilerError, -} from "../errors"; +} from "../error/errors"; import { CompilerContext, createContextStore, Store } from "../context"; import { ConstantDescription, diff --git a/src/types/resolveErrors.ts b/src/types/resolveErrors.ts index 4a4bf9986..1b7807924 100644 --- a/src/types/resolveErrors.ts +++ b/src/types/resolveErrors.ts @@ -3,7 +3,7 @@ import { CompilerContext, createContextStore } from "../context"; import { AstNode, FactoryAst, isRequire } from "../grammar/ast"; import { traverse } from "../grammar/iterators"; import { evalConstantExpression } from "../constEval"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { getAllStaticFunctions, getAllTypes, diff --git a/src/types/resolveExpression.ts b/src/types/resolveExpression.ts index f4ba9df24..197fb7d38 100644 --- a/src/types/resolveExpression.ts +++ b/src/types/resolveExpression.ts @@ -22,7 +22,7 @@ import { AstCommentValue, AstStructValue, } from "../grammar/ast"; -import { idTextErr, throwCompilationError } from "../errors"; +import { idTextErr, throwCompilationError } from "../error/errors"; import { CompilerContext, createContextStore } from "../context"; import { getAllTypes, @@ -37,7 +37,7 @@ import { StatementContext } from "./resolveStatements"; import { MapFunctions } from "../abi/map"; import { GlobalFunctions } from "../abi/global"; import { isAssignable, moreGeneralType } from "./subtyping"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { StructFunctions } from "../abi/struct"; import { prettyPrint } from "../prettyPrinter"; diff --git a/src/types/resolveSignatures.ts b/src/types/resolveSignatures.ts index 5e1559660..dfabdd63c 100644 --- a/src/types/resolveSignatures.ts +++ b/src/types/resolveSignatures.ts @@ -6,7 +6,7 @@ import { idTextErr, throwConstEvalError, throwInternalCompilerError, -} from "../errors"; +} from "../error/errors"; import { getType, getAllTypes } from "./resolveDescriptors"; import { BinaryReceiverSelector, @@ -14,7 +14,7 @@ import { ReceiverDescription, TypeDescription, } from "./types"; -import { throwCompilationError } from "../errors"; +import { throwCompilationError } from "../error/errors"; import { AstNumber, AstReceiver, FactoryAst } from "../grammar/ast"; import { commentPseudoOpcode } from "../generator/writers/writeRouter"; import { sha256_sync } from "@ton/crypto"; diff --git a/src/types/resolveStatements.ts b/src/types/resolveStatements.ts index 39d01d67c..ccb923265 100644 --- a/src/types/resolveStatements.ts +++ b/src/types/resolveStatements.ts @@ -17,7 +17,7 @@ import { throwCompilationError, throwConstEvalError, throwInternalCompilerError, -} from "../errors"; +} from "../error/errors"; import { getAllStaticFunctions, getStaticConstant, diff --git a/src/types/types.ts b/src/types/types.ts index de49c2e56..754db4298 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1,5 +1,5 @@ import { ABIField } from "@ton/core"; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; import { AstConstantDef, AstFunctionDef, diff --git a/src/utils/tricks.ts b/src/utils/tricks.ts index 40ca8578a..1d81f566e 100644 --- a/src/utils/tricks.ts +++ b/src/utils/tricks.ts @@ -89,7 +89,7 @@ export const match = ( }) as MV, never>; }; -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; /** * Convert union to intersection. See https://stackoverflow.com/q/50374908 diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 8d3a45ec9..c5cd373a6 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,4 +1,4 @@ -import { throwInternalCompilerError } from "../errors"; +import { throwInternalCompilerError } from "../error/errors"; export function topologicalSort(src: T[], references: (src: T) => T[]) { const result: T[] = [];