Skip to content

Runtime/standard library: fix tuple printing, reflection, and casting #4898

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

Merged
merged 3 commits into from
Sep 21, 2016

Conversation

DougGregor
Copy link
Member

This pull request provides various improvements for the runtime handling of tuples, including:

  • Printing the labels with print and String.init(describing:)
  • Providing label names in mirrors
  • Dynamic casting between tuple types element-by-element

Resolves at least rdar://problem/23130016, rdar://problem/22191852, and rdar://problem/19892202

@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

When printing a tuple via print(...), print tuple labels when they are
available. This is possible now that the runtime metadata properly
stores tuple labels. Fixes rdar://problem/23130016.
This allows dynamic casting to succeed between tuple types with
different element types, converting each element in turn. Fixes
rdar://problem/19892202.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member Author

@shahmishal the macOS smoke test failed with a "wrong sha" failure:

https://ci.swift.org/view/Pull%20Request/job/swift-PR-osx-smoke-test/1843/console

@DougGregor
Copy link
Member Author

@jrose-apple
Copy link
Contributor

jrose-apple commented Sep 21, 2016

I don't think we should support dynamic casting if we don't support static casting, no?

<stdin>:1:28: error: cannot express tuple conversion '(Int, Int)' to '(Any, Any)'
let x: (Any, Any) = (1, 1) as (Int, Int)
                           ^

@DougGregor
Copy link
Member Author

Yeah, but this works:

let x: (Any, Any) = (1, 1)

@DougGregor DougGregor merged commit 2942b85 into swiftlang:master Sep 21, 2016
@DougGregor
Copy link
Member Author

All tests pass, but the status API doesn't see it. Forcing the issue.

@DougGregor DougGregor deleted the tuple-casting branch September 21, 2016 17:09
@jrose-apple
Copy link
Contributor

That's not the same thing. Constructing a new tuple coerces the elements, but going from one tuple to another doesn't.

let x: (Int, Int) = (1, 2)
let y: (Any, Any) = x

@jckarter
Copy link
Contributor

The "cannot express" is the infamous "LAME:" error message we output because we don't have the AST nodes necessary to represent tuple-to-tuple conversions. AIUI covariant tuple conversions are intended to work. Elementwise conversions do work:

let x1 = 1
let x2 = 2
let y: (Any, Any) = (x1, x2)

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.

3 participants