Skip to content

Commit

Permalink
Version 3.4.0-8.0.dev
Browse files Browse the repository at this point in the history
Merge 611a092 into dev
  • Loading branch information
Dart CI committed Jan 8, 2024
2 parents 7870500 + 611a092 commit eb945be
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 45 deletions.
22 changes: 1 addition & 21 deletions pkg/dart2wasm/lib/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -619,20 +619,7 @@ class AsyncCodeGenerator extends CodeGenerator {
}

// _AsyncCompleter _completer
final DartType returnType = functionNode.returnType;
final DartType completerType;
if (returnType is InterfaceType &&
returnType.classNode == translator.coreTypes.futureClass) {
// Return type = Future<T>, completer type = _AsyncCompleter<T>.
completerType = returnType.typeArguments.single;
} else if (returnType is FutureOrType) {
// Return type = FutureOr<T>, completer type = _AsyncCompleter<T>.
completerType = returnType.typeArgument;
} else {
// In all other cases we use _AsyncCompleter<dynamic>.
completerType = const DynamicType();
}
types.makeType(this, completerType);
types.makeType(this, functionNode.emittedValueType!);
call(translator.makeAsyncCompleter.reference);

// Allocate `_AsyncSuspendState`
Expand Down Expand Up @@ -774,8 +761,6 @@ class AsyncCodeGenerator extends CodeGenerator {
b.local_get(suspendStateLocal);
b.struct_get(
asyncSuspendStateInfo.struct, FieldIndex.asyncSuspendStateCompleter);
// Non-null Dart field represented as nullable Wasm field.
b.ref_as_non_null();
b.ref_null(translator.topInfo.struct);
call(translator.completerComplete.reference);
b.return_();
Expand All @@ -790,7 +775,6 @@ class AsyncCodeGenerator extends CodeGenerator {
b.local_get(suspendStateLocal);
b.struct_get(
asyncSuspendStateInfo.struct, FieldIndex.asyncSuspendStateCompleter);
b.ref_as_non_null();
b.local_get(exceptionLocal);
b.local_get(stackTraceLocal);
call(translator.completerCompleteError.reference);
Expand Down Expand Up @@ -1205,8 +1189,6 @@ class AsyncCodeGenerator extends CodeGenerator {
b.local_get(suspendStateLocal);
b.struct_get(
asyncSuspendStateInfo.struct, FieldIndex.asyncSuspendStateCompleter);
// Non-null Dart field represented as nullable Wasm field.
b.ref_as_non_null();
b.local_get(suspendStateLocal);
b.struct_get(asyncSuspendStateInfo.struct,
FieldIndex.asyncSuspendStateCurrentReturnValue);
Expand Down Expand Up @@ -1264,8 +1246,6 @@ class AsyncCodeGenerator extends CodeGenerator {
b.local_get(suspendStateLocal);
b.struct_get(
asyncSuspendStateInfo.struct, FieldIndex.asyncSuspendStateCompleter);
// Non-null Dart field represented as nullable Wasm field.
b.ref_as_non_null();
}

final value = node.expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ class A {

@ClassDefinitionBuildField(
name: 'x',
getter: '=> 3',
getter: '`int` get x => 3;',
setter: null, // TODO(davidmorgan): test setter.
initializer: null, // TODO(davidmorgan): test initializer.
initializerComments: null, // TODO(davidmorgan): test comments.
)
class B {
int get x;
// TODO(davidmorgan): should "abstract" be allowed, required?
abstract final int x;
}

@ClassDefinitionBuildMethod(
name: 'x',
body: '=> 3',
body: '=> 3;',
comments: null, // TODO(davidmorgan): test comments.
)
class C {
Expand Down
29 changes: 16 additions & 13 deletions tests/language/macros/augment/impl/class_definition_macro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ macro class ClassDefinitionBuildConstructor implements ClassDefinitionMacro {
@override
Future<void> buildDefinitionForClass(
ClassDeclaration clazz, TypeDefinitionBuilder builder) async {
final nameIdentifier =
await builder.resolveIdentifier(clazz.library.uri, name);
final nameIdentifier = (await builder.constructorsOf(clazz))
.singleWhere((c) => c.identifier.name == name)
.identifier;
(await builder.buildConstructor(nameIdentifier)).augment(
body: await builder.code(body),
body: await builder.maybeCode(body),
initializers: initializers == null
? null
: initializers!.map((s) => DeclarationCode.fromString(s)).toList(),
docComments: await builder.code(comments));
docComments: await builder.maybeCode(comments));
}
}

Expand All @@ -46,13 +47,14 @@ macro class ClassDefinitionBuildField implements ClassDefinitionMacro {
@override
Future<void> buildDefinitionForClass(
ClassDeclaration clazz, TypeDefinitionBuilder builder) async {
final nameIdentifier =
await builder.resolveIdentifier(clazz.library.uri, name);
final nameIdentifier = (await builder.fieldsOf(clazz))
.singleWhere((c) => c.identifier.name == name)
.identifier;
(await builder.buildField(nameIdentifier)).augment(
getter: await builder.code(getter),
setter: await builder.code(setter),
initializer: await builder.code(initializer),
initializerDocComments: await builder.code(initializerComments),
getter: await builder.maybeCode(getter),
setter: await builder.maybeCode(setter),
initializer: await builder.maybeCode(initializer),
initializerDocComments: await builder.maybeCode(initializerComments),
);
}
}
Expand All @@ -68,11 +70,12 @@ macro class ClassDefinitionBuildMethod implements ClassDefinitionMacro {
@override
Future<void> buildDefinitionForClass(
ClassDeclaration clazz, TypeDefinitionBuilder builder) async {
final nameIdentifier =
await builder.resolveIdentifier(clazz.library.uri, name);
final nameIdentifier = (await builder.methodsOf(clazz))
.singleWhere((c) => c.identifier.name == name)
.identifier;
(await builder.buildMethod(nameIdentifier)).augment(
await builder.code(body),
docComments: await builder.code(comments),
docComments: await builder.maybeCode(comments),
);
}
}
20 changes: 13 additions & 7 deletions tests/language/macros/augment/impl/impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ extension TypePhaseIntrospecterExtension on TypePhaseIntrospector {
///
/// If [string] is `null`, just return `null`; or throw if `T` is not
/// nullable.
Future<T> code<T extends Code?>(String? string) async {
if (string == null) return null as T;

Future<T> code<T extends Code>(String string) async {
final parts = <Object>[];
final chunks = string.split('`');
var isIdentifier = false;
Expand All @@ -33,14 +31,22 @@ extension TypePhaseIntrospecterExtension on TypePhaseIntrospector {
isIdentifier = !isIdentifier;
}

if (T == DeclarationCode) {
if (T == CommentCode) {
return CommentCode.fromParts(parts) as T;
} else if (T == DeclarationCode) {
return DeclarationCode.fromParts(parts) as T;
} else if (T == ExpressionCode) {
return ExpressionCode.fromParts(parts) as T;
} else if (T == FunctionBodyCode) {
return FunctionBodyCode.fromParts(parts) as T;
} else if (T == CommentCode) {
return CommentCode.fromParts(parts) as T;
} else {
throw UnsupportedError(T.toString());
throw UnsupportedError(T.runtimeType.toString());
}
}

/// As [code] but returns `null` for `null` input
Future<T?> maybeCode<T extends Code>(String? string) async {
if (string == null) return null;
return await code<T>(string);
}
}
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 4
PATCH 0
PRERELEASE 7
PRERELEASE 8
PRERELEASE_PATCH 0

0 comments on commit eb945be

Please sign in to comment.