Skip to content

[SR-628][Sema] Improved handling of mixed lvalues & rvalues in tuple exprs #1150

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 1 commit into from
Feb 16, 2016

Conversation

gregomni
Copy link
Contributor

My previous commit here didn’t work correctly for nested tuples, both because it didn’t recurse into them to propagate access kind correctly and because an outer TupleIndex overload (when indexing into the nested tuple) could still be expecting an lvalue type.

This fix is much better. ConstraintSystem::resolveOverload now correctly always expects rvalue types from rvalue tuples. And during applyMemberRefExpr, if the overload expects an rvalue but the tuple contains lvalues, coerceToType() can correctly do any recursive munging of the tuple expr required. Note the small change to coerceToType: it knows how to handle lvalue to rvalue tuple conversions correctly, but it was performing it incorrectly (too simplistically) for tuples if the solver recorded a knownRestriction.

Test added, tests pass. Could still use a better diagnosis for (3,x).1 = 7 - will look at that next.

@gregomni gregomni changed the title Improved handling of mixed lvalues & rvalues in tuple exprs [SR-628][Sema] Improved handling of mixed lvalues & rvalues in tuple exprs Jan 31, 2016
@lattner
Copy link
Contributor

lattner commented Feb 1, 2016

I haven't had a chance to look at this, but FWIW, I'd love to get to a model where LValueType was never embedded inside of a tuple. It doesn't make sense for a tuple to be partially mutable or not, because the tuple either occurs on the LHS of an assignment or not. If all the tuple members are lvalues, then the tuple should be an lvalue. If any are rvalues, then the whole thing should be rvalues.

@slavapestov
Copy link
Contributor

@swift-ci Please test

@slavapestov
Copy link
Contributor

@lattner I'm guessing it used to be such that calling a function with a mix of inout and non-inout arguments would create such a tuple, but this is no longer the case?

@jckarter
Copy link
Contributor

jckarter commented Feb 1, 2016

We still represent arguments as tuples, but those will contain InOutType rather than LValueType. @cwillmor has some WIP to separate arguments and tuples.

@gregomni
Copy link
Contributor Author

gregomni commented Feb 2, 2016

At the moment (before & after this commit), tuple expressions get created with individual element lvalue or rvalue types - just whatever the result type is of each expr inside. It should be the case in valid argument tuples that "&" converts LValueType to InOutType, so I don't think we lose anything from making the suggested restriction (except maybe slightly worse diagnostics or harder to make good diagnostics when missing "&"s), but it does effect a lot of places. I can look into it.

@slavapestov
Copy link
Contributor

Hi @gregomni, it looks like this is ready to merge, except for the broken tests. Mind taking a look?

@swift-ci Please test

@slavapestov
Copy link
Contributor

This looks like it might be unrelated?

["Test Case \'MiscellaneousTestCase.testManifestExcludes2\' started."]
["/home/buildnode/jenkins/workspace/swift-PR-Linux-all/swiftpm/Sources/../Tests/Functional/TestMiscellaneous.swift:66: error: MiscellaneousTestCase.testManifestExcludes2 : failed - `swift build\' failed:\n\nexit(1): [\"/home/buildnode/jenkins/workspace/swift-PR-Linux-all/Ninja-ReleaseAssert/swiftpm-linux-x86_64/.bootstrap/bin/swift-build\", \"--chdir\", \"/tmp/Miscellaneous_ExcludeDiagnostic2.4sNmQK/ExcludeDiagnostic2\"]\n\n\n"]

Hmm. @jrose-apple ideas?

@gregomni
Copy link
Contributor Author

gregomni commented Feb 3, 2016

Yeah, I ran swiftpm's tests and get no failures locally, so I'm not sure what's going on. I'm not that familiar with Jenkins or its output, though, so I'm not sure what's up beside it saying that that test fails.

@jrose-apple
Copy link
Contributor

@mxcl Does that failure look familiar? Is swiftpm currently busted?

(It seems unlikely that it's this change's fault.)

@slavapestov
Copy link
Contributor

@swift-ci Please test

@gregomni
Copy link
Contributor Author

Apparently this is an unstable test in swiftpm? https://bugs.swift.org/browse/SR-712

@slavapestov
Copy link
Contributor

@swift-ci Please test

@slavapestov
Copy link
Contributor

@gregomni It looks like this is still failing, can you see if maybe there's a regression that wasn't caught by the tests?

@gregomni
Copy link
Contributor Author

@slavapestov I'll get everything up to date on this branch and take a look again, but that Build #22 that failed is still the one that ran back on Feb 1st. Maybe I need to push another change before it'll run that set of tests again...

My previous commit here didn’t work correctly for nested tuples, both
because it didn’t recurse into them to propagate access kind correctly
and because an outer TupleIndex overload (when indexing into the nested
tuple) could still be expecting an lvalue type.

This fix is much better. ConstraintSystem::resolveOverload now
correctly always expects rvalue types from rvalue tuples. And during
applyMemberRefExpr, if the overload expects an rvalue but the tuple
contains lvalues, coerceToType() correctly does any recursive munging
of the tuple expr required.
@slavapestov
Copy link
Contributor

We could just merge it and revert it if something breaks. :)

@slavapestov
Copy link
Contributor

Please just go ahead and rebase this on master and push it again. I'll merge it and keep an eye on the bots.

@gregomni gregomni force-pushed the tuple-element-lvalue branch from b30157e to 37d05ea Compare February 16, 2016 05:33
@gregomni
Copy link
Contributor Author

Oh good, that's what I just did. :)

@slavapestov
Copy link
Contributor

@swift-ci Please test

slavapestov added a commit that referenced this pull request Feb 16, 2016
[SR-628][Sema] Improved handling of mixed lvalues & rvalues in tuple exprs
@slavapestov slavapestov merged commit 6139c49 into swiftlang:master Feb 16, 2016
@gregomni
Copy link
Contributor Author

@slavapestov Cool, thanks.

@gregomni gregomni deleted the tuple-element-lvalue branch August 18, 2020 23: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.

5 participants