<div dir="ltr">CS.getType(FVE) already gets rid of the optionality, so the lookThrough/getAnyOptionalObjectType isn&#39;t necessary at all.<div><br></div><div>I&#39;m still not sure whether this is the right solution. Are there no other expression types that need similar treatment? Is ASTWalker really the right tool for this job? These are questions for someone who knows CSGen better than I...</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Sat, Dec 31, 2016 at 1:31 PM, Robert Widmann <span dir="ltr">&lt;<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>Whoops, should only look through one level of optionality.  You get the gist.</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>~Robert Widmann</div></font></span><div><div class="gmail-h5"><br><div><blockquote type="cite"><div>On Dec 31, 2016, at 2:31 PM, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>&gt; wrote:</div><br class="gmail-m_-436856257548543851Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>I taught <span style="font-family:menlo;font-size:11px">LinkedExprAnalyzer </span>abou<wbr>t <span style="color:rgb(79,129,135);font-family:menlo;font-size:11px">ForceValueExpr</span></div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">      </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">if</span><span style="font-variant-ligatures:no-common-ligatures"> (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">auto</span><span style="font-variant-ligatures:no-common-ligatures"> FVE = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">dyn_cast</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">ForceValueExpr</span><span style="font-variant-ligatures:no-common-ligatures">&gt;(expr)<wbr>) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">LTI</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">collectedTypes</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">insert</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">CS</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures">g<wbr>etType</span><span style="font-variant-ligatures:no-common-ligatures">(FVE)-&gt;</span><span style="font-variant-ligatures:no-common-ligatures">lookThroughAllAny<wbr>OptionalTypes</span><span style="font-variant-ligatures:no-common-ligatures">().</span><span style="font-variant-ligatures:no-common-ligatures">getPointer</span><span style="font-variant-ligatures:no-common-ligatures">());</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">false</span><span style="font-variant-ligatures:no-common-ligatures">, expr };</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">      }</span></div></div><div><br></div><div>This seems to get it - didn’t check whether this regresses things, but this seems to be the right fix at a high level.</div><div><br></div><div>~Robert Widmann</div><div><br></div><br><div><blockquote type="cite"><div>On Dec 31, 2016, at 11:22 AM, Mark Lacey via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br class="gmail-m_-436856257548543851Apple-interchange-newline"><div><div dir="auto" style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div><blockquote type="cite"><div><br class="gmail-m_-436856257548543851Apple-interchange-newline">On Dec 30, 2016, at 2:07 PM, Jacob Bandes-Storch via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br class="gmail-m_-436856257548543851Apple-interchange-newline"><div><div dir="ltr">This is a pretty great bug:<span class="gmail-m_-436856257548543851Apple-converted-space"> </span><a href="https://bugs.swift.org/browse/SR-3483" target="_blank">https://bugs.swift.org/<wbr>browse/SR-3483</a><div><div><br></div><div><div><font face="monospace, monospace">    let x: Double? = 1</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    </font><span style="font-family:monospace,monospace">// error: ambiguous reference to member &#39;+&#39;</span></div><div><font face="monospace, monospace">    let sum = x! + x! + x!</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    </font><span style="font-family:monospace,monospace">//  error: value of optional type &#39;Double?&#39; not unwrapped; did you mean to use &#39;!&#39; or &#39;?&#39;?</span></div><div><font face="monospace, monospace">    let sum: Double = x! + x! + x!</font></div></div><div><br></div><div>I&#39;ve been poking around and I think the problem might be in LinkedExprAnalyzer.<span class="gmail-m_-436856257548543851Apple-converted-space"> </span></div></div></div></div></blockquote><div><br></div><div>Yeah I think you’re onto something there. Just looking at the output of the constraint solver and where bindings are happening in matchTypes(), it looks like the constraint optimizer is trying to force the result type of both adds to ‘Double?’ rather than ‘Double’, so we only ever try to solve for that type.</div><div><br></div><div>I haven’t looked at the constraint optimizer code in a while, so I don’t have a lot of insight into the best fix, but it’s clearly the problematic piece here.</div><div><br></div><div>Mark</div><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div><div>This class collects type info about elements in a chain of binary operators to speed up constraint solving. It does so in this case by grabbing the DeclRefExpr&#39;s type:<span class="gmail-m_-436856257548543851Apple-converted-space"> </span><a href="https://github.com/apple/swift/tree/474096b9cbd6ff7ac998d7cea41d629512e25570#L230-L239" target="_blank">https://github.com/<wbr>apple/swift/tree/<wbr>474096b9cbd6ff7ac998d7cea41d62<wbr>9512e25570#L230-L239</a></div><div><br></div><div>However, since this is an ASTWalker, (I think) it automatically traverses into the ForceValueExpr without remembering that the type it finds inside (from the DeclRefExpr) should have one level of optionality removed when added to the constraint system.</div><div><br></div><div>This theory sort of makes sense to me, but it doesn&#39;t explain why the simpler &quot;<font face="monospace, monospace">let sum = x! + x!</font>&quot; typechecks correctly, because that goes through the same code path.</div><div><br></div><div>Am I correct that the LinkedExprAnalyzer probably needs to make sure it doesn&#39;t keep the Optional when adding the type of a ForceValueExpr? Why wouldn&#39;t this also cause problems for a single binop application?</div><div><br></div><div>Would it be more appropriate for LinkedExprAnalyzer to be an ASTVisitor (ExprVisitor) so that instead of just saying &quot;yes, continue traversing downwards&quot; (by returning {true, expr}), its ForceValueExpr case could recursively call visit() and then getAnyOptionalObjectType on the result?</div><div><br></div><div><br></div><div>Semi-eptly,</div><div><div><div class="gmail-m_-436856257548543851gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div></div></div></div>______________________________<wbr>_________________<br>swift-dev mailing list<br><a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br></div></blockquote></div><br></div><span style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">______________________________<wbr>_________________</span><br style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">swift-dev mailing list</span><br style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-dev@swift.org" style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-dev@swift.org</a><br style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-dev" style="font-family:helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div>