From 873e1c3ba8baba3e747be4a571f7e91e148ce89c Mon Sep 17 00:00:00 2001 From: Patrick Ferris Date: Sat, 26 Oct 2024 11:13:13 +0100 Subject: [PATCH] Prepare for 5.2 AST bump --- src/trace_atd.ts | 50 +++++++++++++++++++++++------------------- trace/ppx/trace_ppx.ml | 14 +++++++++--- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/trace_atd.ts b/src/trace_atd.ts index 7bf7fa827..aebe96087 100644 --- a/src/trace_atd.ts +++ b/src/trace_atd.ts @@ -1,18 +1,24 @@ -// Generated by atdts from type definitions in 'trace.atd'. -// -// Type-safe translations from/to JSON -// -// For each type 'Foo', there is a pair of functions: -// - 'writeFoo': convert a 'Foo' value into a JSON-compatible value. -// - 'readFoo': convert a JSON-compatible value into a TypeScript value -// of type 'Foo'. +/* + Generated by atdts from type definitions in 'trace.atd'. + Type-safe translations from/to JSON + + For each type 'Foo', there is a pair of functions: + - 'writeFoo': convert a 'Foo' value into a JSON-compatible value. + - 'readFoo': convert a JSON-compatible value into a TypeScript value + of type 'Foo'. +*/ + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck +/* tslint:disable */ +/* eslint-disable */ export type Item = { kind: Kind[]; - goal_id: Int; - runtime_id: Int; - step: Int; + goal_id: number /*int*/; + runtime_id: number /*int*/; + step: number /*int*/; name: string; payload: string[]; } @@ -89,9 +95,9 @@ export type Location = export type FileLocation = { filename: string; - line: Int; - column: Int; - character: Int; + line: number /*int*/; + column: number /*int*/; + character: number /*int*/; } export type Event = @@ -124,11 +130,11 @@ export type Frame = { runtime_id: RuntimeId; } -export type GoalId = Int +export type GoalId = number /*int*/ -export type StepId = Int +export type StepId = number /*int*/ -export type RuntimeId = Int +export type RuntimeId = number /*int*/ export type GoalText = string @@ -786,8 +792,6 @@ export function readChrText(x: any, context: any = x): ChrText { // Runtime library ///////////////////////////////////////////////////////////////////// -export type Int = number - export type Option = null | { value: T } function _atd_missing_json_field(type_name: string, json_field_name: string) { @@ -820,7 +824,7 @@ function _atd_bad_ts(expected_type: string, ts_value: any, context: any) { ` Occurs in '${JSON.stringify(context)}'.`) } -function _atd_check_json_tuple(len: Int, x: any, context: any) { +function _atd_check_json_tuple(len: number /*int*/, x: any, context: any) { if (! Array.isArray(x) || x.length !== len) _atd_bad_json('tuple of length ' + len, x, context); } @@ -843,7 +847,7 @@ function _atd_read_bool(x: any, context: any): boolean { } } -function _atd_read_int(x: any, context: any): Int { +function _atd_read_int(x: any, context: any): number /*int*/ { if (Number.isInteger(x)) return x else { @@ -1024,7 +1028,7 @@ function _atd_write_bool(x: any, context: any): boolean { } } -function _atd_write_int(x: any, context: any): Int { +function _atd_write_int(x: any, context: any): number /*int*/ { if (Number.isInteger(x)) return x else { @@ -1133,7 +1137,7 @@ function _atd_write_required_field(type_name: string, } function _atd_write_optional_field(write_elt: (x: T, context: any) => any, - x: T, + x: T | undefined, context: any): any { if (x === undefined || x === null) return x diff --git a/trace/ppx/trace_ppx.ml b/trace/ppx/trace_ppx.ml index 5727b37ae..3c3302bf5 100644 --- a/trace/ppx/trace_ppx.ml +++ b/trace/ppx/trace_ppx.ml @@ -173,9 +173,17 @@ let map_trace = object(self) let args = List.map (fun (x,y) -> x, self#expression y) args in if args = [] then hd else { e with pexp_desc = Pexp_apply (hd,args)} - | Pexp_fun(_,_,pat,rest) when not !enabled -> - let has_iftrace { ppat_attributes = l; _ } = has_iftrace_attribute l in - if has_iftrace pat then self#expression rest + | Pexp_function (param :: params, constraint_, rest) when not !enabled -> + let has_iftrace_pat { ppat_attributes = l; _ } = has_iftrace_attribute l in + let has_iftrace_param = function + | { pparam_desc = Pparam_val (_, _, pat); _ } -> has_iftrace_pat pat + | _ -> false + in + if has_iftrace_param param then begin + match params, rest with + | [], Pfunction_body exp -> self#expression exp + | _ -> self#expression { e with pexp_desc = Pexp_function (params, constraint_, rest) } + end else e | Pexp_let(_,[{pvb_pat = { ppat_attributes = l; _}; _}],rest) when not !enabled -> if has_iftrace_attribute l then self#expression rest