Skip to content

Conversation

@hamishknight
Copy link
Contributor

Split this out of #83724 since it's also needed for another patch I'm working on. If we have a missing member or invalid expression, eagerly produce a hole since we know that's where the issue is.

@@ -1,4 +1,4 @@
// {"kind":"typecheck","signature":"(anonymous namespace)::ConnectedComponents::unionSets(swift::TypeVariableType*, swift::TypeVariableType*)","signatureAssert":"Assertion failed: (validComponentCount > 0), function unionSets"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying crashes here aren't really fixed, I've added some similar variants as part of #85407, and the fuzzer should hopefully pick up more cases for the rest

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the next step here is to be more aggressively with holes in ApplicableFunction constraint. I was thinking that we can bind right-hand side of that constraint to a placeholder if one of the arguments on the left is and skip attempting a disjunction in such case. That would help with performance for situations when a missing member is involved in a complex expression like an operator chain because it would propagate the holes to the right of the missing member.

// Eagerly turn the member type variable into a hole since we know
// this is where the issue is and we've recorded a fix for it. This
// avoids producing unnecessary holes for e.g generic parameters.
recordTypeVariablesAsHoles(memberTypeVar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't do this originally because sometimes it still helpful to wait and infer member type from the context to help avoid _ in diagnostics but that indeed leads to some unnecessary hole propagation. But we do want to be more aggressive with missing members so I think this is okay to try and see how it goes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we ought to be able to handle those cases in repairFailures instead

We know this is where the issue is so we ought to always produce a
concrete hole.
We know this is where the issue is so we can immediately bind to a hole,
ensuring we don't produce unnecessary downstream diagnostics from
things we can't infer.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

let _ = [i, j, k].reduce(0 as Int?) { // expected-error {{missing argument label 'into:' in call}}
// expected-error@-1 {{cannot convert value of type 'Int?' to expected argument type '(inout (Bool, Bool) -> Bool?, Int?) throws -> ()'}}
$0 && $1 ? $0 + $1 : ($0 ? $0 : ($1 ? $1 : nil))
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed the fact that the diagnostic changed here, this is because the extra check for hole in repairFailures, previously we were recording a redundant fix and then declining to emit a diagnostic for it, so now we're picking a different overload of +. The original diagnostic wasn't very good anyway, so I'm going to leave this for a follow-up since it doesn't immediately look like a straightforward fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this expression is very tricky to diagnose properly…

@hamishknight
Copy link
Contributor Author

swiftlang/swift-docc#1352

@swift-ci please test Windows

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test Linux

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.

2 participants