First Draft: Static Single Assignment
Peter C
peterc at gmail.com
Sat Dec 6 06:51:17 UTC 2025
On Saturday, 6 December 2025 at 06:41:19 UTC, Peter C wrote:
>
> ...
> -- this is really how I want it to work --
>
What a true type‑level fixed annotation would look like if it
were added to D:
// Passing fixed into functions
class Database { void bump() {} }
void useDb(fixed Database db)
{
db.bump(); // interior mutation allowed
db = new Database(); // error: cannot rebind fixed parameter
}
void main()
{
fixed Database db = new Database();
useDb(db); // passes as fixed, guarantee preserved.
}
// -----------------------------------
// Returning fixed from functions
fixed Database makeDb()
{
return new Database(); // initialized once, returned as fixed
}
void main()
{
auto db = makeDb(); // inferred as fixed Database
db = new Database(); // error: cannot rebind
db.bump(); // interior mutation allowed
}
// ---------------------------
More information about the dip.development
mailing list