Skip to content

Commit

Permalink
Better causality error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-serrano committed Dec 7, 2023
1 parent 6db2727 commit b5ea674
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 33 deletions.
10 changes: 4 additions & 6 deletions lib/bourdoncle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ------------------------------------------------------------- */
/* Author : Jayanth Krishnamurthy */
/* Creation : Tue Jul 9 11:59:33 2019 */
/* Last change : Mon Dec 4 08:21:54 2023 (serrano) */
/* Last change : Thu Dec 7 16:32:30 2023 (serrano) */
/* Copyright : 2020-23 Inria */
/* ------------------------------------------------------------- */
/* HipHop causality error messages */
Expand Down Expand Up @@ -202,7 +202,7 @@ function findCausalityErrorDeep(machine, compilePhase = false) {
tccLocInfo[ solComponent[ i ].debug_id ] = tcc_loc[ i ];
}

let { cycle,posFlag }= findCycleLength(tccLocInfo);
let { cycle, posFlag }= findCycleLength(tccLocInfo);
cycle.len = cycle.length;
let tempFileList = [];
let cycleLength = 0;
Expand Down Expand Up @@ -264,16 +264,14 @@ function findCausalityErrorDeep(machine, compilePhase = false) {
const finalResult = Object.keys(tarjanComponent)
.map(key => tarjanComponent[key]);

let myJSON = JSON.stringify(finalResult);

// remove nets.dfn and nets.head
cleanNets();

return {
loc: myJSON,
loc: false,
size: cycle.len,
signals: tempSignal,
json: myJSON,
json: JSON.stringify(finalResult),
posFlag: posFlag,
cycles: finalResult
}
Expand Down
4 changes: 2 additions & 2 deletions lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ------------------------------------------------------------- */
/* Author : Manuel Serrano */
/* Creation : Thu Aug 2 12:32:26 2018 */
/* Last change : Fri Dec 1 07:03:53 2023 (serrano) */
/* Last change : Thu Dec 7 15:04:50 2023 (serrano) */
/* Copyright : 2018-23 Manuel Serrano */
/* ------------------------------------------------------------- */
/* HipHop exception constructors. */
Expand Down Expand Up @@ -53,7 +53,7 @@ function HHTypeError(msg, loc) {
const stk = err.stack;
let i = stk.indexOf("\n");
let nstk = stk.substring(0, i);
nstk += `"\n at HipHop (file://${loc.filename}:${loc.pos})`
nstk += `\n at HipHop (file://${loc.filename}:${loc.pos})`
nstk += stk.substring(i);
err.stack = nstk;
}
Expand Down
47 changes: 34 additions & 13 deletions lib/machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ------------------------------------------------------------- */
/* Author : Manuel Serrano */
/* Creation : Tue Jul 17 08:19:22 2018 */
/* Last change : Thu Dec 7 14:37:13 2023 (serrano) */
/* Last change : Thu Dec 7 16:18:43 2023 (serrano) */
/* Copyright : 2018-23 Manuel Serrano */
/* ------------------------------------------------------------- */
/* HipHop reactive machines */
Expand Down Expand Up @@ -579,22 +579,25 @@ function react(mach) {
if (nonpropagated_nets > 0) {
const { loc, size, signals, json, cycles } = findCausalityError(mach);

if (hop.isServer) {
dumpCausalityError(json);
}

let nets = mach.nets.filter(n => !n.isInKnownList);

// Checking the error type
if (size > 0) {
if (mach.verbose >=0) {
console.error(`*** CAUSALITY ERROR: cycle of length ${size} detected, involving signals "${signals.join(', ')}"`);
if (cycles && hop.isServer) {
reportCausalityCycles(cycles);
if (mach.verbose >= 0) {
console.error(`*** CAUSALITY ERROR: cycle detected involving signals "${signals.join(', ')}"`);
if (hop.isServer) {
if (cycles.length > 0) {
reportCausalityCycles(cycles);
dumpCausalityError(json);
} else {
const { json: djson, cycles: dcycles } = findCausalityErrorDefault(mach);
reportCausalityCycles(dcycles);
dumpCausalityError(djson);
}
}
}
throw error.CausalityError("causality error");
} else {
let nets = mach.nets.filter(n => !n.isInKnownList);

throw error.CausalityError(`internal causality error: ${nets.map(n => n.debug_name).toString()}`, nets[0].ast_node.loc);
}
}
Expand Down Expand Up @@ -815,6 +818,23 @@ function findCausalityErrorDefault(machine) {
return res;
}

function findCycleSources() {
let nets = machine.nets.filter(n => !n.isInKnownList);
const cycles = {};
nets.forEach(nets => {
const { filename, pos } = nets.ast_node.loc;
if (typeof pos === "number") {
if (filename in cycles) {
cycles[filename].push(pos);
} else {
cycles[filename] = [pos];
}
}
});

return Object.keys(cycles).map(k => [{ filename: k, locations: cycles[k] }]);
}

function cycleSize(src) {
let stack = [];
let res = 0;
Expand All @@ -835,13 +855,14 @@ function findCausalityErrorDefault(machine) {
let head = nets.find(isCyclic);

if (head) {
const cycles = findCycleSources();
return {
loc: head.ast_node.loc,
size: cycleSize(head),
signals: findCycleSignals(head),
json: null,
json: JSON.stringify(cycles),
posFlag: undefined,
cycles: null
cycles: cycles
};
} else {
return {
Expand Down
32 changes: 20 additions & 12 deletions modules/http.hh.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*=====================================================================*/
/* serrano/prgm/project/hiphop/hiphop/modules/http.hh.js */
/* serrano/prgm/project/hiphop/1.3.x/modules/http.hh.js */
/* ------------------------------------------------------------- */
/* Author : manuel serrano */
/* Creation : Tue Jan 11 18:12:15 2022 */
/* Last change : Fri Sep 15 16:15:44 2023 (serrano) */
/* Last change : Thu Dec 7 14:55:48 2023 (serrano) */
/* Copyright : 2022-23 manuel serrano */
/* ------------------------------------------------------------- */
/* HTTP HipHop module. */
Expand All @@ -16,8 +16,9 @@
/*---------------------------------------------------------------------*/
import * as http from "http";
import * as https from "https";
import { parse } from "url";

export { request, HttpRequest };
export { httpRequest, HttpRequest };

/*---------------------------------------------------------------------*/
/* debug ... */
Expand All @@ -36,30 +37,37 @@ function debug_url(protocol, options) {
}

/*---------------------------------------------------------------------*/
/* Http ... */
/* HttpRequest ... */
/*---------------------------------------------------------------------*/
hiphop interface HttpRequest {
out result;
out response;
}

/*---------------------------------------------------------------------*/
/* request ... */
/*---------------------------------------------------------------------*/
hiphop module request(protocol, options, payload = undefined) implements HttpRequest {
hiphop module httpRequest(requestOrUrl, payload = undefined) implements HttpRequest {
let state = "active";
let buf = "";
let req = false;
let ended = false;
let res = undefined;
let self;

async (result) {
const proto = (protocol === "https" ? https : http);
async (response) {
let request;

if (typeof requestOrUrl === "string") {
request = parse(requestOrUrl);
} else {
request = requestOrUrl;
}
const proto = ((request?.protocol === "https:" ?? request?.protocol === "https") ? https : http);
self = this;
req = proto.request(options, _res => {
req = proto.request(request, _res => {
res = _res;
if (debug()) {
console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]",
console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]",
"statusCode: " + res.statusCode);
}
if (res.statusCode !== 200) {
Expand All @@ -70,7 +78,7 @@ hiphop module request(protocol, options, payload = undefined) implements HttpReq
res.buffer = buf;

if (debug()) {
console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]",
console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]",
"buf: [" + buf + "]");
}

Expand All @@ -92,7 +100,7 @@ hiphop module request(protocol, options, payload = undefined) implements HttpReq

req.on('error', error => {
if (debug()) {
console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]",
console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]",
"error: " + error);
}
if (state === "active") self.notify("error");
Expand Down

0 comments on commit b5ea674

Please sign in to comment.