New Issue: Should we have inlined param procs?

18788, "e-kayrakli", "Should we have inlined param procs?", "2021-12-02T20:13:05Z"

Case 1

Here's the particular use case that this came up:

// imagine this is an arkouda function that generates a message as string
proc div(x: int, y:int) {
  if y == 0 then
    return getErrorMsg("Divide by zero");
  else
    return (x/y):string; 
}

proc getErrorMsg(param msg: string) param {
  use Reflection;
  return getFilename()+":"+getLineNumber()+" "+msg;
}

This feels intuitive but doesn't work as expected today, because getErrorMsg will always return it's own file and line number. If we were to inline that function before resolving it, would that be helpful? getErrorMsg could than look like:

inline proc getErrorMsg(param msg:string) param { /* same body */ }

I think this feels nice and obvious.

Case 2

But somehow the below make me feel less confident about this:

inline proc getErrorMsg(param msg: string) param {
  use Reflection;
  return getFilename()+":"+getLineNumber()+" in function "+getRoutineName()+" "+msg;
}

For some reason, it feels more intuitive to me for getRoutineName to return getErrorMsg rather than its callsite. (And that would make this no different than where we are today)

Case 3

But doing a bit more introspection, I like the example below which relies on the same functionality:

module CheckFunctionality {
  inline proc doIHaveEverythingINeedForAnOptimization() param {
    use Reflection;
    return canResolve("foo") && canResolve("bar") && !_local;  // or more complicated
  }
}

module Main {
  use CheckFunctionality;

  proc doIt() {
    if doIHaveEverythingINeedForAnOptimization() {
      doTheFancyThing();
    }
    else {
      doTheSlowThing();
    }
  }
}

This is not much different than Case 2 in terms of its power. But this feels more intuitive for some reason that I can't explain.

In any case, inline param procs can be our way of doing preprocessor-like operations. And when I think about such things, I can never decide whether I like them, or I am scared of the power that they have. I use them in C, for sure, though :slight_smile: