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

Runtime: enum type descriptor returns enum tag for nested enum value in single case payload (release-only) #61708

Closed
stephencelis opened this issue Oct 25, 2022 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself IRGen LLVM IR generation optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@stephencelis
Copy link
Contributor

stephencelis commented Oct 25, 2022

Describe the bug

Given the following nested enums:

public enum E1 {
  case c1(E2)
}

public enum E2 {
  case c1(Bool)
  case c2(Bool)
  case c3(Any)
}

Using the runtime to inspect the enum "tag" of E1.c1(.c2(true)) should result in returning 0 to match the index of its only case, c1.

And it does...in debug configurations.

In release configurations it returns 1 instead, which reflects the nested tag, E2.c2(true).

Steps To Reproduce

I'm using @Azoy's Echo for ease of access to the Swift runtime metadata. In particular I am using @ole's PR fork, which adds support for release builds.

Steps to reproduce the behavior:

  1. Clone https://github.com/stephencelis/EnumRuntimeBug

  2. cd EnumRuntimeBug

  3. Run this code:

    https://github.com/stephencelis/EnumRuntimeBug/blob/01e5ee9ee92594930df8040da8c4b4e1eebc3c94/Sources/EnumRuntimeBug/main.swift#L1-L21

    And compare in debug/release:

    $ swift run -c debug EnumRuntimeBug
    tag 0
    $ swift run -c release EnumRuntimeBug
    tag 1
    Trace/BPT trap: 5

Expected behavior

Both debug and release should evaluate the same enum tag and print tag 0.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please fill out the following information)

  • OS: macOS 12
  • Xcode Version/Tag/Branch: 14.1 (Swift 5.7)
@stephencelis stephencelis added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Oct 25, 2022
@ole
Copy link
Contributor

ole commented Oct 26, 2022

@stephencelis Looks like you have a copy/paste error in your bug description: (edit: fixed!)

@stephencelis
Copy link
Contributor Author

@ole Ah yup! Thanks and done!

@tbkka
Copy link
Contributor

tbkka commented Oct 26, 2022

CC: @drexin @aschwaighofer

@Azoy
Copy link
Contributor

Azoy commented Nov 8, 2022

#61966

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself optimized only Flag: An issue whose reproduction requires optimized compilation runtime The Swift Runtime IRGen LLVM IR generation and removed runtime The Swift Runtime labels Nov 8, 2022
@drexin
Copy link
Contributor

drexin commented Nov 10, 2022

Fixed in #61966

@drexin drexin closed this as completed Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself IRGen LLVM IR generation optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

6 participants