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

Comments

[WIP] Aa lower lib - work in progress#1985

Closed
somzzz wants to merge 3 commits intodlang:masterfrom
somzzz:aaLower_lib
Closed

[WIP] Aa lower lib - work in progress#1985
somzzz wants to merge 3 commits intodlang:masterfrom
somzzz:aaLower_lib

Conversation

@somzzz
Copy link
Contributor

@somzzz somzzz commented Dec 7, 2017

@dlang-bot
Copy link
Contributor

dlang-bot commented Dec 7, 2017

Thanks for your pull request and interest in making D better, @somzzz! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

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.

@somzzz somzzz changed the title Aa lower lib - work in progress [WIP] Aa lower lib - work in progress Dec 7, 2017
@dlang-bot dlang-bot added the WIP Work In Progress - not ready for review or pulling label Dec 7, 2017
@schveiguy
Copy link
Member

ping @quickfur as I think you attempted something like this at one point.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so did you get to build successfully with these changes?

@@ -0,0 +1,1046 @@
/**
* Implementation of associative arrays.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Implementation/Templated implementation/

private enum HASH_DELETED = 0x1;
private enum HASH_FILLED_MARK = size_t(1) << 8 * size_t.sizeof - 1;

private @property bool empty(in AssocArray!(void, void)* aa) pure nothrow @nogc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all functions in this module be vacuous templates so as to force on-demand compilation? I mean:

private @property bool empty()(in AssocArray!(void, void)* aa) pure nothrow @nogc

}


bool hasPostblit(in TypeInfo ti)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here etc

return ti;
}

struct AssocArray(K, V)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, the methods inside this struct don't need to be vacuous templates because they already are templates as members of a template struct.

}
return ti;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert a comment explaining what AssocArray is and does.

@quickfur
Copy link
Member

quickfur commented Dec 7, 2017

I haven't looked into this in detail yet, but from a cursory glance, I have the following comments:

  1. The current usage of AssocArray!(void,void)* seems to be strange and questionable. Isn't the whole point of a templated AA implementation to take advantage of compile-time type information?

  2. And to that point, the continued usage of TypeInfo seems to indicate that this implementation isn't that different from the one we already have now. So where does the templated part come in? By that, I don't mean the mere fact that there are templated parameters, but how they are benefitting the code in ways the current implementation can't do. If all we're doing is to tack on template parameters for the key and value types, and then cast that away and revert to using TypeInfos, then this new implementation is, frankly, pointless. We already have a perfectly fine TypeInfo-based implementation now. The whole thrust behind a templated AA type is to get rid of the dependency on TypeInfos. The key and value types of the AA are already known at compile-time, we should be taking advantage of that, instead of waiting until runtime to inspect the TypeInfo and make decisions then.

  3. If done carelessly, a templated AA type is going to introduce massive amounts of template bloat into existing code, which is Not Nice. Much of the AA implementation doesn't actually (need to) depend on the specifics of the key/value types, e.g., the rehashing algorithm, the collision resolution algorithm, the management of the main table of buckets, etc.. Only a few places actually need to know the specifics of the type: when computing a hash value, when comparing keys, when storing a key / value in a bucket, and when returning the result of a lookup. Ideally, these two parts should be separately implemented; the type-agnostic code should be in a core, non-templated submodule that provides the low-level primitives, and the templated part should be primarily in the user-facing side of things (probably in object.d). Doing this will probably entail a radically different code organization than what is currently there, even if the underlying algorithms will pretty much be the same. (I don't recommend trying to also replace the algorithms, the scope of the code change will be too large to handle in that case, and too prone to breakage. Let's get the templated implementation working first, then we can worry about improving the algorithms.)

  4. Another thing that might be worth considering in a template AA implementation is the possibility of compile-time evaluation. This may be a long shot, but in the ideal case, it would be very nice if AA literals that don't involve runtime values can be completely constructed at compile-time and stored directly in the object file. Then we can have static immutable AA's that don't incur runtime initialization overhead.

@andralex
Copy link
Member

andralex commented Dec 8, 2017

  1. The current usage of AssocArray!(void,void)* seems to be strange and questionable. Isn't the whole point of a templated AA implementation to take advantage of compile-time type information?

This is a WIP on a difficult goal and we decided to first go through a proof of concepts stage whereby AssocArray!(void,void)* stands in for the current dynamically-typed associative array. Later on we'll get more fancy.

  1. And to that point, the continued usage of TypeInfo seems to indicate that this implementation isn't that different from the one we already have now.

Indeed. That is intentional. We want to make sure the lowering generates correct calls to methods of a template type.

So where does the templated part come in? By that, I don't mean the mere fact that there are templated parameters, but how they are benefitting the code in ways the current implementation can't do. If all we're doing is to tack on template parameters for the key and value types, and then cast that away and revert to using TypeInfos, then this new implementation is, frankly, pointless. We already have a perfectly fine TypeInfo-based implementation now. The whole thrust behind a templated AA type is to get rid of the dependency on TypeInfos. The key and value types of the AA are already known at compile-time, we should be taking advantage of that, instead of waiting until runtime to inspect the TypeInfo and make decisions then.

Agreed. Yes, the plan is to move to a non-Typeinfo implementation.

  1. If done carelessly, a templated AA type is going to introduce massive amounts of template bloat into existing code, which is Not Nice.

We'll indeed look forward to improvements once we get the templated basics in place.

  1. Another thing that might be worth considering in a template AA implementation is the possibility of compile-time evaluation. This may be a long shot, but in the ideal case, it would be very nice if AA literals that don't involve runtime values can be completely constructed at compile-time and stored directly in the object file. Then we can have static immutable AA's that don't incur runtime initialization overhead.

I think we already have that (which may cause difficulty to this project).

@andralex
Copy link
Member

andralex commented Dec 8, 2017

@somzzz please rebase

@quickfur
Copy link
Member

quickfur commented Dec 8, 2017

@andralex Thanks for clarifying. Using AssocArray!(void,void) as a transitional measure to bridge to the current state of things is not a bad idea. Hoping to see the final results of this effort!

@rainers
Copy link
Member

rainers commented Dec 9, 2017

You should use some git rename command for rt.aaa.d -> assoc_array.d to not lose history and make it a lot easier to review actual changes.

}

//==============================================================================
// API AssocArrayementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test replacement error

* If key was not in the aa, a mutable pointer to newly inserted value which
* is set to all zeros
*/
extern (C) void* _aaGetY(AssocArray!(void, void)** aa, const TypeInfo_AssociativeArray ti, in size_t valsz,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use ref AssocArray!(void, void)* aa here to avoid repeating (*aa) below. Or assign it to some local.

/*
public template AssocArray(K, V)
{
import assoc_array;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see the import being delayed here. I'd recommend to put assoc_array into some sub package of core or core.internal, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd insist on that.

@dlang-bot dlang-bot added Needs Rebase needs a `git rebase` performed Needs Work labels Jan 1, 2018
@somzzz somzzz closed this Feb 15, 2018
@somzzz somzzz reopened this Feb 15, 2018
edi33416 added a commit to edi33416/druntime that referenced this pull request Feb 4, 2019
@RazvanN7 RazvanN7 closed this Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Needs Rebase needs a `git rebase` performed Needs Work stalled WIP Work In Progress - not ready for review or pulling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants