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

encapsulate CSE #9993

Merged
merged 1 commit into from
Jun 17, 2019
Merged

encapsulate CSE #9993

merged 1 commit into from
Jun 17, 2019

Conversation

WalterBright
Copy link
Member

This is not perfect, but it's what I mean by encapsulation:

  1. global data was encapsulated and made private
  2. allocation of data structures was encapsulated and made private
  3. the details of the data structure, such as it being an array, are now encapsulated and made private
  4. the mechanics of loops were separated from what the loop was trying to do (could go further with this and use algorithms)
  5. the slot number is now semantically separated from being an array index
  6. the code should be a lot easier to follow now
  7. no more foreach_reverse

If I did this right, the deficiencies of the CSE storage methods (outlined at the end of cgcse.d) can be addressed without changing any file other than cgcse.d.

@WalterBright WalterBright added the Severity:Refactoring No semantic changes to code label Jun 8, 2019
@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#9993"

@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented Jun 8, 2019

With this PR all methods are static and all data is static in CSE. Would it be better to have everything non-static and then have a single global instance of CSE? That might make it easier to move to a non-global, non-static version of CSE in the future.

}


/********************
* The above implementation of CSE is inefficient:
* 1. the optimization to not store CSE's that are never reloaded is based on the slot number,
Copy link
Contributor

Choose a reason for hiding this comment

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

None of the functions have a Ddoc Params section.

}

private:
__gshared:
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove the indentation of these. We never have an indentation of two spaces, as far as I know.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've used it many times for attributes.

/******************
* Returns:
* total size used by CSE's
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use the more compact Ddoc in the form of /// as has been done for offset.

@jacob-carlborg
Copy link
Contributor

I do see now that you have non-static data. Would it be better to separate the static from the non-static data?


/***
* Finish generating code for this function.
* Get rid of unused cse temporaries by shrinking the array.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a newline before this line. The first line will be a summary and should be short.


bool empty()
{
while (i)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a foreach_reverse would be simpler. When reading code and you see the while keyword you have no idea of what it's doing. While when reading the foreach_reverse keyword you know that in 99% percent of the cases it's going to iterate a data structure in reverse. The difference here is that with while you need to read the whole body but with foreach_reverse you only need to read the keyword.

Copy link
Member Author

Choose a reason for hiding this comment

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

On the other hand, many people complain about foreach_reverse. The loop is trivial enough I don't think it matters, and can't see how people would be confused about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, many people complain about foreach_reverse

Yes, and I'm one of them. I have complained that it's a dedicated keyword. It could have been implemented like foreach.reverse, in which case only foreach would be a keyword. Or not have any language support at all and instead rely on a library solution like std.range.retro.

struct Range
{
const elem* e;
int i;
Copy link
Contributor

@jacob-carlborg jacob-carlborg Jun 8, 2019

Choose a reason for hiding this comment

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

Why is int used and not size_t?

Copy link
Member Author

Choose a reason for hiding this comment

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

At one point I had it going to -1.

@WalterBright
Copy link
Member Author

Would it be better to separate the static from the non-static data?

I thought about it. I didn't think it would improve things.

Would it be better to have everything non-static and then have a single global instance of CSE?

That was my original plan, but it didn't seem to improve anything.

@jacob-carlborg
Copy link
Contributor

That was my original plan, but it didn't seem to improve anything.

In it's current form, no, I agree. But for the future, assuming we want to remove global data (which the static data inside CSE basically is) I think it would be easier.

@WalterBright
Copy link
Member Author

the buildkite failure seems spurious

@andralex andralex merged commit 0652f49 into dlang:master Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Severity:Refactoring No semantic changes to code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants