# How does the compiler look for opaque types?

**URL:** <https://forums.swift.org/t/how-does-the-compiler-look-for-opaque-types/42592>\
**Category:** Compiler\
**Tags:** opaque-types, parsing\
**Created:** [December 8, 2020, 4:16am UTC](https://forums.swift.org/t/how-does-the-compiler-look-for-opaque-types/42592 "2020-12-08T04:16:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [December 8, 2020, 4:16am UTC](https://forums.swift.org/t/how-does-the-compiler-look-for-opaque-types/42592/1 "2020-12-08T04:16:26Z")

</div>

I was browsing the Swift source code (in C++ using the LLVM interface libraries). I was reading the file about recognizing type expressions and another file about recognizing value expressions. I was thinking about trying to add a type construction that involves an opaque type. I was ready to think about parsing a "`some`" followed by another type expression, but I got worried about what if the opaque type is hidden behind a type alias. I recently tried a (macOS) playground, and it doesn't allow making an opaque type into an alias.

That's good from a user viewpoint. But now I'm wondering how opaque types are identified. Does each type expression that allows an opaque type within it search for a "`some`" followed by another type expression? Or is there a common code all those experiences share? And if it's shared code (I hope so), where is it?

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/typesanitizer/32/8661_2.png) [@typesanitizer](https://forums.swift.org/u/typesanitizer)\
**Post date:** [December 8, 2020, 4:39am UTC](https://forums.swift.org/t/how-does-the-compiler-look-for-opaque-types/42592/2 "2020-12-08T04:39:12Z")

</div>

In some sense yes. (I don't think they are allowed in nested positions though.). You can take a look at this method for more details.

```swift
OpaqueTypeDecl *
OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
                                  ValueDecl *originatingDecl) const 

```

It has one of the calls to `OpaqueTypeArchetypeType::get` which is a factory method.

You can also take a look at `getOpaqueResultTypeDecl()` and it's callers. (Xcode trips over at displaying the call hierarchy for `OpaqueResultTypeRequest::evaluate`, so you might think nothing is calling it.)
