[Issue 13589] [git-head] Asm statement could be assumed to nothrow, safe, pure by the enclosing function attribute

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Oct 8 08:54:18 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13589

--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Martin Nowak from comment #2)
> (In reply to Kenji Hara from comment #1)
> > And more, I'd disallow asm @safe {/*...*/} , because we already have the
> > best attribute @trusted to assume the code as such.
> 
> Disallowing @safe makes sense.
> 
> I don't agree with reusing the containing function attributes though because
> it breaks the let me try if I can make this function pure/nothrow/@safe
> pattern.

I don't argue the current feature `asm attributes {...}`. It is still useful
with attribute inference.

void foo(T)(int value) {
    asm nothrow @trusted pure {...}  // the baseline of attributes
    T t = value;   // foo's attribute will depends on the T's constructor
}

> When I add an attribute to a function with an asm statement it would
> silently compile even though noone checked the attributes.

It's not silent, because the code will explicitly display the trusting of
attribute.

1. The function attributes are explicit if it is specified.
2. asm statement is always explicit, different from attribute violations in
normal D code.

> Think of a github
> pull request diff where you see added attributes on a function but not the
> asm statement withing the body.

For example, we can just mark the casImpl function in core.druntime as pure
nothrow @nogc instead of marking the all asm statements in its body.

  https://github.com/D-Programming-Language/druntime/pull/975/files

The many diff is not theoretical issue. But practically problematic.

--


More information about the Digitalmars-d-bugs mailing list