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

Fix debug description for cases with multiple items #32282

Merged
merged 4 commits into from Jun 10, 2020

Conversation

vedantk
Copy link
Member

@vedantk vedantk commented Jun 9, 2020

Basically, when the user types:

   case .one(let x), .two(let x):
     <body> // break here

They should be able to po x when they break in the case body.

The interesting changes here are split up into the commits:

  • [SILGenPattern] Defer debug description of case variables
  • [SILGenFunction] Don't create redundant nested debug scopes

Those commit descriptions have detailed info about what's going on.

Resolves SR-7973, and reduces SILDebugScope allocations by ~20%
(measured when compiling the x86_64 macOS stdlib).

rdar://41048339

Instead of emitting:

```
sil_scope 4 { loc "main.swift":6:19 parent 3 }
sil_scope 5 { loc "main.swift":7:3 parent 4 }
sil_scope 6 { loc "main.swift":7:3 parent 5 }
sil_scope 7 { loc "main.swift":7:3 parent 5 }
sil_scope 8 { loc "main.swift":9:5 parent 4 }
```

Emit:

```
sil_scope 4 { loc "main.swift":6:19 parent 3 }
sil_scope 5 { loc "main.swift":7:3 parent 4 }
sil_scope 6 { loc "main.swift":9:5 parent 5 }
```
If we attempt to store a value with the wrong type into a slot reserved
for a shadow copy, diagnose what went wrong.
Create unique nested debug scopes for a switch, each of its case labels,
and each of its case bodies. This looks like:

```
  switch ... { // Enter scope 1.
    case ... : // Enter scope 2, nested within scope 1.
      <body-1> // Enter scope 3, nested within scope 2.

    case ... : // Enter scope 4, nested within scope 1.
      <body-2> // Enter scope 5, nested within scope 4.
  }
```

Use the new scope structure to defer emitting debug descriptions of case
bindings. Specifically, defer the work until we can nest the scope for a
case body under the scope for a pattern match.

This fixes SR-7973, a problem where it was impossible to inspect a case
binding in lldb when stopped at a case with multiple items.

Previously, we would emit the debug descriptions too early (in the
pattern match), leading to duplicate/conflicting descriptions. The only
reason that the ambiguous description was allowed to compile was because
the debug scopes were nested incorrectly.

rdar://41048339
@vedantk
Copy link
Member Author

vedantk commented Jun 9, 2020

@swift-ci smoke test

@vedantk
Copy link
Member Author

vedantk commented Jun 9, 2020

@swift-ci test

@vedantk
Copy link
Member Author

vedantk commented Jun 10, 2020

@swift-ci smoke test

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.

None yet

1 participant