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
feat(compiler-cli): explain why an expression cannot be used in AOT compilations #37587
Conversation
| if (maxDepth === 0) { | ||
| return 'Array'; | ||
| } | ||
| return `[${value.map(v => describeResolvedType(v, maxDepth - 1)).join(', ')}]`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I choose to display arrays as a tuple representation (e.g. [string, string, number]), but we may as well choose to show them as array with a union type (e.g. (string | number)[]). Alternatively, we could limit the number of entries to include.
packages/compiler-cli/src/ngtsc/partial_evaluator/src/diagnostics.ts
Outdated
Show resolved
Hide resolved
A couple of optional nits and a couple of commit message typos. Otherwise looks great
- 2nd commit:
has to ability to statically evaluate-->has the ability to statically evaluate(?) - 3rd commit:
a function calls-->a function call
| @@ -55,6 +56,11 @@ export const enum DynamicValueReason { | |||
| */ | |||
| INVALID_EXPRESSION_TYPE, | |||
|
|
|||
| /** | |||
| * A function call could not be evaluated as its body is not a single return statement. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The current wording makes it sound as if the call has a body
| * A function call could not be evaluated as its body is not a single return statement. | |
| * A function call could not be evaluated as the function's body is not a single return statement. |
| } else if (value instanceof ResolvedModule) { | ||
| return 'module'; | ||
| } else if (value instanceof EnumValue) { | ||
| return value.enumRef.debugName ?? '(anonymous)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to include something to show it is an enum value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum values are essentially just References, but refer to a particular member of that enum. As we're just printing the type here, only the information from the reference is used. As such, it's displayed as other References would be. We could include the kind of declaration for any Reference, e.g. show class MyCmp and enum ViewEncapsulation, but I kept the notation as close as TS's native representation of types.
What might make sense to do is to extend createValueHasWrongTypeError such that it creates a ts.DiagnosticRelationInformation pointing to the declaration of the enum, as it does for References.
| } | ||
| return `[${value.map(v => describeResolvedType(v, maxDepth - 1)).join(', ')}]`; | ||
| } else if (value instanceof DynamicValue) { | ||
| return 'dynamic'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I am wondering whether dynamic is somewhat ambiguous for the user. Would something like not statically analyzable be more helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed as proposed. I also went over all others and added parenthesis to some to indicate that these are not actual types.
…dInformation` Previously, an anonymous type was used for creating a diagnostic with related information. The anonymous type would then be translated into the necessary `ts.DiagnosticRelatedInformation` shape within `makeDiagnostic`. This commit switches the `makeDiagnostic` signature over to taking `ts.DiagnosticRelatedInformation` directly and introduces `makeRelatedInformation` to easily create such objects. This is done to aid in making upcoming work more readable.
…ompilations During AOT compilation, the value of some expressions need to be known at compile time. The compiler has the ability to statically evaluate expressions the best it can, but there can be occurrences when an expression cannot be evaluated statically. For instance, the evaluation could depend on a dynamic value or syntax is used that the compiler does not understand. Alternatively, it is possible that an expression could be statically evaluated but the resulting value would be of an incorrect type. In these situations, it would be helpful if the compiler could explain why it is unable to evaluate an expression. To this extend, the static interpreter in Ivy keeps track of a trail of `DynamicValue`s which follow the path of nodes that were considered all the way to the node that causes an expression to be considered dynamic. Up until this commit, this rich trail of information was not surfaced to a developer so the compiler was of little help to explain why static evaluation failed, resulting in situations that are hard to debug and resolve. This commit adds much more insight to the diagnostic that is produced for static evaluation errors. For dynamic values, the trail of `DynamicValue` instances is presented to the user in a meaningful way. If a value is available but not of the correct type, the type of the resolved value is shown. Resolves FW-2155
This commit introduces a dedicated `DynamicValue` kind to indicate that a value cannot be evaluated statically as the function body is not just a single return statement. This allows more accurate reporting of why a function call failed to be evaluated, i.e. we now include a reference to the function declaration and have a tailor-made diagnostic message.
…n AOT compilations
…ompilations (#37587) During AOT compilation, the value of some expressions need to be known at compile time. The compiler has the ability to statically evaluate expressions the best it can, but there can be occurrences when an expression cannot be evaluated statically. For instance, the evaluation could depend on a dynamic value or syntax is used that the compiler does not understand. Alternatively, it is possible that an expression could be statically evaluated but the resulting value would be of an incorrect type. In these situations, it would be helpful if the compiler could explain why it is unable to evaluate an expression. To this extend, the static interpreter in Ivy keeps track of a trail of `DynamicValue`s which follow the path of nodes that were considered all the way to the node that causes an expression to be considered dynamic. Up until this commit, this rich trail of information was not surfaced to a developer so the compiler was of little help to explain why static evaluation failed, resulting in situations that are hard to debug and resolve. This commit adds much more insight to the diagnostic that is produced for static evaluation errors. For dynamic values, the trail of `DynamicValue` instances is presented to the user in a meaningful way. If a value is available but not of the correct type, the type of the resolved value is shown. Resolves FW-2155 PR Close #37587
…all (#37587) This commit introduces a dedicated `DynamicValue` kind to indicate that a value cannot be evaluated statically as the function body is not just a single return statement. This allows more accurate reporting of why a function call failed to be evaluated, i.e. we now include a reference to the function declaration and have a tailor-made diagnostic message. PR Close #37587
…dInformation` (angular#37587) Previously, an anonymous type was used for creating a diagnostic with related information. The anonymous type would then be translated into the necessary `ts.DiagnosticRelatedInformation` shape within `makeDiagnostic`. This commit switches the `makeDiagnostic` signature over to taking `ts.DiagnosticRelatedInformation` directly and introduces `makeRelatedInformation` to easily create such objects. This is done to aid in making upcoming work more readable. PR Close angular#37587
…ompilations (angular#37587) During AOT compilation, the value of some expressions need to be known at compile time. The compiler has the ability to statically evaluate expressions the best it can, but there can be occurrences when an expression cannot be evaluated statically. For instance, the evaluation could depend on a dynamic value or syntax is used that the compiler does not understand. Alternatively, it is possible that an expression could be statically evaluated but the resulting value would be of an incorrect type. In these situations, it would be helpful if the compiler could explain why it is unable to evaluate an expression. To this extend, the static interpreter in Ivy keeps track of a trail of `DynamicValue`s which follow the path of nodes that were considered all the way to the node that causes an expression to be considered dynamic. Up until this commit, this rich trail of information was not surfaced to a developer so the compiler was of little help to explain why static evaluation failed, resulting in situations that are hard to debug and resolve. This commit adds much more insight to the diagnostic that is produced for static evaluation errors. For dynamic values, the trail of `DynamicValue` instances is presented to the user in a meaningful way. If a value is available but not of the correct type, the type of the resolved value is shown. Resolves FW-2155 PR Close angular#37587
…all (angular#37587) This commit introduces a dedicated `DynamicValue` kind to indicate that a value cannot be evaluated statically as the function body is not just a single return statement. This allows more accurate reporting of why a function call failed to be evaluated, i.e. we now include a reference to the function declaration and have a tailor-made diagnostic message. PR Close angular#37587
…nction call (angular#37587)" This reverts commit ce879fc. Reason for revert: failing tests on Windows (related to file paths).
…in AOT compilations (angular#37587)" This reverts commit 712f1bd. Reason for revert: failing tests on Windows (related to file paths).
…icRelatedInformation` (angular#37587)" This reverts commit d2fb552. Reason for revert: failing tests on Windows (related to file paths).
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…dInformation` (#37587) Previously, an anonymous type was used for creating a diagnostic with related information. The anonymous type would then be translated into the necessary `ts.DiagnosticRelatedInformation` shape within `makeDiagnostic`. This commit switches the `makeDiagnostic` signature over to taking `ts.DiagnosticRelatedInformation` directly and introduces `makeRelatedInformation` to easily create such objects. This is done to aid in making upcoming work more readable. PR Close #37587
…dInformation` (angular#37587) Previously, an anonymous type was used for creating a diagnostic with related information. The anonymous type would then be translated into the necessary `ts.DiagnosticRelatedInformation` shape within `makeDiagnostic`. This commit switches the `makeDiagnostic` signature over to taking `ts.DiagnosticRelatedInformation` directly and introduces `makeRelatedInformation` to easily create such objects. This is done to aid in making upcoming work more readable. PR Close angular#37587
…ompilations (angular#37587) During AOT compilation, the value of some expressions need to be known at compile time. The compiler has the ability to statically evaluate expressions the best it can, but there can be occurrences when an expression cannot be evaluated statically. For instance, the evaluation could depend on a dynamic value or syntax is used that the compiler does not understand. Alternatively, it is possible that an expression could be statically evaluated but the resulting value would be of an incorrect type. In these situations, it would be helpful if the compiler could explain why it is unable to evaluate an expression. To this extend, the static interpreter in Ivy keeps track of a trail of `DynamicValue`s which follow the path of nodes that were considered all the way to the node that causes an expression to be considered dynamic. Up until this commit, this rich trail of information was not surfaced to a developer so the compiler was of little help to explain why static evaluation failed, resulting in situations that are hard to debug and resolve. This commit adds much more insight to the diagnostic that is produced for static evaluation errors. For dynamic values, the trail of `DynamicValue` instances is presented to the user in a meaningful way. If a value is available but not of the correct type, the type of the resolved value is shown. Resolves FW-2155 PR Close angular#37587
…all (angular#37587) This commit introduces a dedicated `DynamicValue` kind to indicate that a value cannot be evaluated statically as the function body is not just a single return statement. This allows more accurate reporting of why a function call failed to be evaluated, i.e. we now include a reference to the function declaration and have a tailor-made diagnostic message. PR Close angular#37587
During AOT compilation, the value of some expressions need to be known at
compile time. The compiler has to ability to statically evaluate expressions
the best it can, but there can be occurrences when an expression cannot be
evaluated statically. For instance, the evaluation could depend on a dynamic
value or syntax is used that the compiler does not understand. Alternatively,
it is possible that an expression could be statically evaluated but the
resulting value would be of an incorrect type.
In these situations, it would be helpful if the compiler could explain why it
is unable to evaluate an expression. To this extend, the static interpreter
in Ivy keeps track of a trail of
DynamicValues which follow the path of nodesthat were considered all the way to the node that causes an expression to be
considered dynamic. Up until this commit, this rich trail of information was
not surfaced to a developer so the compiler was of little help to explain
why static evaluation failed, resulting in situations that are hard to debug
and resolve.
This commit adds much more insight to the diagnostic that is produced for static
evaluation errors. For dynamic values, the trail of
DynamicValueinstancesis presented to the user in a meaningful way. If a value is available but not
of the correct type, the type of the resolved value is shown.
Resolves FW-2155
The text was updated successfully, but these errors were encountered: