[be] Skip debug logging if content has not changed

Avoids printing debug information if it exactly matches what was last printed. 
This means when debug printing (eg with `@only`) you'll see things like: 

``` 

BuildReactiveFunctions: 

...debug view... 

FlattenReactiveLoops: (no change) 

PropagateScopeDependencies: 

...debug view... 

``` 

Which saves time figuring out if something changed in a given pass.
This commit is contained in:
Joe Savona
2023-01-17 16:00:42 -08:00
parent 8a15b65e1a
commit de83adc739
+29 -3
View File
@@ -11,20 +11,46 @@ import { printReactiveFunction } from "../ReactiveScopes";
let ENABLED: boolean = false;
let lastLogged: string;
export function toggleLogging(enabled: boolean) {
ENABLED = enabled;
}
export function logHIR(step: string, ir: HIR): void {
log(() => `${step}:\n${printHIR(ir)}`);
if (ENABLED) {
const printed = printHIR(ir);
if (printed !== lastLogged) {
lastLogged = printed;
process.stdout.write(`${step}:\n${printed}\n\n`);
} else {
process.stdout.write(`${step}: (no change)\n\n`);
}
}
}
export function logHIRFunction(step: string, fn: HIRFunction): void {
log(() => `${step}:\n${printFunction(fn)}`);
if (ENABLED) {
const printed = printFunction(fn);
if (printed !== lastLogged) {
lastLogged = printed;
process.stdout.write(`${step}:\n${printed}\n\n`);
} else {
process.stdout.write(`${step}: (no change)\n\n`);
}
}
}
export function logReactiveFunction(step: string, fn: ReactiveFunction): void {
log(() => `${step}:\n${printReactiveFunction(fn)}`);
if (ENABLED) {
const printed = printReactiveFunction(fn);
if (printed !== lastLogged) {
lastLogged = printed;
process.stdout.write(`${step}:\n${printed}\n\n`);
} else {
process.stdout.write(`${step}: (no change)\n\n`);
}
}
}
export function log(fn: () => string) {