Skip to content
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

Restriction on annotation values to anydata #70

Closed
hasithaa opened this issue Apr 17, 2019 · 6 comments
Closed

Restriction on annotation values to anydata #70

hasithaa opened this issue Apr 17, 2019 · 6 comments
Labels
Area/Lang Relates to the Ballerina language specification design/usability Design does not work well for some tasks

Comments

@hasithaa
Copy link
Contributor

The Spec says,

ballerina-spec/lang/spec.html

Lines 5190 to 5193 in 0d4003e

The type-descriptor specifies the type of the annotation tag. The type must be a
subtype of one of the following three types: <code>true</code>,
<code>map&lt;anydata></code>, <code>map&lt;anydata>[]</code>. If the
type-descriptor is omitted, then the type is <code>true</code>.

But in the implementation, some annotations use function pointers values. (e.g: In the ballerina/transaction module)

To allow this, we have to use any instead of anydata. But that leads to other problems like

  • We can't freeze an annotation value.
  • Source/Const semantics might not work with any type.
@hasithaa hasithaa added Area/Lang Relates to the Ballerina language specification design/implementability Difficulty implementing the design labels Apr 17, 2019
@jclark jclark added design/usability Design does not work well for some tasks and removed design/implementability Difficulty implementing the design labels Apr 17, 2019
@jclark
Copy link
Collaborator

jclark commented Apr 17, 2019

I think it would be very problematic to allow function values to be part of annotations (and thus type descriptors), given that they are mutable (because of closures and arguably references to module state).

Maybe it would be sufficient to be able to refer to the module-level name of a function. Other annotations refer to names of variables and parameters.

@jclark
Copy link
Collaborator

jclark commented Apr 17, 2019

It might be possible to make compile time const function values work, which would effectively restrict them to names of module-level functions.

@hasithaa
Copy link
Contributor Author

Maybe it would be sufficient to be able to refer to the module-level name of a function.

Above works, but if annotation developer wants to type check an annotation value, he has to write compiler extension.

It might be possible to make compile-time const function values work, which would effectively restrict them to names of module-level functions.

If we allow compile-time const function in an annotation value, it is no longer an anydata. Isn't it? Then we can't freeze an annotation value.

@jclark
Copy link
Collaborator

jclark commented Apr 19, 2019

@hasithaa Frozen mappings and other containers can contain inherently immutable values, even if they are not anydata. So it is not impossible to extend compile-time consts to include things that are inherently immutable. Values of compile-time consts are constrained both by what type we say they must have and by the kinds of expression we allow in compile-time consts. So we could support this by allowing variable-references in compile-time consts to refer to module-level functions, and by loosening the constraint on the type that compile-time consts must have. This raises the question of what exactly immutable means, and does it make sense to consider some (e.g. module level functions) or all functions as immutable.

@jclark jclark changed the title Using map<any> instead of map<anydata> in annotation tag Restriction on annotation values to anydata Apr 19, 2019
@jclark jclark added this to the 2019Rn milestone May 22, 2019
@jclark
Copy link
Collaborator

jclark commented Jun 18, 2019

This can be addressed as part of #189

@jclark
Copy link
Collaborator

jclark commented Mar 25, 2020

We can make the type be anydata|readonly as for error detail record fields, using #462.

@jclark jclark added this to the 2020R2 milestone Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification design/usability Design does not work well for some tasks
Projects
None yet
Development

No branches or pull requests

2 participants