Skip to content

[record_use] (De)serialization context#3107

Open
dcharkes wants to merge 1 commit intomainfrom
record-use-de-serialization-context
Open

[record_use] (De)serialization context#3107
dcharkes wants to merge 1 commit intomainfrom
record-use-de-serialization-context

Conversation

@dcharkes
Copy link
Collaborator

Organize the serialization/deserialization with a context object:

@dcharkes dcharkes requested a review from goderbauer February 16, 2026 15:09
@github-actions
Copy link

github-actions bot commented Feb 16, 2026

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
record_use Breaking 0.4.2 0.5.0-wip 0.5.0-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/test/debug_release_test.dart
pkgs/objective_c/example/command_line/lib/main.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

@coveralls
Copy link

coveralls commented Feb 16, 2026

Coverage Status

coverage: 78.184% (+0.006%) from 78.178%
when pulling c9d07a1 on record-use-de-serialization-context
into 938b861 on main.

@dcharkes dcharkes force-pushed the record-use-de-serialization-context branch from d887446 to 3f7fd4b Compare February 17, 2026 07:18
/// This library defines the context objects used for serialization
/// and deserialization of normalized JSON.
///
/// ### Layer Responsibilities
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to relate this back to the code. Where would I find the implementation of the syntax layer and semantics layer? Can you leave some breadcrumbs in the doc?

Comment on lines 26 to 27
/// 1. **Constants**: Resolved first.
/// 2. **Recordings**: Resolved last. References Constants.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What constants and recordings is this referring to? The objects below only have constants. Can you leave some breadcrumbs in the doc so future readers know what this is referring to?


import 'constant.dart';

/// The final deserialization state where all pools are resolved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document: What is a pool in this context? (I don't think we've used that term before in record_use?)


/// The final serialization state where all index maps are available.
final class SerializationContext {
final Map<Constant, int> constants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this. What does the int represent?


factory Recordings._fromSyntax(RecordedUsesSyntax syntax) {
final constants = <Constant>[];
final context = DeserializationContext(constants: constants);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon first reading through this PR I was confused that nothing appears to ever be added to this context. That made me wonder: Is there ever a reason to construct a DeserializationContext with a non-empty constants list? If not, maybe DeserializationContext.constants should just be internally initialized to an empty lists to remove the constructor argument and this code should be refactored to do context.constants.add to make it explicit that we are adding to the context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe I should have folded the follow up PR into this. There I add a comment about this.

The interesting thing is that the serialization is able to do it without mutation because we create the mapping from semantic objects to indices, and then use those indices for the syntax objects. So that can go in one batch. And I tried to keep the contexts mirroring each other for serialization and deserialization. So it feels kind of off to initialize with a mutable list for one but not for the other.

We might want to change this code again, because currently the order is non-determenistic:

@dcharkes dcharkes force-pushed the record-use-de-serialization-context branch from 3f7fd4b to 56d73b7 Compare February 17, 2026 14:08
@dcharkes dcharkes requested a review from goderbauer February 17, 2026 14:09
@dcharkes dcharkes force-pushed the record-use-de-serialization-context branch from 56d73b7 to 851504c Compare February 17, 2026 14:13
@dcharkes dcharkes force-pushed the record-use-de-serialization-context branch from 851504c to c9d07a1 Compare February 17, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants