Skip to content

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 16, 2025

Drop the separate level number infrastructure (which was too coarse anyway) and base level checking exclsuively on owners.

Copy link
Contributor

@Linyxus Linyxus left a comment

Choose a reason for hiding this comment

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

Overall LGTM!

There are two tests that look like an expressiveness problem. I investigated a bit, and I think it may be due to Capability.visibility returns an owner that too narrow for local bindings. For instance for an object foo in a function main, its visibility will just be foo itself. But by principle, it should be visible in the entire main.

I tried to fix this by using levelOwner for visibility. This requires some tweaks to the tests. The commit for this change: dotty-staging@d8c44aa.

Most tweaks look reasonable to me, and it resolves the expressiveness problem. There are something in this change that looks suspicious to me. Like here a local c in function body shows up in the hidden set inside function result. But it does not look unsound to me. I guess a more general question is what does it mean for a capture set to have an owner? I have the intuition that for capture sets created under the same owner, there can be subtle differences for them too.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks suspicious to me. Seems like a expressiveness problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also looks suspicious.

We map them to fresh caps but their hidden sets should not accept new elements.
Allows us to diagnose when a specific variable is created or obtains
new elements.
The previous scheme was too coarse since it treated all vaks in a method the same.
Remove old level checking code and debug infra to compare old with new.
@odersky
Copy link
Contributor Author

odersky commented Sep 19, 2025

@Linyxus I don't think using levelOwner would work. The problem is when the element is inside some block, like here:

def foo = 
  val a = 
     val b: C^ = ...
     b

That will add the invisible b to the capture set of a, since levelOwner of b is foo.

 - In levelOwner, don't skip constructors. These are significant now.
 - Skip non-static modules when computing the visibility of FreshCaps
@odersky odersky force-pushed the fix-level-checking-2 branch from 3fe6080 to de35cbb Compare September 19, 2025 17:12
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