dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix Issue 22987 - Make traits getLocation have an option to return an…

Open maxhaton opened this issue 3 years ago • 12 comments
trafficstars

… absolute path

The feature is required for an application of metaprogramming within Symmetry.

A flag is added rather than changing the default in case it breaks something.

maxhaton avatar Apr 04 '22 16:04 maxhaton

Thanks for your pull request, @maxhaton!

Bugzilla references

Auto-close Bugzilla Severity Description
22987 normal __traits(getLocation) needs a way to get an absolute path.

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#13947"

dlang-bot avatar Apr 04 '22 16:04 dlang-bot

The feature is required for an application of metaprogramming within Symmetry.

Why isn't a relative path sufficient?

MoonlightSentinel avatar Apr 04 '22 16:04 MoonlightSentinel

The feature is required for an application of metaprogramming within Symmetry.

Why isn't a relative path sufficient?

Because we need the absolute path at compile time, without this patch we have to inject some crap into our build system which is quite irritating.

maxhaton avatar Apr 04 '22 16:04 maxhaton

@ibuclaw The CircleCI thing strikes again!

maxhaton avatar Apr 04 '22 16:04 maxhaton

Because we need the absolute path at compile time, without this patch we have to inject some crap into our build system which is quite irritating.

That's a better place than injecting some crap into the D language.

dkorpel avatar Apr 04 '22 16:04 dkorpel

Because we need the absolute path at compile time, without this patch we have to inject some crap into our build system which is quite irritating.

That's a better place than injecting some crap into the D language.

I strongly contend this is not crap, traits is supposed to be for getting info out of the compiler, this is info we need. We generate interpreter hooks at compile time, we need to know where the hooks come from, this doesn't really work with a relative path, hence this patch. On top of that the cost of adding it is zero.

In fact, dmd actually already outputs absolute paths sometimes

/home/mhh/.dub/packages/intel-intrinsics-1.8.0/intel-intrinsics/source/inteli/math.d:39
asdasd/test.d:3

maxhaton avatar Apr 04 '22 16:04 maxhaton

I strongly contend this is not crap

Agreed, I just mirrored your wording. I would call it an instance of feature creep.

this is info we need.

This does not provide new info, you already have the working directory and a relative path, you're just letting dmd do the conversion work.

this doesn't really work with a relative path

Why not?

On top of that the cost of adding it is zero.

Features add maintenance cost. This one in particular adds a dependency on dmd.root.filename to traits.d and makes semanticTraits more dependent on global state, making refactoring that giant function harder than it already is.

In fact, dmd actually already outputs absolute paths sometimes

Is that a bug? If I want a relative path always, are we going to add __traits(getLocation, symbol, false, true)?

dkorpel avatar Apr 05 '22 08:04 dkorpel

@ibuclaw The CircleCI thing strikes again!

It's just you, and it only happens for pipelines under /app.circleci.com/pipelines/github/maxhaton/ namespace, so can't do much to help. Delete your dmd repo and recreate? :shrug:

ibuclaw avatar Apr 05 '22 10:04 ibuclaw

The point about global state is pretty dumb. It's a couple of branches, if you were refactoring you could copy the whole thing because it's self-contained. So again, no cost. If I'd implemented a new reflection API as a trait and dumped it in there I'd agree, but I haven't.

If we had a function to convert to a relative path then I'd have made the default a relative path but as far as I can tell there isn't one in dmd.root. the point about refactoring is misguided, the point about adding another boolean parameter is positively stupid.

On Tue, 5 Apr 2022, 09:37 Dennis, @.***> wrote:

I strongly contend this is not crap

Agreed, I just mirrored your wording. I would call it an instance of feature creep.

this is info we need.

This does not provide new info, you already have the working directory and a relative path, you're just letting dmd do the conversion work.

this doesn't really work with a relative path

Why not?

On top of that the cost of adding it is zero.

Features add maintenance cost. This one in particular adds a dependency on dmd.root.filename to traits.d and makes semanticTraits more dependent on global state, making refactoring that giant function harder than it already is.

In fact, dmd actually already outputs absolute paths sometimes

Is that a bug? If I want a relative path always, are we going to add __traits(getLocation, symbol, false, true)?

— Reply to this email directly, view it on GitHub https://github.com/dlang/dmd/pull/13947#issuecomment-1088425985, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLI75GSQI5NISWAMFNLAFDVDP3TNANCNFSM5SQARBDQ . You are receiving this because you authored the thread.Message ID: @.***>

maxhaton avatar Apr 05 '22 17:04 maxhaton

@ibuclaw The CircleCI thing strikes again!

It's just you, and it only happens for pipelines under /app.circleci.com/pipelines/github/maxhaton/ namespace, so can't do much to help. Delete your dmd repo and recreate? 🤷

That's probably what I'm going to do although if it's stateful on CircleCI then I have no idea

maxhaton avatar Apr 05 '22 17:04 maxhaton

cc @atilaneves @WalterBright

RazvanN7 avatar Apr 25 '22 13:04 RazvanN7

@maxhaton any chance on picking this up?

RazvanN7 avatar Jul 05 '22 12:07 RazvanN7

I suggest wrapping the __traits(getLocation, symbol) with:

https://dlang.org/phobos/std_path.html#absolutePath

in the application (not the compiler).

WalterBright avatar Mar 26 '24 05:03 WalterBright