Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Comments

add SafeObject to object.d#2141

Closed
WalterBright wants to merge 1 commit intodlang:masterfrom
WalterBright:SafeObject
Closed

add SafeObject to object.d#2141
WalterBright wants to merge 1 commit intodlang:masterfrom
WalterBright:SafeObject

Conversation

@WalterBright
Copy link
Member

Since Object has resisted all attempts to add attributes, I created a derived class SafeObject that adds in all the attributes. By deriving from SafeObject instead of Object, one can create objects that are pure, nothrow, const, etc.

Note that derived classes will not be able to remove the pure, nothrow, @nogc, etc. attributes. For classes that cannot abide by this, they can still derive from Object.

Having SafeObject enables Phobos code to have separate overloads for SafeObject, so that they can operate safely.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@jacob-carlborg
Copy link
Contributor

I recommend putting the PR description in the commit message. Next time, if you have only one commit, GitHub will use the commit message as the PR title and description. Just separate the title and description with an empty newline.

@wilzbach
Copy link
Contributor

I thought @andralex wanted to go the other way and define an RootObject without opEquals and friends, s.t. it's easier to overwrite it.

See: #1439 (comment) (the PR itself was a solution to this problem too)

@WalterBright
Copy link
Member Author

It's nice to have multiple ideas put forth to solving it. I have been thinking about this for a while, and decided to just put it out there to push some progress.

@12345swordy
Copy link
Contributor

Couple of questions regarding this:
What if I want only some attributes and not all of them? Can I create a safe only class that allows gc to run?
Does calling the SafeObject finalize member function have the attributes pure, nothrow, nogc, etc? If it doesn't have a finalize member function what is the equivalent for this?
Wouldn't implementing system default metaclasses(I.E. SafeClass, NoGCClass, PureClass) better suited for this?

@andralex
Copy link
Member

@WalterBright and I discussed and agreed we'll pursue the ProtoObject angle instead of this. This is a good catalyst nevertheless to get the DIP started!

@andralex andralex closed this Mar 13, 2018
@WalterBright
Copy link
Member Author

Actually what we're going to do is write a DIP and see if we can't think of all the angles.

@WalterBright WalterBright deleted the SafeObject branch March 13, 2018 20:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants