Skip to content

Improve -debug-constraints output for key path components #24084

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 6 commits into from
Apr 18, 2019

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Apr 17, 2019

During constraint debugging, the AST dumper currently shows all KeyPathExpr components with <null> types because it can't look into the constraint system to find type variables. This PR improves this debugging experience, which should help us fight some of the bugs in key path type-checking.

  • Make key path component type variables consistently accessible by constraint locator
  • Add callback for ASTDumper to find them
  • Colorize, rearrange, and otherwise improve key path component AST dump formatting

Before

Screen Shot 2019-04-16 at 9 22 44 PM

After

Screen Shot 2019-04-16 at 9 22 10 PM

@beccadax beccadax requested review from jckarter and xedin April 17, 2019 03:29
@beccadax beccadax marked this pull request as ready for review April 17, 2019 03:29
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

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.

LGTM! But I'd prefer we didn't iterate over type variables to find one associated with each component, that could be done separately though.

There are two places where we can dump an expr with types from the constraint solver. There should only be one.
ASTDumper doesn’t have any way to look up key path component types in the constraint solver, so they’re currently shown as null. This change adds a hook to look them up and looks in the key path component’s FunctionResult locator, which is where subscripts already keep their return type.
Previously, nearly all of the type vars for a key path component were dumped under the KeyPathExpr itself, whcih made them difficult to differentiate when debugging. Attach each one to “key path component #N -> function result” instead.

# Conflicts:
#	lib/Sema/CSGen.cpp
@beccadax beccadax requested a review from xedin April 17, 2019 22:05
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.

LGTM, thank you!

@beccadax beccadax force-pushed the whos-that-key-path-component branch from f1c82f1 to 849b12e Compare April 18, 2019 01:17
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test and merge

1 similar comment
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test and merge

Avoids digging through the long list of type vars to find the ones related to key path components when dumping an expression.
We’ll use this instead of the function result, except for subscript components, which are already structured similarly to subscript expressions.
@beccadax beccadax force-pushed the whos-that-key-path-component branch from 849b12e to 760d4be Compare April 18, 2019 04:16
@beccadax
Copy link
Contributor Author

Missed a bug, and simplified history while I was at it.

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test linux platform

@xedin
Copy link
Contributor

xedin commented Apr 18, 2019

@swift-ci please smoke test Linux platform

@xedin
Copy link
Contributor

xedin commented Apr 18, 2019

@swift-ci please test source compatibility

@beccadax
Copy link
Contributor Author

beccadax commented Apr 18, 2019

The test failure didn't include any useful information; I'm hoping a re-run will either fix the issue or give me more leads.

@swift-ci please smoke test Linux platform

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test Linux platform

@beccadax beccadax merged commit 334b76a into swiftlang:master Apr 18, 2019
@beccadax beccadax deleted the whos-that-key-path-component branch April 18, 2019 22:54
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