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

mir: don't nest the initialization scope in the remainder scope. #33235

Closed
wants to merge 1 commit into from

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Apr 27, 2016

Fixes #32949 by not having the remainder scope as the parent of the initialization scope.
If some MIR analysis will need to know the scope in which a variable "exists", it can be added then.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member Author

eddyb commented Apr 27, 2016

r? @nikomatsakis

@eddyb
Copy link
Member Author

eddyb commented Apr 27, 2016

cc @michaelwoerister

// FIXME #30046 ^~~~

// Don't nest the initializer in the remainder scope.
this.scope_datas[id].parent_scope = parent;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mutating this imperatively feels really hacky. Maybe add a parameter to in_scope? I forget how often we call this.

I'm still not sure if this change is OK-- but I think it's fine to refine as we go.

Copy link
Member Author

Choose a reason for hiding this comment

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

The real problem is that we need to create the remainder scope, place variables and schedule drops in it, without entering it.
Do you think it's feasible to disconnect "create a scope" from "push a ScopeId"?
That might also help with the scope bloat, if nested expression scopes can reuse the same ScopeId, I would think.

@nikomatsakis
Copy link
Contributor

@eddyb

Sorry I've been out of touch last week. Meetings proved far more absorbing than I thought they would be.

The real problem is that we need to create the remainder scope, place variables and schedule drops in it, without entering it.

I have to admit, when I read this, it suggests to me that the real problem is that we are trying to make the scope smaller than they ought to be.

It seems to me that scopes for the purpose of drops, borrowck, etc, are just... slightly different beasts than scopes for the purpose of debuginfo. I hope eventually that we only need to store the latter (at least, after MIR build is done, and drops are encoded). This would also address your concern about there being way too many scopes, since we'd only have to create a ScopeId for basic blocks and other places that names are introduced, and not every subexpression.

I'm still unclear on what's the best thing to do right now though.

@bors
Copy link
Contributor

bors commented May 8, 2016

☔ The latest upstream changes (presumably #33130) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

@eddyb per our conversation last week, I'm convinced by now we should make these the "debug info" scopes. Do you want to keep going with this PR, or do you have some other preferred approach?

@eddyb
Copy link
Member Author

eddyb commented May 17, 2016

@nikomatsakis I want to simplify the handling of scopes based on the fact that you don't need as many visibility scopes as you need the current ones.
The changes made in this PR are relevant in that the same locations will have to be changed, but it wouldn't look as terrible as this.

@eddyb eddyb closed this May 17, 2016
@eddyb eddyb deleted the mir-dbg-viz branch May 17, 2016 00:25
bors added a commit that referenced this pull request Jun 8, 2016
[MIR] Make scopes debuginfo-specific (visibility scopes).

Fixes #32949 by having MIR (visibility) scopes mimic the lexical structure.
Unlike #33235, this PR also removes all scopes without variable bindings.

Printing of scopes also changed, e.g. for:
```rust
fn foo(x: i32, y: i32) { let a = 0; let b = 0; let c = 0; }
```
Before my changes:
```rust
fn foo(arg0: i32, arg1: i32) -> () {
    let var0: i32;                       // "x" in scope 1 at <anon>:1:8: 1:9
    let var1: i32;                       // "y" in scope 1 at <anon>:1:16: 1:17
    let var2: i32;                       // "a" in scope 3 at <anon>:1:30: 1:31
    let var3: i32;                       // "b" in scope 6 at <anon>:1:41: 1:42
    let var4: i32;                       // "c" in scope 9 at <anon>:1:52: 1:53

    ...

    scope tree:
    0 1 2 3 {
        4 5
        6 {
            7 8
            9 10 11
        }
    }
}
```
After my changes:
```rust
fn foo(arg0: i32, arg1: i32) -> () {
    scope 1 {
        let var0: i32;                   // "x" in scope 1 at <anon>:1:8: 1:9
        let var1: i32;                   // "y" in scope 1 at <anon>:1:16: 1:17
        scope 2 {
            let var2: i32;               // "a" in scope 2 at <anon>:1:30: 1:31
            scope 3 {
                let var3: i32;           // "b" in scope 3 at <anon>:1:41: 1:42
                scope 4 {
                    let var4: i32;       // "c" in scope 4 at <anon>:1:52: 1:53
                }
            }
        }
    }

    ...
}
@eddyb eddyb restored the mir-dbg-viz branch March 8, 2017 19:04
@eddyb eddyb deleted the mir-dbg-viz branch March 8, 2017 19:29
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.

5 participants