Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
eddyb
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
10 ms
·
31.
▲
by
eddyb
6y ago
You can use #[cfg(doc)] and #[cfg_attr(doc, ...)], but it looks like that still requires #![feature(doc_cfg)], so I guess it wouldn't be compatible with stable rustc anyway, until it's stabilized itself.
32.
▲
by
eddyb
6y ago
Long-term, with const generics, and VG (or a macro that creates a (a, (b, (c, ()))) nesting like the hlist crate), we could maybe replace format_args! and friends. However , there is one more thing a function can't do: borrowing argum
33.
▲
by
eddyb
7y ago
I wonder if people upthread meant the warning, or e.g. getting the `Foo` in `Result<Foo, BarError>`. ( EDIT : nevermind, just looked again and pcwalton was referring to the warning and specifically `Result<(), E>`; oh well) Be
34.
▲
by
eddyb
7y ago
Monomorphization tends to happen "on the fly", and even if it wasn't, it would still be cheaper than duplicating all of the work of parsing and type-checking (which is needed if the user manually monomorphized).
35.
▲
by
eddyb
7y ago
> I also don't know what you mean by local git dep. Presumably, the `git` URL for dependencies, in `Cargo.toml`, can point to a local git repository. That should let you refer to a branch / commit of that repository, other than
36.
▲
by
eddyb
8y ago
Then you can use the techniques in the thread I linked. But without guarding mutability behind some way to indicate interrupts are disabled, or an outright lock, and without guaranteeing no data races (Sync), it's not actually safe. An
37.
▲
by
eddyb
8y ago
If it's per-core you should look into making `#[thread_local]` statics work, which remove some of the restrictions. `static mut` is not always safe even in a single-threaded environment, because of reentrance - see also https:/
38.
▲
by
eddyb
8y ago
Not using pointers at all for graphs . I suspect a lot of the data where you want to use pointers for efficiency, is already in stricter shapes than graphs.
39.
▲
by
eddyb
8y ago
Not sure how many editors' syntax highlighting do this by default, but at least for me, it really helped to make `?` bold red.
40.
▲
by
eddyb
8y ago
Note that Rust has "forward goto" in the form of "labelled break" (which can even carry a value), so I suspect some cases might not even need converting to a loop-match "state machine".
41.
▲
by
eddyb
8y ago
This is an old link, but I could find https://github.com/google/xi-editor/blob/master/docs/docs/cr... on master.
42.
▲
by
eddyb
8y ago
Yes, but limited to being applied at compile-time, with constant arguments. Fully general dependent type would allow passing in runtime values, which is significantly harder to type-check and execute
43.
▲
by
eddyb
8y ago
Since nobody mentioned it by name, the TLS replacement they're suggesting for lazy_static is `thread_local!` and it's part of libstd.
44.
▲
by
eddyb
8y ago
I don't understand why people don't just support TLS in non-userspace code. It's so convenient for a bunch of things, and sadly Rust, for now, has nothing in between "fully explicit argument passing" and "scope
45.
▲
by
eddyb
8y ago
I would also mention https://github.com/edef1c/libfringe which pretty much solves context-switches (by replacing them with compiler-generated minimal stack spills/restores). But as you might be able to tell from
46.
▲
by
eddyb
8y ago
> guaranteed optimisation to a single stack frame and no allocation where possible You are literally describing stackless coroutines. And the generator state transform is that optimization . If you want to get this without using gen
47.
▲
by
eddyb
8y ago
We've experimented with MIR-only rlibs - https://github.com/rust-lang/rust/issues/38913#issuecomment-... has some recent data on it - which seem to me like the best approach for solving this, but it need
48.
▲
by
eddyb
8y ago
Wasn't the ordering thing in C for stack push order in calling conventions? At least that's one theory I've heard.
49.
▲
by
eddyb
8y ago
You won't be able to entirely validate yourself most memory-related invariants in a language which can allow breaking memory safety, that's why I mentioned the hypothetical language which can encode proofs for invariants. What you
50.
▲
by
eddyb
8y ago
It's interesting to see which things Rust has defined where C refused to, such as fixing a strict evaluation order (mostly post-order on the AST), requiring signed integers to be 2's complement or masking shift amounts (`x <<
51.
▲
by
eddyb
8y ago
The UB is the result of operations which assume invariants, when they are not met. Invariants are useless if you can't assume them. Having no UB in C would require having no way to break those assumptions but C is memory/type-unsa
52.
▲
by
eddyb
8y ago
Some of that is sadly C having bad defaults - like people ending up using signed 32-bit integers (i.e. `int`) to index arrays on 64-bit platforms, which keeps signed integer overflow UB relevant, for optimizing typical indexing C code. Bo
53.
▲
by
eddyb
8y ago
See this sibling thread https://news.ycombinator.com/item?id=17189666 - typically anything touching memory needs invariants to be optimized, which in languages that can directly manipulate memory means there's also U
54.
▲
by
eddyb
8y ago
Indeed. Only wanted to point out that their optimizations also rely on UB, so they're bad examples for specifically "optimizing without relying on UB".
55.
▲
by
eddyb
8y ago
You get register allocation back if you deny taking the address of variables declared with the `register` keyword - and we've gone full circle!
56.
▲
by
eddyb
8y ago
Note that `unsafe` code blocks (or having some unsafe primitives) fundamentally results in some kind of UB in the language as a whole, and you totally can create tons of problems from it, since the rest of the language has invariants it c
57.
▲
by
eddyb
8y ago
The languages that you describe must look nothing like C (other than, ironically, syntax), and must have no untyped direct memory access pointer feature at all, which usually means they rely on a GC instead for memory safety.
58.
▲
by
eddyb
9y ago
Right, you can write a function that returns its argument plus one, but it couldn't e.g. evaluate `e` more than once (which both C and Rust macros can).
59.
▲
by
eddyb
9y ago
What do you think about Cray-style vectors, which are coming back in the form of ARM SVE and the RISC-V V extension? At least the latter claims code compiled once is compatible with all possible hardware configurations, from the start (by
60.
▲
by
eddyb
9y ago
Given an equivalence between (all the values of) two types, you can assume the types are equal , i.e. substitute one for the other in any value, no matter how complex (including functions on values/types etc.). The value/functi
More ›