-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate boxing of protocol types for serialization #2330
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 36 additions & 26 deletions
62
redwood-protocol-guest/api/redwood-protocol-guest.klib.api
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,54 +36,54 @@ import kotlinx.serialization.json.Json | |
* | ||
* This interface is for generated code use only. | ||
*/ | ||
public interface GuestProtocolAdapter : EventSink { | ||
public abstract class GuestProtocolAdapter : EventSink { | ||
@RedwoodCodegenApi | ||
public val json: Json | ||
public abstract val json: Json | ||
|
||
/** | ||
* Host versions prior to 0.10.0 contained a bug where they did not recursively remove widgets | ||
* from the protocol map which leaked any child views of a removed node. We can work around this | ||
* on the guest side by synthesizing removes for every node in the subtree. | ||
*/ | ||
@RedwoodCodegenApi | ||
public val synthesizeSubtreeRemoval: Boolean | ||
public abstract val synthesizeSubtreeRemoval: Boolean | ||
|
||
/** | ||
* The provider of factories of widgets which record property changes and whose children changes | ||
* are also recorded. You **must** attach returned widgets to [root] or the children of a widget | ||
* in the tree beneath [root] in order for it to be tracked. | ||
*/ | ||
public val widgetSystem: WidgetSystem<Unit> | ||
public abstract val widgetSystem: WidgetSystem<Unit> | ||
|
||
/** | ||
* The root of the widget tree onto which [widgetSystem]-produced widgets can be added. Changes to | ||
* this instance are recorded as changes to [Id.Root] and [ChildrenTag.Root]. | ||
*/ | ||
public val root: Widget.Children<Unit> | ||
public abstract val root: Widget.Children<Unit> | ||
|
||
public fun initChangesSink(changesSink: ChangesSink) | ||
public abstract fun initChangesSink(changesSink: ChangesSink) | ||
|
||
public fun emitChanges() | ||
public abstract fun emitChanges() | ||
|
||
@RedwoodCodegenApi | ||
public fun nextId(): Id | ||
public abstract fun nextId(): Id | ||
|
||
@RedwoodCodegenApi | ||
public fun appendCreate( | ||
public abstract fun appendCreate( | ||
id: Id, | ||
tag: WidgetTag, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun <T> appendPropertyChange( | ||
public abstract fun <T> appendPropertyChange( | ||
id: Id, | ||
tag: PropertyTag, | ||
serializer: KSerializer<T>, | ||
value: T, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun appendPropertyChange( | ||
public abstract fun appendPropertyChange( | ||
id: Id, | ||
tag: PropertyTag, | ||
value: Boolean, | ||
|
@@ -97,28 +97,28 @@ public interface GuestProtocolAdapter : EventSink { | |
* https://github.com/Kotlin/kotlinx.serialization/issues/2713 | ||
*/ | ||
@RedwoodCodegenApi | ||
public fun appendPropertyChange( | ||
public abstract fun appendPropertyChange( | ||
id: Id, | ||
tag: PropertyTag, | ||
value: UInt, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun appendModifierChange( | ||
public abstract fun appendModifierChange( | ||
id: Id, | ||
value: Modifier, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun appendAdd( | ||
public abstract fun appendAdd( | ||
id: Id, | ||
tag: ChildrenTag, | ||
index: Int, | ||
child: ProtocolWidget, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun appendMove( | ||
public abstract fun appendMove( | ||
id: Id, | ||
tag: ChildrenTag, | ||
fromIndex: Int, | ||
|
@@ -127,14 +127,44 @@ public interface GuestProtocolAdapter : EventSink { | |
) | ||
|
||
@RedwoodCodegenApi | ||
public fun appendRemove( | ||
public abstract fun appendRemove( | ||
id: Id, | ||
tag: ChildrenTag, | ||
index: Int, | ||
count: Int, | ||
removedIds: List<Id> = listOf(), | ||
removedIds: List<Id>, | ||
) | ||
|
||
@RedwoodCodegenApi | ||
public fun removeWidget(id: Id) | ||
public abstract fun removeWidget(id: Id) | ||
|
||
@RedwoodCodegenApi | ||
public val childrenVisitor: ProtocolWidget.ChildrenVisitor = if (synthesizeSubtreeRemoval) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allocate only once, rather than once per children wrapper. |
||
object : ProtocolWidget.ChildrenVisitor { | ||
override fun visit( | ||
parent: ProtocolWidget, | ||
childrenTag: ChildrenTag, | ||
children: ProtocolWidgetChildren, | ||
) { | ||
// This boxes Id values. Don't bother optimizing since it only serves very old hosts. | ||
val childIds = children.widgets.map(ProtocolWidget::id) | ||
for (childId in childIds) { | ||
removeWidget(childId) | ||
} | ||
appendRemove(parent.id, childrenTag, 0, childIds.size, childIds) | ||
} | ||
} | ||
} else { | ||
object : ProtocolWidget.ChildrenVisitor { | ||
override fun visit( | ||
parent: ProtocolWidget, | ||
childrenTag: ChildrenTag, | ||
children: ProtocolWidgetChildren, | ||
) { | ||
for (childWidget in children.widgets) { | ||
removeWidget(childWidget.id) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused boxing of the
Id
andChildrenTag
in JS if the caller omitted this last argument and relied on the default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can validate boxing doesn't occur in a test case? Or is it only possible when inspecting the generated code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll think about it. You definitely can see the boxing in a full compiler plugin, and maybe in FIR only. Probably also as a lint check.
Filed #2336