Skip to content

refactor: Add attributes to dmd.common.{outbuffer,file} #15531

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PetarKirov
Copy link
Member

  • refactor(dmd/common/file): Add function attributes
  • refactor(dmd/common/outbuffer): Add @nogc and harmonize attributes

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @PetarKirov!

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 run digger -- build "master + dmd#15531"

@PetarKirov
Copy link
Member Author

This is part of a bigger branch, where I was able to add nothrow and/or @nogc (with no casts or try/catch workarounds) to various parts of hdrgen and mtype, but the changeset was starting to become big, so I decided to publish what I have so far.

@PetarKirov
Copy link
Member Author

PetarKirov commented Aug 11, 2023

------------
src/dmd/common/outbuffer.d(543): Error: `@nogc` function `dmd.common.outbuffer.OutBuffer.vprintf` cannot call non-@nogc function `core.stdc.stdarg.va_copy`
...

This must be happening because the CI is using an older version of bootstrap dmd.

Perhaps I should redefine the stdarg functions in the pureMalloc? In addition to nothrow, I wonder if I should also add pure.

@@ -73,7 +73,7 @@ struct OutBuffer
Params:
filename = zero-terminated name of file to map into memory
*/
@trusted this(const(char)* filename)
this(const(char)* filename) @trusted
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not have a mallocNew!(T)(Args...) that we could have be @trusted instead?

Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

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

While in general I like @nogc, it doesn't serve much purpose in the dmd source code because dmd uses the gc here and there.

@WalterBright
Copy link
Member

I tried adding nothrow to the code base, but it turned out to be clumsy because of all the circular control paths. @ibuclaw suggested adding a nothrow compiler switch, and I implemented that.

@PetarKirov
Copy link
Member Author

@WalterBright, yes I followed the progress on the -nothrow switch, nice work 👍

That said, I still find value in explicit attributes for the use case of using dmd as a library. I plan to continue work on this PR once I have time.

@RazvanN7
Copy link
Contributor

@PetarKirov Any updates on this?

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

Successfully merging this pull request may close these issues.

5 participants