Skip to content
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

[Do not submit] Add model digest #131

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkgs/dart_model/lib/src/dart_model.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// This file is generated. To make changes edit tool/dart_model_generator
// then run from the repo root: dart tool/dart_model_generator/bin/main.dart

// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'dart:typed_data';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:crypto/crypto.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:dart_model/src/deep_cast_map.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
Expand Down Expand Up @@ -251,6 +255,11 @@ extension type Model.fromJson(Map<String, Object?> node) implements Object {
Scope.createGrowableMap(),
types,
));
// A digest of all the bytes in the current buffer.
Digest get digest => md5.convert(switch (node) {
MapInBuffer mapInBuffer => mapInBuffer.buffer.serialize(),
_ => (JsonBufferBuilder()..map.addAll(node)).serialize(),
});

/// Libraries by URI.
Map<String, Library> get uris =>
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_model/lib/src/json_buffer/iterables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _IteratorFunctionIterable<T> extends Iterable<T> {

/// A `Map` in a `JsonBufferBuilder`.
abstract interface class MapInBuffer {
/// The buffer backing this `Map`.
/// The buffer backing this [Map].
JsonBufferBuilder get buffer;

/// The `Map` that contains this value, or `null` if this value has not been
Expand Down
4 changes: 4 additions & 0 deletions pkgs/dart_model/lib/src/macro_metadata.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// This file is generated. To make changes edit tool/dart_model_generator
// then run from the repo root: dart tool/dart_model_generator/bin/main.dart

// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'dart:typed_data';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:crypto/crypto.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:dart_model/src/deep_cast_map.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
Expand Down
1 change: 1 addition & 0 deletions pkgs/dart_model/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:

dependencies:
collection: ^1.19.0
crypto: ^3.0.6

dev_dependencies:
benchmark_harness: ^2.2.2
Expand Down
5 changes: 5 additions & 0 deletions pkgs/dart_model/test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ void main() {
expect(copiedModel.qualifiedNameOf(member.node), null);
expect(model.qualifiedNameOf(copiedMember.node), null);
});

test('can produce and compare digests for buffer and SDK maps', () {
final copiedModel = Model.fromJson(_copyMap(model.node));
expect(model.digest, copiedModel.digest);
});
});

group('QualifiedName', () {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/macro_service/lib/src/handshake.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// This file is generated. To make changes edit tool/dart_model_generator
// then run from the repo root: dart tool/dart_model_generator/bin/main.dart

// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'dart:typed_data';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:crypto/crypto.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:dart_model/src/deep_cast_map.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
Expand Down
4 changes: 4 additions & 0 deletions pkgs/macro_service/lib/src/macro_service.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// This file is generated. To make changes edit tool/dart_model_generator
// then run from the repo root: dart tool/dart_model_generator/bin/main.dart

// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'dart:typed_data';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:crypto/crypto.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
import 'package:dart_model/src/dart_model.g.dart';
// ignore: implementation_imports,unused_import,prefer_relative_imports
Expand Down
25 changes: 15 additions & 10 deletions tool/dart_model_generator/lib/definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,21 @@ static Protocol handshakeProtocol = Protocol(
description: 'The named parameters of this member, '
'if it has them.'),
]),
Definition.clazz('Model',
description: 'Partial model of a corpus of Dart source code.',
createInBuffer: true,
properties: [
Property('uris',
type: 'Map<Library>', description: 'Libraries by URI.'),
Property('types',
type: 'TypeHierarchy',
description: 'The resolved static type hierarchy.'),
]),
Definition.clazz(
'Model',
description: 'Partial model of a corpus of Dart source code.',
createInBuffer: true,
properties: [
Property('uris',
type: 'Map<Library>', description: 'Libraries by URI.'),
Property('types',
type: 'TypeHierarchy',
description: 'The resolved static type hierarchy.'),
],
extraCode: '// A digest of all the bytes in the current buffer.\n'
'Digest get digest => '
'md5.convert((node as MapInBuffer).buffer.serialize());',
),
Definition.clazz('NamedFunctionTypeParameter',
description:
'A resolved named parameter as part of a [FunctionTypeDesc].',
Expand Down
2 changes: 2 additions & 0 deletions tool/dart_model_generator/lib/generate_dart_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class GenerationContext {
lookupDeclaringSchema(typeName),
}.nonNulls;
return ([
"import 'dart:typed_data';",
"import 'package:crypto/crypto.dart';",
"import 'package:dart_model/src/json_buffer/json_buffer_builder.dart';",
"import 'package:dart_model/src/deep_cast_map.dart';",
"import 'package:dart_model/src/scopes.dart';",
Expand Down
Loading