Rustc-dev-guide: Explaining what is pure function in the context?

Created on 15 Aug 2020  路  3Comments  路  Source: rust-lang/rustc-dev-guide

The Caching/Memoization section talks about pure functions.
Can we link to pure function definition?

Most helpful comment

Isn't it already explained?

The provider function must be a pure function, that is, for the same key it must always yield the same result.

All 3 comments

Isn't it already explained?

The provider function must be a pure function, that is, for the same key it must always yield the same result.

I mean it is more than that.
Quoted wiki:

In computer programming, a pure function is a function that has the following properties:

  1. Its return value is the same for the same arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams from I/O devices).

    1. Its evaluation has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams).

So I think it is a good idea to define exactly pure function in our cases.

jyn514 in https://github.com/rust-lang/rustc-dev-guide/pull/1001#issuecomment-753702663

@lzutao I think it's unlikely anyone will know what changes you wanted other than you. Are you interested in making a PR with the information you were talking about?

Maybe I was too picky about definition of "pure function" in caching implementation of rustc.
If Caching/Memoization of rustc may have side effects (mutation of local static variables, non-local variables, mutable reference arguments or I/O streams), the current explanation in #1001 is good enough.

Closing as such.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexreg picture alexreg  路  3Comments

spastorino picture spastorino  路  5Comments

popzxc picture popzxc  路  6Comments

mark-i-m picture mark-i-m  路  5Comments

spastorino picture spastorino  路  4Comments