Skip to content

Commit

Permalink
Investigating reasons for tapecalc stalling
Browse files Browse the repository at this point in the history
Delaney's large grammar is stalling during loading, so I added some console logs to see what's up.  (Turns out you CAN view the logs from Google's servers, they're in the project space under Executions.)

It's a bit hard to debug this way (seems like Google occasionally loses log lines), but the problem seems to be during tapecalc, probably during getTapesQualified, and within that the getTapesDefault stage at the end.  This stage is, I think, ultimately semantically unnecessary, but if I remember correctly a few of our tests fail if you don't do this.  I'm going to dig into what's up with those tests next (maybe those tests are wrong or testing something inappropriate).

But for now, some other tests have failed, so I'm committing what I have and going back to main to see when exactly things started failing.
  • Loading branch information
littell committed Aug 14, 2024
1 parent ee1d7ca commit e496bec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
44 changes: 37 additions & 7 deletions packages/interpreter/src/passes/calculateTapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,19 @@ export class CalculateTapes extends AutoPass<Grammar> {
getTapesQualified(g: QualifiedGrammar, env: TapesEnv): Msg<Grammar> {
const msgs: Message[] = [];

console.log(`calculating tapes of Qualified`);

while (true) {
const newMsgs: Message[] = [];

// first get the initial tapes for each symbol
let tapeIDs: TapeDict = mapValues(g.symbols, v => v.tapes);

console.log(tapeIDs);

tapeIDs = Tapes.resolveAll(tapeIDs);

console.log('resolved');
// check for unresolved content, and throw an exception immediately.
// otherwise we have to puzzle it out from exceptions elsewhere.
for (const [k,v] of Object.entries(tapeIDs)) {
Expand All @@ -185,13 +190,22 @@ export class CalculateTapes extends AutoPass<Grammar> {
//const tapePusher = new CalculateTapes(true, tapeIDs);

const tapePushEnv = new TapesEnv(env.opt, true, tapeIDs);
g.symbols = mapValues(g.symbols, v =>
this.transform(v, tapePushEnv).msgTo(newMsgs));

for (const [k, v] of Object.entries(g.symbols)) {
console.log(`pushing tape results into ${k}`);
const transformed = this.transform(v, tapePushEnv).msgTo(newMsgs);
g.symbols[k] = transformed;
}

//g.symbols = mapValues(g.symbols, v =>
// this.transform(v, tapePushEnv).msgTo(newMsgs));

msgs.push(...newMsgs);

if (newMsgs.length === 0) break;

console.log(`found errors, recalculating: ${newMsgs}`);

// if there are any errors, the graph may have changed. we
// need to restart the process from scratch.
//const TapeRefresher = new CalculateTapes(true);
Expand All @@ -201,13 +215,17 @@ export class CalculateTapes extends AutoPass<Grammar> {
this.transform(v, tapeRefreshEnv).msgTo(newMsgs));
}

console.log(`done with qual`);

//return updateTapes(g, Tapes.Lit()).msg(msgs);

// TODO: The following interpretation of tapes is incorrect,
// but matches what we've been doing previously. I'm going to
// get it "working" exactly like the old way, before fixing it to be
// semantically sound.
return getTapesDefault(g).msg(msgs);
const result = getTapesDefault(g, true).msg(msgs);
console.log(`done with default`);
return result;

}
}
Expand All @@ -216,16 +234,28 @@ function updateTapes(g: Grammar, tapes: TapeSet): Grammar {
return update(g, { tapes });
}

function getChildTapes(g: Grammar): TapeSet {
const childTapes = children(g).map(c => c.tapes);
function getChildTapes(g: Grammar, verbose: boolean = false): TapeSet {
const childTapes: TapeSet[] = [];
const cs = children(g);
if (verbose) console.log(`grammar has ${cs.length} children`);
for (const child of cs) {
const tapes = child.tapes;
if (verbose) {
console.log(`tapes of child ${child.tag}`);
}
childTapes.push(tapes);
}

// const childTapes = children(g).map(c => c.tapes);
if (childTapes.length === 0) return Tapes.Lit();
return foldRight(childTapes.slice(1), Tapes.Sum, childTapes[0]);
}

function getTapesDefault(
g: Grammar
g: Grammar,
verbose: boolean = false
): Grammar {
return updateTapes(g, getChildTapes(g));
return updateTapes(g, getChildTapes(g, verbose));
}

function getTapesShort(g: ShortGrammar): Grammar {
Expand Down
5 changes: 4 additions & 1 deletion packages/sheets_addon/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ class GoogleSheetsDevEnvironment {
}

loadSource(sheetName) {
console.log(`loading ${sheetName}`);
let sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
if (sheet == undefined) {
throw new Error(`There is no sheet named ${sheetName}`);
}
console.log(`loaded ${sheetName}`);
const range = sheet.getDataRange();
const values = range.getDisplayValues();
return values;
Expand Down Expand Up @@ -311,7 +313,8 @@ function makeInterpreter() {
const sheetName = sheet.getName();

const devEnv = new GoogleSheetsDevEnvironment(sheetName);
const interpreter = gramble.Interpreter.fromSheet(devEnv, sheetName);
const opts = { verbose: gramble.VERBOSE_TIME };
const interpreter = gramble.Interpreter.fromSheet(devEnv, sheetName, opts);
return [interpreter, devEnv];
}

Expand Down

0 comments on commit e496bec

Please sign in to comment.