<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think Jon's trying to build something on top of swiftc or SourceKit. Yes?</div><div class=""><br class=""></div><div class="">You can do something like this to build your own metatype:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">ASTContext &ctx = …</div><div class="">Type intTy = ctx.getIntDecl()->getDeclaredType();</div><div class="">auto *intMetaTy = MetatypeType::get(intTy, ctx);</div></blockquote><div class=""><br class=""></div>And then compare types using TypeBase::isEqual (which looks through typealiases and such—it's comparing "canonical" types).<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">Type unknownTy = …</div><div class="">if (unknownTy->isEqual(intMetaTy)) {</div><div class=""> // celebrate</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">Hope that helps,</div>Jordan<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 13:47 , Slava Pestov via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">You can probably get the mangled name of the metatype, and refer to that. Eg,<br class=""><br class="">public func f() -> Any.Type {<br class=""> return Int.self<br class="">}<br class=""><br class="">f()<br class=""><br class="">Compile this with -emit-ir:<br class=""><br class="">@_TMSi = external global %swift.type, align 8<br class=""><br class="">define %swift.type* @_TF4blah1fFT_PMP_() #0 {<br class="">entry:<br class=""> ret %swift.type* @_TMSi<br class="">}<br class=""><br class="">So in your C++ program,<br class=""><br class="">extern "C" {<br class=""> extern void *_TMSi;<br class="">}<br class=""><br class="">Note that this is completely unsupported, and probably insane. You have been warned.<br class=""><br class="">Slava<br class=""><br class=""><blockquote type="cite" class="">On Dec 18, 2015, at 12:14 PM, Rafkind, Jon via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class="">Sorry I should have been more specific. I am working at the C++ level. I have a swift::MetaType* and want to compare it to something.<br class=""><br class="">On 12/18/2015 12:10 PM, Dave Abrahams wrote:<br class=""><br class=""><br class=""><br class=""><br class="">On Dec 18, 2015, at 11:16 AM, Rafkind, Jon via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>><<a href="mailto:swift-dev@swift.org" class="">mailto:swift-dev@swift.org</a>> wrote:<br class=""><br class="">Given a swift::MetaType how can I tell if it corresponds to the MetaType of the standard Int type? Is there a way to get a reference to the MetaType from the StdlibModule or TheBuiltinModule?<br class=""><br class="">For now I can convert the MetaType to a string and compare it to "Int.Type" but that is yucky.<br class=""><br class=""><br class=""><br class="">Equality comparison works:<br class=""><br class="">(swift) String.self == Int.self<br class="">// r2 : Bool = false<br class="">(swift) Int.self == Int.self<br class="">// r3 : Bool = true<br class=""><br class=""><br class=""><br class=""><br class=""><br class="">--<br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><<a href="mailto:swift-dev@swift.org" class="">mailto:swift-dev@swift.org</a>><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""><br class=""><br class=""><br class="">-Dave<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class="">--<br class="">_______________________________________________<br class="">swift-dev mailing list<br class="">swift-dev@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></div></blockquote></div><br class=""></div></body></html>