Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Hashmap be used in @nogc code? #60

Open
p0nce opened this issue Aug 4, 2016 · 4 comments
Open

Can Hashmap be used in @nogc code? #60

p0nce opened this issue Aug 4, 2016 · 4 comments

Comments

@p0nce
Copy link
Contributor

p0nce commented Aug 4, 2016

I thought that attribute inference would let HashMap be @nogc when using Mallocator?

Error: @nogc function 'dplug.gui.font.Font.getGlyphCoverage' cannot call non-@nogc function 'containers.hashmap.HashMap!(GlyphKey, Image!(Color!(ubyte, "l")), Mallocator, generateHash, true).HashMap.opBinaryRight!"in".opBinaryRight'
@Hackerpilot
Copy link
Contributor

I think this was caused by attribute inferrence not working on the various functions in HashMap. The problem is that the @nogc-ness of the HashMap depends on the hash function also being @nogc.

@Stretto
Copy link

Stretto commented Aug 25, 2016

One can get around @nogc attributes by casting. Making the hash function(s) predicates with defaulting to the built in types might be the way to go?

@mleise
Copy link

mleise commented Sep 9, 2016

Druntime should offer @nogc hashing for basic types. Structs and classes will work if they implement toHash() @nogc. Also all the container methods using hashes like insert(Key, Value) would have to become templates for attribute inference to kick in.
I've just hit the same issues when implementing a hash table. For now I'll use a separate hashOf() function that reimplements hashing of basic types.

@Stretto Predicates for the hash function are a good idea. It is just not quite so obvious to have as the less comparator in sorted lists. There may be many ways in which one thing is greater than another, but typically only one way it equals another.

@CyberShadow
Copy link
Member

I don't think this is practical right now in D. We need to select the attributes (with/without @nogc) depending on the allocator and the supportGC parameter, which is currently doable only by duplicating all function declarations. Inference for template functions is usable but only for methods and not e.g. destructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants