Zulip Chat Archive

Stream: lean4

Topic: Two Types of Inling?


Mac (Jun 22 2022 at 04:42):

What is the difference between @[inline] and @[macroInline]?

Leonardo de Moura (Jun 22 2022 at 18:27):

[inline] respects Lean calling convention: call-by-value, [macroInline] is just delta+beta reduction.
Example:

def f (x y : Nat) := if x > 0 then y else 0

def g (a : Nat) := f a (fib (a + 1000))

If f is marked as [inline], g becomes

let x := a
let y := fib (a + 1000)
if x > 0 then y else 0

If f is marked as [macroInline], we have

if a > 0 then fib (a + 1000) else 0

Leonardo de Moura (Jun 22 2022 at 18:29):

We use [macroInline] in definitions such as

@[macroInline] def or (x y : Bool) : Bool :=
  match x with
  | true  => true
  | false => y

to make sure we get the behavior most users expect: y is not evaluated if x evaluates to true.

Mac (Jun 23 2022 at 02:03):

Thanks!


Last updated: Dec 20 2023 at 11:08 UTC