@harmoniclabs/pebble 0.3.4 → 0.3.5

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.
@@ -428,7 +428,7 @@ function _getMatchedRedeemerBlockStatements(compiler, stmts, paramsInternalNames
428
428
  }
429
429
  const realVarName = contextVarsMapping[fieldIdentifier.text];
430
430
  if (!realVarName && typeof realVarName !== "string") {
431
- return compiler.error(DiagnosticCode._0_is_not_aviable_in_this_contract_method_context, fieldIdentifier.range, fieldIdentifier.text);
431
+ return compiler.error(DiagnosticCode._0_is_not_available_in_this_contract_method_context, fieldIdentifier.range, fieldIdentifier.text);
432
432
  }
433
433
  if (destructuredFieldsIds.includes(fieldIdentifier.text)) {
434
434
  return compiler.error(DiagnosticCode.Duplicate_identifier_0, fieldVarDecl.range, fieldIdentifier.text);
@@ -165,7 +165,12 @@ export function expressifyVars(ctx, expr) {
165
165
  if (c.pattern instanceof TirArrayLikeDeconstr)
166
166
  throw new Error("case expression not yet supported for array-like deconstruction");
167
167
  const pattern = toNamedDeconstructVarDecl(c.pattern);
168
- const branchBodyStmts = flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(pattern, branchCtx);
168
+ const branchBodyStmts = flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(pattern, branchCtx,
169
+ // user case-arm pattern: the body references each binding by its
170
+ // OWN name (`is P{ field: alias } => …` uses `alias`), so the
171
+ // rename must NOT be keyed by the struct field name (which could
172
+ // shadow an outer variable of that name).
173
+ false);
169
174
  branchBodyStmts.push(new TirReturnStmt(c.body, c.body.range));
170
175
  c.body = expressifyFuncBody(branchCtx, branchBodyStmts, undefined);
171
176
  }
@@ -6,4 +6,19 @@ import { ExpressifyCtx } from "./ExpressifyCtx.js";
6
6
  *
7
7
  * @returns the extracted nested deconstructions
8
8
  */
9
- export declare function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(decl: TirNamedDeconstructVarDecl | TirSingleDeconstructVarDecl, ctx: ExpressifyCtx): TirVarDecl[];
9
+ export declare function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(decl: TirNamedDeconstructVarDecl | TirSingleDeconstructVarDecl, ctx: ExpressifyCtx,
10
+ /**
11
+ * The field-name → binding rename below is a REMAP device used by
12
+ * synthesized destructures (e.g. loop state `State{ a: §a_fresh }`, where
13
+ * the original body references the source name `a` and must be redirected
14
+ * to the fresh threaded binding). For those, key the rename by the field
15
+ * name (`fName`).
16
+ *
17
+ * A USER case-arm / destructure pattern (`P{ field: alias }`) is different:
18
+ * it INTRODUCES a fresh binding the body references by its own name
19
+ * (`alias` = `varDecl.name`); the field name is NOT a name the body uses.
20
+ * Keying by `fName` there shadows any outer variable that happens to share
21
+ * the struct field's name (a silent miscompilation). Such callers pass
22
+ * `false` so the rename is keyed by the binding's own name instead.
23
+ */
24
+ fieldNameIsBodyReference?: boolean): TirVarDecl[];
@@ -8,14 +8,32 @@ import { isSingleConstrStruct } from "./isSingleConstrStruct.js";
8
8
  *
9
9
  * @returns the extracted nested deconstructions
10
10
  */
11
- export function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(decl, ctx) {
11
+ export function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct(decl, ctx,
12
+ /**
13
+ * The field-name → binding rename below is a REMAP device used by
14
+ * synthesized destructures (e.g. loop state `State{ a: §a_fresh }`, where
15
+ * the original body references the source name `a` and must be redirected
16
+ * to the fresh threaded binding). For those, key the rename by the field
17
+ * name (`fName`).
18
+ *
19
+ * A USER case-arm / destructure pattern (`P{ field: alias }`) is different:
20
+ * it INTRODUCES a fresh binding the body references by its own name
21
+ * (`alias` = `varDecl.name`); the field name is NOT a name the body uses.
22
+ * Keying by `fName` there shadows any outer variable that happens to share
23
+ * the struct field's name (a silent miscompilation). Such callers pass
24
+ * `false` so the rename is keyed by the binding's own name instead.
25
+ */
26
+ fieldNameIsBodyReference = true) {
12
27
  const extracted = [];
13
28
  const restFields = new Map();
14
29
  for (const [fName, varDecl] of decl.fields) {
15
30
  if (varDecl instanceof TirSimpleVarDecl) {
16
31
  restFields.set(fName, varDecl.name);
17
32
  ctx.introduceFuncParams([varDecl]);
18
- ctx.setNewVariableName(fName, varDecl.name); // added to fix reassigned variables on non-terminating statements
33
+ // register the rename so reassigned bindings thread on
34
+ // non-terminating statements; key by the name the body references
35
+ // (see `fieldNameIsBodyReference`).
36
+ ctx.setNewVariableName(fieldNameIsBodyReference ? fName : varDecl.name, varDecl.name);
19
37
  if (isSingleConstrStruct(varDecl.type)) {
20
38
  const structType = getUnaliased(varDecl.type);
21
39
  const constr = structType.constructors[0];
@@ -191,6 +191,9 @@ export function populateStdNamespace(program) {
191
191
  defineBuiltin(blsNsScope, "g1Uncompress", IRNativeTag.bls12_381_G1_uncompress, new TirFuncT([bytes_t], g1_t), blsNs);
192
192
  // CIP-0381 multi-scalar multiplication: Σ scalars[i] · points[i]
193
193
  defineBuiltin(blsNsScope, "g1MultiScalarMul", IRNativeTag.bls12_381_G1_multiScalarMul, new TirFuncT([new TirListT(int_t), new TirListT(g1_t)], g1_t), blsNs);
194
+ // `multiScalarMul` is a convenience alias for the G1 variant (the usual
195
+ // group for commitments); the explicit `g1`/`g2` names remain available.
196
+ defineBuiltin(blsNsScope, "multiScalarMul", IRNativeTag.bls12_381_G1_multiScalarMul, new TirFuncT([new TirListT(int_t), new TirListT(g1_t)], g1_t), blsNs);
194
197
  defineBuiltin(blsNsScope, "g2Add", IRNativeTag.bls12_381_G2_add, new TirFuncT([g2_t, g2_t], g2_t), blsNs);
195
198
  defineBuiltin(blsNsScope, "g2Neg", IRNativeTag.bls12_381_G2_neg, new TirFuncT([g2_t], g2_t), blsNs);
196
199
  defineBuiltin(blsNsScope, "g2ScalarMul", IRNativeTag.bls12_381_G2_scalarMul, new TirFuncT([int_t, g2_t], g2_t), blsNs);
@@ -98,7 +98,7 @@ export declare enum DiagnosticCode {
98
98
  _context_can_only_be_destructured_in_a_constant_declaration = 292,
99
99
  _context_can_only_be_accessed_in_a_contract_method = 293,
100
100
  _this_in_a_contract_context_can_only_be_used_to_read_parameters_in_a_contract_method = 293,
101
- _0_is_not_aviable_in_this_contract_method_context = 294,
101
+ _0_is_not_available_in_this_contract_method_context = 294,
102
102
  _context_can_only_be_destructured_as_an_unnamed_object = 295,
103
103
  _0_is_not_a_contract_parameter = 296,
104
104
  Importing_the_table_disables_some_indirect_call_optimizations = 901,
@@ -100,7 +100,7 @@ export var DiagnosticCode;
100
100
  DiagnosticCode[DiagnosticCode["_context_can_only_be_destructured_in_a_constant_declaration"] = 292] = "_context_can_only_be_destructured_in_a_constant_declaration";
101
101
  DiagnosticCode[DiagnosticCode["_context_can_only_be_accessed_in_a_contract_method"] = 293] = "_context_can_only_be_accessed_in_a_contract_method";
102
102
  DiagnosticCode[DiagnosticCode["_this_in_a_contract_context_can_only_be_used_to_read_parameters_in_a_contract_method"] = 293] = "_this_in_a_contract_context_can_only_be_used_to_read_parameters_in_a_contract_method";
103
- DiagnosticCode[DiagnosticCode["_0_is_not_aviable_in_this_contract_method_context"] = 294] = "_0_is_not_aviable_in_this_contract_method_context";
103
+ DiagnosticCode[DiagnosticCode["_0_is_not_available_in_this_contract_method_context"] = 294] = "_0_is_not_available_in_this_contract_method_context";
104
104
  DiagnosticCode[DiagnosticCode["_context_can_only_be_destructured_as_an_unnamed_object"] = 295] = "_context_can_only_be_destructured_as_an_unnamed_object";
105
105
  DiagnosticCode[DiagnosticCode["_0_is_not_a_contract_parameter"] = 296] = "_0_is_not_a_contract_parameter";
106
106
  DiagnosticCode[DiagnosticCode["Importing_the_table_disables_some_indirect_call_optimizations"] = 901] = "Importing_the_table_disables_some_indirect_call_optimizations";
@@ -393,7 +393,7 @@ export function diagnosticCodeToString(code) {
393
393
  case 292: return "`context` can only be destructured in a constant declaration.";
394
394
  case 293: return "`context` can only be accessed in a contract method.";
395
395
  case 293: return "`this`, in a contract context, can only be used to read parameters in a contract method.";
396
- case 294: return "`{0}` is not aviable in this contract method `context`.";
396
+ case 294: return "`{0}` is not available in this contract method `context`.";
397
397
  case 295: return "`context` can only be destructured as an unnamed object.";
398
398
  case 296: return "'{0}' is not a contract parameter.";
399
399
  case 901: return "Importing the table disables some indirect call optimizations.";
@@ -1 +1 @@
1
- export declare const COMPILER_VERSION = "0.3.4";
1
+ export declare const COMPILER_VERSION = "0.3.5";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated by scripts/genVersion.js. Do not edit.
2
- export const COMPILER_VERSION = "0.3.4";
2
+ export const COMPILER_VERSION = "0.3.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",