Skip to content

Update reflectable such that test_reflectable can run tests using pub run build_runner test #119

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

Merged
merged 23 commits into from
Apr 5, 2018

Conversation

eernstg
Copy link
Collaborator

@eernstg eernstg commented Mar 22, 2018

One rather voluminous change in this PR is about function types: Until now, reflectable was not aware of inline function types (like an inline int Function(), as opposed to the ones which were defined indirectly defined via a typedef). This PR introduces support for the new function type syntax.

There is one outstanding issue: We cannot recognize generic function types, because they must be defined in terms of a typedef, and the corresponding Type objects are not equal even though two given typedefs define the same generic function type. However, it is still possible to use generic function types if they are defined via a typedef and the client is careful to always use the same typedef for the same function type. This will be fixed, but this is a change to Type and not a change to reflectable.

A number of other changes are associated with the "administration" of the package, e.g., .gitignore was updated to match the new paths used by Dart tools for generated files, CHANGELOG.md and README.md were updated, and so was pubspec.yaml. Changes to build.yaml were necessary in order to get the desired behavior of the build package (which handles code generation and accepts the reflectable code generator as a kind of plugin).

@eernstg eernstg requested a review from sigurdm March 22, 2018 14:10
@@ -835,7 +852,7 @@ class _ReflectorDomain {
classDomain._instanceMembers.forEach(members.add);

// Add all the formal parameters (as a single, global set) which
// are declared by any of the methods in `classDomain._declarations`
// are declared by any of the methods in `classDomain._declarations`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Stray space?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, fixed.

@@ -856,8 +873,7 @@ class _ReflectorDomain {
} else if (variable is TopLevelVariableElement) {
topLevelVariables.add(variable);
} else {
throw unimplementedError(
"This kind of variable is not yet supported");
logger.error("This kind of variable is not yet supported");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add the typename to the error message for easier diagnostics?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// Requested: just the name of the typedef; get it and return.
int dartTypeNumber = typedefs.containsKey(dartType)
? typedefs[dartType]
: typedefNumber++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use typedefs.size instead of typedefNumber?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved IRL: Could not do that due to ordering conflicts in the collection of information about typedefs.

typeVariablesInScope = new Set<String>();
}
for (TypeParameterElement element in dartType.typeFormals) {
typeVariablesInScope.add(element.name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: You can use Set.addAll

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

} else {
// Requested: the spelled-out generic function type; continue.
if (typeVariablesInScope == null) {
typeVariablesInScope = new Set<String>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Could be

typeVariablesInScope ?= new Set<String>();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

importCollector, typeVariablesInScope, typedefs, logger,
useNameOfGenericFunctionType: useNameOfGenericFunctionType);
String typeArguments = "";
if (!dartType.typeFormals.isEmpty) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we have Set.isNotEmpty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed several similar occurrences.

_capabilities, constructorName, _getEvaluatedMetadata(metadata));
Resolver resolver,
TransformLogger logger) {
var result = _supportsNewInstance(_capabilities, constructorName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Could you just

return _supportsNewInstance(...);

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done (was an leftover from printf debugging).

@@ -2596,22 +2773,26 @@ class _Capabilities {
bool supportsInstanceInvoke(
String methodName,
Iterable<ElementAnnotation> metadata,
Iterable<ElementAnnotation> getterMetadata) {
Iterable<ElementAnnotation> getterMetadata,
TransformLogger logger) {
var v = _supportsInstanceInvoke(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Could you just

return _supportsInstanceInvoke(...);

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -3774,6 +3973,7 @@ initializeReflectable() {
if (const bool.fromEnvironment("reflectable.pause.at.exit")) {
_processedEntryPointCount++;
}
_resolver.release();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we wrap this code in a local function, so we only have to release the resolver in one spot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reorganized the code without abstractions, because they seemed to require a non-local return. See https://dartpad.dartlang.org/e6351d655334455c511288345c5fbaec for details.

@eernstg eernstg merged commit 7764c55 into master Apr 5, 2018
@eernstg eernstg deleted the update_gitignore_mar18 branch May 30, 2018 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants