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

Global Initialization checker: Widen values in assignment #21512

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

liufengyun
Copy link
Contributor

Global Initialization checker: Widen values in assignment

Copy link
Contributor

@olhotak olhotak left a comment

Choose a reason for hiding this comment

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

Otherwise (functionally) this looks good to me.

* User-specified widening annotations are repected.
*/
def widenEscapedValue(value: Value, expr: Tree): Contextual[Value] =
expr.tpe.getAnnotation(defn.InitWidenAnnot) match
Copy link
Contributor

Choose a reason for hiding this comment

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

This implements the default as 1 or 2 if there is no annotation, but the default when there is a malformed annotation is always 1.

It would be cleaner to first compute the default widening level (1 or 2), and then do the parsing of the annotation, using that default widening level if annotation parsing fails.

Even cleaner would be a function like:

def parseAnnotation: Option[Int]

that returns None if there is no annotation or there is an annotation that cannot be parsed. Then

parseAnnotation match
  case Some(i) => value.widen(i)
  case None => if ... then value.widen(2) else value.widen(1)

* The default widening is 1 for most values, 2 for function values.
* User-specified widening annotations are repected.
*/
def widenEscapedValue(value: Value, expr: Tree): Contextual[Value] =
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest renaming expr to something more specific such as annotatedTree or annotationHost.

@olhotak olhotak merged commit ec094fe into scala:main Sep 3, 2024
28 checks passed
@olhotak olhotak deleted the liufengyun/widen-assignment branch September 3, 2024 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants