# @inbounds equivalent for type assertions

**URL:** <https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107>\
**Category:** General Usage\
**Tags:** performance, type\
**Created:** [October 22, 2022, 3:13pm UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107 "2022-10-22T15:13:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HashBrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hashbrown/32/43601_2.png) [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Post date:** [October 22, 2022, 3:13pm UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107/1 "2022-10-22T15:13:22Z")

</div>

Is there an @inbounds equivalent for type assertions? That is allow the compiler to aggressively compile a specialization based on a type assertion that is unsafe if the type is not correct?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 8, 2022, 11:09am UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107/2 "2022-11-08T11:09:03Z")

</div>

This occurred to me as related to your question:

> [@Unreasonable slow speed in numerical integration](https://discourse.julialang.org/t/unreasonable-slow-speed-in-numerical-integration/89910/2):
>
> Note also that your [argument-type and return-type declarations don’t impact performance](https://docs.julialang.org/en/v1/manual/functions/#Argument-type-declarations) and it is probably clearer to omit them.

See also: [Be aware of when Julia avoids specializing](https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 8, 2022, 3:31pm UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107/3 "2022-11-08T15:31:17Z")

</div>

You can assert a type of a value or expression. The compiler knows that this means the expression is either of that type or raises an error. There’s no way to do this unsafely.
