Skip to content

Commit

Permalink
[CFE] Make strong/weak suite fuzzing work with parts
Browse files Browse the repository at this point in the history
This CL follows up on
https://dart-review.googlesource.com/c/sdk/+/239668
where parts was left non-working.

Now part files are ignored (i.e. we don't try to split it and add
imports/exports where it isn't supported), and the part declaration(s)
is(/are) kept only in the "main" file.

Change-Id: I63fa8ac8fcf173234a8162297f1c5eb1d94b00da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241961
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
  • Loading branch information
jensjoha authored and Commit Bot committed Apr 22, 2022
1 parent 84d75cb commit a5a7b4c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
35 changes: 25 additions & 10 deletions pkg/front_end/test/fasta/testing/suite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ class FuzzCompiles
}

List<Uri> originalUris = List<Uri>.of(fs.data.keys);
uriLoop:
for (Uri uri in originalUris) {
print("Work on $uri");
LibraryBuilder? builder = builders[uri];
Expand All @@ -1599,14 +1600,21 @@ class FuzzCompiles

// Put each chunk into its own file.
StringBuffer headerSb = new StringBuffer();
StringBuffer orgFileOnlyHeaderSb = new StringBuffer();
List<FuzzAstVisitorSorterChunk> nonHeaderChunks = [];

print("Found ${fuzzAstVisitorSorter.chunks.length} chunks...");

for (FuzzAstVisitorSorterChunk chunk in fuzzAstVisitorSorter.chunks) {
if (chunk.originalType == FuzzOriginalType.Import ||
if (chunk.originalType == FuzzOriginalType.PartOf) {
print("Skipping part...");
continue uriLoop;
} else if (chunk.originalType == FuzzOriginalType.Part) {
// The part declaration should only be in the "main" file.
orgFileOnlyHeaderSb.writeln(chunk.getSource());
} else if (chunk.originalType == FuzzOriginalType.Import ||
chunk.originalType == FuzzOriginalType.Export ||
chunk.originalType == FuzzOriginalType.LibraryName ||
chunk.originalType == FuzzOriginalType.Part ||
chunk.originalType == FuzzOriginalType.PartOf ||
chunk.originalType == FuzzOriginalType.LanguageVersion) {
headerSb.writeln(chunk.getSource());
} else {
Expand All @@ -1625,24 +1633,24 @@ class FuzzCompiles
// exports, etc.
StringBuffer sb = new StringBuffer();
sb.writeln(headerSb.toString());
for (int i = 0; i < totalSubFiles; i++) {
if (i == currentSubFile) continue;
sb.writeln("import '${getUriForChunk(i)}';");
sb.writeln("export '${getUriForChunk(i)}';");
}
sb.writeln("import '${uri.pathSegments.last}';");
sb.writeln(chunk.getSource());
fs.data[getUriForChunk(currentSubFile)] =
utf8.encode(sb.toString()) as Uint8List;
print(" => Split into ${getUriForChunk(currentSubFile)}:\n"
"${sb.toString()}\n-------------\n");
currentSubFile++;
}

// Rewrite main file.
StringBuffer sb = new StringBuffer();
sb.writeln(headerSb.toString());
for (int i = 0; i < totalSubFiles; i++) {
sb.writeln("import '${getUriForChunk(i)}';");
sb.writeln("export '${getUriForChunk(i)}';");
sb.writeln("import '${getUriForChunk(i).pathSegments.last}';");
sb.writeln("export '${getUriForChunk(i).pathSegments.last}';");
}
sb.writeln(orgFileOnlyHeaderSb.toString());
print(" => Main file becomes:\n${sb.toString()}\n-------------\n");
fs.data[uri] = utf8.encode(sb.toString()) as Uint8List;
}

Expand Down Expand Up @@ -1715,6 +1723,13 @@ class FuzzAstVisitorSorter extends ParserAstVisitor {
enableExtensionMethods: true,
enableNonNullable: nnbd);
accept(ast);

if (metadataStart == null &&
ast.token.precedingComments != null &&
chunks.isEmpty) {
_chunkOutLanguageVersionComment(ast.token);
}

if (metadataStart != null) {
String metadata = asString.substring(
metadataStart!.charOffset, metadataEndInclusive!.charEnd);
Expand Down
3 changes: 1 addition & 2 deletions pkg/front_end/testcases/strong.status
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ const_functions/const_functions_list: SemiFuzzCrash
generic_metadata/typedef_generic_types_in_arguments_and_bounds: SemiFuzzCrash

# These tests have "privacy issues" and isn't compatiable with splitting files (fuzzing):
constructor_tearoffs/lowering/typedef_from: semiFuzzFailureOnForceRebuildBodies # parts not supported
dart2js/mixin_default_values/main: semiFuzzFailureOnForceRebuildBodies # private method
dartdevc/factory_patch/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
dartdevc/private_covariant: semiFuzzFailureOnForceRebuildBodies # private method in class
late_lowering/injected_late_field_checks/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
late_lowering/issue41436/issue41436: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
late_lowering/issue41922: semiFuzzFailureOnForceRebuildBodies # private field
late_lowering/private_members: semiFuzzFailureOnForceRebuildBodies # parts not supported
late_lowering/private_members: semiFuzzFailureOnForceRebuildBodies # private class
macros/inject_constructor: semiFuzzFailureOnForceRebuildBodies # Macro injection --- think it might introduce a class in a file?
nnbd/injected_late_field_checks/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
nnbd/issue42504: semiFuzzFailureOnForceRebuildBodies # private class
Expand Down
8 changes: 2 additions & 6 deletions pkg/front_end/testcases/weak.status
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ regress/utf_16_le_content.crash: SemiFuzzCrash
static_field_lowering/opt_in: SemiFuzzFailure

# These tests have "privacy issues" and isn't compatiable with splitting files (fuzzing):
constructor_tearoffs/lowering/typedef_from: semiFuzzFailureOnForceRebuildBodies # parts not supported
dart2js/mixin_default_values/main: semiFuzzFailureOnForceRebuildBodies # private method
dartdevc/factory_patch/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
dartdevc/private_covariant: semiFuzzFailureOnForceRebuildBodies # private method in class
Expand All @@ -47,20 +46,17 @@ general/issue45101/main: semiFuzzFailureOnForceRebuildBodies # needs custom libr
general/issue47036: semiFuzzFailureOnForceRebuildBodies # private class
general/issue48548: semiFuzzFailureOnForceRebuildBodies # private field
general/nested_lib_spec/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
general/part_as_entry_point: semiFuzzFailureOnForceRebuildBodies # parts not supported
general/private_members: semiFuzzFailureOnForceRebuildBodies # parts not supported
general/private_members: semiFuzzFailureOnForceRebuildBodies # private class (etc).
general/private_method_tearoff: semiFuzzFailureOnForceRebuildBodies # private method in class
general/redirecting_factory_const_inference: semiFuzzFailureOnForceRebuildBodies # private class
general/redirecting_factory_invocation_metadata: semiFuzzFailureOnForceRebuildBodies # parts not supported
general/store_load: semiFuzzFailureOnForceRebuildBodies # private field in class
general/top_level_accessors: semiFuzzFailureOnForceRebuildBodies # parts not supported
general/typedef: semiFuzzFailureOnForceRebuildBodies # private typedef
inference/downwards_inference_on_list_literals_infer_if_value_types_match_context: semiFuzzFailureOnForceRebuildBodies # private field
late_lowering/injected_late_field_checks/main: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here

late_lowering/issue41436/issue41436: semiFuzzFailureOnForceRebuildBodies # needs custom libraries.json (and platform?) not setup here
late_lowering/issue41922: semiFuzzFailureOnForceRebuildBodies # private field
late_lowering/private_members: semiFuzzFailureOnForceRebuildBodies # parts not supported
late_lowering/private_members: semiFuzzFailureOnForceRebuildBodies # private class (etc)
macros/inject_constructor: semiFuzzFailureOnForceRebuildBodies # Macro injection --- think it might introduce a class in a file?
nnbd_mixed/issue46518: semiFuzzFailureOnForceRebuildBodies # private method
nnbd_mixed/no_null_shorting_explicit_extension: semiFuzzFailureOnForceRebuildBodies # private field in class
Expand Down

0 comments on commit a5a7b4c

Please sign in to comment.