Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Convert InterpolatedStringLiteralExpr to not use tc.callWitness(). #26076
2 times, most recently
Jul 11, 2019
slavapestov left a comment
I only have two minor cosmetic comments, otherwise its ready to merge once you fix a small conflict.
I think @brentdax should chime in on the relative merits of merging TapExpr vs keeping it separate. If you do decide to go ahead with that, I would suggest doing it in a separate PR.
Also, feel free to actually delete callWitness(), either here or in a follow-up.
You can delete TapExpr if you want, but these days I’m thinking we should just fix captures of partially initialized values and generate a closure so that it doesn’t need a specialized mechanism at all, and that change might be a bit easier if TapExpr is still separate. But we don’t know if that will actually happen, and if it doesn’t or it takes a long time, merging would be better.
Not partially applied functions, but partially initialized values. The main reason we don't currently enclose the append statements of a string interpolation in a closure is that things like this won't work with a closure:
let tuple: (Int, Int) tuple.0 = 42 print("\(tuple.0)")
The closure would try to capture all of
The tuple example is a bit silly, but the same problem happens in the first phase of an initializer, when you can't capture
What I'm saying is that, if this capture issue ever goes away, it'll be easier to refactor to use closures if
OpaqueValueExpr re-orders the sil in a way that confuses the constant evaluation. I did the simplest thing of inlining the work for TapExpr. Attaching a closure that computes the RValue instead of the RValue itself as the OpaqueValue would make the old code work.
@brentdax Alas, no, this was SILOptimizer/OSLogPrototypeCompileTest.swift. I diffed the SIL before and after, and just moving around a single alloc_box instruction fixed the issue (it triggers: oslog_non_constant_message). Manually evaluating the TapExpr without OpaqueValue lets me control the emitted order which makes the test pass. Now, the only difference in the sil from this change is that the metatype instructions are moved closer to the callsite of the initializers.