subtype,
@subtype@insufferable.tools avatar

Why are compilers like this.

// <a href="http://main.rs" rel="ugc">main.rs</a>
#![no_main]
#![no_std]

#[no_mangle]
pub unsafe extern "C" fn foo() -> i32 {
    return 0;
}

$ rustc -O --target=wasm32-unknown-unknown <a href="http://main.rs" rel="ugc">main.rs</a> -o main.wasm
error: `#[panic_handler]` function required, but not found

error: aborting due to 1 previous error

but then

#![no_main]
#![no_std]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
    loop {}
}

#[no_mangle]
pub unsafe extern "C" fn foo() -> i32 {
    return 0;
}

$ rustc -O --target=wasm32-unknown-unknown <a href="http://main.rs" rel="ugc">main.rs</a> -o main.wasm
$ wasm2wat main.wasm -o main.wat
$ cat main.wat
(module
  (type (;0;) (func (result i32)))
  (func $foo (type 0) (result i32)
    i32.const 0)
  (memory (;0;) 16)
  (global $__stack_pointer (mut i32) (i32.const 1048576))
  (global (;1;) i32 (i32.const 1048576))
  (global (;2;) i32 (i32.const 1048576))
  (export "memory" (memory 0))
  (export "foo" (func $foo))
  (export "__data_end" (global 1))
  (export "__heap_base" (global 2)))

Where’s the panic that you wanted so much, rustc? And no, -Cpanic=abort changes nothing.

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype wait until you find the lifetimes in the compiled object :gnutroll2:

subtype,
@subtype@insufferable.tools avatar

@Ukko wait what

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype what I'm trying to say is that the language specification (pretend rust has one) requires a panic handler to always be present, just like it requires the type system and lifetime checker to pass, even tho that doesn't appear in the binary

subtype,
@subtype@insufferable.tools avatar

@Ukko well yeah but the whole point of lifetimes is that they’re only present at compile time, that’s obvious.

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype sure, but i think requiring a panic handler on a spec level and then stripping it out is better than not caring about having one and then failing with obscure linking errors like some gopher languages do

subtype,
@subtype@insufferable.tools avatar

@Ukko okay fine. it could defer the same exact error to the time when the panic handler is actually needed, though? maybe that would pointlessly increase the complexity of the compiler.

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype yes and with it always required it's easy to just look and see "oh ok, this is the base minimum i need" instead of "ah i can't use this language construct because then i'll need to implement more builtins". I actually don't hate golang it's just a perfect example of deferring the error but also they have way more such magic builtins to care about.

Why limit ourselves to just panic, why not have the entire std compiled only when needed like zig does it

subtype,
@subtype@insufferable.tools avatar

@Ukko okay but panic handler is the only thing that’s required with no_std. there’s also eh_personality that’s required on some targets, but I guess rustc forgave me that I don’t have one.

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype the eh_personality is needed for C++ throws or something like that

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype you know what, i am arguing only to argue so you win sorry for wasting time

subtype,
@subtype@insufferable.tools avatar

@Ukko we're arguing? :cirno_how: don't worry I'm bored too lol

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype we're not fighting but we're complaining about opposite things

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype get troled

subtype,
@subtype@insufferable.tools avatar

@Ukko okay fine, if I actually use a panic in the code it does get compiled. still a bit weird that it's always compiled and then conditionally stripped.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Hentai
  • doujinshi
  • announcements
  • general
  • All magazines