Skip to content

Commit

Permalink
Corrected debugger behavior in the presence of reused values.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 6, 2024
1 parent d2ddaf6 commit f59632c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
We'll note all notable changes in this file, including bug fixes, enhancements, and all closed issues.
Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http://semver.org/) format.

## 0.12.2 2024-10-5

### Fixed

- Corrected debugger behavior in the presence of reused values.

## 0.12.1 2024-09-28

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wordplay",
"version": "0.12.0",
"version": "0.12.2",
"scripts": {
"postinstall": "run-script-os",
"postinstall:default": "svelte-kit sync && cp .env.template .env",
Expand Down
4 changes: 1 addition & 3 deletions src/components/annotations/Annotations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@
);
if (firstExpression) {
const value =
evaluator.getLatestExpressionValueInEvaluation(
firstExpression,
);
evaluator.getLatestExpressionValue(firstExpression);
if (value)
nodeView = document.querySelector(
`.value[data-id="${value.id}"]`,
Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@
.map((expr) => {
return {
expression: expr,
value: $evaluation.evaluator.getLatestExpressionValueInEvaluation(
value: $evaluation.evaluator.getLatestExpressionValue(
expr,
),
};
Expand Down
5 changes: 1 addition & 4 deletions src/components/editor/NodeView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
node instanceof Expression &&
!node.isEvaluationInvolved()
)
value =
$evaluation.evaluator.getLatestExpressionValueInEvaluation(
node,
);
value = $evaluation.evaluator.getLatestExpressionValue(node);
}
const blocks = isBlocks();
Expand Down
5 changes: 3 additions & 2 deletions src/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,14 @@ export default class Project {
/** Return true if the given expression is in this project and depends only on contants. */
isConstant(expression: Expression): boolean {
let constant = this.constants.get(expression);
const context = this.getNodeContext(expression);
// If we haven't visited this expression yet, compute it.
if (constant === undefined) {
// Mark this as not constant, assuming (and preventing) cycles.
this.constants.set(expression, false);
// Compute whether the expression is constant.
const context = this.getNodeContext(expression);
constant = expression.isConstant(context);
// Now actually compute whether it's constant.
// Cache the determination for later.
this.constants.set(expression, constant);
}
return constant;
Expand Down
5 changes: 3 additions & 2 deletions src/nodes/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ export default abstract class Expression extends Node {
evaluator: Evaluator,
): Markup;

/** Utility function for getting an optional result */
/** Utility function for getting an optional result */
getValueIfDefined(
locales: Locales,
context: Context,
evaluator: Evaluator,
) {
const value = evaluator.peekValue();
const value =
evaluator.peekValue() ?? evaluator.getLatestExpressionValue(this);
return value ? new ValueRef(value, locales, context) : undefined;
}

Expand Down
10 changes: 6 additions & 4 deletions src/runtime/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,15 @@ export default class Evaluator {
return this.getLatestSourceValue(this.project.getMain());
}

/** Evaluate until we're done */
/** Prepare for evaluation, and finish if playing. */
start(changedStreams?: StreamValue[], limit = true): void {
// If we're not done, finish first, if we were interrupted before.
if (!this.isDone()) this.finish();

// First, initialize any stream dependencies
// If there are changed streams, construct a set of affected expressions that need to be reevaluated.
// We'll reuse previous values for anything not affected.
if (changedStreams && !this.isInPast()) {
if (changedStreams && changedStreams.length > 0) {
this.#currentStreamDependencies = new Set();
for (const stream of changedStreams) {
const dependencies = this.#streamDependencies.get(
Expand Down Expand Up @@ -1131,8 +1131,10 @@ export default class Evaluator {
// Reset the project to the beginning of time (but preserve stream history, since that's stored in project).
this.resetForEvaluation(true, broadcast);

// Start the evaluation fresh.
this.start();
console.log('Step back to', change);

// Start the evaluation fresh, using the changed streams if we found any.
this.start(change ? change.changes.map((c) => c.stream) : undefined);

// Step until reaching the target step index.
while (this.#stepIndex < destinationStep) {
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/Finish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function finish(evaluator: Evaluator, expr: Expression) {
if (shouldSkip(evaluator, expr)) {
const priorValue = evaluator.getLatestExpressionValue(expr);
if (priorValue !== undefined) {
// Ask the evaluator to remember the value we computed.
// evaluator.rememberExpressionValue(expr, priorValue);
// Evaluate any side effects
return expr.evaluate(evaluator, priorValue);
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/Start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function start(evaluator: Evaluator, expr: Expression) {
shouldSkip(evaluator, expr) &&
evaluator.getLatestExpressionValue(expr)
) {
console.log('Skipping ' + expr.toWordplay());
// Ask the evaluator to jump past this start's corresponding finish.
evaluator.jumpPast(expr);
}
Expand All @@ -46,7 +47,7 @@ export function start(evaluator: Evaluator, expr: Expression) {
export function shouldSkip(evaluator: Evaluator, expr: Expression) {
return (
!expr.isInternal() &&
!evaluator.isInPast() &&
// !evaluator.isInPast() &&
(evaluator.project.isConstant(expr) ||
(evaluator.isReacting() &&
!evaluator.isEvaluatingReaction() &&
Expand Down

0 comments on commit f59632c

Please sign in to comment.