@typesol/cli 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +2 -1
  3. package/dist/compiler/analyze.js +41 -1
  4. package/dist/compiler/emit/base.d.ts +40 -7
  5. package/dist/compiler/emit/base.js +33 -0
  6. package/dist/compiler/emit/borsh.d.ts +7 -0
  7. package/dist/compiler/emit/borsh.js +86 -1
  8. package/dist/compiler/emit/calls.d.ts +102 -2
  9. package/dist/compiler/emit/calls.js +663 -49
  10. package/dist/compiler/emit/cpi-core.d.ts +9 -3
  11. package/dist/compiler/emit/cpi-core.js +12 -7
  12. package/dist/compiler/emit/cpi.js +8 -14
  13. package/dist/compiler/emit/create.d.ts +3 -3
  14. package/dist/compiler/emit/create.js +33 -25
  15. package/dist/compiler/emit/expressions.js +51 -2
  16. package/dist/compiler/emit/function.js +2 -2
  17. package/dist/compiler/emit/outline.d.ts +24 -0
  18. package/dist/compiler/emit/outline.js +100 -0
  19. package/dist/compiler/emit/program.js +7 -2
  20. package/dist/compiler/emit/shared.d.ts +35 -1
  21. package/dist/compiler/emit/shared.js +9 -1
  22. package/dist/compiler/emit/statements.d.ts +31 -0
  23. package/dist/compiler/emit/statements.js +272 -14
  24. package/dist/compiler/emit/storage.d.ts +27 -1
  25. package/dist/compiler/emit/storage.js +124 -11
  26. package/dist/compiler/emit/token.d.ts +11 -8
  27. package/dist/compiler/emit/token.js +233 -104
  28. package/dist/compiler/hints.js +6 -0
  29. package/dist/compiler/model.d.ts +20 -1
  30. package/dist/compiler/model.js +5 -0
  31. package/dist/testing-stake.d.ts +216 -0
  32. package/dist/testing-stake.js +526 -0
  33. package/dist/testing.d.ts +1 -0
  34. package/dist/testing.js +1 -0
  35. package/docs/architecture.md +1 -1
  36. package/docs/case-study-spl-stake-pool.md +122 -0
  37. package/docs/errors.md +1 -1
  38. package/docs/language.md +107 -14
  39. package/docs/security-model.md +4 -0
  40. package/docs/stability.md +13 -0
  41. package/docs/test-your-program.md +47 -0
  42. package/docs/testing.md +19 -0
  43. package/lib/typesol.d.ts +241 -40
  44. package/llms-full.txt +172 -15
  45. package/llms.txt +1 -1
  46. package/package.json +1 -1
  47. package/runtime/typesol_rt.h +69 -0
@@ -1,12 +1,24 @@
1
1
  import ts from "typescript";
2
- import { type AccountParam, type ErrorDef, type FieldType, type Helper, type StructDef } from "../model.js";
3
- import { type Value, type Ref, type Closure } from "./shared.js";
2
+ import { type AccountParam, type ErrorDef, type FieldType, type Helper, type StructDef, type ValueType } from "../model.js";
3
+ import { type Value, type Ref, type CpiAcct, type CpiProgram, type Closure } from "./shared.js";
4
4
  import { ExpressionEmitter } from "./expressions.js";
5
5
  export declare abstract class CallEmitter extends ExpressionEmitter {
6
6
  protected call(node: ts.CallExpression, topLevel: boolean): Value | undefined;
7
7
  /** "unsupported call" naming the callee, with the TypeSOL form of common JavaScript calls. */
8
8
  private unsupportedCall;
9
9
  protected vecMethod(node: ts.CallExpression, method: string, v: Ref): Value | undefined;
10
+ /**
11
+ * The methods a BigVec adds or changes (SPL's big_vec): `push` into the account's room, `retain`, and the refusals;
12
+ * undefined for the methods it shares with other lists (`set`).
13
+ */
14
+ private bigVecMethod;
15
+ /**
16
+ * BigVec::retain over struct elements, walked with a pointer: the predicate gets each element in place, a kept one
17
+ * costs its predicate and the step. `run` is the first element not yet moved (the run of kept ones since the last
18
+ * removal), `dst` where that run goes; each run moves down once, when the next removal (or the end) is found, and
19
+ * only once something before it was removed. The length is written once, at the end (the moves never reach it).
20
+ */
21
+ private retainStructs;
10
22
  /** sha256(...) / keccak256(...) over strings, Pubkeys, Hashes, integers (LE) and booleans. */
11
23
  protected hashCall(node: ts.CallExpression, fn: "sha256" | "keccak256"): Value;
12
24
  /**
@@ -33,9 +45,73 @@ export declare abstract class CallEmitter extends ExpressionEmitter {
33
45
  * sysvar (ts_ix_* in the runtime). Undefined when the call is something else.
34
46
  */
35
47
  protected instructionsCall(node: ts.CallExpression, callee: ts.PropertyAccessExpression, method: string): Value | undefined;
48
+ /** `fixedArray<T, N>(fill)` written inline (a list method, a map / filter chain or `for … of` over it). */
49
+ protected isInlineArray(node: ts.Expression): boolean;
50
+ /**
51
+ * Whether `node` is a read-only view of a Vec argument or the instruction data, without emitting code: a local or
52
+ * helper parameter holding one, or `.slice(start, end?)` of such a view.
53
+ */
54
+ protected isVecArgView(node: ts.Expression): boolean;
55
+ /**
56
+ * The view `node` names (see isVecArgView) as a `TS_VecArg` C expression. `.slice(start, end)` is elements start..end-1
57
+ * in place (`end` defaults to the length): unlike JS's slice it does not clamp, an `end` past the length or before
58
+ * `start` fails with 5104. Undefined when `node` is not such a view.
59
+ */
60
+ protected vecArgView(node: ts.Expression): {
61
+ c: string;
62
+ type: ValueType & {
63
+ kind: "vecArg";
64
+ };
65
+ } | undefined;
66
+ /**
67
+ * A list's elements as one contiguous run, for a bulk copy or a CPI: a Vec argument, the instruction data or a slice
68
+ * of them; a Vec, FixedVec, BigVec (slice) or FixedArray in account data or a local. Undefined for anything else.
69
+ */
70
+ protected listSpan(e: ts.Expression): {
71
+ items: string;
72
+ count: string;
73
+ elem: FieldType;
74
+ view: boolean;
75
+ } | undefined;
76
+ /** `pushAll(items)`'s source: a list of exactly `elem` (see listSpan). */
77
+ protected bulkSource(e: ts.Expression, elem: FieldType): {
78
+ items: string;
79
+ count: string;
80
+ };
81
+ /**
82
+ * Whether `node` names one account a choice may pick, without emitting code: a remaining account (`rest.get(i)`), a
83
+ * local or `RemainingAccount` helper parameter bound to one, an `AccountInfo` parameter, or a choice between those.
84
+ */
85
+ protected looksLikeAccountHandle(node: ts.Expression): boolean;
86
+ /**
87
+ * `c ? rest.get(5n) : reserve`: one of two accounts, chosen at run time (only the chosen side runs), as a `TsAccount *`
88
+ * usable wherever a remaining account is. Each side is a remaining account, a local or helper parameter bound to one,
89
+ * an `AccountInfo` parameter or another such choice; a `programAt` check is kept when both sides carry the same one.
90
+ */
91
+ protected accountChoice(node: ts.ConditionalExpression): Value;
36
92
  protected handle(node: ts.Expression): string | undefined;
37
93
  /** A declared account parameter or a remaining account, as a `TsAccount *` C expression. */
38
94
  protected anyAccount(node: ts.Expression, what: string): string;
95
+ /**
96
+ * An account argument of a typed CPI: a declared account parameter (`param`, its kind and writability checked by
97
+ * the caller), or a remaining account, a local bound to one, a RemainingAccount helper parameter or a loaded struct
98
+ * (no compile-time checks: the called program and the runtime check them).
99
+ */
100
+ protected cpiAccount(node: ts.Expression, what: string): CpiAcct;
101
+ /** A declared program parameter as the program of a typed CPI. */
102
+ protected programParam(a: AccountParam): CpiProgram;
103
+ /**
104
+ * `programAt<P>(acct)` / `sysvarAt<S>(acct)`: the account (a remaining account or an AccountInfo parameter) checked
105
+ * to be that program or sysvar by its key, once, then usable with P's typed methods. A wrong program fails with
106
+ * ProgramError.IncorrectProgramId and a wrong sysvar with ProgramError.InvalidArgument, as solana_program's checks do.
107
+ */
108
+ protected programAt(node: ts.CallExpression, fn: "programAt" | "sysvarAt"): Value;
109
+ /** A value `programAt` / `sysvarAt` checked (a local bound to one, or the call itself), as the program it is. */
110
+ protected programAtValue(node: ts.Expression): CpiProgram | undefined;
111
+ /** `stake.split(…)` on a programAt value: the same typed methods as on a declared program parameter. */
112
+ protected programAtMethod(node: ts.CallExpression, at: CpiProgram, method: string): Value | undefined;
113
+ /** StakeHistorySysvar's has / effective / activating / deactivating(epoch), on the sysvar account `h`. */
114
+ protected stakeHistoryRead(node: ts.CallExpression, h: string, method: string): Value;
39
115
  /** `readData<T>(account, offset)`: a bounds-checked little-endian read of any account's data. */
40
116
  protected readData(node: ts.CallExpression): Value;
41
117
  /** `writeData<T>(account, offset, value)`: a little-endian store into a writable AccountInfo's data. */
@@ -47,6 +123,24 @@ export declare abstract class CallEmitter extends ExpressionEmitter {
47
123
  * from byte 0, checked as a `#[repr(C)]` type's load_checked does: this program's (3007), large enough (3003).
48
124
  */
49
125
  protected loadRaw(node: ts.CallExpression, mut: boolean): Value;
126
+ /**
127
+ * `const v = loadBorsh<T>(acct)`: the account's data from byte 0 decoded as Borsh into a local `T` (a copy), as
128
+ * `try_from_slice_unchecked` reads it: no owner check, no discriminator, trailing bytes ignored; bytes that are not
129
+ * a valid `T` (too short, an Option tag or bool not 0/1, an enum tag out of range) fail with BorshIoError.
130
+ */
131
+ protected loadBorsh(node: ts.CallExpression, c: string, declared: StructDef | undefined): StructDef;
132
+ /**
133
+ * `storeBorsh(acct, value)`: `value` encoded as Borsh into the account's data from byte 0, as Rust's
134
+ * `value.serialize(&mut &mut data[..])` writes it: only the encoded bytes (the rest of the account is left as it
135
+ * was), BorshIoError when they do not fit. The account must be writable.
136
+ */
137
+ protected storeBorsh(node: ts.CallExpression): undefined;
138
+ /** The struct loadBorsh / storeBorsh decodes or encodes: from the type argument, else the declared type. */
139
+ private borshNativeStruct;
140
+ /** The account loadBorsh reads or storeBorsh writes (writable: checked at run time, or Mut<AccountInfo>). */
141
+ private borshAccount;
142
+ /** `TS_FAIL` with a built-in ProgramError (no custom code), logged as `require(…, ProgramError.X)` logs it. */
143
+ protected programErrorFail(name: string, node: ts.Node): string;
50
144
  /** `loadAccount<T>(acct)` / `loadAccountMut<T>(acct)`: checked view of a program account. */
51
145
  protected loadAccount(node: ts.CallExpression, mut: boolean): Value;
52
146
  /**
@@ -77,6 +171,12 @@ export declare abstract class CallEmitter extends ExpressionEmitter {
77
171
  protected callHelper(node: ts.CallExpression, h: Helper): Value | undefined;
78
172
  /** One helper argument: a C argument list fragment (accounts, seeds, references) or a value to settle. */
79
173
  protected helperArg(h: Helper, p: Helper["params"][number], n: ts.Expression): Value | string;
174
+ /**
175
+ * A struct, array or data-enum helper argument written as a literal (`f({ a: 1n, b: { c } })`, `g([1n, 2n])`, or a
176
+ * ternary with a literal branch): built in a local of its own, as `const x: T = { … }; f(x)` would, and passed by
177
+ * pointer (the helper cannot change it, and nothing else sees it). Undefined for anything else.
178
+ */
179
+ protected literalArg(n: ts.Expression, want: FieldType): string | undefined;
80
180
  /**
81
181
  * A struct/array/data-enum helper argument. Helpers that take accounts may change account data, so they get a
82
182
  * copy taken at the call (JS passes the object as it was); other helpers cannot write, so a pointer is enough.