Skip to content

Commit 0206a6e

Browse files
committed
Update docs
1 parent b6371ea commit 0206a6e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,21 @@ transparent inline def zero: Int = 0
284284
val one: 1 = zero + 1
285285
```
286286

287+
### Transparent vs. non-transparent inline
288+
As we already discussed, transparent inline methods will provide a more precise.
289+
Technically this implies that transparent inline methods must be expanded while typing the program. Other inline methods are inlined later after the program is fully typed.
290+
291+
For example the following two functions will be typed the same way but will be inlined at different times.
292+
```scala
293+
inline def f1: T = ...
294+
transparent inline def f2: T = (...): T
295+
```
296+
297+
A noteworthy difference is the behavior of `transparent inline given`.
298+
If there is an error reported when inlining that definition, it will be considered as an implicit search mismatch and the search will continue.
299+
A `transparent inline given` can add a type ascription in its RHS (as in `f2` from the previous example) to avoid the precise type but keep the search behavior.
300+
On the other hand `inline given` be taken as the implicit and then after typing is done the code is inlined and any error will be emitted as usual.
301+
287302
## Inline Conditionals
288303

289304
An if-then-else expression whose condition is a constant expression can be simplified to
@@ -313,6 +328,8 @@ below:
313328
| This location is in code that was inlined at ...
314329
```
315330

331+
In a transparent inline, an `inline if` will force the inlining of any inline definition in its condition.
332+
316333
## Inline Matches
317334

318335
A `match` expression in the body of an `inline` method definition may be

docs/docs/reference/metaprogramming/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,9 @@ def setForExpr[T: Type](using Quotes): Expr[Set[T]] =
618618
case _ => '{ new HashSet[T] }
619619
```
620620

621-
## Relationship with Whitebox Inline
621+
## Relationship with Transparent Inline
622622

623-
[Inline](./inline.md) documents inlining. The code below introduces a whitebox
623+
[Inline](./inline.md) documents inlining. The code below introduces a transparent
624624
inline method that can calculate either a value of type `Int` or a value of type
625625
`String`.
626626

library/src/scala/compiletime/testing/package.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package scala.compiletime
22
package testing
33

44
/** Whether the code type checks in the current context?
5+
*
6+
* An inline definition with a call to `typeChecks` should be transparent.
57
*
68
* @param code The code to be type checked
79
*
@@ -20,6 +22,8 @@ transparent inline def typeChecks(inline code: String): Boolean =
2022
* version to version. This API is to be used for testing purposes
2123
* only.
2224
*
25+
* An inline definition with a call to `typeCheckErrors` should be transparent.
26+
*
2327
* @param code The code to be type checked
2428
*
2529
* @return a list of errors encountered during parsing and typechecking.

0 commit comments

Comments
 (0)