Skip to content

Commit

Permalink
Version 3.5.0-264.0.dev
Browse files Browse the repository at this point in the history
Merge 689852e into dev
  • Loading branch information
Dart CI committed Jun 14, 2024
2 parents 2c1ec68 + 689852e commit c58765e
Show file tree
Hide file tree
Showing 41 changed files with 738 additions and 424 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vars = {

# co19 is a cipd package automatically generated for each co19 commit.
# Use tests/co19/update.sh to update this hash.
"co19_rev": "8738630ac89dd2433b5be27157ae607ce46a7e9a",
"co19_rev": "831b22d5e496fe63a813ca1c1b64f533c2f9fa0c",

# The internal benchmarks to use. See go/dart-benchmarks-internal
"benchmarks_internal_rev": "a7c23b2422492dcc515d1ba4abe3609b50e2a139",
Expand Down
2 changes: 2 additions & 0 deletions pkg/dart2wasm/lib/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Future<CompilerOutput?> compileToModule(compiler.WasmCompilerOptions options,
}
final WasmTarget target = WasmTarget(
enableExperimentalFfi: options.translatorOptions.enableExperimentalFfi,
enableExperimentalWasmInterop:
options.translatorOptions.enableExperimentalWasmInterop,
removeAsserts: !options.translatorOptions.enableAsserts,
mode: mode);
CompilerOptions compilerOptions = CompilerOptions()
Expand Down
3 changes: 3 additions & 0 deletions pkg/dart2wasm/lib/dart2wasm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ final List<Option> options = [
Flag("verify-type-checks",
(o, value) => o.translatorOptions.verifyTypeChecks = value,
defaultsTo: _d.translatorOptions.verifyTypeChecks),
Flag("enable-experimental-wasm-interop",
(o, value) => o.translatorOptions.enableExperimentalWasmInterop = value,
defaultsTo: _d.translatorOptions.enableExperimentalWasmInterop),
IntOption(
"inlining-limit", (o, value) => o.translatorOptions.inliningLimit = value,
defaultsTo: "${_d.translatorOptions.inliningLimit}"),
Expand Down
45 changes: 31 additions & 14 deletions pkg/dart2wasm/lib/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ class ConstantResolver extends Transformer {
class WasmTarget extends Target {
WasmTarget(
{this.enableExperimentalFfi = true,
this.enableExperimentalWasmInterop = true,
this.removeAsserts = false,
this.mode = Mode.regular});

final bool removeAsserts;
final Mode mode;
final bool enableExperimentalFfi;
final bool enableExperimentalWasmInterop;
Class? _growableList;
Class? _immutableList;
Class? _wasmDefaultMap;
Expand Down Expand Up @@ -175,13 +177,28 @@ class WasmTarget extends Target {
bool mayDefineRestrictedType(Uri uri) => uri.isScheme('dart');

@override
bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) =>
super.allowPlatformPrivateLibraryAccess(importer, imported) ||
importer.path.contains('tests/web/wasm') ||
importer.isScheme('package') &&
(importer.path == 'js/js.dart' ||
importer.path.startsWith('ui/') &&
imported.toString() == 'dart:_wasm');
bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) {
if (super.allowPlatformPrivateLibraryAccess(importer, imported)) {
return true;
}

if (imported.toString() == 'dart:_wasm') {
return enableExperimentalWasmInterop;
}

final importerString = importer.toString();

// We have some tests that import dart:js*
if (importerString.contains('tests/web/wasm')) return true;

// Flutter's dart:ui is also package:ui (in test mode)
if (importerString.startsWith('package:ui/')) return true;

// package:js can import dart:js* & dart:_js_*
if (importerString.startsWith('package:js/')) return true;

return false;
}

void _patchHostEndian(CoreTypes coreTypes) {
// Fix Endian.host to be a const field equal to Endian.little instead of
Expand Down Expand Up @@ -247,10 +264,12 @@ class WasmTarget extends Target {
ReferenceFromIndex? referenceFromIndex,
{void Function(String msg)? logger,
ChangedStructureNotifier? changedStructureNotifier}) {
// Check `wasm:import` and `wasm:export` pragmas before FFI transforms as
// FFI transforms convert JS interop annotations to these pragmas.
_checkWasmImportExportPragmas(libraries, coreTypes,
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>);
if (!enableExperimentalWasmInterop) {
// Check `wasm:import` and `wasm:export` pragmas before FFI transforms as
// FFI transforms convert JS interop annotations to these pragmas.
_checkWasmImportExportPragmas(libraries, coreTypes,
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>);
}

Set<Library> transitiveImportingJSInterop = {
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
Expand Down Expand Up @@ -545,9 +564,7 @@ void _checkWasmImportExportPragmas(List<Library> libraries, CoreTypes coreTypes,
if (importUri.isScheme('dart') ||
(importUri.isScheme('package') &&
JsInteropChecks.allowedInteropLibrariesInDart2WasmPackages
.any((pkg) => importUri.pathSegments.first == pkg)) ||
(importUri.path.contains('tests/web/wasm') &&
!importUri.path.contains('reject_import_export_pragmas'))) {
.any((pkg) => importUri.pathSegments.first == pkg))) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions pkg/dart2wasm/lib/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TranslatorOptions {
bool verifyTypeChecks = false;
bool verbose = false;
bool enableExperimentalFfi = false;
bool enableExperimentalWasmInterop = false;
int inliningLimit = 0;
int? sharedMemoryMaxPages;
List<int> watchPoints = [];
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/builder/builder_mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mixin DeclarationBuilderMixin implements IDeclarationBuilder {
{required bool hasExplicitTypeArguments}) {
return buildAliasedTypeWithBuiltArguments(
library,
nullabilityBuilder.build(library),
nullabilityBuilder.build(),
buildAliasedTypeArguments(library, arguments, hierarchy),
typeUse,
fileUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class BuiltinTypeDeclarationBuilder extends TypeDeclarationBuilderImpl
int charOffset,
ClassHierarchyBase? hierarchy,
{required bool hasExplicitTypeArguments}) {
return type.withDeclaredNullability(nullabilityBuilder.build(library));
return type.withDeclaredNullability(nullabilityBuilder.build());
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/builder/class_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ abstract class ClassBuilderImpl extends DeclarationBuilderImpl
}
return buildAliasedTypeWithBuiltArguments(
library,
nullabilityBuilder.build(library),
nullabilityBuilder.build(),
buildAliasedTypeArguments(library, arguments, hierarchy),
typeUse,
fileUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ abstract class FunctionTypeBuilderImpl extends FunctionTypeBuilder {
t.bound?.build(library, TypeUse.typeParameterBound);
}
}
return new FunctionType(positionalParameters, builtReturnType,
nullabilityBuilder.build(library),
return new FunctionType(
positionalParameters, builtReturnType, nullabilityBuilder.build(),
namedParameters: namedParameters ?? const <NamedType>[],
typeParameters: typeParameters ?? const <StructuralParameter>[],
requiredParameterCount: requiredParameterCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FutureOrTypeDeclarationBuilder extends BuiltinTypeDeclarationBuilder {
return new FutureOrType(
arguments!.single
.buildAliased(library, TypeUse.typeArgument, hierarchy),
nullabilityBuilder.build(library));
nullabilityBuilder.build());
}

@override
Expand Down
118 changes: 58 additions & 60 deletions pkg/front_end/lib/src/fasta/builder/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
library fasta.library_builder;

import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;

import 'package:kernel/ast.dart' show Class, Library, Nullability;
import 'package:kernel/ast.dart' show Class, Library;

import '../combinator.dart' show CombinatorBuilder;

import '../problems.dart' show internalProblem;

import '../export.dart' show Export;

import '../loader.dart' show Loader;

import '../messages.dart'
show
FormattedMessage,
Expand All @@ -24,19 +18,24 @@ import '../messages.dart'
templateInternalProblemConstructorNotFound,
templateInternalProblemNotFoundIn,
templateInternalProblemPrivateConstructorAccess;

import '../problems.dart' show internalProblem;
import '../scope.dart';

import '../source/name_scheme.dart';
import '../source/offset_map.dart';
import '../source/source_class_builder.dart';
import '../source/source_function_builder.dart';
import '../source/source_library_builder.dart';
import 'builder.dart';
import 'constructor_reference_builder.dart';
import 'declaration_builders.dart';
import 'inferable_type_builder.dart';
import 'member_builder.dart';
import 'modifier_builder.dart';
import 'name_iterator.dart';
import 'nullability_builder.dart';
import 'prefix_builder.dart';
import 'type_builder.dart';

abstract class CompilationUnit {
sealed class CompilationUnit {
/// Returns the import uri for the compilation unit.
///
/// This is the canonical uri for the compilation unit, for instance
Expand Down Expand Up @@ -93,6 +92,54 @@ abstract class CompilationUnit {
bool problemOnLibrary = false});
}

abstract class DillCompilationUnit implements CompilationUnit {}

abstract class SourceCompilationUnit implements CompilationUnit {
SourceLibraryBuilder createLibrary();

// TODO(johnniwinther): Remove this.
SourceLibraryBuilder get sourceLibraryBuilder;

OffsetMap get offsetMap;

List<ConstructorReferenceBuilder> get constructorReferences;

List<Export> get exporters;

LanguageVersion get languageVersion;

// TODO(johnniwinther): Remove this.
Library get library;

// TODO(johnniwinther): Remove this?
LibraryName get libraryName;

List<NamedTypeBuilder> get unresolvedNamedTypes;

List<SourceFunctionBuilder> get nativeMethods;

void set partOfLibrary(LibraryBuilder? value);

String? get partOfName;

Uri? get partOfUri;

Scope get scope;

List<NominalVariableBuilder> get unboundNominalVariables;

List<StructuralVariableBuilder> get unboundStructuralVariables;

void collectInferableTypes(List<InferableType> inferableTypes);

void takeMixinApplications(
Map<SourceClassBuilder, TypeBuilder> mixinApplications);

void addDependencies(Library library, Set<SourceLibraryBuilder> seen);

void validatePart(SourceLibraryBuilder? library, Set<Uri>? usedParts);
}

abstract class LibraryBuilder implements Builder {
Scope get scope;

Expand Down Expand Up @@ -161,9 +208,6 @@ abstract class LibraryBuilder implements Builder {
/// Duplicates and augmenting members are _not_ included.
NameIterator<T> fullMemberNameIterator<T extends Builder>();

void addExporter(LibraryBuilder exporter,
List<CombinatorBuilder>? combinators, int charOffset);

/// Add a problem with a severity determined by the severity of the message.
///
/// If [fileUri] is null, it defaults to `this.fileUri`.
Expand Down Expand Up @@ -216,17 +260,6 @@ abstract class LibraryBuilder implements Builder {
void recordAccess(
CompilationUnit accessor, int charOffset, int length, Uri fileUri);

Nullability get nullable;

Nullability nullableIfTrue(bool isNullable);

NullabilityBuilder get nullableBuilder;

NullabilityBuilder get nonNullableBuilder;

/// Unused in interface; left in on purpose.
NullabilityBuilder nullableBuilderIfTrue(bool isNullable);

/// Returns `true` if [cls] is the 'Function' class defined in [coreLibrary].
static bool isFunction(Class cls, LibraryBuilder coreLibrary) {
return cls.name == 'Function' && _isCoreClass(cls, coreLibrary);
Expand Down Expand Up @@ -312,14 +345,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
parent: this, includeDuplicates: true, includeAugmentations: true);
}

@override
void addExporter(LibraryBuilder exporter,
List<CombinatorBuilder>? combinators, int charOffset) {
exporters.add(
// TODO(johnniwinther): Avoid casting to [CompilationUnit] here.
new Export(exporter, this as CompilationUnit, combinators, charOffset));
}

@override
FormattedMessage? addProblem(
Message message, int charOffset, int length, Uri? fileUri,
Expand Down Expand Up @@ -430,33 +455,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
void recordAccess(
CompilationUnit accessor, int charOffset, int length, Uri fileUri) {}

@override
Nullability get nullable {
return Nullability.nullable;
}

@override
Nullability nullableIfTrue(bool isNullable) {
return isNullable ? Nullability.nullable : Nullability.nonNullable;
}

@override
NullabilityBuilder get nullableBuilder {
return const NullabilityBuilder.nullable();
}

@override
NullabilityBuilder get nonNullableBuilder {
return const NullabilityBuilder.omitted();
}

@override
NullabilityBuilder nullableBuilderIfTrue(bool isNullable) {
return isNullable
? const NullabilityBuilder.nullable()
: const NullabilityBuilder.omitted();
}

@override
StringBuffer printOn(StringBuffer buffer) {
return buffer..write(isPart || isAugmenting ? fileUri : importUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NeverTypeDeclarationBuilder extends BuiltinTypeDeclarationBuilder {
int charOffset,
ClassHierarchyBase? hierarchy,
{required bool hasExplicitTypeArguments}) {
return type.withDeclaredNullability(nullabilityBuilder.build(library));
return type.withDeclaredNullability(nullabilityBuilder.build());
}

@override
Expand Down
4 changes: 1 addition & 3 deletions pkg/front_end/lib/src/fasta/builder/nullability_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import 'package:kernel/ast.dart';

import 'library_builder.dart';

/// Represents the nullability modifiers encountered while parsing the types.
///
/// The syntactic nullability needs to be interpreted, that is, built, into the
Expand Down Expand Up @@ -48,7 +46,7 @@ class NullabilityBuilder {
}
}

Nullability build(LibraryBuilder libraryBuilder) {
Nullability build() {
switch (_syntacticNullability) {
case SyntacticNullability.nullable:
return Nullability.nullable;
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/builder/record_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ abstract class RecordTypeBuilderImpl extends RecordTypeBuilder {

// TODO(johnniwinther): Should we create an [InvalidType] if there is <= 1
// entries?
return new RecordType(positionalEntries, namedEntries ?? [],
nullabilityBuilder.build(library));
return new RecordType(
positionalEntries, namedEntries ?? [], nullabilityBuilder.build());
}

@override
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/builder/type_alias_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
DartType thisType = buildThisType();
if (thisType is InvalidType) return thisType;

Nullability nullability = nullabilityBuilder.build(library);
Nullability nullability = nullabilityBuilder.build();
return buildAliasedTypeWithBuiltArguments(
library,
nullability,
Expand Down Expand Up @@ -373,7 +373,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
if (typeVariables != null)
for (NominalVariableBuilder typeVariable in typeVariables!)
new NamedTypeBuilderImpl.fromTypeDeclarationBuilder(
typeVariable, libraryBuilder.nonNullableBuilder,
typeVariable, const NullabilityBuilder.omitted(),
arguments: const [],
fileUri: fileUri,
charOffset: charOffset,
Expand Down
Loading

0 comments on commit c58765e

Please sign in to comment.