Reply To: OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert

Why OSVVM™? Forums OSVVM OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert Reply To: OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert

#986

Unfortunately VHDL already breaks referential transparency of pure functions by allowing reports in them. Still compilers might be able to optimize pure functions which do not contain any report statements or calls to other pure function containing report statements.

Consider the following code:

entity test is

end entity;

architecture a of test is

  function expensive_function_returning_false return boolean is

  begin

    report “This cost much”;

    return false;

  end function;

begin

  main : process

  begin

    assert (not (expensive_function_returning_false or expensive_function_returning_false));

    wait;

  end process;

end architecture;

This cannot and is not optimized by at least Modelsim and GHDL.

Modelsim outputs this “This cost much” twice as does GHDL. NVC which is another open source VHDL simulator will print nothing. It is likely it performs a static constant folding removing the assert entirely falsely believing it can optimize pure functions in this way.
It is not easy to determine if GHDL or Modelsim would have performed constant folding and optimized away the assert if there were no report statement without deep knowledge of their binary formats and a binary viewer.