The proper way to get all visible protocols in a decl context

Hi,

I'm using Swift to do some language feature research. One feature I'm
testing is automatic identifying implicit conformations if a nominal type
implicitly satisfies a protocol's requirement. Then I can use that type as
the protocol directly.

The way I'm doing is in the second AST visiting pass of the TypeChecker.
When visiting a nominal type node,
- Finding all visible protocols in this context
- For each protocol, add a synthesized conformance, and use the conformance
checker to check
- If fail, remove the synthesized conformance

Just wondering the proper way to get all visible protocols in a decl
context? Right now, I record all the protocols during the type checker's
first AST visit pass. Seems not good. Any suggestions to this and to the
above conformance checking?

Many thanks!

Dunno, but if you figure it out, please share!

···

On Feb 29, 2016, at 5:00 PM, Haichuan Wang via swift-dev <swift-dev@swift.org> wrote:

Hi,

I'm using Swift to do some language feature research. One feature I'm testing is automatic identifying implicit conformations if a nominal type implicitly satisfies a protocol's requirement. Then I can use that type as the protocol directly.

The way I'm doing is in the second AST visiting pass of the TypeChecker. When visiting a nominal type node,
- Finding all visible protocols in this context
- For each protocol, add a synthesized conformance, and use the conformance checker to check
- If fail, remove the synthesized conformance

Just wondering the proper way to get all visible protocols in a decl context? Right now, I record all the protocols during the type checker's first AST visit pass. Seems not good. Any suggestions to this and to the above conformance checking?

Many thanks!
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

There’s no data structure that specifically encodes this. The easiest thing to do is use getTopLevelDecls() on the module and dyn_cast each returned result to ProtocolDecl to get the protocols.

  - Doug

···

On Feb 29, 2016, at 3:00 PM, Haichuan Wang via swift-dev <swift-dev@swift.org> wrote:

Hi,

I'm using Swift to do some language feature research. One feature I'm testing is automatic identifying implicit conformations if a nominal type implicitly satisfies a protocol's requirement. Then I can use that type as the protocol directly.

The way I'm doing is in the second AST visiting pass of the TypeChecker. When visiting a nominal type node,
- Finding all visible protocols in this context
- For each protocol, add a synthesized conformance, and use the conformance checker to check
- If fail, remove the synthesized conformance

Just wondering the proper way to get all visible protocols in a decl context? Right now, I record all the protocols during the type checker's first AST visit pass. Seems not good. Any suggestions to this and to the above conformance checking?