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

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #969
    #972

    Changing the function signature of GenRandSeed to “impure function” makes it not violate the LRM and I believe it has no limitations on the usage of the function since its a member of a protected type. 

    NOTE: The GHDL error is actually a run-time error occurring when the call is made and not a statical error on analysis. Thus I cannot promise that there are no other instances of this problem within the OSVVM code since I do not have any running example which executes the entire code base. However every subprogram that is a pure function within a protected type is a potential problem.

    #975
    Jim Lewis
    Member

    Hi Olof,

    I will change it in the next release (either May or June) if it does not break any of the other supported simulators.  Currently I test with ModelSim/QuestaSim and ActiveHDL/RivieraPro.  

    I will also talk to the GHDL folks about their implementation and pure subprograms.  I will have to look at the LRM as the intent of a pure function is that since it accesses an internal, it may return a different value on different executions.  Maybe that applies here since the alerts cause fileIO and cause variables internal to the Alert structure to change.  

    Whether GHDL is right or not about the usage issue, as long as the change does not impact other tools, I will make it – OSVVM is about things working.

    Jim

    #976

    I am sure it applies since the state changes between calls and thus the program result is affected by the number of calls to the function. Is not the idea behind pure functions to provide referential transparency (https://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29)?

    Anyway I am convinced that changing the signature to impure cannot have any effects since it is a subprogram within a protected type which cannot be passed as an argument to a pure function anyway and cannot be used anywhere where a pure function would be required.

    I have made this modification myself locally to OSVVM 2015.03 and I am able to use it with the latest GHDL using the LLVM backend and VHDL 2008 by the way. I was quite impressed by development of GHDL lately.

    #981
    Lars Asplund
    Member

    Isn’t the problem that the intent

    ” Certain functions, designated pure functions,
    return the same value each time they are called with the same values as actual
    parameters”

    isn’t the same as saying that you can’t access shared variables, files and so on? As long as you just write to them the intent is fulfilled.

    #982
    #985
    Lars Asplund
    Member

    You’re right Olof. I guess there’s not much point in having pure and impure if it’s just about repetitive behaviour and can’t be used by the compiler to make optimizations. 

    #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.

    #988
    Lars Asplund
    Member

    Olof, you just answered my follow-up question. Do you know if there a difference in how the simulators treat report (write to stdout) and a write to a file?

    #989

    Yes report is allowed in pure functions, presumably to debug code executed during elaboration, while writing to file is not allowed by not allowing file variables or passing files as parameters. 

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.