Bug 24100 – proposal to implement "partially pure" functions

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2023-08-22T21:00:35Z
Last change time
2024-12-13T19:30:34Z
Assigned to
No Owner
Creator
andreiD
Moved to GitHub: dmd#20324 →

Comments

Comment #0 by andreiD — 2023-08-22T21:00:35Z
proposal to implement "partially pure" functions (in the footsteps of Issue 24096) Rationale: 1. Expand the range of access restrictions to arbitrary program data. 2. Make a pure function deterministic. usage relationship diagram. no pure / | \ pure(in) pure(out) pure(ref) \ | / \ pure I\O A possible syntax for defining a "partially pure" function is: pure(in) type fun(...); //does not change external variables pure(out) type fun(...); //not changed by external variables pure(ref) type fun(...); //can use I/O functions but cannot use pure(in)/pure(out) functions example: int a; void f(){int x = a;} //ok void f(){int x; a = x;} //ok void f(){writeln("no ok"} //ok pure(in) void f(){int x = a;} // ok pure(in) void f(){int x; a = x;} //error pure(in) void f(){writeln("no ok"} // error pure(out) void f(){int x; a = x;} // ok pure(out) void f(){int x = a;} //error pure(out) void f(){writeln("no ok"} // error pure(ref) void f(){ writeln("ok");} // ok pure(ref) void f(){int x = a;} // error pure(ref) void f(){int x; a = x;} //error pure void f(){int x = a;} // error pure void f(){int x; a = x;} //error pure void f(){writeln("no ok"} // error pure(in) - can be thought of as a closure. pure(out) - can be comprehended as a method/subprogram. pure(ref) - can be thought of as a non-monad IO / function for resource management.
Comment #1 by andreiD — 2023-08-22T21:23:25Z
"pure" will become an attribute of the deterministic function. pure(static) - current pure.
Comment #2 by robert.schadek — 2024-12-13T19:30:34Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20324 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB