Skip to content

Commit

Permalink
Fix post-rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ileasile committed Sep 13, 2021
1 parent e4984ae commit 001534c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
9 changes: 4 additions & 5 deletions src/main/kotlin/org/jetbrains/kotlinx/jupyter/apiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class NotebookImpl(
private var currentCellVariables = mapOf<Int, Set<String>>()
private val history = arrayListOf<CodeCellImpl>()
private var mainCellCreated = false
private val unchangedVariables: MutableSet<String> = mutableSetOf()
private val _unchangedVariables: MutableSet<String> = mutableSetOf()

val unchangedVariables: Set<String> get() = _unchangedVariables
val displays = DisplayContainerImpl()

override fun getAllDisplays(): List<DisplayResultWithCell> {
Expand All @@ -148,16 +149,14 @@ class NotebookImpl(
fun updateVariablesState(evaluator: InternalEvaluator) {
variablesState += evaluator.variablesHolder
currentCellVariables = evaluator.cellVariables
unchangedVariables.clear()
unchangedVariables.addAll(evaluator.getUnchangedVariables())
_unchangedVariables.clear()
_unchangedVariables.addAll(evaluator.getUnchangedVariables())
}

fun updateVariablesState(varsStateUpdate: Map<String, VariableState>) {
variablesState += varsStateUpdate
}

fun unchangedVariables(): Set<String> = unchangedVariables

fun variablesReportAsHTML(): String {
return generateHTMLVarsReport(variablesState)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/jetbrains/kotlinx/jupyter/protocol.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fun JupyterConnection.Socket.shellMessagesHandler(msg: Message, repl: ReplForJup
val data = content.data ?: return sendWrapped(msg, makeReplyMessage(msg, MessageType.SERIALIZATION_REPLY))

val messageContent = getVariablesDescriptorsFromJson(data)
GlobalScope.launch(Dispatchers.Default) {
connection.launchJob {
repl.serializeVariables(
messageContent.topLevelDescriptorName,
messageContent.descriptorsState,
Expand All @@ -340,7 +340,7 @@ fun JupyterConnection.Socket.shellMessagesHandler(msg: Message, repl: ReplForJup
}
}
is SerializationRequest -> {
GlobalScope.launch(Dispatchers.Default) {
connection.launchJob {
if (content.topLevelDescriptorName.isNotEmpty()) {
repl.serializeVariables(content.topLevelDescriptorName, content.descriptorsState, content.pathToDescriptor) { result ->
sendWrapped(msg, makeReplyMessage(msg, MessageType.SERIALIZATION_REPLY, content = result))
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,10 @@ class ReplForJupyterImpl(
val newImports: List<String>
val oldDeclarations: MutableMap<String, Int> = mutableMapOf()
oldDeclarations.putAll(internalEvaluator.getVariablesDeclarationInfo())
val jupyterId = evalData.jupyterId
val result = try {
log.debug("Current cell id: ${evalData.jupyterId}")
executor.execute(evalData.code, evalData.displayHandler, currentCellId = evalData.jupyterId - 1) { internalId, codeToExecute ->
log.debug("Current cell id: $jupyterId")
executor.execute(evalData.code, evalData.displayHandler, currentCellId = jupyterId - 1) { internalId, codeToExecute ->
if (evalData.storeHistory) {
cell = notebook.addCell(internalId, codeToExecute, EvalData(evalData))
}
Expand Down Expand Up @@ -444,7 +445,7 @@ class ReplForJupyterImpl(
// printVars()
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
val variablesCells: Map<String, Int> = notebook.variablesState.mapValues { internalEvaluator.findVariableCell(it.key) }
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState, oldDeclarations, variablesCells, notebook.unchangedVariables())
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState, oldDeclarations, variablesCells, notebook.unchangedVariables)

GlobalScope.launch(Dispatchers.Default) {
variablesSerializer.tryValidateCache(jupyterId - 1, notebook.cellVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,14 @@ class ReplVarsTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 1
)
var state = repl.notebook.unchangedVariables()
var state = repl.notebook.unchangedVariables
val res = eval(
"""
l += 11111
""".trimIndent(),
jupyterId = 2
).metadata.evaluatedVariablesState
state = repl.notebook.unchangedVariables()
state = repl.notebook.unchangedVariables
assertEquals(1, state.size)
assertTrue(state.contains("m"))
}
Expand Down Expand Up @@ -911,7 +911,7 @@ class ReplVarsTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 1
)
var state = repl.notebook.unchangedVariables()
var state = repl.notebook.unchangedVariables
assertEquals(3, state.size)

eval(
Expand All @@ -922,7 +922,7 @@ class ReplVarsTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 2
)
state = repl.notebook.unchangedVariables()
state = repl.notebook.unchangedVariables
assertEquals(0, state.size)

eval(
Expand All @@ -931,7 +931,7 @@ class ReplVarsTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 3
)
state = repl.notebook.unchangedVariables()
state = repl.notebook.unchangedVariables
assertEquals(1, state.size)
}
}
Expand Down Expand Up @@ -967,7 +967,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
assertEquals(listOf(1, 2, 3, 4).toString().substring(1, actualContainer.value!!.length + 1), actualContainer.value)

val serializer = repl.variablesSerializer
val newData = serializer.doIncrementalSerialization(0, "x", "data", actualContainer)
serializer.doIncrementalSerialization(0, "x", "data", actualContainer)
}

@Test
Expand All @@ -983,7 +983,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
assertEquals(2, varsData.size)
assertTrue(varsData.containsKey("x"))
assertTrue(varsData.containsKey("f"))
var unchangedVariables = repl.notebook.unchangedVariables()
var unchangedVariables = repl.notebook.unchangedVariables
assertTrue(unchangedVariables.isNotEmpty())

eval(
Expand All @@ -992,7 +992,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 1
)
unchangedVariables = repl.notebook.unchangedVariables()
unchangedVariables = repl.notebook.unchangedVariables
assertTrue(unchangedVariables.contains("x"))
assertTrue(unchangedVariables.contains("f"))
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {

val serializer = repl.variablesSerializer

val newData = serializer.doIncrementalSerialization(0, "c", "i", descriptor["i"]!!)
serializer.doIncrementalSerialization(0, "c", "i", descriptor["i"]!!)
}

@Test
Expand Down Expand Up @@ -1345,7 +1345,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 1
)
var state = repl.notebook.unchangedVariables()
val state = repl.notebook.unchangedVariables
val setOfCell = setOf("x", "f", "z")
assertTrue(state.isNotEmpty())
assertEquals(setOfCell, state)
Expand All @@ -1372,7 +1372,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 1
)
val state = repl.notebook.unchangedVariables()
var state = repl.notebook.unchangedVariables
val setOfCell = setOf("x", "f", "z")
assertTrue(state.isNotEmpty())
assertEquals(setOfCell, state)
Expand All @@ -1396,7 +1396,7 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 3
)
state = repl.notebook.unchangedVariables()
state = repl.notebook.unchangedVariables
// assertTrue(state.isNotEmpty())
// assertEquals(state, setOfPrevCell)

Expand All @@ -1408,20 +1408,20 @@ class ReplVarsSerializationTest : AbstractSingleReplTest() {
""".trimIndent(),
jupyterId = 4
)
state = repl.notebook.unchangedVariables()
state = repl.notebook.unchangedVariables
assertTrue(state.isEmpty())
}

@Test
fun testSerializationClearInfo() {
var res = eval(
eval(
"""
val x = listOf(1, 2, 3, 4)
""".trimIndent(),
jupyterId = 1
).metadata.evaluatedVariablesState
var state = repl.notebook.unchangedVariables()
res = eval(
repl.notebook.unchangedVariables
eval(
"""
val x = listOf(1, 2, 3, 4)
""".trimIndent(),
Expand Down

0 comments on commit 001534c

Please sign in to comment.