Comments (13)
It doesn't have anything to do with the array syntax, it's just an invalid non-constant initializer for a global as expected. I've added a full example in https://issues.dlang.org/show_bug.cgi?id=24469#c2. And it's actually a DMD regression (since v2.079).
from ldc.
Okay, I'll put there, thanks for the help :)
from ldc.
@kinke Some update on that: Although it compiles with DMD, it starts crashing randomly on a later step function return... Maybe this have an alternative?
from ldc.
Well in that case LDC might be doing the right thing, contrary to DMD. ;) - Your code somehow requires the delegate as a static constant, as part of an initializer for a global or so. And that cannot work if the delegate uses an outer context, e.g., the outer gemName
parameter in your snippet, as that context is obviously dynamic.
from ldc.
You can use -vv
when compiling with LDC, to see what it's doing right before the error; that could help.
from ldc.
Well in that case LDC might be doing the right thing, contrary to DMD. ;) - Your code somehow requires the delegate as a static constant, as part of an initializer for a global or so. And that cannot work if the delegate uses an outer context, e.g., the outer
gemName
parameter in your snippet, as that context is obviously dynamic.
I opened an issue on DMD: https://issues.dlang.org/show_bug.cgi?id=24469
What is a static constant delegate? I'm pretty sure I'm not using any kind of fancy keywords with delegates. Maybe is it possible to create a better error message like showing why have it turned to be required to be static constant?
I'll test with -vv
and comment again
from ldc.
@kinke I was able to reduce the error after looking in all my code:
struct ExistenceChecker
{
///Optional.
bool delegate() checkExistenceFn;
}
ExistenceChecker makeExistenceChecker(string gemName)
{
return ExistenceChecker(()
{
return executeShell("gem list | grep "~gemName).status == 0;
});
}
ExistenceChecker[] chks = [
makeExistenceChecker("test")
];
from ldc.
Maybe is it possible to put in the error that because of the array syntax there, it can't access the outer variables?
from ldc.
I'll put this as a feature request for showing which part requested for static initialization of a non constant delegate
from ldc.
I suggest you ask for better diagnostics (agreed; what would IMO be very helpful is knowing where the problematic initializer is) upstream, not here.
from ldc.
Wrt. how to work around this - create the array at runtime, not at compile-time, in a module ctor or so.
from ldc.
@kinke Btw I was checking that:
int delegate() makeClosure(int start)
{
return (){return start+1;};
}
auto b = makeClosure(1);
void main()
{
}
You can see it shows from where it comes from. Does that also requires to be asked on upstream? Because the upstream doesn't even show an error 🤔
from ldc.
With run.dlang.io's current DMD v2.105, it shows the same CTFE error as LDC for your example above, nicely including the initializer line:
onlineapp.d(3): Error: closures are not yet supported in CTFE
onlineapp.d(6): called from here: `makeClosure(1)`
This doesn't come from LDC directly, but the frontend's CTFE interpreter. The original error with the struct container seems to slip through there, and that's most likely where the fix should land (so in the DMD frontend, that's why I asked for the upstream issue).
from ldc.
Related Issues (20)
- Re-enable frame pointers for optimized code
- undefined symbol on hidden function: LDC should detect usage of symbols in inline assembly for LTO builds and keep them HOT 4
- Test failures on linux aarch64 HOT 3
- [x86] segmentation fault with aligned struct parameters HOT 5
- GC Memory leak HOT 10
- betterC - alloca - missing __chkstk HOT 1
- ARM/AArch64 cross-compilation targets aren't respected in an MSVC environment on Windows. HOT 2
- Cross-compilation targets aren't respected when preprocessing C files with `clang-cl` (on Windows). HOT 1
- LDC sets both never-inline and always-inline on inline functions containing DMD-style inline assembly. HOT 3
- Assertion failure when a struct contains a struct which contains bit fields spanning [17, 25) or [33, 57) bits. HOT 2
- Bad codegen for comparison with postfix HOT 5
- ld: Assertion failed: (0 && "lto symbol should not be in layout"), function symbolForAtom, file Layout.cpp, line 1381. HOT 3
- LDC bug (regression) in 1.37.0 when attempting to use std.net.curl.HTTP.responseHeaders HOT 3
- `--x86-asm-syntax=intel` option not documented HOT 2
- Memory sanitizer doesn't appear to be compiled with -fPIC on linux HOT 1
- LDC 1.38.0 crash on default parameter with `new` HOT 2
- WebAssembly: doesn't support emscripten data layout HOT 1
- lit test broken for Python >= 3.12 HOT 2
- core.stdc.stdlib.d is missing some type definitions for wasm32-unknown-unknown-wasm target HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ldc.