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

convert aa.c to aarray.d #8831

Merged
merged 1 commit into from Oct 17, 2018
Merged

convert aa.c to aarray.d #8831

merged 1 commit into from Oct 17, 2018

Conversation

WalterBright
Copy link
Member

@WalterBright WalterBright commented Oct 14, 2018

Since virtual functions are problematic in -betterC, I replaced the hash table inheritance with parametric polymorphism, i.e. templates. Had to add a little bit extra to interface it with C++. Once it's all in D, the inlining should make it significantly faster.

@WalterBright WalterBright added Refactoring No semantic changes to code D Conversion labels Oct 14, 2018
@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.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#8831"

@WalterBright WalterBright force-pushed the aarray.d branch 2 times, most recently from e33ebb0 to 7dc4b3c Compare October 14, 2018 10:43
@jacob-carlborg
Copy link
Contributor

Seems like GitHub doesn't understand the rename. If you can make the rename a separate commit it will be much easier to review.

@WalterBright
Copy link
Member Author

It's not a rename, it's a rewrite. aarray.d is a new file, aa.c is deleted.


alias hash_t = size_t;

struct aaA
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this can be private.

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Does not follow standard D naming conventions
  • Please come up with a better name and avoid abbreviations

Copy link
Member Author

Choose a reason for hiding this comment

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

It's largely copy/pasted from the previous implementation in aa.c. I try to avoid renaming things in the first translated version, for reasons expounded upon several times.

Copy link
Contributor

Choose a reason for hiding this comment

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

I interpreted your previous comment as this is not a direct translation and therefore added quite a lot of comments that I would not normally do for a direct translation PR.

import core.stdc.stdlib;
import core.stdc.string;

alias hash_t = size_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

Private?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it'll be used by anyone using this module.

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a comment

Choose a reason for hiding this comment

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

Many of the public functions are missing documentation or missing standard sections like Returns and Params.

/* value */
}

struct AArray(TKey, Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

No documentation.


struct AArray(TKey, Value)
{
alias Key = TKey.Key; // key type
Copy link
Contributor

Choose a reason for hiding this comment

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

No documentation.

destroy();
}

void destroy()
Copy link
Contributor

Choose a reason for hiding this comment

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

No documentation.

}
}

size_t length()
Copy link
Contributor

Choose a reason for hiding this comment

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

No documentation.

/*************************************************
* Get pointer to value in associative array indexed by key.
* Add entry for key if it is not already there.
* Returns:
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing Params section.

if (!nodes)
return null;

const aligned_keysize = aligntsize(Key.sizeof);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not follow standard D naming conventions.

if (!nodes)
return;

size_t newbuckets_length = prime_list[$ - 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not follow standard D naming conventions.

break;
}
}
auto newbuckets = cast(aaA**)calloc(newbuckets_length, (aaA*).sizeof);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not follow standard D naming conventions.

return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1);
}

immutable uint[14] prime_list =
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not follow standard D naming conventions.

/***************************************************************/

// Simple values
public struct Tinfo(K)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be by anyone making a simple hash table with a simple key. Currently it is only used by the test code further down.

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.

I'll approve because previous code was just as undocumented so in a way adding docs is "optional". @WalterBright please consider adding docs though prior to merging.

@WalterBright
Copy link
Member Author

Sigh. I though buildkite was fixed. It's failing again with no log.

@jacob-carlborg
Copy link
Contributor

@WalterBright the output is:

[INFO] Running /var/lib/buildkite-agent/builds/buildkite-agent-01-1/dlang/dmd/build/dlang-dub/test/interactive-remove.sh...
Package dub not found for registry at https://code.dlang.org/ (fallback ["registry at http://code.dlang.org/", "registry at https://code-mirror.dlang.io/", "registry at https://code-mirror2.dlang.io/", "registry at https://dub-registry.herokuapp.com/"]): No package candidate found for dub 0.9.20
No package dub was found matching the dependency 0.9.20
Fetching dub 0.9.21...
[ERROR] /var/lib/buildkite-agent/builds/buildkite-agent-01-1/dlang/dmd/build/dlang-dub/test/interactive-remove.sh:10 command failed

Not sure if it's related or expected.

@WalterBright
Copy link
Member Author

The semaphoreci one looks spurious as well.

@WalterBright WalterBright merged commit bedd02a into dlang:master Oct 17, 2018
@WalterBright WalterBright deleted the aarray.d branch October 17, 2018 10:20
@wilzbach
Copy link
Member

@WalterBright the output is:

[INFO] Running /var/lib/buildkite-agent/builds/buildkite-agent-01-1/dlang/dmd/build/dlang-dub/test/interactive-remove.sh...
Package dub not found for registry at https://code.dlang.org/ (fallback ["registry at http://code.dlang.org/", "registry at https://code-mirror.dlang.io/", "registry at https://code-mirror2.dlang.io/", "registry at https://dub-registry.herokuapp.com/"]): No package candidate found for dub 0.9.20
No package dub was found matching the dependency 0.9.20
Fetching dub 0.9.21...
[ERROR] /var/lib/buildkite-agent/builds/buildkite-agent-01-1/dlang/dmd/build/dlang-dub/test/interactive-remove.sh:10 command failed

Not sure if it's related or expected.

FYI: dlang/dlang-bot#202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Refactoring No semantic changes to code
Projects
None yet
5 participants