Skip to content

Better protocol conformance and substitution map printing #16622

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 7 commits into from
May 15, 2018

Conversation

huonw
Copy link
Contributor

@huonw huonw commented May 15, 2018

This stops recursive conformances from printing forever, and replaces them with something like:

protocol P { associatedtype A: P }
struct X: P { typealias A = X }
/*
(normal_conformance type=X protocol=P
  (assoc_type req=A type=X)
  (normal_conformance type=X protocol=P (details printed above)))
*/

(Also, notice that the above says (assoc_type req=A type=X) with the type desugared to X, whereas previously it would print the sugared version X.A because of the typealias.)

This also makes substitution map printed lisp-style and indent-awarely... nice for specialised conformances:

protocol P {}
struct X: P {}
class Super<T: P>: P {}
class Sub: Super<X> {}
/*
(inherited_conformance type=Sub protocol=P
  (specialized_conformance type=Super<X> protocol=P
    (substitution_map generic_signature=<T where T : P>
      (substitution T -> X)
      (conformance type=T
        (normal_conformance type=X protocol=P)))
    (normal_conformance type=Super<T> protocol=P)))
*/

And, lastly, minimises the size of substitution maps inside expressions (which occur on decl refs pointing to something generic):

func generic<T: Hashable>(_: T) {}
let _: (Int) -> () = generic
/*
...
(declref_expr type='(Int) -> ()' ... [with (substitution_map generic_signature=<T where T : Hashable> (substitution T -> Int))] function_ref=unapplied))
*/

Fixes rdar://problem/40074968.

@huonw
Copy link
Contributor Author

huonw commented May 15, 2018

@swift-ci please smoke test

@huonw huonw force-pushed the better-protocol-conformance-printing branch 2 times, most recently from 04e1cb1 to 41bdc91 Compare May 15, 2018 11:31
@huonw
Copy link
Contributor Author

huonw commented May 15, 2018

@swift-ci please smoke test

@huonw
Copy link
Contributor Author

huonw commented May 15, 2018

@swift-ci please smoke test macOS

huonw added 6 commits May 15, 2018 22:17
…en filled out.

If they're printed before being checked, they have little useful content:
just (normal_conformance type=Basic protocol=P1), with no details about their
contents at all.
A recursive conformance would previously recur infinitely, but now prints just
the header plus "(details printed above)".

Fixes (most of) rdar://problem/40074968
This is much easier to read when part of a larger dump, where it now occurs in
expressions and specialized conformances.

Part of rdar://problem/40074968.
…ions.

Within a dump of a DeclRef (or, more likely, a larger entity that includes one),
the full multiline details of a substitution map are likely to not be hugely
relevant, and just get in the way of understanding the interesting parts of the
dump. Thus, this is a variant that is a single line and just includes the
substitutions; the conformances (or, at least, the protocols involved) can be
inferred from the generic signature combined with those substitutions.

The style is controlled via a enum rather than a boolean, to avoid problems with
trying to pass an indent like `map->dump(out, indent)`, where the integer indent
coerces to a bool, rather than error.

Fixes rdar://problem/40074968.
@huonw huonw force-pushed the better-protocol-conformance-printing branch from 41bdc91 to 835c2c9 Compare May 15, 2018 12:18
@huonw
Copy link
Contributor Author

huonw commented May 15, 2018

@swift-ci please smoke test

Otherwise, since typealiases are used so often, one ends up with dumps
that say nothing new/useful:

    (normal_conformance type=X protocol=P
      (assoc_type req=A type=X.A))
@huonw
Copy link
Contributor Author

huonw commented May 15, 2018

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

Excellent!

@huonw huonw merged commit 51c14c8 into swiftlang:master May 15, 2018
@huonw huonw deleted the better-protocol-conformance-printing branch May 15, 2018 22:40
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