julia icon indicating copy to clipboard operation
julia copied to clipboard

Make `Base.donotdelete` public

Open LilithHafner opened this issue 1 year ago • 3 comments

I rely on Base.donotdelete in Chairmarks.jl and I'd like it to be public. I imagine that other benchmarking tools also rely on it. It's been around since 1.8 (see also: #55773) and I think we should commit to keeping it functional for the rest of 1.x.

LilithHafner avatar Sep 14 '24 17:09 LilithHafner

donotdelete is actually defined in Core, and it's a built-in, as opposed to a generic function. As far as I understand exposing non-generic functions isn't a good practice. Perhaps it'd make sense to define something like this in Base, and make that public:

function donotdelete(args...)
    Core.donotdelete(args)
end

nsajko avatar Sep 14 '24 21:09 nsajko

Rust exposes very similar functionality here:

  • https://doc.rust-lang.org/beta/std/hint/fn.black_box.html

Also some C++ libraries (implemented using inline assembly). For example, folly has doNotOptimizeAway.

nsajko avatar Jun 09 '25 16:06 nsajko

Tagging Triage as this expands the public API

LilithHafner avatar Jun 09 '25 18:06 LilithHafner

What's wrong with exposing builtin functions?

Exporting a public generic function seems like it'd be of somewhat questionable utility, too. Are there any upsides to letting users override this function? I can only think of downsides.

MasonProtter avatar Jul 03 '25 08:07 MasonProtter

Are there any upsides to letting users override this function? I can only think of downsides.

I suppose you're right and past me was wrong. Not really sure though. Hoping someone who knows for sure chimes in on triage.

nsajko avatar Jul 03 '25 09:07 nsajko

BTW there are Git conflicts here.

nsajko avatar Jul 03 '25 09:07 nsajko

Triage thinks it's fine (and best) to ~export~ publicize the builtin rather than adding a layer of indirection.

Triage approves adding this to public API as Base.donotdelete.

LilithHafner avatar Jul 03 '25 17:07 LilithHafner