From a8efd66fa3b916a9fec0f2fd1d7263faf268b2e0 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Fri, 26 Aug 2022 02:01:27 +0200 Subject: [PATCH] handle topology changes in the project --- .../ReducerProject/ReducerProject.res | 26 ++++++++++++++----- .../ReducerProject/ReducerProject_T.res | 9 ++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res index 5f2fdce0..49571ff9 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res @@ -24,22 +24,35 @@ module Private = { let createProject = () => { let project: t = { - "tag": "reducerProject", + "iAmProject": true, "items": Belt.Map.String.empty, "stdLib": ReducerInterface_StdLib.internalStdLib, "environment": InternalExpressionValue.defaultEnvironment, + "previousRunOrder": [], } project } - let rec touchSource = (project: t, sourceId: string): unit => { + let rec touchSource_ = (project: t, sourceId: string): unit => { let item = project->getItem(sourceId) let newItem = ProjectItem.touchSource(item) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) - touchDependents(project, sourceId) } and touchDependents = (project: t, sourceId: string): unit => { - let _ = getDependents(project, sourceId)->Belt.Array.forEach(_, touchSource(project, _)) + let _ = getDependents(project, sourceId)->Belt.Array.forEach(_, touchSource_(project, _)) + } + + let touchSource = (project: t, sourceId: string): unit => { + touchSource_(project, sourceId) + touchDependents(project, sourceId) + } + + let handleNewTopology = (project: t): unit => { + let previousRunOrder = project["previousRunOrder"] + let currentRunOrder = Topology.getRunOrder(project) + let diff = Topology.runOrderDiff(currentRunOrder, previousRunOrder) + Belt.Array.forEach(diff, touchSource(project, _)) + T.Private.setFieldPreviousRunOrder(project, currentRunOrder) } let getSource = (project: t, sourceId: string): option => @@ -73,7 +86,7 @@ module Private = { let setContinues = (project: t, sourceId: string, continues: array): unit => { let newItem = project->getItem(sourceId)->ProjectItem.setContinues(continues) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) - touchSource(project, sourceId) + handleNewTopology(project) } let getContinues = (project: t, sourceId: string): array => ProjectItem.getContinues(project->getItem(sourceId)) @@ -81,7 +94,7 @@ module Private = { let removeContinues = (project: t, sourceId: string): unit => { let newItem = project->getItem(sourceId)->ProjectItem.removeContinues Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) - touchSource(project, sourceId) + handleNewTopology(project) } let getContinuation = (project: t, sourceId: string): ProjectItem.T.continuationArgumentType => @@ -113,6 +126,7 @@ module Private = { let parseIncludes = (project: t, sourceId: string): unit => { let newItem = project->getItem(sourceId)->ProjectItem.parseIncludes Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) + handleNewTopology(project) } let rawParse = (project: t, sourceId): unit => { diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res index a9411c43..e1ec91f4 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res @@ -3,17 +3,18 @@ module ExpressionT = Reducer_Expression_T module ProjectAccessorsT = ReducerProject_ProjectAccessors_T @genType.opaque -type project = {"tag": string} +type project = {"iAmProject": bool} //re-export @genType type t = project module Private = { type internalProject = { - "tag": string, + "iAmProject": bool, "items": Belt.Map.String.t, "stdLib": Reducer_Bindings.t, "environment": ExpressionT.environment, + "previousRunOrder": array, } type t = internalProject @@ -22,7 +23,9 @@ module Private = { @set external setFieldStdLib: (t, Reducer_Bindings.t) => unit = "stdLib" @set - external setFieldEnvironment: (t, ExpressionT.environment) => unit = "stdLib" + external setFieldEnvironment: (t, ExpressionT.environment) => unit = "environment" + @set + external setFieldPreviousRunOrder: (t, array) => unit = "previousRunOrder" external castFromInternalProject: t => project = "%identity" external castToInternalProject: project => t = "%identity"