Skip to content

Commit 999f6e4

Browse files
authored
Multi thread safe b (#1393)
* prettier could be run in parallel, this should add a layer of safety for those cases. * fixing extensions * using a separate object from Prettier's options * cleaning up type
1 parent 5687d71 commit 999f6e4

225 files changed

Lines changed: 1956 additions & 1081 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/slang-nodes/AbicoderPragma.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { AbicoderVersion } from './AbicoderVersion.js';
44

55
import type * as ast from '@nomicfoundation/slang/ast';
66
import type { AstPath, Doc } from 'prettier';
7-
import type { PrintFunction } from '../types.d.ts';
7+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
88

99
export class AbicoderPragma extends SlangNode {
1010
readonly kind = NonterminalKind.AbicoderPragma;
1111

1212
version: AbicoderVersion;
1313

14-
constructor(ast: ast.AbicoderPragma) {
15-
super(ast);
14+
constructor(ast: ast.AbicoderPragma, collected: CollectedMetadata) {
15+
super(ast, collected);
1616

17-
this.version = new AbicoderVersion(ast.version);
17+
this.version = new AbicoderVersion(ast.version, collected);
1818
}
1919

2020
print(path: AstPath<AbicoderPragma>, print: PrintFunction): Doc {

src/slang-nodes/AbicoderVersion.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { SlangNode } from './SlangNode.js';
33

44
import type * as ast from '@nomicfoundation/slang/ast';
55
import type { Doc } from 'prettier';
6+
import type { CollectedMetadata } from '../types.d.ts';
67

78
export class AbicoderVersion extends SlangNode {
89
readonly kind = NonterminalKind.AbicoderVersion;
910

1011
variant: string;
1112

12-
constructor(ast: ast.AbicoderVersion) {
13-
super(ast);
13+
constructor(ast: ast.AbicoderVersion, collected: CollectedMetadata) {
14+
super(ast, collected);
1415

1516
this.variant = ast.variant.unparse();
1617
}

src/slang-nodes/AdditiveExpression.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Expression } from './Expression.js';
88

99
import type * as ast from '@nomicfoundation/slang/ast';
1010
import type { AstPath, Doc, ParserOptions } from 'prettier';
11-
import type { PrintFunction } from '../types.d.ts';
11+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1212
import type { AstNode } from './types.d.ts';
1313

1414
const tryToHug = createHugFunction(['%']);
@@ -35,13 +35,19 @@ export class AdditiveExpression extends SlangNode {
3535

3636
rightOperand: Expression['variant'];
3737

38-
constructor(ast: ast.AdditiveExpression, options: ParserOptions<AstNode>) {
39-
super(ast);
38+
constructor(
39+
ast: ast.AdditiveExpression,
40+
collected: CollectedMetadata,
41+
options: ParserOptions<AstNode>
42+
) {
43+
super(ast, collected);
4044

41-
this.leftOperand = extractVariant(new Expression(ast.leftOperand, options));
45+
this.leftOperand = extractVariant(
46+
new Expression(ast.leftOperand, collected, options)
47+
);
4248
this.operator = ast.operator.unparse();
4349
this.rightOperand = extractVariant(
44-
new Expression(ast.rightOperand, options)
50+
new Expression(ast.rightOperand, collected, options)
4551
);
4652

4753
this.updateMetadata(this.leftOperand, this.rightOperand);

src/slang-nodes/AddressType.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { SlangNode } from './SlangNode.js';
33

44
import type * as ast from '@nomicfoundation/slang/ast';
55
import type { Doc } from 'prettier';
6+
import type { CollectedMetadata } from '../types.d.ts';
67

78
export class AddressType extends SlangNode {
89
readonly kind = NonterminalKind.AddressType;
910

1011
payableKeyword?: string;
1112

12-
constructor(ast: ast.AddressType) {
13-
super(ast);
13+
constructor(ast: ast.AddressType, collected: CollectedMetadata) {
14+
super(ast, collected);
1415

1516
this.payableKeyword = ast.payableKeyword?.unparse();
1617
}

src/slang-nodes/AndExpression.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Expression } from './Expression.js';
66

77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
9-
import type { PrintFunction } from '../types.d.ts';
9+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1010
import type { AstNode } from './types.d.ts';
1111

1212
export class AndExpression extends SlangNode {
@@ -18,13 +18,19 @@ export class AndExpression extends SlangNode {
1818

1919
rightOperand: Expression['variant'];
2020

21-
constructor(ast: ast.AndExpression, options: ParserOptions<AstNode>) {
22-
super(ast);
21+
constructor(
22+
ast: ast.AndExpression,
23+
collected: CollectedMetadata,
24+
options: ParserOptions<AstNode>
25+
) {
26+
super(ast, collected);
2327

24-
this.leftOperand = extractVariant(new Expression(ast.leftOperand, options));
28+
this.leftOperand = extractVariant(
29+
new Expression(ast.leftOperand, collected, options)
30+
);
2531
this.operator = ast.operator.unparse();
2632
this.rightOperand = extractVariant(
27-
new Expression(ast.rightOperand, options)
33+
new Expression(ast.rightOperand, collected, options)
2834
);
2935

3036
this.updateMetadata(this.leftOperand, this.rightOperand);

src/slang-nodes/ArgumentsDeclaration.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration
55
import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js';
66

77
import type { ParserOptions } from 'prettier';
8+
import type { CollectedMetadata } from '../types.d.ts';
89
import type { AstNode } from './types.d.ts';
910

1011
function createNonterminalVariant(
1112
variant: ast.ArgumentsDeclaration['variant'],
13+
collected: CollectedMetadata,
1214
options: ParserOptions<AstNode>
1315
): ArgumentsDeclaration['variant'] {
1416
if (variant instanceof ast.PositionalArgumentsDeclaration) {
15-
return new PositionalArgumentsDeclaration(variant, options);
17+
return new PositionalArgumentsDeclaration(variant, collected, options);
1618
}
1719
if (variant instanceof ast.NamedArgumentsDeclaration) {
18-
return new NamedArgumentsDeclaration(variant, options);
20+
return new NamedArgumentsDeclaration(variant, collected, options);
1921
}
2022
const exhaustiveCheck: never = variant;
2123
throw new Error(`Unexpected variant: ${JSON.stringify(exhaustiveCheck)}`);
@@ -26,10 +28,14 @@ export class ArgumentsDeclaration extends SlangNode {
2628

2729
variant: PositionalArgumentsDeclaration | NamedArgumentsDeclaration;
2830

29-
constructor(ast: ast.ArgumentsDeclaration, options: ParserOptions<AstNode>) {
30-
super(ast);
31+
constructor(
32+
ast: ast.ArgumentsDeclaration,
33+
collected: CollectedMetadata,
34+
options: ParserOptions<AstNode>
35+
) {
36+
super(ast, collected);
3137

32-
this.variant = createNonterminalVariant(ast.variant, options);
38+
this.variant = createNonterminalVariant(ast.variant, collected, options);
3339

3440
this.updateMetadata(this.variant);
3541
}

src/slang-nodes/ArrayExpression.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ import { ArrayValues } from './ArrayValues.js';
44

55
import type * as ast from '@nomicfoundation/slang/ast';
66
import type { AstPath, Doc, ParserOptions } from 'prettier';
7-
import type { PrintFunction } from '../types.d.ts';
7+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
88
import type { AstNode } from './types.d.ts';
99

1010
export class ArrayExpression extends SlangNode {
1111
readonly kind = NonterminalKind.ArrayExpression;
1212

1313
items: ArrayValues;
1414

15-
constructor(ast: ast.ArrayExpression, options: ParserOptions<AstNode>) {
16-
super(ast);
15+
constructor(
16+
ast: ast.ArrayExpression,
17+
collected: CollectedMetadata,
18+
options: ParserOptions<AstNode>
19+
) {
20+
super(ast, collected);
1721

18-
this.items = new ArrayValues(ast.items, options);
22+
this.items = new ArrayValues(ast.items, collected, options);
1923
}
2024

2125
print(path: AstPath<ArrayExpression>, print: PrintFunction): Doc {

src/slang-nodes/ArrayTypeName.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Expression } from './Expression.js';
66

77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
9-
import type { PrintFunction } from '../types.d.ts';
9+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1010
import type { AstNode } from './types.d.ts';
1111

1212
export class ArrayTypeName extends SlangNode {
@@ -16,12 +16,20 @@ export class ArrayTypeName extends SlangNode {
1616

1717
index?: Expression['variant'];
1818

19-
constructor(ast: ast.ArrayTypeName, options: ParserOptions<AstNode>) {
20-
super(ast);
19+
constructor(
20+
ast: ast.ArrayTypeName,
21+
collected: CollectedMetadata,
22+
options: ParserOptions<AstNode>
23+
) {
24+
super(ast, collected);
2125

22-
this.operand = extractVariant(new TypeName(ast.operand, options));
26+
this.operand = extractVariant(
27+
new TypeName(ast.operand, collected, options)
28+
);
2329
if (ast.index) {
24-
this.index = extractVariant(new Expression(ast.index, options));
30+
this.index = extractVariant(
31+
new Expression(ast.index, collected, options)
32+
);
2533
}
2634

2735
this.updateMetadata(this.operand, this.index);

src/slang-nodes/ArrayValues.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ import { Expression } from './Expression.js';
66

77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
9-
import type { PrintFunction } from '../types.d.ts';
9+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1010
import type { AstNode } from './types.d.ts';
1111

1212
export class ArrayValues extends SlangNode {
1313
readonly kind = NonterminalKind.ArrayValues;
1414

1515
items: Expression['variant'][];
1616

17-
constructor(ast: ast.ArrayValues, options: ParserOptions<AstNode>) {
18-
super(ast, true);
17+
constructor(
18+
ast: ast.ArrayValues,
19+
collected: CollectedMetadata,
20+
options: ParserOptions<AstNode>
21+
) {
22+
super(ast, collected, true);
1923

2024
this.items = ast.items.map((item) =>
21-
extractVariant(new Expression(item, options))
25+
extractVariant(new Expression(item, collected, options))
2226
);
2327
}
2428

src/slang-nodes/AssemblyFlags.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import { StringLiteral } from './StringLiteral.js';
55

66
import type * as ast from '@nomicfoundation/slang/ast';
77
import type { AstPath, Doc, ParserOptions } from 'prettier';
8-
import type { PrintFunction } from '../types.d.ts';
8+
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
99
import type { AstNode } from './types.d.ts';
1010

1111
export class AssemblyFlags extends SlangNode {
1212
readonly kind = NonterminalKind.AssemblyFlags;
1313

1414
items: StringLiteral[];
1515

16-
constructor(ast: ast.AssemblyFlags, options: ParserOptions<AstNode>) {
17-
super(ast, true);
16+
constructor(
17+
ast: ast.AssemblyFlags,
18+
collected: CollectedMetadata,
19+
options: ParserOptions<AstNode>
20+
) {
21+
super(ast, collected, true);
1822

19-
this.items = ast.items.map((item) => new StringLiteral(item, options));
23+
this.items = ast.items.map(
24+
(item) => new StringLiteral(item, collected, options)
25+
);
2026
}
2127

2228
print(path: AstPath<AssemblyFlags>, print: PrintFunction): Doc {

0 commit comments

Comments
 (0)