| author | |
| committer | |
| log | ac21ade667f0f42b8b1aec5831cbc99cbaed8565 |
| tree | f66d847662b81eefe8c30de88dfedb0d93cdc524 |
| parent | d979df585d05de8d7385495fe6aee2b1d4e1380f |
| parent | bc0e2089bc9408fa76716652a8ede5b5b44a817a |
| signature |
haiku: get cmake bootstrap working37 files changed, 2032 insertions(+), 1747 deletions(-)
build.zig+3| ... | ... | @@ -747,6 +747,9 @@ fn addCmakeCfgOptionsToExe( |
| 747 | 747 | try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); |
| 748 | 748 | try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); |
| 749 | 749 | }, |
| 750 | .haiku => { | |
| 751 | try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); | |
| 752 | }, | |
| 750 | 753 | else => {}, |
| 751 | 754 | } |
| 752 | 755 | } |
lib/std/Target.zig+7| ... | ... | @@ -2740,6 +2740,13 @@ pub fn is_libc_lib_name(target: std.Target, name: []const u8) bool { |
| 2740 | 2740 | return true; |
| 2741 | 2741 | } |
| 2742 | 2742 | |
| 2743 | if (target.os.tag == .haiku) { | |
| 2744 | if (eqlIgnoreCase(ignore_case, name, "root")) | |
| 2745 | return true; | |
| 2746 | if (eqlIgnoreCase(ignore_case, name, "network")) | |
| 2747 | return true; | |
| 2748 | } | |
| 2749 | ||
| 2743 | 2750 | return false; |
| 2744 | 2751 | } |
| 2745 | 2752 |
lib/std/c/haiku.zig+808-681| ... | ... | @@ -5,28 +5,18 @@ const maxInt = std.math.maxInt; |
| 5 | 5 | const iovec = std.posix.iovec; |
| 6 | 6 | const iovec_const = std.posix.iovec_const; |
| 7 | 7 | |
| 8 | extern "c" fn _errnop() *c_int; | |
| 8 | pub extern "root" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64; | |
| 9 | 9 | |
| 10 | pub const _errno = _errnop; | |
| 11 | ||
| 12 | pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64; | |
| 10 | pub extern "root" fn find_thread(thread_name: ?*anyopaque) i32; | |
| 13 | 11 | |
| 14 | pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32; | |
| 12 | pub extern "root" fn get_system_info(system_info: *system_info) usize; | |
| 15 | 13 | |
| 16 | pub extern "c" fn get_system_info(system_info: *system_info) usize; | |
| 14 | pub extern "root" fn _get_team_info(team: i32, team_info: *team_info, size: usize) i32; | |
| 17 | 15 | |
| 18 | pub extern "c" fn _get_team_info(team: c_int, team_info: *team_info, size: usize) i32; | |
| 19 | ||
| 20 | pub extern "c" fn _get_next_area_info(team: c_int, cookie: *i64, area_info: *area_info, size: usize) i32; | |
| 16 | pub extern "root" fn _get_next_area_info(team: i32, cookie: *i64, area_info: *area_info, size: usize) i32; | |
| 21 | 17 | |
| 22 | 18 | // TODO revisit if abi changes or better option becomes apparent |
| 23 | pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info, size: usize) i32; | |
| 24 | ||
| 25 | pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize; | |
| 26 | ||
| 27 | pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, st: *Stat, stat_size: i32) usize; | |
| 28 | ||
| 29 | pub extern "c" fn _kern_get_current_team() i32; | |
| 19 | pub extern "root" fn _get_next_image_info(team: i32, cookie: *i32, image_info: *image_info, size: usize) i32; | |
| 30 | 20 | |
| 31 | 21 | pub const sem_t = extern struct { |
| 32 | 22 | type: i32, |
| ... | ... | @@ -45,7 +35,7 @@ pub const pthread_attr_t = extern struct { |
| 45 | 35 | __stack_address: ?*anyopaque, |
| 46 | 36 | }; |
| 47 | 37 | |
| 48 | pub const EAI = enum(c_int) { | |
| 38 | pub const EAI = enum(i32) { | |
| 49 | 39 | /// address family for hostname not supported |
| 50 | 40 | ADDRFAMILY = 1, |
| 51 | 41 | |
| ... | ... | @@ -99,11 +89,7 @@ pub const AI = struct { |
| 99 | 89 | |
| 100 | 90 | pub const AI_NUMERICSERV = AI.NUMERICSERV; |
| 101 | 91 | |
| 102 | pub const fd_t = c_int; | |
| 103 | pub const pid_t = c_int; | |
| 104 | pub const uid_t = u32; | |
| 105 | pub const gid_t = u32; | |
| 106 | pub const mode_t = c_uint; | |
| 92 | pub const fd_t = i32; | |
| 107 | 93 | |
| 108 | 94 | pub const socklen_t = u32; |
| 109 | 95 | |
| ... | ... | @@ -129,8 +115,8 @@ pub const dl_phdr_info = extern struct { |
| 129 | 115 | }; |
| 130 | 116 | |
| 131 | 117 | pub const Flock = extern struct { |
| 132 | type: c_short, | |
| 133 | whence: c_short, | |
| 118 | type: i16, | |
| 119 | whence: i16, | |
| 134 | 120 | start: off_t, |
| 135 | 121 | len: off_t, |
| 136 | 122 | pid: pid_t, |
| ... | ... | @@ -159,54 +145,6 @@ pub const msghdr = extern struct { |
| 159 | 145 | msg_flags: i32, |
| 160 | 146 | }; |
| 161 | 147 | |
| 162 | pub const off_t = i64; | |
| 163 | pub const ino_t = u64; | |
| 164 | ||
| 165 | pub const Stat = extern struct { | |
| 166 | dev: i32, | |
| 167 | ino: u64, | |
| 168 | mode: u32, | |
| 169 | nlink: i32, | |
| 170 | uid: i32, | |
| 171 | gid: i32, | |
| 172 | size: i64, | |
| 173 | rdev: i32, | |
| 174 | blksize: i32, | |
| 175 | atim: timespec, | |
| 176 | mtim: timespec, | |
| 177 | ctim: timespec, | |
| 178 | crtim: timespec, | |
| 179 | st_type: u32, | |
| 180 | blocks: i64, | |
| 181 | ||
| 182 | pub fn atime(self: @This()) timespec { | |
| 183 | return self.atim; | |
| 184 | } | |
| 185 | pub fn mtime(self: @This()) timespec { | |
| 186 | return self.mtim; | |
| 187 | } | |
| 188 | pub fn ctime(self: @This()) timespec { | |
| 189 | return self.ctim; | |
| 190 | } | |
| 191 | pub fn birthtime(self: @This()) timespec { | |
| 192 | return self.crtim; | |
| 193 | } | |
| 194 | }; | |
| 195 | ||
| 196 | pub const timespec = extern struct { | |
| 197 | tv_sec: isize, | |
| 198 | tv_nsec: isize, | |
| 199 | }; | |
| 200 | ||
| 201 | pub const dirent = extern struct { | |
| 202 | dev: i32, | |
| 203 | pdev: i32, | |
| 204 | ino: i64, | |
| 205 | pino: i64, | |
| 206 | reclen: u16, | |
| 207 | name: [256]u8, | |
| 208 | }; | |
| 209 | ||
| 210 | 148 | pub const B_OS_NAME_LENGTH = 32; // OS.h |
| 211 | 149 | |
| 212 | 150 | pub const area_info = extern struct { |
| ... | ... | @@ -354,17 +292,6 @@ pub const PROT = struct { |
| 354 | 292 | pub const NONE = 0x00; |
| 355 | 293 | }; |
| 356 | 294 | |
| 357 | pub const CLOCK = struct { | |
| 358 | /// system-wide monotonic clock (aka system time) | |
| 359 | pub const MONOTONIC = 0; | |
| 360 | /// system-wide real time clock | |
| 361 | pub const REALTIME = -1; | |
| 362 | /// clock measuring the used CPU time of the current process | |
| 363 | pub const PROCESS_CPUTIME_ID = -2; | |
| 364 | /// clock measuring the used CPU time of the current thread | |
| 365 | pub const THREAD_CPUTIME_ID = -3; | |
| 366 | }; | |
| 367 | ||
| 368 | 295 | pub const MSF = struct { |
| 369 | 296 | pub const ASYNC = 1; |
| 370 | 297 | pub const INVALIDATE = 2; |
| ... | ... | @@ -404,159 +331,526 @@ pub const W = struct { |
| 404 | 331 | } |
| 405 | 332 | }; |
| 406 | 333 | |
| 407 | // /system/develop/headers/posix/poll.h | |
| 408 | ||
| 409 | pub const nfds_t = usize; | |
| 334 | // access function | |
| 335 | pub const F_OK = 0; // test for existence of file | |
| 336 | pub const X_OK = 1; // test for execute or search permission | |
| 337 | pub const W_OK = 2; // test for write permission | |
| 338 | pub const R_OK = 4; // test for read permission | |
| 410 | 339 | |
| 411 | pub const pollfd = extern struct { | |
| 412 | fd: i32, | |
| 413 | events: i16, | |
| 414 | revents: i16, | |
| 415 | }; | |
| 340 | pub const F = struct { | |
| 341 | pub const DUPFD = 0x0001; | |
| 342 | pub const GETFD = 0x0002; | |
| 343 | pub const SETFD = 0x0004; | |
| 344 | pub const GETFL = 0x0008; | |
| 345 | pub const SETFL = 0x0010; | |
| 416 | 346 | |
| 417 | pub const POLL = struct { | |
| 418 | /// any readable data available | |
| 419 | pub const IN = 0x0001; | |
| 420 | /// file descriptor is writeable | |
| 421 | pub const OUT = 0x0002; | |
| 422 | pub const RDNORM = IN; | |
| 423 | pub const WRNORM = OUT; | |
| 424 | /// priority readable data | |
| 425 | pub const RDBAND = 0x0008; | |
| 426 | /// priority data can be written | |
| 427 | pub const WRBAND = 0x0010; | |
| 428 | /// high priority readable data | |
| 429 | pub const PRI = 0x0020; | |
| 347 | pub const GETLK = 0x0020; | |
| 348 | pub const SETLK = 0x0080; | |
| 349 | pub const SETLKW = 0x0100; | |
| 350 | pub const DUPFD_CLOEXEC = 0x0200; | |
| 430 | 351 | |
| 431 | /// errors pending | |
| 432 | pub const ERR = 0x0004; | |
| 433 | /// disconnected | |
| 434 | pub const HUP = 0x0080; | |
| 435 | /// invalid file descriptor | |
| 436 | pub const NVAL = 0x1000; | |
| 352 | pub const RDLCK = 0x0040; | |
| 353 | pub const UNLCK = 0x0200; | |
| 354 | pub const WRLCK = 0x0400; | |
| 437 | 355 | }; |
| 438 | 356 | |
| 439 | // /system/develop/headers/posix/signal.h | |
| 440 | ||
| 441 | pub const sigset_t = u64; | |
| 442 | pub const empty_sigset: sigset_t = 0; | |
| 443 | pub const filled_sigset = ~@as(sigset_t, 0); | |
| 444 | ||
| 445 | pub const SIG = struct { | |
| 446 | pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0); | |
| 447 | pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1); | |
| 448 | pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize)); | |
| 449 | ||
| 450 | pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3); | |
| 451 | ||
| 452 | pub const HUP = 1; | |
| 453 | pub const INT = 2; | |
| 454 | pub const QUIT = 3; | |
| 455 | pub const ILL = 4; | |
| 456 | pub const CHLD = 5; | |
| 457 | pub const ABRT = 6; | |
| 458 | pub const IOT = ABRT; | |
| 459 | pub const PIPE = 7; | |
| 460 | pub const FPE = 8; | |
| 461 | pub const KILL = 9; | |
| 462 | pub const STOP = 10; | |
| 463 | pub const SEGV = 11; | |
| 464 | pub const CONT = 12; | |
| 465 | pub const TSTP = 13; | |
| 466 | pub const ALRM = 14; | |
| 467 | pub const TERM = 15; | |
| 468 | pub const TTIN = 16; | |
| 469 | pub const TTOU = 17; | |
| 470 | pub const USR1 = 18; | |
| 471 | pub const USR2 = 19; | |
| 472 | pub const WINCH = 20; | |
| 473 | pub const KILLTHR = 21; | |
| 474 | pub const TRAP = 22; | |
| 475 | pub const POLL = 23; | |
| 476 | pub const PROF = 24; | |
| 477 | pub const SYS = 25; | |
| 478 | pub const URG = 26; | |
| 479 | pub const VTALRM = 27; | |
| 480 | pub const XCPU = 28; | |
| 481 | pub const XFSZ = 29; | |
| 482 | pub const BUS = 30; | |
| 483 | pub const RESERVED1 = 31; | |
| 484 | pub const RESERVED2 = 32; | |
| 485 | ||
| 486 | pub const BLOCK = 1; | |
| 487 | pub const UNBLOCK = 2; | |
| 488 | pub const SETMASK = 3; | |
| 357 | pub const LOCK = struct { | |
| 358 | pub const SH = 0x01; | |
| 359 | pub const EX = 0x02; | |
| 360 | pub const NB = 0x04; | |
| 361 | pub const UN = 0x08; | |
| 489 | 362 | }; |
| 490 | 363 | |
| 491 | pub const siginfo_t = extern struct { | |
| 492 | signo: c_int, | |
| 493 | code: c_int, | |
| 494 | errno: c_int, | |
| 364 | pub const FD_CLOEXEC = 1; | |
| 495 | 365 | |
| 496 | pid: pid_t, | |
| 497 | uid: uid_t, | |
| 498 | addr: *allowzero anyopaque, | |
| 366 | pub const SEEK = struct { | |
| 367 | pub const SET = 0; | |
| 368 | pub const CUR = 1; | |
| 369 | pub const END = 2; | |
| 499 | 370 | }; |
| 500 | 371 | |
| 501 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | |
| 502 | pub const Sigaction = extern struct { | |
| 503 | pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; | |
| 504 | pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; | |
| 505 | ||
| 506 | /// signal handler | |
| 507 | handler: extern union { | |
| 508 | handler: handler_fn, | |
| 509 | sigaction: sigaction_fn, | |
| 510 | }, | |
| 372 | pub const SOCK = struct { | |
| 373 | pub const STREAM = 1; | |
| 374 | pub const DGRAM = 2; | |
| 375 | pub const RAW = 3; | |
| 376 | pub const SEQPACKET = 5; | |
| 511 | 377 | |
| 512 | /// signal mask to apply | |
| 513 | mask: sigset_t, | |
| 378 | /// WARNING: this flag is not supported by windows socket functions directly, | |
| 379 | /// it is only supported by std.os.socket. Be sure that this value does | |
| 380 | /// not share any bits with any of the `SOCK` values. | |
| 381 | pub const CLOEXEC = 0x10000; | |
| 382 | /// WARNING: this flag is not supported by windows socket functions directly, | |
| 383 | /// it is only supported by std.os.socket. Be sure that this value does | |
| 384 | /// not share any bits with any of the `SOCK` values. | |
| 385 | pub const NONBLOCK = 0x20000; | |
| 386 | }; | |
| 514 | 387 | |
| 515 | /// see signal options | |
| 516 | flags: c_int, | |
| 388 | pub const SO = struct { | |
| 389 | pub const ACCEPTCONN = 0x00000001; | |
| 390 | pub const BROADCAST = 0x00000002; | |
| 391 | pub const DEBUG = 0x00000004; | |
| 392 | pub const DONTROUTE = 0x00000008; | |
| 393 | pub const KEEPALIVE = 0x00000010; | |
| 394 | pub const OOBINLINE = 0x00000020; | |
| 395 | pub const REUSEADDR = 0x00000040; | |
| 396 | pub const REUSEPORT = 0x00000080; | |
| 397 | pub const USELOOPBACK = 0x00000100; | |
| 398 | pub const LINGER = 0x00000200; | |
| 517 | 399 | |
| 518 | /// will be passed to the signal handler, BeOS extension | |
| 519 | userdata: *allowzero anyopaque = undefined, | |
| 400 | pub const SNDBUF = 0x40000001; | |
| 401 | pub const SNDLOWAT = 0x40000002; | |
| 402 | pub const SNDTIMEO = 0x40000003; | |
| 403 | pub const RCVBUF = 0x40000004; | |
| 404 | pub const RCVLOWAT = 0x40000005; | |
| 405 | pub const RCVTIMEO = 0x40000006; | |
| 406 | pub const ERROR = 0x40000007; | |
| 407 | pub const TYPE = 0x40000008; | |
| 408 | pub const NONBLOCK = 0x40000009; | |
| 409 | pub const BINDTODEVICE = 0x4000000a; | |
| 410 | pub const PEERCRED = 0x4000000b; | |
| 520 | 411 | }; |
| 521 | 412 | |
| 522 | pub const SA = struct { | |
| 523 | pub const NOCLDSTOP = 0x01; | |
| 524 | pub const NOCLDWAIT = 0x02; | |
| 525 | pub const RESETHAND = 0x04; | |
| 526 | pub const NODEFER = 0x08; | |
| 527 | pub const RESTART = 0x10; | |
| 528 | pub const ONSTACK = 0x20; | |
| 529 | pub const SIGINFO = 0x40; | |
| 530 | pub const NOMASK = NODEFER; | |
| 531 | pub const STACK = ONSTACK; | |
| 532 | pub const ONESHOT = RESETHAND; | |
| 413 | pub const SOL = struct { | |
| 414 | pub const SOCKET = -1; | |
| 533 | 415 | }; |
| 534 | 416 | |
| 535 | pub const SS = struct { | |
| 536 | pub const ONSTACK = 0x1; | |
| 537 | pub const DISABLE = 0x2; | |
| 417 | pub const PF = struct { | |
| 418 | pub const UNSPEC = AF.UNSPEC; | |
| 419 | pub const INET = AF.INET; | |
| 420 | pub const ROUTE = AF.ROUTE; | |
| 421 | pub const LINK = AF.LINK; | |
| 422 | pub const INET6 = AF.INET6; | |
| 423 | pub const LOCAL = AF.LOCAL; | |
| 424 | pub const UNIX = AF.UNIX; | |
| 425 | pub const BLUETOOTH = AF.BLUETOOTH; | |
| 538 | 426 | }; |
| 539 | 427 | |
| 540 | pub const MINSIGSTKSZ = 8192; | |
| 541 | pub const SIGSTKSZ = 16384; | |
| 542 | ||
| 543 | pub const stack_t = extern struct { | |
| 544 | sp: [*]u8, | |
| 545 | size: isize, | |
| 546 | flags: i32, | |
| 428 | pub const AF = struct { | |
| 429 | pub const UNSPEC = 0; | |
| 430 | pub const INET = 1; | |
| 431 | pub const APPLETALK = 2; | |
| 432 | pub const ROUTE = 3; | |
| 433 | pub const LINK = 4; | |
| 434 | pub const INET6 = 5; | |
| 435 | pub const DLI = 6; | |
| 436 | pub const IPX = 7; | |
| 437 | pub const NOTIFY = 8; | |
| 438 | pub const LOCAL = 9; | |
| 439 | pub const UNIX = LOCAL; | |
| 440 | pub const BLUETOOTH = 10; | |
| 441 | pub const MAX = 11; | |
| 547 | 442 | }; |
| 548 | 443 | |
| 549 | pub const NSIG = 65; | |
| 444 | pub const DT = struct {}; | |
| 550 | 445 | |
| 551 | pub const mcontext_t = vregs; | |
| 446 | /// add event to kq (implies enable) | |
| 447 | pub const EV_ADD = 0x0001; | |
| 552 | 448 | |
| 553 | pub const ucontext_t = extern struct { | |
| 554 | link: ?*ucontext_t, | |
| 555 | sigmask: sigset_t, | |
| 556 | stack: stack_t, | |
| 557 | mcontext: mcontext_t, | |
| 449 | /// delete event from kq | |
| 450 | pub const EV_DELETE = 0x0002; | |
| 451 | ||
| 452 | /// enable event | |
| 453 | pub const EV_ENABLE = 0x0004; | |
| 454 | ||
| 455 | /// disable event (not reported) | |
| 456 | pub const EV_DISABLE = 0x0008; | |
| 457 | ||
| 458 | /// only report one occurrence | |
| 459 | pub const EV_ONESHOT = 0x0010; | |
| 460 | ||
| 461 | /// clear event state after reporting | |
| 462 | pub const EV_CLEAR = 0x0020; | |
| 463 | ||
| 464 | /// force immediate event output | |
| 465 | /// ... with or without EV_ERROR | |
| 466 | /// ... use KEVENT_FLAG_ERROR_EVENTS | |
| 467 | /// on syscalls supporting flags | |
| 468 | pub const EV_RECEIPT = 0x0040; | |
| 469 | ||
| 470 | /// disable event after reporting | |
| 471 | pub const EV_DISPATCH = 0x0080; | |
| 472 | ||
| 473 | pub const EVFILT_READ = -1; | |
| 474 | pub const EVFILT_WRITE = -2; | |
| 475 | ||
| 476 | /// attached to aio requests | |
| 477 | pub const EVFILT_AIO = -3; | |
| 478 | ||
| 479 | /// attached to vnodes | |
| 480 | pub const EVFILT_VNODE = -4; | |
| 481 | ||
| 482 | /// attached to struct proc | |
| 483 | pub const EVFILT_PROC = -5; | |
| 484 | ||
| 485 | /// attached to struct proc | |
| 486 | pub const EVFILT_SIGNAL = -6; | |
| 487 | ||
| 488 | /// timers | |
| 489 | pub const EVFILT_TIMER = -7; | |
| 490 | ||
| 491 | /// Process descriptors | |
| 492 | pub const EVFILT_PROCDESC = -8; | |
| 493 | ||
| 494 | /// Filesystem events | |
| 495 | pub const EVFILT_FS = -9; | |
| 496 | ||
| 497 | pub const EVFILT_LIO = -10; | |
| 498 | ||
| 499 | /// User events | |
| 500 | pub const EVFILT_USER = -11; | |
| 501 | ||
| 502 | /// Sendfile events | |
| 503 | pub const EVFILT_SENDFILE = -12; | |
| 504 | ||
| 505 | pub const EVFILT_EMPTY = -13; | |
| 506 | ||
| 507 | pub const T = struct { | |
| 508 | pub const CGETA = 0x8000; | |
| 509 | pub const CSETA = 0x8001; | |
| 510 | pub const CSETAF = 0x8002; | |
| 511 | pub const CSETAW = 0x8003; | |
| 512 | pub const CWAITEVENT = 0x8004; | |
| 513 | pub const CSBRK = 0x8005; | |
| 514 | pub const CFLSH = 0x8006; | |
| 515 | pub const CXONC = 0x8007; | |
| 516 | pub const CQUERYCONNECTED = 0x8008; | |
| 517 | pub const CGETBITS = 0x8009; | |
| 518 | pub const CSETDTR = 0x8010; | |
| 519 | pub const CSETRTS = 0x8011; | |
| 520 | pub const IOCGWINSZ = 0x8012; | |
| 521 | pub const IOCSWINSZ = 0x8013; | |
| 522 | pub const CVTIME = 0x8014; | |
| 523 | pub const IOCGPGRP = 0x8015; | |
| 524 | pub const IOCSPGRP = 0x8016; | |
| 525 | pub const IOCSCTTY = 0x8017; | |
| 526 | pub const IOCMGET = 0x8018; | |
| 527 | pub const IOCMSET = 0x8019; | |
| 528 | pub const IOCSBRK = 0x8020; | |
| 529 | pub const IOCCBRK = 0x8021; | |
| 530 | pub const IOCMBIS = 0x8022; | |
| 531 | pub const IOCMBIC = 0x8023; | |
| 532 | pub const IOCGSID = 0x8024; | |
| 533 | ||
| 534 | pub const FIONREAD = 0xbe000001; | |
| 535 | pub const FIONBIO = 0xbe000000; | |
| 536 | }; | |
| 537 | ||
| 538 | pub const winsize = extern struct { | |
| 539 | ws_row: u16, | |
| 540 | ws_col: u16, | |
| 541 | ws_xpixel: u16, | |
| 542 | ws_ypixel: u16, | |
| 543 | }; | |
| 544 | ||
| 545 | pub const S = struct { | |
| 546 | pub const IFMT = 0o170000; | |
| 547 | pub const IFSOCK = 0o140000; | |
| 548 | pub const IFLNK = 0o120000; | |
| 549 | pub const IFREG = 0o100000; | |
| 550 | pub const IFBLK = 0o060000; | |
| 551 | pub const IFDIR = 0o040000; | |
| 552 | pub const IFCHR = 0o020000; | |
| 553 | pub const IFIFO = 0o010000; | |
| 554 | pub const INDEX_DIR = 0o4000000000; | |
| 555 | ||
| 556 | pub const IUMSK = 0o7777; | |
| 557 | pub const ISUID = 0o4000; | |
| 558 | pub const ISGID = 0o2000; | |
| 559 | pub const ISVTX = 0o1000; | |
| 560 | pub const IRWXU = 0o700; | |
| 561 | pub const IRUSR = 0o400; | |
| 562 | pub const IWUSR = 0o200; | |
| 563 | pub const IXUSR = 0o100; | |
| 564 | pub const IRWXG = 0o070; | |
| 565 | pub const IRGRP = 0o040; | |
| 566 | pub const IWGRP = 0o020; | |
| 567 | pub const IXGRP = 0o010; | |
| 568 | pub const IRWXO = 0o007; | |
| 569 | pub const IROTH = 0o004; | |
| 570 | pub const IWOTH = 0o002; | |
| 571 | pub const IXOTH = 0o001; | |
| 572 | ||
| 573 | pub fn ISREG(m: u32) bool { | |
| 574 | return m & IFMT == IFREG; | |
| 575 | } | |
| 576 | ||
| 577 | pub fn ISLNK(m: u32) bool { | |
| 578 | return m & IFMT == IFLNK; | |
| 579 | } | |
| 580 | ||
| 581 | pub fn ISBLK(m: u32) bool { | |
| 582 | return m & IFMT == IFBLK; | |
| 583 | } | |
| 584 | ||
| 585 | pub fn ISDIR(m: u32) bool { | |
| 586 | return m & IFMT == IFDIR; | |
| 587 | } | |
| 588 | ||
| 589 | pub fn ISCHR(m: u32) bool { | |
| 590 | return m & IFMT == IFCHR; | |
| 591 | } | |
| 592 | ||
| 593 | pub fn ISFIFO(m: u32) bool { | |
| 594 | return m & IFMT == IFIFO; | |
| 595 | } | |
| 596 | ||
| 597 | pub fn ISSOCK(m: u32) bool { | |
| 598 | return m & IFMT == IFSOCK; | |
| 599 | } | |
| 600 | ||
| 601 | pub fn ISINDEX(m: u32) bool { | |
| 602 | return m & INDEX_DIR == INDEX_DIR; | |
| 603 | } | |
| 604 | }; | |
| 605 | ||
| 606 | pub const HOST_NAME_MAX = 255; | |
| 607 | ||
| 608 | pub const addrinfo = extern struct { | |
| 609 | flags: i32, | |
| 610 | family: i32, | |
| 611 | socktype: i32, | |
| 612 | protocol: i32, | |
| 613 | addrlen: socklen_t, | |
| 614 | canonname: ?[*:0]u8, | |
| 615 | addr: ?*sockaddr, | |
| 616 | next: ?*addrinfo, | |
| 617 | }; | |
| 618 | ||
| 619 | pub const IPPROTO = struct { | |
| 620 | pub const IP = 0; | |
| 621 | pub const HOPOPTS = 0; | |
| 622 | pub const ICMP = 1; | |
| 623 | pub const IGMP = 2; | |
| 624 | pub const TCP = 6; | |
| 625 | pub const UDP = 17; | |
| 626 | pub const IPV6 = 41; | |
| 627 | pub const ROUTING = 43; | |
| 628 | pub const FRAGMENT = 44; | |
| 629 | pub const ESP = 50; | |
| 630 | pub const AH = 51; | |
| 631 | pub const ICMPV6 = 58; | |
| 632 | pub const NONE = 59; | |
| 633 | pub const DSTOPTS = 60; | |
| 634 | pub const ETHERIP = 97; | |
| 635 | pub const RAW = 255; | |
| 636 | pub const MAX = 256; | |
| 637 | }; | |
| 638 | ||
| 639 | pub const rlimit_resource = enum(i32) { | |
| 640 | CORE = 0, | |
| 641 | CPU = 1, | |
| 642 | DATA = 2, | |
| 643 | FSIZE = 3, | |
| 644 | NOFILE = 4, | |
| 645 | STACK = 5, | |
| 646 | AS = 6, | |
| 647 | NOVMON = 7, | |
| 648 | _, | |
| 649 | }; | |
| 650 | ||
| 651 | pub const rlim_t = i64; | |
| 652 | ||
| 653 | pub const RLIM = struct { | |
| 654 | /// No limit | |
| 655 | pub const INFINITY: rlim_t = (1 << 63) - 1; | |
| 656 | ||
| 657 | pub const SAVED_MAX = INFINITY; | |
| 658 | pub const SAVED_CUR = INFINITY; | |
| 659 | }; | |
| 660 | ||
| 661 | pub const rlimit = extern struct { | |
| 662 | /// Soft limit | |
| 663 | cur: rlim_t, | |
| 664 | /// Hard limit | |
| 665 | max: rlim_t, | |
| 666 | }; | |
| 667 | ||
| 668 | pub const SHUT = struct { | |
| 669 | pub const RD = 0; | |
| 670 | pub const WR = 1; | |
| 671 | pub const RDWR = 2; | |
| 672 | }; | |
| 673 | ||
| 674 | // TODO fill out if needed | |
| 675 | pub const directory_which = enum(i32) { | |
| 676 | B_USER_SETTINGS_DIRECTORY = 0xbbe, | |
| 677 | ||
| 678 | _, | |
| 679 | }; | |
| 680 | ||
| 681 | pub const MSG_NOSIGNAL = 0x0800; | |
| 682 | ||
| 683 | // /system/develop/headers/os/kernel/OS.h | |
| 684 | ||
| 685 | pub const area_id = i32; | |
| 686 | pub const port_id = i32; | |
| 687 | pub const sem_id = i32; | |
| 688 | pub const team_id = i32; | |
| 689 | pub const thread_id = i32; | |
| 690 | ||
| 691 | // /system/develop/headers/os/support/Errors.h | |
| 692 | ||
| 693 | pub const E = enum(i32) { | |
| 694 | pub const B_GENERAL_ERROR_BASE: i32 = std.math.minInt(i32); | |
| 695 | pub const B_OS_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x1000; | |
| 696 | pub const B_APP_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x2000; | |
| 697 | pub const B_INTERFACE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x3000; | |
| 698 | pub const B_MEDIA_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4000; | |
| 699 | pub const B_TRANSLATION_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4800; | |
| 700 | pub const B_MIDI_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x5000; | |
| 701 | pub const B_STORAGE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x6000; | |
| 702 | pub const B_POSIX_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x7000; | |
| 703 | pub const B_MAIL_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x8000; | |
| 704 | pub const B_PRINT_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x9000; | |
| 705 | pub const B_DEVICE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0xa000; | |
| 706 | ||
| 707 | pub const B_ERRORS_END = B_GENERAL_ERROR_BASE + 0xffff; | |
| 708 | ||
| 709 | pub const B_NO_MEMORY = B_GENERAL_ERROR_BASE + 0; | |
| 710 | pub const B_IO_ERROR = B_GENERAL_ERROR_BASE + 1; | |
| 711 | pub const B_PERMISSION_DENIED = B_GENERAL_ERROR_BASE + 2; | |
| 712 | pub const B_BAD_INDEX = B_GENERAL_ERROR_BASE + 3; | |
| 713 | pub const B_BAD_TYPE = B_GENERAL_ERROR_BASE + 4; | |
| 714 | pub const B_BAD_VALUE = B_GENERAL_ERROR_BASE + 5; | |
| 715 | pub const B_MISMATCHED_VALUES = B_GENERAL_ERROR_BASE + 6; | |
| 716 | pub const B_NAME_NOT_FOUND = B_GENERAL_ERROR_BASE + 7; | |
| 717 | pub const B_NAME_IN_USE = B_GENERAL_ERROR_BASE + 8; | |
| 718 | pub const B_TIMED_OUT = B_GENERAL_ERROR_BASE + 9; | |
| 719 | pub const B_INTERRUPTED = B_GENERAL_ERROR_BASE + 10; | |
| 720 | pub const B_WOULD_BLOCK = B_GENERAL_ERROR_BASE + 11; | |
| 721 | pub const B_CANCELED = B_GENERAL_ERROR_BASE + 12; | |
| 722 | pub const B_NO_INIT = B_GENERAL_ERROR_BASE + 13; | |
| 723 | pub const B_NOT_INITIALIZED = B_GENERAL_ERROR_BASE + 13; | |
| 724 | pub const B_BUSY = B_GENERAL_ERROR_BASE + 14; | |
| 725 | pub const B_NOT_ALLOWED = B_GENERAL_ERROR_BASE + 15; | |
| 726 | pub const B_BAD_DATA = B_GENERAL_ERROR_BASE + 16; | |
| 727 | pub const B_DONT_DO_THAT = B_GENERAL_ERROR_BASE + 17; | |
| 728 | ||
| 729 | pub const B_BAD_IMAGE_ID = B_OS_ERROR_BASE + 0x300; | |
| 730 | pub const B_BAD_ADDRESS = B_OS_ERROR_BASE + 0x301; | |
| 731 | pub const B_NOT_AN_EXECUTABLE = B_OS_ERROR_BASE + 0x302; | |
| 732 | pub const B_MISSING_LIBRARY = B_OS_ERROR_BASE + 0x303; | |
| 733 | pub const B_MISSING_SYMBOL = B_OS_ERROR_BASE + 0x304; | |
| 734 | pub const B_UNKNOWN_EXECUTABLE = B_OS_ERROR_BASE + 0x305; | |
| 735 | pub const B_LEGACY_EXECUTABLE = B_OS_ERROR_BASE + 0x306; | |
| 736 | ||
| 737 | pub const B_FILE_ERROR = B_STORAGE_ERROR_BASE + 0; | |
| 738 | pub const B_FILE_EXISTS = B_STORAGE_ERROR_BASE + 2; | |
| 739 | pub const B_ENTRY_NOT_FOUND = B_STORAGE_ERROR_BASE + 3; | |
| 740 | pub const B_NAME_TOO_LONG = B_STORAGE_ERROR_BASE + 4; | |
| 741 | pub const B_NOT_A_DIRECTORY = B_STORAGE_ERROR_BASE + 5; | |
| 742 | pub const B_DIRECTORY_NOT_EMPTY = B_STORAGE_ERROR_BASE + 6; | |
| 743 | pub const B_DEVICE_FULL = B_STORAGE_ERROR_BASE + 7; | |
| 744 | pub const B_READ_ONLY_DEVICE = B_STORAGE_ERROR_BASE + 8; | |
| 745 | pub const B_IS_A_DIRECTORY = B_STORAGE_ERROR_BASE + 9; | |
| 746 | pub const B_NO_MORE_FDS = B_STORAGE_ERROR_BASE + 10; | |
| 747 | pub const B_CROSS_DEVICE_LINK = B_STORAGE_ERROR_BASE + 11; | |
| 748 | pub const B_LINK_LIMIT = B_STORAGE_ERROR_BASE + 12; | |
| 749 | pub const B_BUSTED_PIPE = B_STORAGE_ERROR_BASE + 13; | |
| 750 | pub const B_UNSUPPORTED = B_STORAGE_ERROR_BASE + 14; | |
| 751 | pub const B_PARTITION_TOO_SMALL = B_STORAGE_ERROR_BASE + 15; | |
| 752 | pub const B_PARTIAL_READ = B_STORAGE_ERROR_BASE + 16; | |
| 753 | pub const B_PARTIAL_WRITE = B_STORAGE_ERROR_BASE + 17; | |
| 754 | ||
| 755 | SUCCESS = 0, | |
| 756 | ||
| 757 | @"2BIG" = B_POSIX_ERROR_BASE + 1, | |
| 758 | CHILD = B_POSIX_ERROR_BASE + 2, | |
| 759 | DEADLK = B_POSIX_ERROR_BASE + 3, | |
| 760 | FBIG = B_POSIX_ERROR_BASE + 4, | |
| 761 | MLINK = B_POSIX_ERROR_BASE + 5, | |
| 762 | NFILE = B_POSIX_ERROR_BASE + 6, | |
| 763 | NODEV = B_POSIX_ERROR_BASE + 7, | |
| 764 | NOLCK = B_POSIX_ERROR_BASE + 8, | |
| 765 | NOSYS = B_POSIX_ERROR_BASE + 9, | |
| 766 | NOTTY = B_POSIX_ERROR_BASE + 10, | |
| 767 | NXIO = B_POSIX_ERROR_BASE + 11, | |
| 768 | SPIPE = B_POSIX_ERROR_BASE + 12, | |
| 769 | SRCH = B_POSIX_ERROR_BASE + 13, | |
| 770 | FPOS = B_POSIX_ERROR_BASE + 14, | |
| 771 | SIGPARM = B_POSIX_ERROR_BASE + 15, | |
| 772 | DOM = B_POSIX_ERROR_BASE + 16, | |
| 773 | RANGE = B_POSIX_ERROR_BASE + 17, | |
| 774 | PROTOTYPE = B_POSIX_ERROR_BASE + 18, | |
| 775 | PROTONOSUPPORT = B_POSIX_ERROR_BASE + 19, | |
| 776 | PFNOSUPPORT = B_POSIX_ERROR_BASE + 20, | |
| 777 | AFNOSUPPORT = B_POSIX_ERROR_BASE + 21, | |
| 778 | ADDRINUSE = B_POSIX_ERROR_BASE + 22, | |
| 779 | ADDRNOTAVAIL = B_POSIX_ERROR_BASE + 23, | |
| 780 | NETDOWN = B_POSIX_ERROR_BASE + 24, | |
| 781 | NETUNREACH = B_POSIX_ERROR_BASE + 25, | |
| 782 | NETRESET = B_POSIX_ERROR_BASE + 26, | |
| 783 | CONNABORTED = B_POSIX_ERROR_BASE + 27, | |
| 784 | CONNRESET = B_POSIX_ERROR_BASE + 28, | |
| 785 | ISCONN = B_POSIX_ERROR_BASE + 29, | |
| 786 | NOTCONN = B_POSIX_ERROR_BASE + 30, | |
| 787 | SHUTDOWN = B_POSIX_ERROR_BASE + 31, | |
| 788 | CONNREFUSED = B_POSIX_ERROR_BASE + 32, | |
| 789 | HOSTUNREACH = B_POSIX_ERROR_BASE + 33, | |
| 790 | NOPROTOOPT = B_POSIX_ERROR_BASE + 34, | |
| 791 | NOBUFS = B_POSIX_ERROR_BASE + 35, | |
| 792 | INPROGRESS = B_POSIX_ERROR_BASE + 36, | |
| 793 | ALREADY = B_POSIX_ERROR_BASE + 37, | |
| 794 | ILSEQ = B_POSIX_ERROR_BASE + 38, | |
| 795 | NOMSG = B_POSIX_ERROR_BASE + 39, | |
| 796 | STALE = B_POSIX_ERROR_BASE + 40, | |
| 797 | OVERFLOW = B_POSIX_ERROR_BASE + 41, | |
| 798 | MSGSIZE = B_POSIX_ERROR_BASE + 42, | |
| 799 | OPNOTSUPP = B_POSIX_ERROR_BASE + 43, | |
| 800 | NOTSOCK = B_POSIX_ERROR_BASE + 44, | |
| 801 | HOSTDOWN = B_POSIX_ERROR_BASE + 45, | |
| 802 | BADMSG = B_POSIX_ERROR_BASE + 46, | |
| 803 | CANCELED = B_POSIX_ERROR_BASE + 47, | |
| 804 | DESTADDRREQ = B_POSIX_ERROR_BASE + 48, | |
| 805 | DQUOT = B_POSIX_ERROR_BASE + 49, | |
| 806 | IDRM = B_POSIX_ERROR_BASE + 50, | |
| 807 | MULTIHOP = B_POSIX_ERROR_BASE + 51, | |
| 808 | NODATA = B_POSIX_ERROR_BASE + 52, | |
| 809 | NOLINK = B_POSIX_ERROR_BASE + 53, | |
| 810 | NOSR = B_POSIX_ERROR_BASE + 54, | |
| 811 | NOSTR = B_POSIX_ERROR_BASE + 55, | |
| 812 | NOTSUP = B_POSIX_ERROR_BASE + 56, | |
| 813 | PROTO = B_POSIX_ERROR_BASE + 57, | |
| 814 | TIME = B_POSIX_ERROR_BASE + 58, | |
| 815 | TXTBSY = B_POSIX_ERROR_BASE + 59, | |
| 816 | NOATTR = B_POSIX_ERROR_BASE + 60, | |
| 817 | NOTRECOVERABLE = B_POSIX_ERROR_BASE + 61, | |
| 818 | OWNERDEAD = B_POSIX_ERROR_BASE + 62, | |
| 819 | ||
| 820 | NOMEM = B_NO_MEMORY, | |
| 821 | ||
| 822 | ACCES = B_PERMISSION_DENIED, | |
| 823 | INTR = B_INTERRUPTED, | |
| 824 | IO = B_IO_ERROR, | |
| 825 | BUSY = B_BUSY, | |
| 826 | FAULT = B_BAD_ADDRESS, | |
| 827 | TIMEDOUT = B_TIMED_OUT, | |
| 828 | /// Also used for WOULDBLOCK | |
| 829 | AGAIN = B_WOULD_BLOCK, | |
| 830 | BADF = B_FILE_ERROR, | |
| 831 | EXIST = B_FILE_EXISTS, | |
| 832 | INVAL = B_BAD_VALUE, | |
| 833 | NAMETOOLONG = B_NAME_TOO_LONG, | |
| 834 | NOENT = B_ENTRY_NOT_FOUND, | |
| 835 | PERM = B_NOT_ALLOWED, | |
| 836 | NOTDIR = B_NOT_A_DIRECTORY, | |
| 837 | ISDIR = B_IS_A_DIRECTORY, | |
| 838 | NOTEMPTY = B_DIRECTORY_NOT_EMPTY, | |
| 839 | NOSPC = B_DEVICE_FULL, | |
| 840 | ROFS = B_READ_ONLY_DEVICE, | |
| 841 | MFILE = B_NO_MORE_FDS, | |
| 842 | XDEV = B_CROSS_DEVICE_LINK, | |
| 843 | LOOP = B_LINK_LIMIT, | |
| 844 | NOEXEC = B_NOT_AN_EXECUTABLE, | |
| 845 | PIPE = B_BUSTED_PIPE, | |
| 846 | ||
| 847 | _, | |
| 558 | 848 | }; |
| 559 | 849 | |
| 850 | // /system/develop/headers/os/support/SupportDefs.h | |
| 851 | ||
| 852 | pub const status_t = i32; | |
| 853 | ||
| 560 | 854 | // /system/develop/headers/posix/arch/*/signal.h |
| 561 | 855 | |
| 562 | 856 | pub const vregs = switch (builtin.cpu.arch) { |
| ... | ... | @@ -736,531 +1030,364 @@ pub const vregs = switch (builtin.cpu.arch) { |
| 736 | 1030 | reserved2: u16, |
| 737 | 1031 | mxcsr: u32, |
| 738 | 1032 | reserved3: u32, |
| 739 | fp_mmx: [8]fp_register, | |
| 740 | xmmx: [8]xmm_register, | |
| 741 | reserved4: [224]u8, | |
| 742 | }; | |
| 743 | ||
| 744 | pub const extended_regs = extern struct { | |
| 745 | state: extern union { | |
| 746 | old_format: old_extended_regs, | |
| 747 | new_format: new_extended_regs, | |
| 748 | }, | |
| 749 | format: u32, | |
| 750 | }; | |
| 751 | ||
| 752 | eip: u32, | |
| 753 | eflags: u32, | |
| 754 | eax: u32, | |
| 755 | ecx: u32, | |
| 756 | edx: u32, | |
| 757 | esp: u32, | |
| 758 | ebp: u32, | |
| 759 | reserved: u32, | |
| 760 | xregs: extended_regs, | |
| 761 | edi: u32, | |
| 762 | esi: u32, | |
| 763 | ebx: u32, | |
| 764 | }, | |
| 765 | .x86_64 => extern struct { | |
| 766 | pub const fp_register = extern struct { | |
| 767 | value: [10]u8, | |
| 768 | reserved: [6]u8, | |
| 769 | }; | |
| 770 | ||
| 771 | pub const xmm_register = extern struct { | |
| 772 | value: [16]u8, | |
| 773 | }; | |
| 774 | ||
| 775 | pub const fpu_state = extern struct { | |
| 776 | control: u16, | |
| 777 | status: u16, | |
| 778 | tag: u16, | |
| 779 | opcode: u16, | |
| 780 | rip: u64, | |
| 781 | rdp: u64, | |
| 782 | mxcsr: u32, | |
| 783 | mscsr_mask: u32, | |
| 784 | ||
| 785 | fp_mmx: [8]fp_register, | |
| 786 | xmm: [16]xmm_register, | |
| 787 | reserved: [96]u8, | |
| 788 | }; | |
| 789 | ||
| 790 | pub const xstate_hdr = extern struct { | |
| 791 | bv: u64, | |
| 792 | xcomp_bv: u64, | |
| 793 | reserved: [48]u8, | |
| 794 | }; | |
| 795 | ||
| 796 | pub const savefpu = extern struct { | |
| 797 | fxsave: fpu_state, | |
| 798 | xstate: xstate_hdr, | |
| 799 | ymm: [16]xmm_register, | |
| 800 | }; | |
| 801 | ||
| 802 | rax: u64, | |
| 803 | rbx: u64, | |
| 804 | rcx: u64, | |
| 805 | rdx: u64, | |
| 806 | rdi: u64, | |
| 807 | rsi: u64, | |
| 808 | rbp: u64, | |
| 809 | r8: u64, | |
| 810 | r9: u64, | |
| 811 | r10: u64, | |
| 812 | r11: u64, | |
| 813 | r12: u64, | |
| 814 | r13: u64, | |
| 815 | r14: u64, | |
| 816 | r15: u64, | |
| 817 | rsp: u64, | |
| 818 | rip: u64, | |
| 819 | rflags: u64, | |
| 820 | fpu: savefpu, | |
| 821 | }, | |
| 822 | else => void, | |
| 823 | }; | |
| 824 | ||
| 825 | // access function | |
| 826 | pub const F_OK = 0; // test for existence of file | |
| 827 | pub const X_OK = 1; // test for execute or search permission | |
| 828 | pub const W_OK = 2; // test for write permission | |
| 829 | pub const R_OK = 4; // test for read permission | |
| 830 | ||
| 831 | pub const F = struct { | |
| 832 | pub const DUPFD = 0x0001; | |
| 833 | pub const GETFD = 0x0002; | |
| 834 | pub const SETFD = 0x0004; | |
| 835 | pub const GETFL = 0x0008; | |
| 836 | pub const SETFL = 0x0010; | |
| 837 | ||
| 838 | pub const GETLK = 0x0020; | |
| 839 | pub const SETLK = 0x0080; | |
| 840 | pub const SETLKW = 0x0100; | |
| 841 | pub const DUPFD_CLOEXEC = 0x0200; | |
| 842 | ||
| 843 | pub const RDLCK = 0x0040; | |
| 844 | pub const UNLCK = 0x0200; | |
| 845 | pub const WRLCK = 0x0400; | |
| 846 | }; | |
| 847 | ||
| 848 | pub const LOCK = struct { | |
| 849 | pub const SH = 0x01; | |
| 850 | pub const EX = 0x02; | |
| 851 | pub const NB = 0x04; | |
| 852 | pub const UN = 0x08; | |
| 853 | }; | |
| 854 | ||
| 855 | pub const FD_CLOEXEC = 1; | |
| 856 | ||
| 857 | pub const SEEK = struct { | |
| 858 | pub const SET = 0; | |
| 859 | pub const CUR = 1; | |
| 860 | pub const END = 2; | |
| 861 | }; | |
| 862 | ||
| 863 | pub const SOCK = struct { | |
| 864 | pub const STREAM = 1; | |
| 865 | pub const DGRAM = 2; | |
| 866 | pub const RAW = 3; | |
| 867 | pub const SEQPACKET = 5; | |
| 868 | ||
| 869 | /// WARNING: this flag is not supported by windows socket functions directly, | |
| 870 | /// it is only supported by std.os.socket. Be sure that this value does | |
| 871 | /// not share any bits with any of the `SOCK` values. | |
| 872 | pub const CLOEXEC = 0x10000; | |
| 873 | /// WARNING: this flag is not supported by windows socket functions directly, | |
| 874 | /// it is only supported by std.os.socket. Be sure that this value does | |
| 875 | /// not share any bits with any of the `SOCK` values. | |
| 876 | pub const NONBLOCK = 0x20000; | |
| 877 | }; | |
| 878 | ||
| 879 | pub const SO = struct { | |
| 880 | pub const ACCEPTCONN = 0x00000001; | |
| 881 | pub const BROADCAST = 0x00000002; | |
| 882 | pub const DEBUG = 0x00000004; | |
| 883 | pub const DONTROUTE = 0x00000008; | |
| 884 | pub const KEEPALIVE = 0x00000010; | |
| 885 | pub const OOBINLINE = 0x00000020; | |
| 886 | pub const REUSEADDR = 0x00000040; | |
| 887 | pub const REUSEPORT = 0x00000080; | |
| 888 | pub const USELOOPBACK = 0x00000100; | |
| 889 | pub const LINGER = 0x00000200; | |
| 890 | ||
| 891 | pub const SNDBUF = 0x40000001; | |
| 892 | pub const SNDLOWAT = 0x40000002; | |
| 893 | pub const SNDTIMEO = 0x40000003; | |
| 894 | pub const RCVBUF = 0x40000004; | |
| 895 | pub const RCVLOWAT = 0x40000005; | |
| 896 | pub const RCVTIMEO = 0x40000006; | |
| 897 | pub const ERROR = 0x40000007; | |
| 898 | pub const TYPE = 0x40000008; | |
| 899 | pub const NONBLOCK = 0x40000009; | |
| 900 | pub const BINDTODEVICE = 0x4000000a; | |
| 901 | pub const PEERCRED = 0x4000000b; | |
| 902 | }; | |
| 1033 | fp_mmx: [8]fp_register, | |
| 1034 | xmmx: [8]xmm_register, | |
| 1035 | reserved4: [224]u8, | |
| 1036 | }; | |
| 903 | 1037 | |
| 904 | pub const SOL = struct { | |
| 905 | pub const SOCKET = -1; | |
| 906 | }; | |
| 1038 | pub const extended_regs = extern struct { | |
| 1039 | state: extern union { | |
| 1040 | old_format: old_extended_regs, | |
| 1041 | new_format: new_extended_regs, | |
| 1042 | }, | |
| 1043 | format: u32, | |
| 1044 | }; | |
| 907 | 1045 | |
| 908 | pub const PF = struct { | |
| 909 | pub const UNSPEC = AF.UNSPEC; | |
| 910 | pub const INET = AF.INET; | |
| 911 | pub const ROUTE = AF.ROUTE; | |
| 912 | pub const LINK = AF.LINK; | |
| 913 | pub const INET6 = AF.INET6; | |
| 914 | pub const LOCAL = AF.LOCAL; | |
| 915 | pub const UNIX = AF.UNIX; | |
| 916 | pub const BLUETOOTH = AF.BLUETOOTH; | |
| 917 | }; | |
| 1046 | eip: u32, | |
| 1047 | eflags: u32, | |
| 1048 | eax: u32, | |
| 1049 | ecx: u32, | |
| 1050 | edx: u32, | |
| 1051 | esp: u32, | |
| 1052 | ebp: u32, | |
| 1053 | reserved: u32, | |
| 1054 | xregs: extended_regs, | |
| 1055 | edi: u32, | |
| 1056 | esi: u32, | |
| 1057 | ebx: u32, | |
| 1058 | }, | |
| 1059 | .x86_64 => extern struct { | |
| 1060 | pub const fp_register = extern struct { | |
| 1061 | value: [10]u8, | |
| 1062 | reserved: [6]u8, | |
| 1063 | }; | |
| 918 | 1064 | |
| 919 | pub const AF = struct { | |
| 920 | pub const UNSPEC = 0; | |
| 921 | pub const INET = 1; | |
| 922 | pub const APPLETALK = 2; | |
| 923 | pub const ROUTE = 3; | |
| 924 | pub const LINK = 4; | |
| 925 | pub const INET6 = 5; | |
| 926 | pub const DLI = 6; | |
| 927 | pub const IPX = 7; | |
| 928 | pub const NOTIFY = 8; | |
| 929 | pub const LOCAL = 9; | |
| 930 | pub const UNIX = LOCAL; | |
| 931 | pub const BLUETOOTH = 10; | |
| 932 | pub const MAX = 11; | |
| 933 | }; | |
| 1065 | pub const xmm_register = extern struct { | |
| 1066 | value: [16]u8, | |
| 1067 | }; | |
| 934 | 1068 | |
| 935 | pub const DT = struct {}; | |
| 1069 | pub const fpu_state = extern struct { | |
| 1070 | control: u16, | |
| 1071 | status: u16, | |
| 1072 | tag: u16, | |
| 1073 | opcode: u16, | |
| 1074 | rip: u64, | |
| 1075 | rdp: u64, | |
| 1076 | mxcsr: u32, | |
| 1077 | mscsr_mask: u32, | |
| 936 | 1078 | |
| 937 | /// add event to kq (implies enable) | |
| 938 | pub const EV_ADD = 0x0001; | |
| 1079 | fp_mmx: [8]fp_register, | |
| 1080 | xmm: [16]xmm_register, | |
| 1081 | reserved: [96]u8, | |
| 1082 | }; | |
| 939 | 1083 | |
| 940 | /// delete event from kq | |
| 941 | pub const EV_DELETE = 0x0002; | |
| 1084 | pub const xstate_hdr = extern struct { | |
| 1085 | bv: u64, | |
| 1086 | xcomp_bv: u64, | |
| 1087 | reserved: [48]u8, | |
| 1088 | }; | |
| 942 | 1089 | |
| 943 | /// enable event | |
| 944 | pub const EV_ENABLE = 0x0004; | |
| 1090 | pub const savefpu = extern struct { | |
| 1091 | fxsave: fpu_state, | |
| 1092 | xstate: xstate_hdr, | |
| 1093 | ymm: [16]xmm_register, | |
| 1094 | }; | |
| 945 | 1095 | |
| 946 | /// disable event (not reported) | |
| 947 | pub const EV_DISABLE = 0x0008; | |
| 1096 | rax: u64, | |
| 1097 | rbx: u64, | |
| 1098 | rcx: u64, | |
| 1099 | rdx: u64, | |
| 1100 | rdi: u64, | |
| 1101 | rsi: u64, | |
| 1102 | rbp: u64, | |
| 1103 | r8: u64, | |
| 1104 | r9: u64, | |
| 1105 | r10: u64, | |
| 1106 | r11: u64, | |
| 1107 | r12: u64, | |
| 1108 | r13: u64, | |
| 1109 | r14: u64, | |
| 1110 | r15: u64, | |
| 1111 | rsp: u64, | |
| 1112 | rip: u64, | |
| 1113 | rflags: u64, | |
| 1114 | fpu: savefpu, | |
| 1115 | }, | |
| 1116 | else => void, | |
| 1117 | }; | |
| 948 | 1118 | |
| 949 | /// only report one occurrence | |
| 950 | pub const EV_ONESHOT = 0x0010; | |
| 1119 | // /system/develop/headers/posix/dirent.h | |
| 1120 | ||
| 1121 | pub const DirEnt = extern struct { | |
| 1122 | /// device | |
| 1123 | dev: dev_t, | |
| 1124 | /// parent device (only for queries) | |
| 1125 | pdev: dev_t, | |
| 1126 | /// inode number | |
| 1127 | ino: ino_t, | |
| 1128 | /// parent inode (only for queries) | |
| 1129 | pino: ino_t, | |
| 1130 | /// length of this record, not the name | |
| 1131 | reclen: u16, | |
| 1132 | /// name of the entry (null byte terminated) | |
| 1133 | name: [0]u8, | |
| 1134 | pub fn getName(dirent: *const DirEnt) [*:0]const u8 { | |
| 1135 | return @ptrCast(&dirent.name); | |
| 1136 | } | |
| 1137 | }; | |
| 951 | 1138 | |
| 952 | /// clear event state after reporting | |
| 953 | pub const EV_CLEAR = 0x0020; | |
| 1139 | // /system/develop/headers/posix/errno.h | |
| 954 | 1140 | |
| 955 | /// force immediate event output | |
| 956 | /// ... with or without EV_ERROR | |
| 957 | /// ... use KEVENT_FLAG_ERROR_EVENTS | |
| 958 | /// on syscalls supporting flags | |
| 959 | pub const EV_RECEIPT = 0x0040; | |
| 1141 | extern "root" fn _errnop() *i32; | |
| 1142 | pub const _errno = _errnop; | |
| 960 | 1143 | |
| 961 | /// disable event after reporting | |
| 962 | pub const EV_DISPATCH = 0x0080; | |
| 1144 | // /system/develop/headers/posix/poll.h | |
| 963 | 1145 | |
| 964 | pub const EVFILT_READ = -1; | |
| 965 | pub const EVFILT_WRITE = -2; | |
| 1146 | pub const nfds_t = usize; | |
| 966 | 1147 | |
| 967 | /// attached to aio requests | |
| 968 | pub const EVFILT_AIO = -3; | |
| 1148 | pub const pollfd = extern struct { | |
| 1149 | fd: i32, | |
| 1150 | events: i16, | |
| 1151 | revents: i16, | |
| 1152 | }; | |
| 969 | 1153 | |
| 970 | /// attached to vnodes | |
| 971 | pub const EVFILT_VNODE = -4; | |
| 1154 | pub const POLL = struct { | |
| 1155 | /// any readable data available | |
| 1156 | pub const IN = 0x0001; | |
| 1157 | /// file descriptor is writeable | |
| 1158 | pub const OUT = 0x0002; | |
| 1159 | pub const RDNORM = IN; | |
| 1160 | pub const WRNORM = OUT; | |
| 1161 | /// priority readable data | |
| 1162 | pub const RDBAND = 0x0008; | |
| 1163 | /// priority data can be written | |
| 1164 | pub const WRBAND = 0x0010; | |
| 1165 | /// high priority readable data | |
| 1166 | pub const PRI = 0x0020; | |
| 972 | 1167 | |
| 973 | /// attached to struct proc | |
| 974 | pub const EVFILT_PROC = -5; | |
| 1168 | /// errors pending | |
| 1169 | pub const ERR = 0x0004; | |
| 1170 | /// disconnected | |
| 1171 | pub const HUP = 0x0080; | |
| 1172 | /// invalid file descriptor | |
| 1173 | pub const NVAL = 0x1000; | |
| 1174 | }; | |
| 975 | 1175 | |
| 976 | /// attached to struct proc | |
| 977 | pub const EVFILT_SIGNAL = -6; | |
| 1176 | // /system/develop/headers/posix/signal.h | |
| 978 | 1177 | |
| 979 | /// timers | |
| 980 | pub const EVFILT_TIMER = -7; | |
| 1178 | pub const sigset_t = u64; | |
| 1179 | pub const empty_sigset: sigset_t = 0; | |
| 1180 | pub const filled_sigset = ~@as(sigset_t, 0); | |
| 981 | 1181 | |
| 982 | /// Process descriptors | |
| 983 | pub const EVFILT_PROCDESC = -8; | |
| 1182 | pub const SIG = struct { | |
| 1183 | pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0); | |
| 1184 | pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1); | |
| 1185 | pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize)); | |
| 984 | 1186 | |
| 985 | /// Filesystem events | |
| 986 | pub const EVFILT_FS = -9; | |
| 1187 | pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3); | |
| 987 | 1188 | |
| 988 | pub const EVFILT_LIO = -10; | |
| 1189 | pub const HUP = 1; | |
| 1190 | pub const INT = 2; | |
| 1191 | pub const QUIT = 3; | |
| 1192 | pub const ILL = 4; | |
| 1193 | pub const CHLD = 5; | |
| 1194 | pub const ABRT = 6; | |
| 1195 | pub const IOT = ABRT; | |
| 1196 | pub const PIPE = 7; | |
| 1197 | pub const FPE = 8; | |
| 1198 | pub const KILL = 9; | |
| 1199 | pub const STOP = 10; | |
| 1200 | pub const SEGV = 11; | |
| 1201 | pub const CONT = 12; | |
| 1202 | pub const TSTP = 13; | |
| 1203 | pub const ALRM = 14; | |
| 1204 | pub const TERM = 15; | |
| 1205 | pub const TTIN = 16; | |
| 1206 | pub const TTOU = 17; | |
| 1207 | pub const USR1 = 18; | |
| 1208 | pub const USR2 = 19; | |
| 1209 | pub const WINCH = 20; | |
| 1210 | pub const KILLTHR = 21; | |
| 1211 | pub const TRAP = 22; | |
| 1212 | pub const POLL = 23; | |
| 1213 | pub const PROF = 24; | |
| 1214 | pub const SYS = 25; | |
| 1215 | pub const URG = 26; | |
| 1216 | pub const VTALRM = 27; | |
| 1217 | pub const XCPU = 28; | |
| 1218 | pub const XFSZ = 29; | |
| 1219 | pub const BUS = 30; | |
| 1220 | pub const RESERVED1 = 31; | |
| 1221 | pub const RESERVED2 = 32; | |
| 989 | 1222 | |
| 990 | /// User events | |
| 991 | pub const EVFILT_USER = -11; | |
| 1223 | pub const BLOCK = 1; | |
| 1224 | pub const UNBLOCK = 2; | |
| 1225 | pub const SETMASK = 3; | |
| 1226 | }; | |
| 992 | 1227 | |
| 993 | /// Sendfile events | |
| 994 | pub const EVFILT_SENDFILE = -12; | |
| 1228 | pub const siginfo_t = extern struct { | |
| 1229 | signo: i32, | |
| 1230 | code: i32, | |
| 1231 | errno: i32, | |
| 995 | 1232 | |
| 996 | pub const EVFILT_EMPTY = -13; | |
| 1233 | pid: pid_t, | |
| 1234 | uid: uid_t, | |
| 1235 | addr: *allowzero anyopaque, | |
| 1236 | }; | |
| 997 | 1237 | |
| 998 | pub const T = struct { | |
| 999 | pub const CGETA = 0x8000; | |
| 1000 | pub const CSETA = 0x8001; | |
| 1001 | pub const CSETAF = 0x8002; | |
| 1002 | pub const CSETAW = 0x8003; | |
| 1003 | pub const CWAITEVENT = 0x8004; | |
| 1004 | pub const CSBRK = 0x8005; | |
| 1005 | pub const CFLSH = 0x8006; | |
| 1006 | pub const CXONC = 0x8007; | |
| 1007 | pub const CQUERYCONNECTED = 0x8008; | |
| 1008 | pub const CGETBITS = 0x8009; | |
| 1009 | pub const CSETDTR = 0x8010; | |
| 1010 | pub const CSETRTS = 0x8011; | |
| 1011 | pub const IOCGWINSZ = 0x8012; | |
| 1012 | pub const IOCSWINSZ = 0x8013; | |
| 1013 | pub const CVTIME = 0x8014; | |
| 1014 | pub const IOCGPGRP = 0x8015; | |
| 1015 | pub const IOCSPGRP = 0x8016; | |
| 1016 | pub const IOCSCTTY = 0x8017; | |
| 1017 | pub const IOCMGET = 0x8018; | |
| 1018 | pub const IOCMSET = 0x8019; | |
| 1019 | pub const IOCSBRK = 0x8020; | |
| 1020 | pub const IOCCBRK = 0x8021; | |
| 1021 | pub const IOCMBIS = 0x8022; | |
| 1022 | pub const IOCMBIC = 0x8023; | |
| 1023 | pub const IOCGSID = 0x8024; | |
| 1238 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | |
| 1239 | pub const Sigaction = extern struct { | |
| 1240 | pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; | |
| 1241 | pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; | |
| 1024 | 1242 | |
| 1025 | pub const FIONREAD = 0xbe000001; | |
| 1026 | pub const FIONBIO = 0xbe000000; | |
| 1243 | /// signal handler | |
| 1244 | handler: extern union { | |
| 1245 | handler: handler_fn, | |
| 1246 | sigaction: sigaction_fn, | |
| 1247 | }, | |
| 1248 | ||
| 1249 | /// signal mask to apply | |
| 1250 | mask: sigset_t, | |
| 1251 | ||
| 1252 | /// see signal options | |
| 1253 | flags: i32, | |
| 1254 | ||
| 1255 | /// will be passed to the signal handler, BeOS extension | |
| 1256 | userdata: *allowzero anyopaque = undefined, | |
| 1027 | 1257 | }; |
| 1028 | 1258 | |
| 1029 | pub const winsize = extern struct { | |
| 1030 | ws_row: u16, | |
| 1031 | ws_col: u16, | |
| 1032 | ws_xpixel: u16, | |
| 1033 | ws_ypixel: u16, | |
| 1259 | pub const SA = struct { | |
| 1260 | pub const NOCLDSTOP = 0x01; | |
| 1261 | pub const NOCLDWAIT = 0x02; | |
| 1262 | pub const RESETHAND = 0x04; | |
| 1263 | pub const NODEFER = 0x08; | |
| 1264 | pub const RESTART = 0x10; | |
| 1265 | pub const ONSTACK = 0x20; | |
| 1266 | pub const SIGINFO = 0x40; | |
| 1267 | pub const NOMASK = NODEFER; | |
| 1268 | pub const STACK = ONSTACK; | |
| 1269 | pub const ONESHOT = RESETHAND; | |
| 1034 | 1270 | }; |
| 1035 | 1271 | |
| 1036 | const B_POSIX_ERROR_BASE = -2147454976; | |
| 1272 | pub const SS = struct { | |
| 1273 | pub const ONSTACK = 0x1; | |
| 1274 | pub const DISABLE = 0x2; | |
| 1275 | }; | |
| 1037 | 1276 | |
| 1038 | pub const E = enum(i32) { | |
| 1039 | @"2BIG" = B_POSIX_ERROR_BASE + 1, | |
| 1040 | CHILD = B_POSIX_ERROR_BASE + 2, | |
| 1041 | DEADLK = B_POSIX_ERROR_BASE + 3, | |
| 1042 | FBIG = B_POSIX_ERROR_BASE + 4, | |
| 1043 | MLINK = B_POSIX_ERROR_BASE + 5, | |
| 1044 | NFILE = B_POSIX_ERROR_BASE + 6, | |
| 1045 | NODEV = B_POSIX_ERROR_BASE + 7, | |
| 1046 | NOLCK = B_POSIX_ERROR_BASE + 8, | |
| 1047 | NOSYS = B_POSIX_ERROR_BASE + 9, | |
| 1048 | NOTTY = B_POSIX_ERROR_BASE + 10, | |
| 1049 | NXIO = B_POSIX_ERROR_BASE + 11, | |
| 1050 | SPIPE = B_POSIX_ERROR_BASE + 12, | |
| 1051 | SRCH = B_POSIX_ERROR_BASE + 13, | |
| 1052 | FPOS = B_POSIX_ERROR_BASE + 14, | |
| 1053 | SIGPARM = B_POSIX_ERROR_BASE + 15, | |
| 1054 | DOM = B_POSIX_ERROR_BASE + 16, | |
| 1055 | RANGE = B_POSIX_ERROR_BASE + 17, | |
| 1056 | PROTOTYPE = B_POSIX_ERROR_BASE + 18, | |
| 1057 | PROTONOSUPPORT = B_POSIX_ERROR_BASE + 19, | |
| 1058 | PFNOSUPPORT = B_POSIX_ERROR_BASE + 20, | |
| 1059 | AFNOSUPPORT = B_POSIX_ERROR_BASE + 21, | |
| 1060 | ADDRINUSE = B_POSIX_ERROR_BASE + 22, | |
| 1061 | ADDRNOTAVAIL = B_POSIX_ERROR_BASE + 23, | |
| 1062 | NETDOWN = B_POSIX_ERROR_BASE + 24, | |
| 1063 | NETUNREACH = B_POSIX_ERROR_BASE + 25, | |
| 1064 | NETRESET = B_POSIX_ERROR_BASE + 26, | |
| 1065 | CONNABORTED = B_POSIX_ERROR_BASE + 27, | |
| 1066 | CONNRESET = B_POSIX_ERROR_BASE + 28, | |
| 1067 | ISCONN = B_POSIX_ERROR_BASE + 29, | |
| 1068 | NOTCONN = B_POSIX_ERROR_BASE + 30, | |
| 1069 | SHUTDOWN = B_POSIX_ERROR_BASE + 31, | |
| 1070 | CONNREFUSED = B_POSIX_ERROR_BASE + 32, | |
| 1071 | HOSTUNREACH = B_POSIX_ERROR_BASE + 33, | |
| 1072 | NOPROTOOPT = B_POSIX_ERROR_BASE + 34, | |
| 1073 | NOBUFS = B_POSIX_ERROR_BASE + 35, | |
| 1074 | INPROGRESS = B_POSIX_ERROR_BASE + 36, | |
| 1075 | ALREADY = B_POSIX_ERROR_BASE + 37, | |
| 1076 | ILSEQ = B_POSIX_ERROR_BASE + 38, | |
| 1077 | NOMSG = B_POSIX_ERROR_BASE + 39, | |
| 1078 | STALE = B_POSIX_ERROR_BASE + 40, | |
| 1079 | OVERFLOW = B_POSIX_ERROR_BASE + 41, | |
| 1080 | MSGSIZE = B_POSIX_ERROR_BASE + 42, | |
| 1081 | OPNOTSUPP = B_POSIX_ERROR_BASE + 43, | |
| 1082 | NOTSOCK = B_POSIX_ERROR_BASE + 44, | |
| 1083 | HOSTDOWN = B_POSIX_ERROR_BASE + 45, | |
| 1084 | BADMSG = B_POSIX_ERROR_BASE + 46, | |
| 1085 | CANCELED = B_POSIX_ERROR_BASE + 47, | |
| 1086 | DESTADDRREQ = B_POSIX_ERROR_BASE + 48, | |
| 1087 | DQUOT = B_POSIX_ERROR_BASE + 49, | |
| 1088 | IDRM = B_POSIX_ERROR_BASE + 50, | |
| 1089 | MULTIHOP = B_POSIX_ERROR_BASE + 51, | |
| 1090 | NODATA = B_POSIX_ERROR_BASE + 52, | |
| 1091 | NOLINK = B_POSIX_ERROR_BASE + 53, | |
| 1092 | NOSR = B_POSIX_ERROR_BASE + 54, | |
| 1093 | NOSTR = B_POSIX_ERROR_BASE + 55, | |
| 1094 | NOTSUP = B_POSIX_ERROR_BASE + 56, | |
| 1095 | PROTO = B_POSIX_ERROR_BASE + 57, | |
| 1096 | TIME = B_POSIX_ERROR_BASE + 58, | |
| 1097 | TXTBSY = B_POSIX_ERROR_BASE + 59, | |
| 1098 | NOATTR = B_POSIX_ERROR_BASE + 60, | |
| 1099 | NOTRECOVERABLE = B_POSIX_ERROR_BASE + 61, | |
| 1100 | OWNERDEAD = B_POSIX_ERROR_BASE + 62, | |
| 1277 | pub const MINSIGSTKSZ = 8192; | |
| 1278 | pub const SIGSTKSZ = 16384; | |
| 1101 | 1279 | |
| 1102 | ACCES = -0x7ffffffe, // Permission denied | |
| 1103 | INTR = -0x7ffffff6, // Interrupted system call | |
| 1104 | IO = -0x7fffffff, // Input/output error | |
| 1105 | BUSY = -0x7ffffff2, // Device busy | |
| 1106 | FAULT = -0x7fffecff, // Bad address | |
| 1107 | TIMEDOUT = -2147483639, // Operation timed out | |
| 1108 | AGAIN = -0x7ffffff5, | |
| 1109 | BADF = -0x7fffa000, // Bad file descriptor | |
| 1110 | EXIST = -0x7fff9ffe, // File exists | |
| 1111 | INVAL = -0x7ffffffb, // Invalid argument | |
| 1112 | NAMETOOLONG = -2147459068, // File name too long | |
| 1113 | NOENT = -0x7fff9ffd, // No such file or directory | |
| 1114 | PERM = -0x7ffffff1, // Operation not permitted | |
| 1115 | NOTDIR = -0x7fff9ffb, // Not a directory | |
| 1116 | ISDIR = -0x7fff9ff7, // Is a directory | |
| 1117 | NOTEMPTY = -2147459066, // Directory not empty | |
| 1118 | NOSPC = -0x7fff9ff9, // No space left on device | |
| 1119 | ROFS = -0x7fff9ff8, // Read-only filesystem | |
| 1120 | MFILE = -0x7fff9ff6, // Too many open files | |
| 1121 | XDEV = -0x7fff9ff5, // Cross-device link | |
| 1122 | NOEXEC = -0x7fffecfe, // Exec format error | |
| 1123 | PIPE = -0x7fff9ff3, // Broken pipe | |
| 1124 | NOMEM = -0x80000000, // Cannot allocate memory | |
| 1125 | LOOP = -2147459060, // Too many levels of symbolic links | |
| 1126 | SUCCESS = 0, | |
| 1127 | _, | |
| 1280 | pub const stack_t = extern struct { | |
| 1281 | sp: [*]u8, | |
| 1282 | size: isize, | |
| 1283 | flags: i32, | |
| 1128 | 1284 | }; |
| 1129 | 1285 | |
| 1130 | pub const S = struct { | |
| 1131 | pub const IFMT = 0o170000; | |
| 1132 | pub const IFSOCK = 0o140000; | |
| 1133 | pub const IFLNK = 0o120000; | |
| 1134 | pub const IFREG = 0o100000; | |
| 1135 | pub const IFBLK = 0o060000; | |
| 1136 | pub const IFDIR = 0o040000; | |
| 1137 | pub const IFCHR = 0o020000; | |
| 1138 | pub const IFIFO = 0o010000; | |
| 1139 | pub const INDEX_DIR = 0o4000000000; | |
| 1140 | ||
| 1141 | pub const IUMSK = 0o7777; | |
| 1142 | pub const ISUID = 0o4000; | |
| 1143 | pub const ISGID = 0o2000; | |
| 1144 | pub const ISVTX = 0o1000; | |
| 1145 | pub const IRWXU = 0o700; | |
| 1146 | pub const IRUSR = 0o400; | |
| 1147 | pub const IWUSR = 0o200; | |
| 1148 | pub const IXUSR = 0o100; | |
| 1149 | pub const IRWXG = 0o070; | |
| 1150 | pub const IRGRP = 0o040; | |
| 1151 | pub const IWGRP = 0o020; | |
| 1152 | pub const IXGRP = 0o010; | |
| 1153 | pub const IRWXO = 0o007; | |
| 1154 | pub const IROTH = 0o004; | |
| 1155 | pub const IWOTH = 0o002; | |
| 1156 | pub const IXOTH = 0o001; | |
| 1286 | pub const NSIG = 65; | |
| 1157 | 1287 | |
| 1158 | pub fn ISREG(m: u32) bool { | |
| 1159 | return m & IFMT == IFREG; | |
| 1160 | } | |
| 1288 | pub const mcontext_t = vregs; | |
| 1161 | 1289 | |
| 1162 | pub fn ISLNK(m: u32) bool { | |
| 1163 | return m & IFMT == IFLNK; | |
| 1164 | } | |
| 1290 | pub const ucontext_t = extern struct { | |
| 1291 | link: ?*ucontext_t, | |
| 1292 | sigmask: sigset_t, | |
| 1293 | stack: stack_t, | |
| 1294 | mcontext: mcontext_t, | |
| 1295 | }; | |
| 1165 | 1296 | |
| 1166 | pub fn ISBLK(m: u32) bool { | |
| 1167 | return m & IFMT == IFBLK; | |
| 1168 | } | |
| 1297 | // /system/develop/headers/posix/sys/stat.h | |
| 1169 | 1298 | |
| 1170 | pub fn ISDIR(m: u32) bool { | |
| 1171 | return m & IFMT == IFDIR; | |
| 1172 | } | |
| 1299 | pub const Stat = extern struct { | |
| 1300 | dev: dev_t, | |
| 1301 | ino: ino_t, | |
| 1302 | mode: mode_t, | |
| 1303 | nlink: nlink_t, | |
| 1304 | uid: uid_t, | |
| 1305 | gid: gid_t, | |
| 1306 | size: off_t, | |
| 1307 | rdev: dev_t, | |
| 1308 | blksize: blksize_t, | |
| 1309 | atim: timespec, | |
| 1310 | mtim: timespec, | |
| 1311 | ctim: timespec, | |
| 1312 | crtim: timespec, | |
| 1313 | type: u32, | |
| 1314 | blocks: blkcnt_t, | |
| 1173 | 1315 | |
| 1174 | pub fn ISCHR(m: u32) bool { | |
| 1175 | return m & IFMT == IFCHR; | |
| 1316 | pub fn atime(self: @This()) timespec { | |
| 1317 | return self.atim; | |
| 1176 | 1318 | } |
| 1177 | ||
| 1178 | pub fn ISFIFO(m: u32) bool { | |
| 1179 | return m & IFMT == IFIFO; | |
| 1319 | pub fn mtime(self: @This()) timespec { | |
| 1320 | return self.mtim; | |
| 1180 | 1321 | } |
| 1181 | ||
| 1182 | pub fn ISSOCK(m: u32) bool { | |
| 1183 | return m & IFMT == IFSOCK; | |
| 1322 | pub fn ctime(self: @This()) timespec { | |
| 1323 | return self.ctim; | |
| 1184 | 1324 | } |
| 1185 | ||
| 1186 | pub fn ISINDEX(m: u32) bool { | |
| 1187 | return m & INDEX_DIR == INDEX_DIR; | |
| 1325 | pub fn birthtime(self: @This()) timespec { | |
| 1326 | return self.crtim; | |
| 1188 | 1327 | } |
| 1189 | 1328 | }; |
| 1190 | 1329 | |
| 1191 | pub const HOST_NAME_MAX = 255; | |
| 1330 | // /system/develop/headers/posix/sys/types.h | |
| 1192 | 1331 | |
| 1193 | pub const addrinfo = extern struct { | |
| 1194 | flags: i32, | |
| 1195 | family: i32, | |
| 1196 | socktype: i32, | |
| 1197 | protocol: i32, | |
| 1198 | addrlen: socklen_t, | |
| 1199 | canonname: ?[*:0]u8, | |
| 1200 | addr: ?*sockaddr, | |
| 1201 | next: ?*addrinfo, | |
| 1202 | }; | |
| 1332 | pub const blkcnt_t = i64; | |
| 1333 | pub const blksize_t = i32; | |
| 1334 | pub const fsblkcnt_t = i64; | |
| 1335 | pub const fsfilcnt_t = i64; | |
| 1336 | pub const off_t = i64; | |
| 1337 | pub const ino_t = i64; | |
| 1338 | pub const cnt_t = i32; | |
| 1339 | pub const dev_t = i32; | |
| 1340 | pub const pid_t = i32; | |
| 1341 | pub const id_t = i32; | |
| 1203 | 1342 | |
| 1204 | pub const IPPROTO = struct { | |
| 1205 | pub const IP = 0; | |
| 1206 | pub const HOPOPTS = 0; | |
| 1207 | pub const ICMP = 1; | |
| 1208 | pub const IGMP = 2; | |
| 1209 | pub const TCP = 6; | |
| 1210 | pub const UDP = 17; | |
| 1211 | pub const IPV6 = 41; | |
| 1212 | pub const ROUTING = 43; | |
| 1213 | pub const FRAGMENT = 44; | |
| 1214 | pub const ESP = 50; | |
| 1215 | pub const AH = 51; | |
| 1216 | pub const ICMPV6 = 58; | |
| 1217 | pub const NONE = 59; | |
| 1218 | pub const DSTOPTS = 60; | |
| 1219 | pub const ETHERIP = 97; | |
| 1220 | pub const RAW = 255; | |
| 1221 | pub const MAX = 256; | |
| 1222 | }; | |
| 1343 | pub const uid_t = u32; | |
| 1344 | pub const gid_t = u32; | |
| 1345 | pub const mode_t = u32; | |
| 1346 | pub const umode_t = u32; | |
| 1347 | pub const nlink_t = i32; | |
| 1223 | 1348 | |
| 1224 | pub const rlimit_resource = enum(c_int) { | |
| 1225 | CORE = 0, | |
| 1226 | CPU = 1, | |
| 1227 | DATA = 2, | |
| 1228 | FSIZE = 3, | |
| 1229 | NOFILE = 4, | |
| 1230 | STACK = 5, | |
| 1231 | AS = 6, | |
| 1232 | NOVMON = 7, | |
| 1233 | _, | |
| 1234 | }; | |
| 1349 | pub const clockid_t = i32; | |
| 1350 | pub const timer_t = *opaque {}; | |
| 1235 | 1351 | |
| 1236 | pub const rlim_t = i64; | |
| 1352 | // /system/develop/headers/posix/time.h | |
| 1237 | 1353 | |
| 1238 | pub const RLIM = struct { | |
| 1239 | /// No limit | |
| 1240 | pub const INFINITY: rlim_t = (1 << 63) - 1; | |
| 1354 | pub const clock_t = i32; | |
| 1355 | pub const suseconds_t = i32; | |
| 1356 | pub const useconds_t = u32; | |
| 1241 | 1357 | |
| 1242 | pub const SAVED_MAX = INFINITY; | |
| 1243 | pub const SAVED_CUR = INFINITY; | |
| 1244 | }; | |
| 1358 | pub const time_t = isize; | |
| 1245 | 1359 | |
| 1246 | pub const rlimit = extern struct { | |
| 1247 | /// Soft limit | |
| 1248 | cur: rlim_t, | |
| 1249 | /// Hard limit | |
| 1250 | max: rlim_t, | |
| 1251 | }; | |
| 1360 | pub const CLOCKS_PER_SEC = 1_000_000; | |
| 1361 | pub const CLK_TCK = CLOCKS_PER_SEC; | |
| 1362 | pub const TIME_UTC = 1; | |
| 1252 | 1363 | |
| 1253 | pub const SHUT = struct { | |
| 1254 | pub const RD = 0; | |
| 1255 | pub const WR = 1; | |
| 1256 | pub const RDWR = 2; | |
| 1364 | pub const CLOCK = struct { | |
| 1365 | /// system-wide monotonic clock (aka system time) | |
| 1366 | pub const MONOTONIC: clockid_t = 0; | |
| 1367 | /// system-wide real time clock | |
| 1368 | pub const REALTIME: clockid_t = -1; | |
| 1369 | /// clock measuring the used CPU time of the current process | |
| 1370 | pub const PROCESS_CPUTIME_ID: clockid_t = -2; | |
| 1371 | /// clock measuring the used CPU time of the current thread | |
| 1372 | pub const THREAD_CPUTIME_ID: clockid_t = -3; | |
| 1257 | 1373 | }; |
| 1258 | 1374 | |
| 1259 | // TODO fill out if needed | |
| 1260 | pub const directory_which = enum(c_int) { | |
| 1261 | B_USER_SETTINGS_DIRECTORY = 0xbbe, | |
| 1375 | pub const timespec = extern struct { | |
| 1376 | /// seconds | |
| 1377 | tv_sec: time_t, | |
| 1378 | /// and nanoseconds | |
| 1379 | tv_nsec: isize, | |
| 1380 | }; | |
| 1262 | 1381 | |
| 1263 | _, | |
| 1382 | pub const itimerspec = extern struct { | |
| 1383 | interval: timespec, | |
| 1384 | value: timespec, | |
| 1264 | 1385 | }; |
| 1265 | 1386 | |
| 1266 | pub const MSG_NOSIGNAL = 0x0800; | |
| 1387 | // /system/develop/headers/private/system/syscalls.h | |
| 1388 | ||
| 1389 | pub extern "root" fn _kern_get_current_team() team_id; | |
| 1390 | pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t; | |
| 1391 | pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize; | |
| 1392 | pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t; | |
| 1393 | pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *Stat, statSize: usize) status_t; |
lib/std/fs/Dir.zig+72-31| ... | ... | @@ -220,71 +220,83 @@ pub const Iterator = switch (native_os) { |
| 220 | 220 | }, |
| 221 | 221 | .haiku => struct { |
| 222 | 222 | dir: Dir, |
| 223 | buf: [1024]u8, // TODO align(@alignOf(posix.dirent64)), | |
| 223 | buf: [@sizeOf(DirEnt) + posix.PATH_MAX]u8 align(@alignOf(DirEnt)), | |
| 224 | offset: usize, | |
| 224 | 225 | index: usize, |
| 225 | 226 | end_index: usize, |
| 226 | 227 | first_iter: bool, |
| 227 | 228 | |
| 228 | 229 | const Self = @This(); |
| 230 | const DirEnt = posix.system.DirEnt; | |
| 229 | 231 | |
| 230 | 232 | pub const Error = IteratorError; |
| 231 | 233 | |
| 232 | 234 | /// Memory such as file names referenced in this returned entry becomes invalid |
| 233 | 235 | /// with subsequent calls to `next`, as well as when this `Dir` is deinitialized. |
| 234 | 236 | pub fn next(self: *Self) Error!?Entry { |
| 235 | start_over: while (true) { | |
| 236 | // TODO: find a better max | |
| 237 | const HAIKU_MAX_COUNT = 10000; | |
| 237 | while (true) { | |
| 238 | 238 | if (self.index >= self.end_index) { |
| 239 | 239 | if (self.first_iter) { |
| 240 | posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions | |
| 240 | switch (@as(posix.E, @enumFromInt(posix.system._kern_rewind_dir(self.dir.fd)))) { | |
| 241 | .SUCCESS => {}, | |
| 242 | .BADF => unreachable, // Dir is invalid | |
| 243 | .FAULT => unreachable, | |
| 244 | .NOTDIR => unreachable, | |
| 245 | .INVAL => unreachable, | |
| 246 | .ACCES => return error.AccessDenied, | |
| 247 | .PERM => return error.AccessDenied, | |
| 248 | else => |err| return posix.unexpectedErrno(err), | |
| 249 | } | |
| 241 | 250 | self.first_iter = false; |
| 242 | 251 | } |
| 243 | 252 | const rc = posix.system._kern_read_dir( |
| 244 | 253 | self.dir.fd, |
| 245 | 254 | &self.buf, |
| 246 | 255 | self.buf.len, |
| 247 | HAIKU_MAX_COUNT, | |
| 256 | self.buf.len / @sizeOf(DirEnt), | |
| 248 | 257 | ); |
| 249 | 258 | if (rc == 0) return null; |
| 250 | 259 | if (rc < 0) { |
| 251 | switch (posix.errno(rc)) { | |
| 252 | .BADF => unreachable, // Dir is invalid or was opened without iteration ability | |
| 260 | switch (@as(posix.E, @enumFromInt(rc))) { | |
| 261 | .BADF => unreachable, // Dir is invalid | |
| 253 | 262 | .FAULT => unreachable, |
| 254 | 263 | .NOTDIR => unreachable, |
| 255 | 264 | .INVAL => unreachable, |
| 265 | .OVERFLOW => unreachable, | |
| 266 | .ACCES => return error.AccessDenied, | |
| 267 | .PERM => return error.AccessDenied, | |
| 256 | 268 | else => |err| return posix.unexpectedErrno(err), |
| 257 | 269 | } |
| 258 | 270 | } |
| 271 | self.offset = 0; | |
| 259 | 272 | self.index = 0; |
| 260 | self.end_index = @as(usize, @intCast(rc)); | |
| 261 | } | |
| 262 | const haiku_entry = @as(*align(1) posix.system.dirent, @ptrCast(&self.buf[self.index])); | |
| 263 | const next_index = self.index + haiku_entry.reclen; | |
| 264 | self.index = next_index; | |
| 265 | const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&haiku_entry.name)), 0); | |
| 266 | ||
| 267 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.ino == 0)) { | |
| 268 | continue :start_over; | |
| 273 | self.end_index = @intCast(rc); | |
| 269 | 274 | } |
| 275 | const dirent: *DirEnt = @ptrCast(@alignCast(&self.buf[self.offset])); | |
| 276 | self.offset += dirent.reclen; | |
| 277 | self.index += 1; | |
| 278 | const name = mem.span(dirent.getName()); | |
| 279 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or dirent.ino == 0) continue; | |
| 270 | 280 | |
| 271 | 281 | var stat_info: posix.Stat = undefined; |
| 272 | const rc = posix.system._kern_read_stat( | |
| 282 | switch (@as(posix.E, @enumFromInt(posix.system._kern_read_stat( | |
| 273 | 283 | self.dir.fd, |
| 274 | &haiku_entry.name, | |
| 284 | name, | |
| 275 | 285 | false, |
| 276 | 286 | &stat_info, |
| 277 | 287 | 0, |
| 278 | ); | |
| 279 | if (rc != 0) { | |
| 280 | switch (posix.errno(rc)) { | |
| 281 | .SUCCESS => {}, | |
| 282 | .BADF => unreachable, // Dir is invalid or was opened without iteration ability | |
| 283 | .FAULT => unreachable, | |
| 284 | .NOTDIR => unreachable, | |
| 285 | .INVAL => unreachable, | |
| 286 | else => |err| return posix.unexpectedErrno(err), | |
| 287 | } | |
| 288 | )))) { | |
| 289 | .SUCCESS => {}, | |
| 290 | .INVAL => unreachable, | |
| 291 | .BADF => unreachable, // Dir is invalid | |
| 292 | .NOMEM => return error.SystemResources, | |
| 293 | .ACCES => return error.AccessDenied, | |
| 294 | .PERM => return error.AccessDenied, | |
| 295 | .FAULT => unreachable, | |
| 296 | .NAMETOOLONG => unreachable, | |
| 297 | .LOOP => unreachable, | |
| 298 | .NOENT => continue, | |
| 299 | else => |err| return posix.unexpectedErrno(err), | |
| 288 | 300 | } |
| 289 | 301 | const statmode = stat_info.mode & posix.S.IFMT; |
| 290 | 302 | |
| ... | ... | @@ -315,7 +327,7 @@ pub const Iterator = switch (native_os) { |
| 315 | 327 | dir: Dir, |
| 316 | 328 | // The if guard is solely there to prevent compile errors from missing `linux.dirent64` |
| 317 | 329 | // definition when compiling for other OSes. It doesn't do anything when compiling for Linux. |
| 318 | buf: [1024]u8 align(if (native_os != .linux) 1 else @alignOf(linux.dirent64)), | |
| 330 | buf: [1024]u8 align(@alignOf(linux.dirent64)), | |
| 319 | 331 | index: usize, |
| 320 | 332 | end_index: usize, |
| 321 | 333 | first_iter: bool, |
| ... | ... | @@ -599,13 +611,21 @@ fn iterateImpl(self: Dir, first_iter_start_value: bool) Iterator { |
| 599 | 611 | .buf = undefined, |
| 600 | 612 | .first_iter = first_iter_start_value, |
| 601 | 613 | }, |
| 602 | .linux, .haiku => return Iterator{ | |
| 614 | .linux => return Iterator{ | |
| 603 | 615 | .dir = self, |
| 604 | 616 | .index = 0, |
| 605 | 617 | .end_index = 0, |
| 606 | 618 | .buf = undefined, |
| 607 | 619 | .first_iter = first_iter_start_value, |
| 608 | 620 | }, |
| 621 | .haiku => return Iterator{ | |
| 622 | .dir = self, | |
| 623 | .offset = 0, | |
| 624 | .index = 0, | |
| 625 | .end_index = 0, | |
| 626 | .buf = undefined, | |
| 627 | .first_iter = first_iter_start_value, | |
| 628 | }, | |
| 609 | 629 | .windows => return Iterator{ |
| 610 | 630 | .dir = self, |
| 611 | 631 | .index = 0, |
| ... | ... | @@ -1429,6 +1449,27 @@ pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) Open |
| 1429 | 1449 | .wasi => { |
| 1430 | 1450 | return openDir(self, mem.sliceTo(sub_path_c, 0), args); |
| 1431 | 1451 | }, |
| 1452 | .haiku => { | |
| 1453 | const rc = posix.system._kern_open_dir(self.fd, sub_path_c); | |
| 1454 | if (rc >= 0) return .{ .fd = rc }; | |
| 1455 | switch (@as(posix.E, @enumFromInt(rc))) { | |
| 1456 | .FAULT => unreachable, | |
| 1457 | .INVAL => unreachable, | |
| 1458 | .BADF => unreachable, | |
| 1459 | .ACCES => return error.AccessDenied, | |
| 1460 | .LOOP => return error.SymLinkLoop, | |
| 1461 | .MFILE => return error.ProcessFdQuotaExceeded, | |
| 1462 | .NAMETOOLONG => return error.NameTooLong, | |
| 1463 | .NFILE => return error.SystemFdQuotaExceeded, | |
| 1464 | .NODEV => return error.NoDevice, | |
| 1465 | .NOENT => return error.FileNotFound, | |
| 1466 | .NOMEM => return error.SystemResources, | |
| 1467 | .NOTDIR => return error.NotDir, | |
| 1468 | .PERM => return error.AccessDenied, | |
| 1469 | .BUSY => return error.DeviceBusy, | |
| 1470 | else => |err| return posix.unexpectedErrno(err), | |
| 1471 | } | |
| 1472 | }, | |
| 1432 | 1473 | else => { |
| 1433 | 1474 | var symlink_flags: posix.O = .{ |
| 1434 | 1475 | .ACCMODE = .RDONLY, |
lib/std/zig/Zir.zig+2-6| ... | ... | @@ -106,12 +106,8 @@ pub const NullTerminatedString = enum(u32) { |
| 106 | 106 | |
| 107 | 107 | /// Given an index into `string_bytes` returns the null-terminated string found there. |
| 108 | 108 | pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 { |
| 109 | const start = @intFromEnum(index); | |
| 110 | var end: u32 = start; | |
| 111 | while (code.string_bytes[end] != 0) { | |
| 112 | end += 1; | |
| 113 | } | |
| 114 | return code.string_bytes[start..end :0]; | |
| 109 | const slice = code.string_bytes[@intFromEnum(index)..]; | |
| 110 | return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0]; | |
| 115 | 111 | } |
| 116 | 112 | |
| 117 | 113 | pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref { |
lib/std/zig/system.zig+7-3| ... | ... | @@ -988,9 +988,13 @@ fn detectAbiAndDynamicLinker( |
| 988 | 988 | // if it finds one, then instead of using /usr/bin/env as the ELF file to examine, it uses the file it references instead, |
| 989 | 989 | // doing the same logic recursively in case it finds another shebang line. |
| 990 | 990 | |
| 991 | // Since /usr/bin/env is hard-coded into the shebang line of many portable scripts, it's a | |
| 992 | // reasonably reliable path to start with. | |
| 993 | var file_name: []const u8 = "/usr/bin/env"; | |
| 991 | var file_name: []const u8 = switch (os.tag) { | |
| 992 | // Since /usr/bin/env is hard-coded into the shebang line of many portable scripts, it's a | |
| 993 | // reasonably reliable path to start with. | |
| 994 | else => "/usr/bin/env", | |
| 995 | // Haiku does not have a /usr root directory. | |
| 996 | .haiku => "/bin/env", | |
| 997 | }; | |
| 994 | 998 | // #! (2) + 255 (max length of shebang line since Linux 5.1) + \n (1) |
| 995 | 999 | var buffer: [258]u8 = undefined; |
| 996 | 1000 | while (true) { |
lib/std/zig/system/NativePaths.zig+7| ... | ... | @@ -105,6 +105,13 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths { |
| 105 | 105 | return self; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | if (builtin.os.tag == .haiku) { | |
| 109 | try self.addLibDir("/system/non-packaged/lib"); | |
| 110 | try self.addLibDir("/system/develop/lib"); | |
| 111 | try self.addLibDir("/system/lib"); | |
| 112 | return self; | |
| 113 | } | |
| 114 | ||
| 108 | 115 | if (builtin.os.tag != .windows and builtin.os.tag != .wasi) { |
| 109 | 116 | const triple = try native_target.linuxTriple(arena); |
| 110 | 117 |
src/Compilation.zig+3-4| ... | ... | @@ -3159,7 +3159,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod |
| 3159 | 3159 | const rt_file_path = try module_reference.src_loc.file_scope.fullPath(gpa); |
| 3160 | 3160 | defer gpa.free(rt_file_path); |
| 3161 | 3161 | ref_traces.appendAssumeCapacity(.{ |
| 3162 | .decl_name = try eb.addString(ip.stringToSlice(module_reference.decl)), | |
| 3162 | .decl_name = try eb.addString(module_reference.decl.toSlice(ip)), | |
| 3163 | 3163 | .src_loc = try eb.addSourceLocation(.{ |
| 3164 | 3164 | .src_path = try eb.addString(rt_file_path), |
| 3165 | 3165 | .span_start = span.start, |
| ... | ... | @@ -4074,8 +4074,7 @@ fn workerCheckEmbedFile( |
| 4074 | 4074 | fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void { |
| 4075 | 4075 | const mod = comp.module.?; |
| 4076 | 4076 | const ip = &mod.intern_pool; |
| 4077 | const sub_file_path = ip.stringToSlice(embed_file.sub_file_path); | |
| 4078 | var file = try embed_file.owner.root.openFile(sub_file_path, .{}); | |
| 4077 | var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{}); | |
| 4079 | 4078 | defer file.close(); |
| 4080 | 4079 | |
| 4081 | 4080 | const stat = try file.stat(); |
| ... | ... | @@ -4444,7 +4443,7 @@ fn reportRetryableEmbedFileError( |
| 4444 | 4443 | const ip = &mod.intern_pool; |
| 4445 | 4444 | const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{ |
| 4446 | 4445 | embed_file.owner.root, |
| 4447 | ip.stringToSlice(embed_file.sub_file_path), | |
| 4446 | embed_file.sub_file_path.toSlice(ip), | |
| 4448 | 4447 | @errorName(err), |
| 4449 | 4448 | }); |
| 4450 | 4449 |
src/InternPool.zig+190-164| ... | ... | @@ -351,7 +351,7 @@ const KeyAdapter = struct { |
| 351 | 351 | pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool { |
| 352 | 352 | _ = b_void; |
| 353 | 353 | if (ctx.intern_pool.items.items(.tag)[b_map_index] == .removed) return false; |
| 354 | return ctx.intern_pool.indexToKey(@as(Index, @enumFromInt(b_map_index))).eql(a, ctx.intern_pool); | |
| 354 | return ctx.intern_pool.indexToKey(@enumFromInt(b_map_index)).eql(a, ctx.intern_pool); | |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | pub fn hash(ctx: @This(), a: Key) u32 { |
| ... | ... | @@ -385,7 +385,7 @@ pub const RuntimeIndex = enum(u32) { |
| 385 | 385 | _, |
| 386 | 386 | |
| 387 | 387 | pub fn increment(ri: *RuntimeIndex) void { |
| 388 | ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1)); | |
| 388 | ri.* = @enumFromInt(@intFromEnum(ri.*) + 1); | |
| 389 | 389 | } |
| 390 | 390 | }; |
| 391 | 391 | |
| ... | ... | @@ -418,12 +418,44 @@ pub const OptionalNamespaceIndex = enum(u32) { |
| 418 | 418 | |
| 419 | 419 | /// An index into `string_bytes`. |
| 420 | 420 | pub const String = enum(u32) { |
| 421 | /// An empty string. | |
| 422 | empty = 0, | |
| 423 | _, | |
| 424 | ||
| 425 | pub fn toSlice(string: String, len: u64, ip: *const InternPool) []const u8 { | |
| 426 | return ip.string_bytes.items[@intFromEnum(string)..][0..@intCast(len)]; | |
| 427 | } | |
| 428 | ||
| 429 | pub fn at(string: String, index: u64, ip: *const InternPool) u8 { | |
| 430 | return ip.string_bytes.items[@intCast(@intFromEnum(string) + index)]; | |
| 431 | } | |
| 432 | ||
| 433 | pub fn toNullTerminatedString(string: String, len: u64, ip: *const InternPool) NullTerminatedString { | |
| 434 | assert(std.mem.indexOfScalar(u8, string.toSlice(len, ip), 0) == null); | |
| 435 | assert(string.at(len, ip) == 0); | |
| 436 | return @enumFromInt(@intFromEnum(string)); | |
| 437 | } | |
| 438 | }; | |
| 439 | ||
| 440 | /// An index into `string_bytes` which might be `none`. | |
| 441 | pub const OptionalString = enum(u32) { | |
| 442 | /// This is distinct from `none` - it is a valid index that represents empty string. | |
| 443 | empty = 0, | |
| 444 | none = std.math.maxInt(u32), | |
| 421 | 445 | _, |
| 446 | ||
| 447 | pub fn unwrap(string: OptionalString) ?String { | |
| 448 | return if (string != .none) @enumFromInt(@intFromEnum(string)) else null; | |
| 449 | } | |
| 450 | ||
| 451 | pub fn toSlice(string: OptionalString, len: u64, ip: *const InternPool) ?[]const u8 { | |
| 452 | return (string.unwrap() orelse return null).toSlice(len, ip); | |
| 453 | } | |
| 422 | 454 | }; |
| 423 | 455 | |
| 424 | 456 | /// An index into `string_bytes`. |
| 425 | 457 | pub const NullTerminatedString = enum(u32) { |
| 426 | /// This is distinct from `none` - it is a valid index that represents empty string. | |
| 458 | /// An empty string. | |
| 427 | 459 | empty = 0, |
| 428 | 460 | _, |
| 429 | 461 | |
| ... | ... | @@ -447,6 +479,19 @@ pub const NullTerminatedString = enum(u32) { |
| 447 | 479 | return @enumFromInt(@intFromEnum(self)); |
| 448 | 480 | } |
| 449 | 481 | |
| 482 | pub fn toSlice(string: NullTerminatedString, ip: *const InternPool) [:0]const u8 { | |
| 483 | const slice = ip.string_bytes.items[@intFromEnum(string)..]; | |
| 484 | return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0]; | |
| 485 | } | |
| 486 | ||
| 487 | pub fn length(string: NullTerminatedString, ip: *const InternPool) u32 { | |
| 488 | return @intCast(string.toSlice(ip).len); | |
| 489 | } | |
| 490 | ||
| 491 | pub fn eqlSlice(string: NullTerminatedString, slice: []const u8, ip: *const InternPool) bool { | |
| 492 | return std.mem.eql(u8, string.toSlice(ip), slice); | |
| 493 | } | |
| 494 | ||
| 450 | 495 | const Adapter = struct { |
| 451 | 496 | strings: []const NullTerminatedString, |
| 452 | 497 | |
| ... | ... | @@ -467,11 +512,11 @@ pub const NullTerminatedString = enum(u32) { |
| 467 | 512 | return @intFromEnum(a) < @intFromEnum(b); |
| 468 | 513 | } |
| 469 | 514 | |
| 470 | pub fn toUnsigned(self: NullTerminatedString, ip: *const InternPool) ?u32 { | |
| 471 | const s = ip.stringToSlice(self); | |
| 472 | if (s.len > 1 and s[0] == '0') return null; | |
| 473 | if (std.mem.indexOfScalar(u8, s, '_')) |_| return null; | |
| 474 | return std.fmt.parseUnsigned(u32, s, 10) catch null; | |
| 515 | pub fn toUnsigned(string: NullTerminatedString, ip: *const InternPool) ?u32 { | |
| 516 | const slice = string.toSlice(ip); | |
| 517 | if (slice.len > 1 and slice[0] == '0') return null; | |
| 518 | if (std.mem.indexOfScalar(u8, slice, '_')) |_| return null; | |
| 519 | return std.fmt.parseUnsigned(u32, slice, 10) catch null; | |
| 475 | 520 | } |
| 476 | 521 | |
| 477 | 522 | const FormatData = struct { |
| ... | ... | @@ -484,11 +529,11 @@ pub const NullTerminatedString = enum(u32) { |
| 484 | 529 | _: std.fmt.FormatOptions, |
| 485 | 530 | writer: anytype, |
| 486 | 531 | ) @TypeOf(writer).Error!void { |
| 487 | const s = data.ip.stringToSlice(data.string); | |
| 532 | const slice = data.string.toSlice(data.ip); | |
| 488 | 533 | if (comptime std.mem.eql(u8, specifier, "")) { |
| 489 | try writer.writeAll(s); | |
| 534 | try writer.writeAll(slice); | |
| 490 | 535 | } else if (comptime std.mem.eql(u8, specifier, "i")) { |
| 491 | try writer.print("{p}", .{std.zig.fmtId(s)}); | |
| 536 | try writer.print("{p}", .{std.zig.fmtId(slice)}); | |
| 492 | 537 | } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'"); |
| 493 | 538 | } |
| 494 | 539 | |
| ... | ... | @@ -504,9 +549,12 @@ pub const OptionalNullTerminatedString = enum(u32) { |
| 504 | 549 | none = std.math.maxInt(u32), |
| 505 | 550 | _, |
| 506 | 551 | |
| 507 | pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString { | |
| 508 | if (oi == .none) return null; | |
| 509 | return @enumFromInt(@intFromEnum(oi)); | |
| 552 | pub fn unwrap(string: OptionalNullTerminatedString) ?NullTerminatedString { | |
| 553 | return if (string != .none) @enumFromInt(@intFromEnum(string)) else null; | |
| 554 | } | |
| 555 | ||
| 556 | pub fn toSlice(string: OptionalNullTerminatedString, ip: *const InternPool) ?[:0]const u8 { | |
| 557 | return (string.unwrap() orelse return null).toSlice(ip); | |
| 510 | 558 | } |
| 511 | 559 | }; |
| 512 | 560 | |
| ... | ... | @@ -690,6 +738,10 @@ pub const Key = union(enum) { |
| 690 | 738 | len: u64, |
| 691 | 739 | child: Index, |
| 692 | 740 | sentinel: Index = .none, |
| 741 | ||
| 742 | pub fn lenIncludingSentinel(array_type: ArrayType) u64 { | |
| 743 | return array_type.len + @intFromBool(array_type.sentinel != .none); | |
| 744 | } | |
| 693 | 745 | }; |
| 694 | 746 | |
| 695 | 747 | /// Extern so that hashing can be done via memory reinterpreting. |
| ... | ... | @@ -1043,7 +1095,7 @@ pub const Key = union(enum) { |
| 1043 | 1095 | storage: Storage, |
| 1044 | 1096 | |
| 1045 | 1097 | pub const Storage = union(enum) { |
| 1046 | bytes: []const u8, | |
| 1098 | bytes: String, | |
| 1047 | 1099 | elems: []const Index, |
| 1048 | 1100 | repeated_elem: Index, |
| 1049 | 1101 | |
| ... | ... | @@ -1203,7 +1255,7 @@ pub const Key = union(enum) { |
| 1203 | 1255 | |
| 1204 | 1256 | if (child == .u8_type) { |
| 1205 | 1257 | switch (aggregate.storage) { |
| 1206 | .bytes => |bytes| for (bytes[0..@intCast(len)]) |byte| { | |
| 1258 | .bytes => |bytes| for (bytes.toSlice(len, ip)) |byte| { | |
| 1207 | 1259 | std.hash.autoHash(&hasher, KeyTag.int); |
| 1208 | 1260 | std.hash.autoHash(&hasher, byte); |
| 1209 | 1261 | }, |
| ... | ... | @@ -1240,7 +1292,7 @@ pub const Key = union(enum) { |
| 1240 | 1292 | |
| 1241 | 1293 | switch (aggregate.storage) { |
| 1242 | 1294 | .bytes => unreachable, |
| 1243 | .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem| | |
| 1295 | .elems => |elems| for (elems[0..@intCast(len)]) |elem| | |
| 1244 | 1296 | std.hash.autoHash(&hasher, elem), |
| 1245 | 1297 | .repeated_elem => |elem| { |
| 1246 | 1298 | var remaining = len; |
| ... | ... | @@ -1505,11 +1557,11 @@ pub const Key = union(enum) { |
| 1505 | 1557 | if (a_info.ty == .c_longdouble_type and a_info.storage != .f80) { |
| 1506 | 1558 | // These are strange: we'll sometimes represent them as f128, even if the |
| 1507 | 1559 | // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80. |
| 1508 | const a_val = switch (a_info.storage) { | |
| 1509 | inline else => |val| @as(u128, @bitCast(@as(f128, @floatCast(val)))), | |
| 1560 | const a_val: u128 = switch (a_info.storage) { | |
| 1561 | inline else => |val| @bitCast(@as(f128, @floatCast(val))), | |
| 1510 | 1562 | }; |
| 1511 | const b_val = switch (b_info.storage) { | |
| 1512 | inline else => |val| @as(u128, @bitCast(@as(f128, @floatCast(val)))), | |
| 1563 | const b_val: u128 = switch (b_info.storage) { | |
| 1564 | inline else => |val| @bitCast(@as(f128, @floatCast(val))), | |
| 1513 | 1565 | }; |
| 1514 | 1566 | return a_val == b_val; |
| 1515 | 1567 | } |
| ... | ... | @@ -1560,11 +1612,11 @@ pub const Key = union(enum) { |
| 1560 | 1612 | const len = ip.aggregateTypeLen(a_info.ty); |
| 1561 | 1613 | const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?; |
| 1562 | 1614 | if (@as(StorageTag, a_info.storage) != @as(StorageTag, b_info.storage)) { |
| 1563 | for (0..@as(usize, @intCast(len))) |elem_index| { | |
| 1615 | for (0..@intCast(len)) |elem_index| { | |
| 1564 | 1616 | const a_elem = switch (a_info.storage) { |
| 1565 | 1617 | .bytes => |bytes| ip.getIfExists(.{ .int = .{ |
| 1566 | 1618 | .ty = .u8_type, |
| 1567 | .storage = .{ .u64 = bytes[elem_index] }, | |
| 1619 | .storage = .{ .u64 = bytes.at(elem_index, ip) }, | |
| 1568 | 1620 | } }) orelse return false, |
| 1569 | 1621 | .elems => |elems| elems[elem_index], |
| 1570 | 1622 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1572,7 +1624,7 @@ pub const Key = union(enum) { |
| 1572 | 1624 | const b_elem = switch (b_info.storage) { |
| 1573 | 1625 | .bytes => |bytes| ip.getIfExists(.{ .int = .{ |
| 1574 | 1626 | .ty = .u8_type, |
| 1575 | .storage = .{ .u64 = bytes[elem_index] }, | |
| 1627 | .storage = .{ .u64 = bytes.at(elem_index, ip) }, | |
| 1576 | 1628 | } }) orelse return false, |
| 1577 | 1629 | .elems => |elems| elems[elem_index], |
| 1578 | 1630 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1585,18 +1637,15 @@ pub const Key = union(enum) { |
| 1585 | 1637 | switch (a_info.storage) { |
| 1586 | 1638 | .bytes => |a_bytes| { |
| 1587 | 1639 | const b_bytes = b_info.storage.bytes; |
| 1588 | return std.mem.eql( | |
| 1589 | u8, | |
| 1590 | a_bytes[0..@as(usize, @intCast(len))], | |
| 1591 | b_bytes[0..@as(usize, @intCast(len))], | |
| 1592 | ); | |
| 1640 | return a_bytes == b_bytes or | |
| 1641 | std.mem.eql(u8, a_bytes.toSlice(len, ip), b_bytes.toSlice(len, ip)); | |
| 1593 | 1642 | }, |
| 1594 | 1643 | .elems => |a_elems| { |
| 1595 | 1644 | const b_elems = b_info.storage.elems; |
| 1596 | 1645 | return std.mem.eql( |
| 1597 | 1646 | Index, |
| 1598 | a_elems[0..@as(usize, @intCast(len))], | |
| 1599 | b_elems[0..@as(usize, @intCast(len))], | |
| 1647 | a_elems[0..@intCast(len)], | |
| 1648 | b_elems[0..@intCast(len)], | |
| 1600 | 1649 | ); |
| 1601 | 1650 | }, |
| 1602 | 1651 | .repeated_elem => |a_elem| { |
| ... | ... | @@ -4175,10 +4224,10 @@ pub const Float64 = struct { |
| 4175 | 4224 | } |
| 4176 | 4225 | |
| 4177 | 4226 | fn pack(val: f64) Float64 { |
| 4178 | const bits = @as(u64, @bitCast(val)); | |
| 4227 | const bits: u64 = @bitCast(val); | |
| 4179 | 4228 | return .{ |
| 4180 | .piece0 = @as(u32, @truncate(bits)), | |
| 4181 | .piece1 = @as(u32, @truncate(bits >> 32)), | |
| 4229 | .piece0 = @truncate(bits), | |
| 4230 | .piece1 = @truncate(bits >> 32), | |
| 4182 | 4231 | }; |
| 4183 | 4232 | } |
| 4184 | 4233 | }; |
| ... | ... | @@ -4197,11 +4246,11 @@ pub const Float80 = struct { |
| 4197 | 4246 | } |
| 4198 | 4247 | |
| 4199 | 4248 | fn pack(val: f80) Float80 { |
| 4200 | const bits = @as(u80, @bitCast(val)); | |
| 4249 | const bits: u80 = @bitCast(val); | |
| 4201 | 4250 | return .{ |
| 4202 | .piece0 = @as(u32, @truncate(bits)), | |
| 4203 | .piece1 = @as(u32, @truncate(bits >> 32)), | |
| 4204 | .piece2 = @as(u16, @truncate(bits >> 64)), | |
| 4251 | .piece0 = @truncate(bits), | |
| 4252 | .piece1 = @truncate(bits >> 32), | |
| 4253 | .piece2 = @truncate(bits >> 64), | |
| 4205 | 4254 | }; |
| 4206 | 4255 | } |
| 4207 | 4256 | }; |
| ... | ... | @@ -4222,12 +4271,12 @@ pub const Float128 = struct { |
| 4222 | 4271 | } |
| 4223 | 4272 | |
| 4224 | 4273 | fn pack(val: f128) Float128 { |
| 4225 | const bits = @as(u128, @bitCast(val)); | |
| 4274 | const bits: u128 = @bitCast(val); | |
| 4226 | 4275 | return .{ |
| 4227 | .piece0 = @as(u32, @truncate(bits)), | |
| 4228 | .piece1 = @as(u32, @truncate(bits >> 32)), | |
| 4229 | .piece2 = @as(u32, @truncate(bits >> 64)), | |
| 4230 | .piece3 = @as(u32, @truncate(bits >> 96)), | |
| 4276 | .piece0 = @truncate(bits), | |
| 4277 | .piece1 = @truncate(bits >> 32), | |
| 4278 | .piece2 = @truncate(bits >> 64), | |
| 4279 | .piece3 = @truncate(bits >> 96), | |
| 4231 | 4280 | }; |
| 4232 | 4281 | } |
| 4233 | 4282 | }; |
| ... | ... | @@ -4244,7 +4293,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { |
| 4244 | 4293 | assert(ip.items.len == 0); |
| 4245 | 4294 | |
| 4246 | 4295 | // Reserve string index 0 for an empty string. |
| 4247 | assert((try ip.getOrPutString(gpa, "")) == .empty); | |
| 4296 | assert((try ip.getOrPutString(gpa, "", .no_embedded_nulls)) == .empty); | |
| 4248 | 4297 | |
| 4249 | 4298 | // So that we can use `catch unreachable` below. |
| 4250 | 4299 | try ip.items.ensureUnusedCapacity(gpa, static_keys.len); |
| ... | ... | @@ -4329,13 +4378,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4329 | 4378 | .type_int_signed => .{ |
| 4330 | 4379 | .int_type = .{ |
| 4331 | 4380 | .signedness = .signed, |
| 4332 | .bits = @as(u16, @intCast(data)), | |
| 4381 | .bits = @intCast(data), | |
| 4333 | 4382 | }, |
| 4334 | 4383 | }, |
| 4335 | 4384 | .type_int_unsigned => .{ |
| 4336 | 4385 | .int_type = .{ |
| 4337 | 4386 | .signedness = .unsigned, |
| 4338 | .bits = @as(u16, @intCast(data)), | |
| 4387 | .bits = @intCast(data), | |
| 4339 | 4388 | }, |
| 4340 | 4389 | }, |
| 4341 | 4390 | .type_array_big => { |
| ... | ... | @@ -4354,8 +4403,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4354 | 4403 | .sentinel = .none, |
| 4355 | 4404 | } }; |
| 4356 | 4405 | }, |
| 4357 | .simple_type => .{ .simple_type = @as(SimpleType, @enumFromInt(data)) }, | |
| 4358 | .simple_value => .{ .simple_value = @as(SimpleValue, @enumFromInt(data)) }, | |
| 4406 | .simple_type => .{ .simple_type = @enumFromInt(data) }, | |
| 4407 | .simple_value => .{ .simple_value = @enumFromInt(data) }, | |
| 4359 | 4408 | |
| 4360 | 4409 | .type_vector => { |
| 4361 | 4410 | const vector_info = ip.extraData(Vector, data); |
| ... | ... | @@ -4506,9 +4555,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4506 | 4555 | } }, |
| 4507 | 4556 | .type_function => .{ .func_type = ip.extraFuncType(data) }, |
| 4508 | 4557 | |
| 4509 | .undef => .{ .undef = @as(Index, @enumFromInt(data)) }, | |
| 4558 | .undef => .{ .undef = @enumFromInt(data) }, | |
| 4510 | 4559 | .opt_null => .{ .opt = .{ |
| 4511 | .ty = @as(Index, @enumFromInt(data)), | |
| 4560 | .ty = @enumFromInt(data), | |
| 4512 | 4561 | .val = .none, |
| 4513 | 4562 | } }, |
| 4514 | 4563 | .opt_payload => { |
| ... | ... | @@ -4670,11 +4719,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4670 | 4719 | }, |
| 4671 | 4720 | .float_f16 => .{ .float = .{ |
| 4672 | 4721 | .ty = .f16_type, |
| 4673 | .storage = .{ .f16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) }, | |
| 4722 | .storage = .{ .f16 = @bitCast(@as(u16, @intCast(data))) }, | |
| 4674 | 4723 | } }, |
| 4675 | 4724 | .float_f32 => .{ .float = .{ |
| 4676 | 4725 | .ty = .f32_type, |
| 4677 | .storage = .{ .f32 = @as(f32, @bitCast(data)) }, | |
| 4726 | .storage = .{ .f32 = @bitCast(data) }, | |
| 4678 | 4727 | } }, |
| 4679 | 4728 | .float_f64 => .{ .float = .{ |
| 4680 | 4729 | .ty = .f64_type, |
| ... | ... | @@ -4771,10 +4820,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4771 | 4820 | }, |
| 4772 | 4821 | .bytes => { |
| 4773 | 4822 | const extra = ip.extraData(Bytes, data); |
| 4774 | const len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(extra.ty)); | |
| 4775 | 4823 | return .{ .aggregate = .{ |
| 4776 | 4824 | .ty = extra.ty, |
| 4777 | .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] }, | |
| 4825 | .storage = .{ .bytes = extra.bytes }, | |
| 4778 | 4826 | } }; |
| 4779 | 4827 | }, |
| 4780 | 4828 | .aggregate => { |
| ... | ... | @@ -4809,14 +4857,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4809 | 4857 | .val = .{ .payload = extra.val }, |
| 4810 | 4858 | } }; |
| 4811 | 4859 | }, |
| 4812 | .enum_literal => .{ .enum_literal = @as(NullTerminatedString, @enumFromInt(data)) }, | |
| 4860 | .enum_literal => .{ .enum_literal = @enumFromInt(data) }, | |
| 4813 | 4861 | .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) }, |
| 4814 | 4862 | |
| 4815 | 4863 | .memoized_call => { |
| 4816 | 4864 | const extra = ip.extraDataTrail(MemoizedCall, data); |
| 4817 | 4865 | return .{ .memoized_call = .{ |
| 4818 | 4866 | .func = extra.data.func, |
| 4819 | .arg_values = @as([]const Index, @ptrCast(ip.extra.items[extra.end..][0..extra.data.args_len])), | |
| 4867 | .arg_values = @ptrCast(ip.extra.items[extra.end..][0..extra.data.args_len]), | |
| 4820 | 4868 | .result = extra.data.result, |
| 4821 | 4869 | } }; |
| 4822 | 4870 | }, |
| ... | ... | @@ -5596,9 +5644,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5596 | 5644 | switch (aggregate.storage) { |
| 5597 | 5645 | .bytes => |bytes| { |
| 5598 | 5646 | assert(child == .u8_type); |
| 5599 | if (bytes.len != len) { | |
| 5600 | assert(bytes.len == len_including_sentinel); | |
| 5601 | assert(bytes[@intCast(len)] == ip.indexToKey(sentinel).int.storage.u64); | |
| 5647 | if (sentinel != .none) { | |
| 5648 | assert(bytes.at(@intCast(len), ip) == ip.indexToKey(sentinel).int.storage.u64); | |
| 5602 | 5649 | } |
| 5603 | 5650 | }, |
| 5604 | 5651 | .elems => |elems| { |
| ... | ... | @@ -5641,11 +5688,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5641 | 5688 | switch (ty_key) { |
| 5642 | 5689 | .anon_struct_type => |anon_struct_type| opv: { |
| 5643 | 5690 | switch (aggregate.storage) { |
| 5644 | .bytes => |bytes| for (anon_struct_type.values.get(ip), bytes) |value, byte| { | |
| 5645 | if (value != ip.getIfExists(.{ .int = .{ | |
| 5646 | .ty = .u8_type, | |
| 5647 | .storage = .{ .u64 = byte }, | |
| 5648 | } })) break :opv; | |
| 5691 | .bytes => |bytes| for (anon_struct_type.values.get(ip), bytes.at(0, ip)..) |value, byte| { | |
| 5692 | if (value == .none) break :opv; | |
| 5693 | switch (ip.indexToKey(value)) { | |
| 5694 | .undef => break :opv, | |
| 5695 | .int => |int| switch (int.storage) { | |
| 5696 | .u64 => |x| if (x != byte) break :opv, | |
| 5697 | else => break :opv, | |
| 5698 | }, | |
| 5699 | else => unreachable, | |
| 5700 | } | |
| 5649 | 5701 | }, |
| 5650 | 5702 | .elems => |elems| if (!std.mem.eql( |
| 5651 | 5703 | Index, |
| ... | ... | @@ -5670,9 +5722,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5670 | 5722 | |
| 5671 | 5723 | repeated: { |
| 5672 | 5724 | switch (aggregate.storage) { |
| 5673 | .bytes => |bytes| for (bytes[1..@as(usize, @intCast(len))]) |byte| | |
| 5674 | if (byte != bytes[0]) break :repeated, | |
| 5675 | .elems => |elems| for (elems[1..@as(usize, @intCast(len))]) |elem| | |
| 5725 | .bytes => |bytes| for (bytes.toSlice(len, ip)[1..]) |byte| | |
| 5726 | if (byte != bytes.at(0, ip)) break :repeated, | |
| 5727 | .elems => |elems| for (elems[1..@intCast(len)]) |elem| | |
| 5676 | 5728 | if (elem != elems[0]) break :repeated, |
| 5677 | 5729 | .repeated_elem => {}, |
| 5678 | 5730 | } |
| ... | ... | @@ -5681,7 +5733,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5681 | 5733 | _ = ip.map.pop(); |
| 5682 | 5734 | const elem = try ip.get(gpa, .{ .int = .{ |
| 5683 | 5735 | .ty = .u8_type, |
| 5684 | .storage = .{ .u64 = bytes[0] }, | |
| 5736 | .storage = .{ .u64 = bytes.at(0, ip) }, | |
| 5685 | 5737 | } }); |
| 5686 | 5738 | assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing); |
| 5687 | 5739 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| ... | ... | @@ -5710,7 +5762,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5710 | 5762 | try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(len_including_sentinel + 1)); |
| 5711 | 5763 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len); |
| 5712 | 5764 | switch (aggregate.storage) { |
| 5713 | .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes[0..@intCast(len)]), | |
| 5765 | .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes.toSlice(len, ip)), | |
| 5714 | 5766 | .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) { |
| 5715 | 5767 | .undef => { |
| 5716 | 5768 | ip.string_bytes.shrinkRetainingCapacity(string_bytes_index); |
| ... | ... | @@ -5730,15 +5782,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5730 | 5782 | else => unreachable, |
| 5731 | 5783 | }, |
| 5732 | 5784 | } |
| 5733 | const has_internal_null = | |
| 5734 | std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null; | |
| 5735 | 5785 | if (sentinel != .none) ip.string_bytes.appendAssumeCapacity( |
| 5736 | 5786 | @intCast(ip.indexToKey(sentinel).int.storage.u64), |
| 5737 | 5787 | ); |
| 5738 | const string: String = if (has_internal_null) | |
| 5739 | @enumFromInt(string_bytes_index) | |
| 5740 | else | |
| 5741 | (try ip.getOrPutTrailingString(gpa, @intCast(len_including_sentinel))).toString(); | |
| 5788 | const string = try ip.getOrPutTrailingString( | |
| 5789 | gpa, | |
| 5790 | @intCast(len_including_sentinel), | |
| 5791 | .maybe_embedded_nulls, | |
| 5792 | ); | |
| 5742 | 5793 | ip.items.appendAssumeCapacity(.{ |
| 5743 | 5794 | .tag = .bytes, |
| 5744 | 5795 | .data = ip.addExtraAssumeCapacity(Bytes{ |
| ... | ... | @@ -5780,7 +5831,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5780 | 5831 | .tag = .memoized_call, |
| 5781 | 5832 | .data = ip.addExtraAssumeCapacity(MemoizedCall{ |
| 5782 | 5833 | .func = memoized_call.func, |
| 5783 | .args_len = @as(u32, @intCast(memoized_call.arg_values.len)), | |
| 5834 | .args_len = @intCast(memoized_call.arg_values.len), | |
| 5784 | 5835 | .result = memoized_call.result, |
| 5785 | 5836 | }), |
| 5786 | 5837 | }); |
| ... | ... | @@ -6753,7 +6804,7 @@ fn finishFuncInstance( |
| 6753 | 6804 | const decl = ip.declPtr(decl_index); |
| 6754 | 6805 | decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{ |
| 6755 | 6806 | fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), |
| 6756 | }); | |
| 6807 | }, .no_embedded_nulls); | |
| 6757 | 6808 | |
| 6758 | 6809 | return func_index; |
| 6759 | 6810 | } |
| ... | ... | @@ -7216,7 +7267,7 @@ pub fn remove(ip: *InternPool, index: Index) void { |
| 7216 | 7267 | } |
| 7217 | 7268 | |
| 7218 | 7269 | fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void { |
| 7219 | const limbs_len = @as(u32, @intCast(limbs.len)); | |
| 7270 | const limbs_len: u32 = @intCast(limbs.len); | |
| 7220 | 7271 | try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len); |
| 7221 | 7272 | ip.items.appendAssumeCapacity(.{ |
| 7222 | 7273 | .tag = tag, |
| ... | ... | @@ -7235,7 +7286,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32 |
| 7235 | 7286 | } |
| 7236 | 7287 | |
| 7237 | 7288 | fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 7238 | const result = @as(u32, @intCast(ip.extra.items.len)); | |
| 7289 | const result: u32 = @intCast(ip.extra.items.len); | |
| 7239 | 7290 | inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| { |
| 7240 | 7291 | ip.extra.appendAssumeCapacity(switch (field.type) { |
| 7241 | 7292 | Index, |
| ... | ... | @@ -7286,7 +7337,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 7286 | 7337 | @sizeOf(u64) => {}, |
| 7287 | 7338 | else => @compileError("unsupported host"), |
| 7288 | 7339 | } |
| 7289 | const result = @as(u32, @intCast(ip.limbs.items.len)); | |
| 7340 | const result: u32 = @intCast(ip.limbs.items.len); | |
| 7290 | 7341 | inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| { |
| 7291 | 7342 | const new: u32 = switch (field.type) { |
| 7292 | 7343 | u32 => @field(extra, field.name), |
| ... | ... | @@ -7374,7 +7425,7 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T { |
| 7374 | 7425 | |
| 7375 | 7426 | @field(result, field.name) = switch (field.type) { |
| 7376 | 7427 | u32 => int32, |
| 7377 | Index => @as(Index, @enumFromInt(int32)), | |
| 7428 | Index => @enumFromInt(int32), | |
| 7378 | 7429 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 7379 | 7430 | }; |
| 7380 | 7431 | } |
| ... | ... | @@ -7410,8 +7461,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes |
| 7410 | 7461 | }; |
| 7411 | 7462 | // TODO: https://github.com/ziglang/zig/issues/1738 |
| 7412 | 7463 | return .{ |
| 7413 | .start = @as(u32, @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb)))), | |
| 7414 | .len = @as(u32, @intCast(limbs.len)), | |
| 7464 | .start = @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb))), | |
| 7465 | .len = @intCast(limbs.len), | |
| 7415 | 7466 | }; |
| 7416 | 7467 | } |
| 7417 | 7468 | |
| ... | ... | @@ -7683,7 +7734,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 7683 | 7734 | .val = error_union.val, |
| 7684 | 7735 | } }), |
| 7685 | 7736 | .aggregate => |aggregate| { |
| 7686 | const new_len = @as(usize, @intCast(ip.aggregateTypeLen(new_ty))); | |
| 7737 | const new_len: usize = @intCast(ip.aggregateTypeLen(new_ty)); | |
| 7687 | 7738 | direct: { |
| 7688 | 7739 | const old_ty_child = switch (ip.indexToKey(old_ty)) { |
| 7689 | 7740 | inline .array_type, .vector_type => |seq_type| seq_type.child, |
| ... | ... | @@ -7696,16 +7747,11 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 7696 | 7747 | else => unreachable, |
| 7697 | 7748 | }; |
| 7698 | 7749 | if (old_ty_child != new_ty_child) break :direct; |
| 7699 | // TODO: write something like getCoercedInts to avoid needing to dupe here | |
| 7700 | 7750 | switch (aggregate.storage) { |
| 7701 | .bytes => |bytes| { | |
| 7702 | const bytes_copy = try gpa.dupe(u8, bytes[0..new_len]); | |
| 7703 | defer gpa.free(bytes_copy); | |
| 7704 | return ip.get(gpa, .{ .aggregate = .{ | |
| 7705 | .ty = new_ty, | |
| 7706 | .storage = .{ .bytes = bytes_copy }, | |
| 7707 | } }); | |
| 7708 | }, | |
| 7751 | .bytes => |bytes| return ip.get(gpa, .{ .aggregate = .{ | |
| 7752 | .ty = new_ty, | |
| 7753 | .storage = .{ .bytes = bytes }, | |
| 7754 | } }), | |
| 7709 | 7755 | .elems => |elems| { |
| 7710 | 7756 | const elems_copy = try gpa.dupe(Index, elems[0..new_len]); |
| 7711 | 7757 | defer gpa.free(elems_copy); |
| ... | ... | @@ -7729,14 +7775,13 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 7729 | 7775 | // lifetime issues, since it'll allow us to avoid referencing `aggregate` after we |
| 7730 | 7776 | // begin interning elems. |
| 7731 | 7777 | switch (aggregate.storage) { |
| 7732 | .bytes => { | |
| 7778 | .bytes => |bytes| { | |
| 7733 | 7779 | // We have to intern each value here, so unfortunately we can't easily avoid |
| 7734 | 7780 | // the repeated indexToKey calls. |
| 7735 | for (agg_elems, 0..) |*elem, i| { | |
| 7736 | const x = ip.indexToKey(val).aggregate.storage.bytes[i]; | |
| 7781 | for (agg_elems, 0..) |*elem, index| { | |
| 7737 | 7782 | elem.* = try ip.get(gpa, .{ .int = .{ |
| 7738 | 7783 | .ty = .u8_type, |
| 7739 | .storage = .{ .u64 = x }, | |
| 7784 | .storage = .{ .u64 = bytes.at(index, ip) }, | |
| 7740 | 7785 | } }); |
| 7741 | 7786 | } |
| 7742 | 7787 | }, |
| ... | ... | @@ -8169,9 +8214,8 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 8169 | 8214 | |
| 8170 | 8215 | .bytes => b: { |
| 8171 | 8216 | const info = ip.extraData(Bytes, data); |
| 8172 | const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty))); | |
| 8173 | break :b @sizeOf(Bytes) + len + | |
| 8174 | @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0); | |
| 8217 | const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); | |
| 8218 | break :b @sizeOf(Bytes) + len + @intFromBool(info.bytes.at(len - 1, ip) != 0); | |
| 8175 | 8219 | }, |
| 8176 | 8220 | .aggregate => b: { |
| 8177 | 8221 | const info = ip.extraData(Tag.Aggregate, data); |
| ... | ... | @@ -8434,15 +8478,35 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex) |
| 8434 | 8478 | }; |
| 8435 | 8479 | } |
| 8436 | 8480 | |
| 8481 | const EmbeddedNulls = enum { | |
| 8482 | no_embedded_nulls, | |
| 8483 | maybe_embedded_nulls, | |
| 8484 | ||
| 8485 | fn StringType(comptime embedded_nulls: EmbeddedNulls) type { | |
| 8486 | return switch (embedded_nulls) { | |
| 8487 | .no_embedded_nulls => NullTerminatedString, | |
| 8488 | .maybe_embedded_nulls => String, | |
| 8489 | }; | |
| 8490 | } | |
| 8491 | ||
| 8492 | fn OptionalStringType(comptime embedded_nulls: EmbeddedNulls) type { | |
| 8493 | return switch (embedded_nulls) { | |
| 8494 | .no_embedded_nulls => OptionalNullTerminatedString, | |
| 8495 | .maybe_embedded_nulls => OptionalString, | |
| 8496 | }; | |
| 8497 | } | |
| 8498 | }; | |
| 8499 | ||
| 8437 | 8500 | pub fn getOrPutString( |
| 8438 | 8501 | ip: *InternPool, |
| 8439 | 8502 | gpa: Allocator, |
| 8440 | s: []const u8, | |
| 8441 | ) Allocator.Error!NullTerminatedString { | |
| 8442 | try ip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1); | |
| 8443 | ip.string_bytes.appendSliceAssumeCapacity(s); | |
| 8503 | slice: []const u8, | |
| 8504 | comptime embedded_nulls: EmbeddedNulls, | |
| 8505 | ) Allocator.Error!embedded_nulls.StringType() { | |
| 8506 | try ip.string_bytes.ensureUnusedCapacity(gpa, slice.len + 1); | |
| 8507 | ip.string_bytes.appendSliceAssumeCapacity(slice); | |
| 8444 | 8508 | ip.string_bytes.appendAssumeCapacity(0); |
| 8445 | return ip.getOrPutTrailingString(gpa, s.len + 1); | |
| 8509 | return ip.getOrPutTrailingString(gpa, slice.len + 1, embedded_nulls); | |
| 8446 | 8510 | } |
| 8447 | 8511 | |
| 8448 | 8512 | pub fn getOrPutStringFmt( |
| ... | ... | @@ -8450,23 +8514,24 @@ pub fn getOrPutStringFmt( |
| 8450 | 8514 | gpa: Allocator, |
| 8451 | 8515 | comptime format: []const u8, |
| 8452 | 8516 | args: anytype, |
| 8453 | ) Allocator.Error!NullTerminatedString { | |
| 8517 | comptime embedded_nulls: EmbeddedNulls, | |
| 8518 | ) Allocator.Error!embedded_nulls.StringType() { | |
| 8454 | 8519 | // ensure that references to string_bytes in args do not get invalidated |
| 8455 | 8520 | const len: usize = @intCast(std.fmt.count(format, args) + 1); |
| 8456 | 8521 | try ip.string_bytes.ensureUnusedCapacity(gpa, len); |
| 8457 | 8522 | ip.string_bytes.writer(undefined).print(format, args) catch unreachable; |
| 8458 | 8523 | ip.string_bytes.appendAssumeCapacity(0); |
| 8459 | return ip.getOrPutTrailingString(gpa, len); | |
| 8524 | return ip.getOrPutTrailingString(gpa, len, embedded_nulls); | |
| 8460 | 8525 | } |
| 8461 | 8526 | |
| 8462 | 8527 | pub fn getOrPutStringOpt( |
| 8463 | 8528 | ip: *InternPool, |
| 8464 | 8529 | gpa: Allocator, |
| 8465 | optional_string: ?[]const u8, | |
| 8466 | ) Allocator.Error!OptionalNullTerminatedString { | |
| 8467 | const s = optional_string orelse return .none; | |
| 8468 | const interned = try getOrPutString(ip, gpa, s); | |
| 8469 | return interned.toOptional(); | |
| 8530 | slice: ?[]const u8, | |
| 8531 | comptime embedded_nulls: EmbeddedNulls, | |
| 8532 | ) Allocator.Error!embedded_nulls.OptionalStringType() { | |
| 8533 | const string = try getOrPutString(ip, gpa, slice orelse return .none, embedded_nulls); | |
| 8534 | return string.toOptional(); | |
| 8470 | 8535 | } |
| 8471 | 8536 | |
| 8472 | 8537 | /// Uses the last len bytes of ip.string_bytes as the key. |
| ... | ... | @@ -8474,7 +8539,8 @@ pub fn getOrPutTrailingString( |
| 8474 | 8539 | ip: *InternPool, |
| 8475 | 8540 | gpa: Allocator, |
| 8476 | 8541 | len: usize, |
| 8477 | ) Allocator.Error!NullTerminatedString { | |
| 8542 | comptime embedded_nulls: EmbeddedNulls, | |
| 8543 | ) Allocator.Error!embedded_nulls.StringType() { | |
| 8478 | 8544 | const string_bytes = &ip.string_bytes; |
| 8479 | 8545 | const str_index: u32 = @intCast(string_bytes.items.len - len); |
| 8480 | 8546 | if (len > 0 and string_bytes.getLast() == 0) { |
| ... | ... | @@ -8483,6 +8549,14 @@ pub fn getOrPutTrailingString( |
| 8483 | 8549 | try string_bytes.ensureUnusedCapacity(gpa, 1); |
| 8484 | 8550 | } |
| 8485 | 8551 | const key: []const u8 = string_bytes.items[str_index..]; |
| 8552 | const has_embedded_null = std.mem.indexOfScalar(u8, key, 0) != null; | |
| 8553 | switch (embedded_nulls) { | |
| 8554 | .no_embedded_nulls => assert(!has_embedded_null), | |
| 8555 | .maybe_embedded_nulls => if (has_embedded_null) { | |
| 8556 | string_bytes.appendAssumeCapacity(0); | |
| 8557 | return @enumFromInt(str_index); | |
| 8558 | }, | |
| 8559 | } | |
| 8486 | 8560 | const gop = try ip.string_table.getOrPutContextAdapted(gpa, key, std.hash_map.StringIndexAdapter{ |
| 8487 | 8561 | .bytes = string_bytes, |
| 8488 | 8562 | }, std.hash_map.StringIndexContext{ |
| ... | ... | @@ -8498,58 +8572,10 @@ pub fn getOrPutTrailingString( |
| 8498 | 8572 | } |
| 8499 | 8573 | } |
| 8500 | 8574 | |
| 8501 | /// Uses the last len bytes of ip.string_bytes as the key. | |
| 8502 | pub fn getTrailingAggregate( | |
| 8503 | ip: *InternPool, | |
| 8504 | gpa: Allocator, | |
| 8505 | ty: Index, | |
| 8506 | len: usize, | |
| 8507 | ) Allocator.Error!Index { | |
| 8508 | try ip.items.ensureUnusedCapacity(gpa, 1); | |
| 8509 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len); | |
| 8510 | ||
| 8511 | const str: String = @enumFromInt(ip.string_bytes.items.len - len); | |
| 8512 | const adapter: KeyAdapter = .{ .intern_pool = ip }; | |
| 8513 | const gop = try ip.map.getOrPutAdapted(gpa, Key{ .aggregate = .{ | |
| 8514 | .ty = ty, | |
| 8515 | .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(str)..] }, | |
| 8516 | } }, adapter); | |
| 8517 | if (gop.found_existing) return @enumFromInt(gop.index); | |
| 8518 | ||
| 8519 | ip.items.appendAssumeCapacity(.{ | |
| 8520 | .tag = .bytes, | |
| 8521 | .data = ip.addExtraAssumeCapacity(Bytes{ | |
| 8522 | .ty = ty, | |
| 8523 | .bytes = str, | |
| 8524 | }), | |
| 8525 | }); | |
| 8526 | return @enumFromInt(ip.items.len - 1); | |
| 8527 | } | |
| 8528 | ||
| 8529 | 8575 | pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString { |
| 8530 | if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{ | |
| 8576 | return if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{ | |
| 8531 | 8577 | .bytes = &ip.string_bytes, |
| 8532 | })) |index| { | |
| 8533 | return @as(NullTerminatedString, @enumFromInt(index)).toOptional(); | |
| 8534 | } else { | |
| 8535 | return .none; | |
| 8536 | } | |
| 8537 | } | |
| 8538 | ||
| 8539 | pub fn stringToSlice(ip: *const InternPool, s: NullTerminatedString) [:0]const u8 { | |
| 8540 | const string_bytes = ip.string_bytes.items; | |
| 8541 | const start = @intFromEnum(s); | |
| 8542 | var end: usize = start; | |
| 8543 | while (string_bytes[end] != 0) end += 1; | |
| 8544 | return string_bytes[start..end :0]; | |
| 8545 | } | |
| 8546 | ||
| 8547 | pub fn stringToSliceUnwrap(ip: *const InternPool, s: OptionalNullTerminatedString) ?[:0]const u8 { | |
| 8548 | return ip.stringToSlice(s.unwrap() orelse return null); | |
| 8549 | } | |
| 8550 | ||
| 8551 | pub fn stringEqlSlice(ip: *const InternPool, a: NullTerminatedString, b: []const u8) bool { | |
| 8552 | return std.mem.eql(u8, stringToSlice(ip, a), b); | |
| 8578 | })) |index| @enumFromInt(index) else .none; | |
| 8553 | 8579 | } |
| 8554 | 8580 | |
| 8555 | 8581 | pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| ... | ... | @@ -8767,7 +8793,7 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 { |
| 8767 | 8793 | return switch (ip.indexToKey(ty)) { |
| 8768 | 8794 | .struct_type => ip.loadStructType(ty).field_types.len, |
| 8769 | 8795 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 8770 | .array_type => |array_type| array_type.len + @intFromBool(array_type.sentinel != .none), | |
| 8796 | .array_type => |array_type| array_type.lenIncludingSentinel(), | |
| 8771 | 8797 | .vector_type => |vector_type| vector_type.len, |
| 8772 | 8798 | else => unreachable, |
| 8773 | 8799 | }; |
src/Module.zig+63-50| ... | ... | @@ -763,11 +763,11 @@ pub const Namespace = struct { |
| 763 | 763 | ) !InternPool.NullTerminatedString { |
| 764 | 764 | const ip = &zcu.intern_pool; |
| 765 | 765 | const count = count: { |
| 766 | var count: usize = ip.stringToSlice(name).len + 1; | |
| 766 | var count: usize = name.length(ip) + 1; | |
| 767 | 767 | var cur_ns = &ns; |
| 768 | 768 | while (true) { |
| 769 | 769 | const decl = zcu.declPtr(cur_ns.decl_index); |
| 770 | count += ip.stringToSlice(decl.name).len + 1; | |
| 770 | count += decl.name.length(ip) + 1; | |
| 771 | 771 | cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse { |
| 772 | 772 | count += ns.file_scope.sub_file_path.len; |
| 773 | 773 | break :count count; |
| ... | ... | @@ -793,7 +793,7 @@ pub const Namespace = struct { |
| 793 | 793 | }; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start); | |
| 796 | return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start, .no_embedded_nulls); | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | pub fn getType(ns: Namespace, zcu: *Zcu) Type { |
| ... | ... | @@ -980,17 +980,13 @@ pub const File = struct { |
| 980 | 980 | const ip = &mod.intern_pool; |
| 981 | 981 | const start = ip.string_bytes.items.len; |
| 982 | 982 | try file.renderFullyQualifiedName(ip.string_bytes.writer(mod.gpa)); |
| 983 | return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start); | |
| 983 | return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start, .no_embedded_nulls); | |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | pub fn fullPath(file: File, ally: Allocator) ![]u8 { |
| 987 | 987 | return file.mod.root.joinString(ally, file.sub_file_path); |
| 988 | 988 | } |
| 989 | 989 | |
| 990 | pub fn fullPathZ(file: File, ally: Allocator) ![:0]u8 { | |
| 991 | return file.mod.root.joinStringZ(ally, file.sub_file_path); | |
| 992 | } | |
| 993 | ||
| 994 | 990 | pub fn dumpSrc(file: *File, src: LazySrcLoc) void { |
| 995 | 991 | const loc = std.zig.findLineColumn(file.source.bytes, src); |
| 996 | 992 | std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 }); |
| ... | ... | @@ -2534,6 +2530,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { |
| 2534 | 2530 | const name_ip = try zcu.intern_pool.getOrPutString( |
| 2535 | 2531 | zcu.gpa, |
| 2536 | 2532 | old_zir.nullTerminatedString(name_zir), |
| 2533 | .no_embedded_nulls, | |
| 2537 | 2534 | ); |
| 2538 | 2535 | try old_names.put(zcu.gpa, name_ip, {}); |
| 2539 | 2536 | } |
| ... | ... | @@ -2551,6 +2548,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { |
| 2551 | 2548 | const name_ip = try zcu.intern_pool.getOrPutString( |
| 2552 | 2549 | zcu.gpa, |
| 2553 | 2550 | old_zir.nullTerminatedString(name_zir), |
| 2551 | .no_embedded_nulls, | |
| 2554 | 2552 | ); |
| 2555 | 2553 | if (!old_names.swapRemove(name_ip)) continue; |
| 2556 | 2554 | // Name added |
| ... | ... | @@ -3555,37 +3553,46 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3555 | 3553 | const gpa = mod.gpa; |
| 3556 | 3554 | const zir = decl.getFileScope(mod).zir; |
| 3557 | 3555 | |
| 3558 | const builtin_type_target_index: InternPool.Index = blk: { | |
| 3556 | const builtin_type_target_index: InternPool.Index = ip_index: { | |
| 3559 | 3557 | const std_mod = mod.std_mod; |
| 3560 | if (decl.getFileScope(mod).mod != std_mod) break :blk .none; | |
| 3558 | if (decl.getFileScope(mod).mod != std_mod) break :ip_index .none; | |
| 3561 | 3559 | // We're in the std module. |
| 3562 | 3560 | const std_file = (try mod.importPkg(std_mod)).file; |
| 3563 | 3561 | const std_decl = mod.declPtr(std_file.root_decl.unwrap().?); |
| 3564 | 3562 | const std_namespace = std_decl.getInnerNamespace(mod).?; |
| 3565 | const builtin_str = try ip.getOrPutString(gpa, "builtin"); | |
| 3566 | const builtin_decl = mod.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = mod }) orelse break :blk .none); | |
| 3567 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :blk .none; | |
| 3568 | if (decl.src_namespace != builtin_namespace) break :blk .none; | |
| 3563 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); | |
| 3564 | const builtin_decl = mod.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = mod }) orelse break :ip_index .none); | |
| 3565 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :ip_index .none; | |
| 3566 | if (decl.src_namespace != builtin_namespace) break :ip_index .none; | |
| 3569 | 3567 | // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index. |
| 3570 | for ([_]struct { []const u8, InternPool.Index }{ | |
| 3571 | .{ "AtomicOrder", .atomic_order_type }, | |
| 3572 | .{ "AtomicRmwOp", .atomic_rmw_op_type }, | |
| 3573 | .{ "CallingConvention", .calling_convention_type }, | |
| 3574 | .{ "AddressSpace", .address_space_type }, | |
| 3575 | .{ "FloatMode", .float_mode_type }, | |
| 3576 | .{ "ReduceOp", .reduce_op_type }, | |
| 3577 | .{ "CallModifier", .call_modifier_type }, | |
| 3578 | .{ "PrefetchOptions", .prefetch_options_type }, | |
| 3579 | .{ "ExportOptions", .export_options_type }, | |
| 3580 | .{ "ExternOptions", .extern_options_type }, | |
| 3581 | .{ "Type", .type_info_type }, | |
| 3582 | }) |pair| { | |
| 3583 | const decl_name = ip.stringToSlice(decl.name); | |
| 3584 | if (std.mem.eql(u8, decl_name, pair[0])) { | |
| 3585 | break :blk pair[1]; | |
| 3586 | } | |
| 3568 | for ([_][]const u8{ | |
| 3569 | "AtomicOrder", | |
| 3570 | "AtomicRmwOp", | |
| 3571 | "CallingConvention", | |
| 3572 | "AddressSpace", | |
| 3573 | "FloatMode", | |
| 3574 | "ReduceOp", | |
| 3575 | "CallModifier", | |
| 3576 | "PrefetchOptions", | |
| 3577 | "ExportOptions", | |
| 3578 | "ExternOptions", | |
| 3579 | "Type", | |
| 3580 | }, [_]InternPool.Index{ | |
| 3581 | .atomic_order_type, | |
| 3582 | .atomic_rmw_op_type, | |
| 3583 | .calling_convention_type, | |
| 3584 | .address_space_type, | |
| 3585 | .float_mode_type, | |
| 3586 | .reduce_op_type, | |
| 3587 | .call_modifier_type, | |
| 3588 | .prefetch_options_type, | |
| 3589 | .export_options_type, | |
| 3590 | .extern_options_type, | |
| 3591 | .type_info_type, | |
| 3592 | }) |type_name, type_ip| { | |
| 3593 | if (decl.name.eqlSlice(type_name, ip)) break :ip_index type_ip; | |
| 3587 | 3594 | } |
| 3588 | break :blk .none; | |
| 3595 | break :ip_index .none; | |
| 3589 | 3596 | }; |
| 3590 | 3597 | |
| 3591 | 3598 | mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .decl = decl_index })); |
| ... | ... | @@ -3725,8 +3732,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3725 | 3732 | } else if (bytes.len == 0) { |
| 3726 | 3733 | return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{}); |
| 3727 | 3734 | } |
| 3728 | const section = try ip.getOrPutString(gpa, bytes); | |
| 3729 | break :blk section.toOptional(); | |
| 3735 | break :blk try ip.getOrPutStringOpt(gpa, bytes, .no_embedded_nulls); | |
| 3730 | 3736 | }; |
| 3731 | 3737 | decl.@"addrspace" = blk: { |
| 3732 | 3738 | const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) { |
| ... | ... | @@ -4101,7 +4107,10 @@ fn newEmbedFile( |
| 4101 | 4107 | .sentinel = .zero_u8, |
| 4102 | 4108 | .child = .u8_type, |
| 4103 | 4109 | } }); |
| 4104 | const array_val = try ip.getTrailingAggregate(gpa, array_ty, bytes.len); | |
| 4110 | const array_val = try ip.get(gpa, .{ .aggregate = .{ | |
| 4111 | .ty = array_ty, | |
| 4112 | .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, bytes.len, .maybe_embedded_nulls) }, | |
| 4113 | } }); | |
| 4105 | 4114 | |
| 4106 | 4115 | const ptr_ty = (try mod.ptrType(.{ |
| 4107 | 4116 | .child = array_ty, |
| ... | ... | @@ -4111,7 +4120,6 @@ fn newEmbedFile( |
| 4111 | 4120 | .address_space = .generic, |
| 4112 | 4121 | }, |
| 4113 | 4122 | })).toIntern(); |
| 4114 | ||
| 4115 | 4123 | const ptr_val = try ip.get(gpa, .{ .ptr = .{ |
| 4116 | 4124 | .ty = ptr_ty, |
| 4117 | 4125 | .addr = .{ .anon_decl = .{ |
| ... | ... | @@ -4122,7 +4130,7 @@ fn newEmbedFile( |
| 4122 | 4130 | |
| 4123 | 4131 | result.* = new_file; |
| 4124 | 4132 | new_file.* = .{ |
| 4125 | .sub_file_path = try ip.getOrPutString(gpa, sub_file_path), | |
| 4133 | .sub_file_path = try ip.getOrPutString(gpa, sub_file_path, .no_embedded_nulls), | |
| 4126 | 4134 | .owner = pkg, |
| 4127 | 4135 | .stat = stat, |
| 4128 | 4136 | .val = ptr_val, |
| ... | ... | @@ -4214,11 +4222,11 @@ const ScanDeclIter = struct { |
| 4214 | 4222 | const zcu = iter.zcu; |
| 4215 | 4223 | const gpa = zcu.gpa; |
| 4216 | 4224 | const ip = &zcu.intern_pool; |
| 4217 | var name = try ip.getOrPutStringFmt(gpa, fmt, args); | |
| 4225 | var name = try ip.getOrPutStringFmt(gpa, fmt, args, .no_embedded_nulls); | |
| 4218 | 4226 | var gop = try iter.seen_decls.getOrPut(gpa, name); |
| 4219 | 4227 | var next_suffix: u32 = 0; |
| 4220 | 4228 | while (gop.found_existing) { |
| 4221 | name = try ip.getOrPutStringFmt(gpa, fmt ++ "_{d}", args ++ .{next_suffix}); | |
| 4229 | name = try ip.getOrPutStringFmt(gpa, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls); | |
| 4222 | 4230 | gop = try iter.seen_decls.getOrPut(gpa, name); |
| 4223 | 4231 | next_suffix += 1; |
| 4224 | 4232 | } |
| ... | ... | @@ -4300,7 +4308,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4300 | 4308 | }; |
| 4301 | 4309 | } else info: { |
| 4302 | 4310 | if (iter.pass != .named) return; |
| 4303 | const name = try ip.getOrPutString(gpa, zir.nullTerminatedString(declaration.name.toString(zir).?)); | |
| 4311 | const name = try ip.getOrPutString( | |
| 4312 | gpa, | |
| 4313 | zir.nullTerminatedString(declaration.name.toString(zir).?), | |
| 4314 | .no_embedded_nulls, | |
| 4315 | ); | |
| 4304 | 4316 | try iter.seen_decls.putNoClobber(gpa, name, {}); |
| 4305 | 4317 | break :info .{ |
| 4306 | 4318 | name, |
| ... | ... | @@ -4362,9 +4374,10 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4362 | 4374 | if (!comp.config.is_test) break :a false; |
| 4363 | 4375 | if (decl_mod != zcu.main_mod) break :a false; |
| 4364 | 4376 | if (is_named_test and comp.test_filters.len > 0) { |
| 4365 | const decl_fqn = ip.stringToSlice(try namespace.fullyQualifiedName(zcu, decl_name)); | |
| 4377 | const decl_fqn = try namespace.fullyQualifiedName(zcu, decl_name); | |
| 4378 | const decl_fqn_slice = decl_fqn.toSlice(ip); | |
| 4366 | 4379 | for (comp.test_filters) |test_filter| { |
| 4367 | if (mem.indexOf(u8, decl_fqn, test_filter)) |_| break; | |
| 4380 | if (mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break; | |
| 4368 | 4381 | } else break :a false; |
| 4369 | 4382 | } |
| 4370 | 4383 | zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update |
| ... | ... | @@ -4377,8 +4390,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4377 | 4390 | // `is_export` is unchanged. In this case, the incremental update mechanism will handle |
| 4378 | 4391 | // re-analysis for us if necessary. |
| 4379 | 4392 | if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) { |
| 4380 | log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{s}' decl_index={d}", .{ | |
| 4381 | namespace.file_scope.sub_file_path, ip.stringToSlice(decl_name), decl_index, | |
| 4393 | log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{ | |
| 4394 | namespace.file_scope.sub_file_path, decl_name.fmt(ip), decl_index, | |
| 4382 | 4395 | }); |
| 4383 | 4396 | comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index }); |
| 4384 | 4397 | } |
| ... | ... | @@ -5300,7 +5313,7 @@ pub fn populateTestFunctions( |
| 5300 | 5313 | const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file; |
| 5301 | 5314 | const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?); |
| 5302 | 5315 | const builtin_namespace = mod.namespacePtr(root_decl.src_namespace); |
| 5303 | const test_functions_str = try ip.getOrPutString(gpa, "test_functions"); | |
| 5316 | const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls); | |
| 5304 | 5317 | const decl_index = builtin_namespace.decls.getKeyAdapted( |
| 5305 | 5318 | test_functions_str, |
| 5306 | 5319 | DeclAdapter{ .zcu = mod }, |
| ... | ... | @@ -5327,16 +5340,16 @@ pub fn populateTestFunctions( |
| 5327 | 5340 | |
| 5328 | 5341 | for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| { |
| 5329 | 5342 | const test_decl = mod.declPtr(test_decl_index); |
| 5330 | const test_decl_name = try gpa.dupe(u8, ip.stringToSlice(try test_decl.fullyQualifiedName(mod))); | |
| 5331 | defer gpa.free(test_decl_name); | |
| 5343 | const test_decl_name = try test_decl.fullyQualifiedName(mod); | |
| 5344 | const test_decl_name_len = test_decl_name.length(ip); | |
| 5332 | 5345 | const test_name_anon_decl: InternPool.Key.Ptr.Addr.AnonDecl = n: { |
| 5333 | 5346 | const test_name_ty = try mod.arrayType(.{ |
| 5334 | .len = test_decl_name.len, | |
| 5347 | .len = test_decl_name_len, | |
| 5335 | 5348 | .child = .u8_type, |
| 5336 | 5349 | }); |
| 5337 | 5350 | const test_name_val = try mod.intern(.{ .aggregate = .{ |
| 5338 | 5351 | .ty = test_name_ty.toIntern(), |
| 5339 | .storage = .{ .bytes = test_decl_name }, | |
| 5352 | .storage = .{ .bytes = test_decl_name.toString() }, | |
| 5340 | 5353 | } }); |
| 5341 | 5354 | break :n .{ |
| 5342 | 5355 | .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(), |
| ... | ... | @@ -5354,7 +5367,7 @@ pub fn populateTestFunctions( |
| 5354 | 5367 | } }), |
| 5355 | 5368 | .len = try mod.intern(.{ .int = .{ |
| 5356 | 5369 | .ty = .usize_type, |
| 5357 | .storage = .{ .u64 = test_decl_name.len }, | |
| 5370 | .storage = .{ .u64 = test_decl_name_len }, | |
| 5358 | 5371 | } }), |
| 5359 | 5372 | } }), |
| 5360 | 5373 | // func |
src/Sema.zig+325-256| ... | ... | @@ -2059,12 +2059,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2059 | 2059 | const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty)); |
| 2060 | 2060 | |
| 2061 | 2061 | // st.instruction_addresses = &addrs; |
| 2062 | const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses"); | |
| 2062 | const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses", .no_embedded_nulls); | |
| 2063 | 2063 | const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true); |
| 2064 | 2064 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); |
| 2065 | 2065 | |
| 2066 | 2066 | // st.index = 0; |
| 2067 | const index_field_name = try ip.getOrPutString(gpa, "index"); | |
| 2067 | const index_field_name = try ip.getOrPutString(gpa, "index", .no_embedded_nulls); | |
| 2068 | 2068 | const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true); |
| 2069 | 2069 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); |
| 2070 | 2070 | |
| ... | ... | @@ -2348,13 +2348,13 @@ fn failWithInvalidFieldAccess( |
| 2348 | 2348 | fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool { |
| 2349 | 2349 | const ip = &mod.intern_pool; |
| 2350 | 2350 | switch (ty.zigTypeTag(mod)) { |
| 2351 | .Array => return ip.stringEqlSlice(field_name, "len"), | |
| 2351 | .Array => return field_name.eqlSlice("len", ip), | |
| 2352 | 2352 | .Pointer => { |
| 2353 | 2353 | const ptr_info = ty.ptrInfo(mod); |
| 2354 | 2354 | if (ptr_info.flags.size == .Slice) { |
| 2355 | return ip.stringEqlSlice(field_name, "ptr") or ip.stringEqlSlice(field_name, "len"); | |
| 2355 | return field_name.eqlSlice("ptr", ip) or field_name.eqlSlice("len", ip); | |
| 2356 | 2356 | } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) { |
| 2357 | return ip.stringEqlSlice(field_name, "len"); | |
| 2357 | return field_name.eqlSlice("len", ip); | |
| 2358 | 2358 | } else return false; |
| 2359 | 2359 | }, |
| 2360 | 2360 | .Type, .Struct, .Union => return true, |
| ... | ... | @@ -2703,12 +2703,20 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2703 | 2703 | break :capture .{ .runtime = sema.typeOf(air_ref).toIntern() }; |
| 2704 | 2704 | }), |
| 2705 | 2705 | .decl_val => |str| capture: { |
| 2706 | const decl_name = try ip.getOrPutString(sema.gpa, sema.code.nullTerminatedString(str)); | |
| 2706 | const decl_name = try ip.getOrPutString( | |
| 2707 | sema.gpa, | |
| 2708 | sema.code.nullTerminatedString(str), | |
| 2709 | .no_embedded_nulls, | |
| 2710 | ); | |
| 2707 | 2711 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? |
| 2708 | 2712 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); |
| 2709 | 2713 | }, |
| 2710 | 2714 | .decl_ref => |str| capture: { |
| 2711 | const decl_name = try ip.getOrPutString(sema.gpa, sema.code.nullTerminatedString(str)); | |
| 2715 | const decl_name = try ip.getOrPutString( | |
| 2716 | sema.gpa, | |
| 2717 | sema.code.nullTerminatedString(str), | |
| 2718 | .no_embedded_nulls, | |
| 2719 | ); | |
| 2712 | 2720 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? |
| 2713 | 2721 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); |
| 2714 | 2722 | }, |
| ... | ... | @@ -2882,7 +2890,7 @@ fn createAnonymousDeclTypeNamed( |
| 2882 | 2890 | |
| 2883 | 2891 | const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ |
| 2884 | 2892 | src_decl.name.fmt(&mod.intern_pool), anon_prefix, @intFromEnum(new_decl_index), |
| 2885 | }) catch unreachable; | |
| 2893 | }, .no_embedded_nulls) catch unreachable; | |
| 2886 | 2894 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2887 | 2895 | return new_decl_index; |
| 2888 | 2896 | }, |
| ... | ... | @@ -2923,7 +2931,7 @@ fn createAnonymousDeclTypeNamed( |
| 2923 | 2931 | }; |
| 2924 | 2932 | |
| 2925 | 2933 | try writer.writeByte(')'); |
| 2926 | const name = try mod.intern_pool.getOrPutString(gpa, buf.items); | |
| 2934 | const name = try mod.intern_pool.getOrPutString(gpa, buf.items, .no_embedded_nulls); | |
| 2927 | 2935 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2928 | 2936 | return new_decl_index; |
| 2929 | 2937 | }, |
| ... | ... | @@ -2937,8 +2945,7 @@ fn createAnonymousDeclTypeNamed( |
| 2937 | 2945 | |
| 2938 | 2946 | const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{ |
| 2939 | 2947 | src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code), |
| 2940 | }); | |
| 2941 | ||
| 2948 | }, .no_embedded_nulls); | |
| 2942 | 2949 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2943 | 2950 | return new_decl_index; |
| 2944 | 2951 | }, |
| ... | ... | @@ -3157,7 +3164,7 @@ fn zirEnumDecl( |
| 3157 | 3164 | const field_name_zir = sema.code.nullTerminatedString(field_name_index); |
| 3158 | 3165 | extra_index += 2; // field name, doc comment |
| 3159 | 3166 | |
| 3160 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir); | |
| 3167 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | |
| 3161 | 3168 | |
| 3162 | 3169 | const tag_overflow = if (has_tag_value) overflow: { |
| 3163 | 3170 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| ... | ... | @@ -3462,7 +3469,7 @@ fn zirErrorSetDecl( |
| 3462 | 3469 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string |
| 3463 | 3470 | const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]); |
| 3464 | 3471 | const name = sema.code.nullTerminatedString(name_index); |
| 3465 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name); | |
| 3472 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls); | |
| 3466 | 3473 | _ = try mod.getErrorValue(name_ip); |
| 3467 | 3474 | const result = names.getOrPutAssumeCapacity(name_ip); |
| 3468 | 3475 | assert(!result.found_existing); // verified in AstGen |
| ... | ... | @@ -3635,7 +3642,7 @@ fn indexablePtrLen( |
| 3635 | 3642 | const is_pointer_to = object_ty.isSinglePointer(mod); |
| 3636 | 3643 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; |
| 3637 | 3644 | try checkIndexable(sema, block, src, indexable_ty); |
| 3638 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len"); | |
| 3645 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls); | |
| 3639 | 3646 | return sema.fieldVal(block, src, object, field_name, src); |
| 3640 | 3647 | } |
| 3641 | 3648 | |
| ... | ... | @@ -3649,7 +3656,7 @@ fn indexablePtrLenOrNone( |
| 3649 | 3656 | const operand_ty = sema.typeOf(operand); |
| 3650 | 3657 | try checkMemOperand(sema, block, src, operand_ty); |
| 3651 | 3658 | if (operand_ty.ptrSize(mod) == .Many) return .none; |
| 3652 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len"); | |
| 3659 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls); | |
| 3653 | 3660 | return sema.fieldVal(block, src, operand, field_name, src); |
| 3654 | 3661 | } |
| 3655 | 3662 | |
| ... | ... | @@ -4363,7 +4370,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4363 | 4370 | } |
| 4364 | 4371 | if (!object_ty.indexableHasLen(mod)) continue; |
| 4365 | 4372 | |
| 4366 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len"), arg_src); | |
| 4373 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), arg_src); | |
| 4367 | 4374 | }; |
| 4368 | 4375 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); |
| 4369 | 4376 | if (len == .none) { |
| ... | ... | @@ -4747,7 +4754,11 @@ fn validateUnionInit( |
| 4747 | 4754 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 4748 | 4755 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4749 | 4756 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4750 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start)); | |
| 4757 | const field_name = try mod.intern_pool.getOrPutString( | |
| 4758 | gpa, | |
| 4759 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), | |
| 4760 | .no_embedded_nulls, | |
| 4761 | ); | |
| 4751 | 4762 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src); |
| 4752 | 4763 | const air_tags = sema.air_instructions.items(.tag); |
| 4753 | 4764 | const air_datas = sema.air_instructions.items(.data); |
| ... | ... | @@ -4890,6 +4901,7 @@ fn validateStructInit( |
| 4890 | 4901 | const field_name = try ip.getOrPutString( |
| 4891 | 4902 | gpa, |
| 4892 | 4903 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), |
| 4904 | .no_embedded_nulls, | |
| 4893 | 4905 | ); |
| 4894 | 4906 | field_index.* = if (struct_ty.isTuple(mod)) |
| 4895 | 4907 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) |
| ... | ... | @@ -5672,25 +5684,26 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5672 | 5684 | |
| 5673 | 5685 | fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5674 | 5686 | const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code); |
| 5675 | return sema.addStrLitNoAlias(bytes); | |
| 5687 | return sema.addStrLit( | |
| 5688 | try sema.mod.intern_pool.getOrPutString(sema.gpa, bytes, .maybe_embedded_nulls), | |
| 5689 | bytes.len, | |
| 5690 | ); | |
| 5676 | 5691 | } |
| 5677 | 5692 | |
| 5678 | fn addStrLit(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref { | |
| 5679 | const duped_bytes = try sema.arena.dupe(u8, bytes); | |
| 5680 | return addStrLitNoAlias(sema, duped_bytes); | |
| 5693 | fn addNullTerminatedStrLit(sema: *Sema, string: InternPool.NullTerminatedString) CompileError!Air.Inst.Ref { | |
| 5694 | return sema.addStrLit(string.toString(), string.length(&sema.mod.intern_pool)); | |
| 5681 | 5695 | } |
| 5682 | 5696 | |
| 5683 | /// Safe to call when `bytes` does not point into `InternPool`. | |
| 5684 | fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref { | |
| 5697 | fn addStrLit(sema: *Sema, string: InternPool.String, len: u64) CompileError!Air.Inst.Ref { | |
| 5685 | 5698 | const mod = sema.mod; |
| 5686 | 5699 | const array_ty = try mod.arrayType(.{ |
| 5687 | .len = bytes.len, | |
| 5700 | .len = len, | |
| 5688 | 5701 | .sentinel = .zero_u8, |
| 5689 | 5702 | .child = .u8_type, |
| 5690 | 5703 | }); |
| 5691 | 5704 | const val = try mod.intern(.{ .aggregate = .{ |
| 5692 | 5705 | .ty = array_ty.toIntern(), |
| 5693 | .storage = .{ .bytes = bytes }, | |
| 5706 | .storage = .{ .bytes = string }, | |
| 5694 | 5707 | } }); |
| 5695 | 5708 | return anonDeclRef(sema, val); |
| 5696 | 5709 | } |
| ... | ... | @@ -6370,7 +6383,11 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6370 | 6383 | const src = inst_data.src(); |
| 6371 | 6384 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6372 | 6385 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6373 | const decl_name = try mod.intern_pool.getOrPutString(mod.gpa, sema.code.nullTerminatedString(extra.decl_name)); | |
| 6386 | const decl_name = try mod.intern_pool.getOrPutString( | |
| 6387 | mod.gpa, | |
| 6388 | sema.code.nullTerminatedString(extra.decl_name), | |
| 6389 | .no_embedded_nulls, | |
| 6390 | ); | |
| 6374 | 6391 | const decl_index = if (extra.namespace != .none) index_blk: { |
| 6375 | 6392 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); |
| 6376 | 6393 | const container_namespace = container_ty.getNamespaceIndex(mod); |
| ... | ... | @@ -6721,7 +6738,11 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6721 | 6738 | const mod = sema.mod; |
| 6722 | 6739 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 6723 | 6740 | const src = inst_data.src(); |
| 6724 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | |
| 6741 | const decl_name = try mod.intern_pool.getOrPutString( | |
| 6742 | sema.gpa, | |
| 6743 | inst_data.get(sema.code), | |
| 6744 | .no_embedded_nulls, | |
| 6745 | ); | |
| 6725 | 6746 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 6726 | 6747 | try sema.addReferencedBy(block, src, decl_index); |
| 6727 | 6748 | return sema.analyzeDeclRef(decl_index); |
| ... | ... | @@ -6731,7 +6752,11 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6731 | 6752 | const mod = sema.mod; |
| 6732 | 6753 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 6733 | 6754 | const src = inst_data.src(); |
| 6734 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | |
| 6755 | const decl_name = try mod.intern_pool.getOrPutString( | |
| 6756 | sema.gpa, | |
| 6757 | inst_data.get(sema.code), | |
| 6758 | .no_embedded_nulls, | |
| 6759 | ); | |
| 6735 | 6760 | const decl = try sema.lookupIdentifier(block, src, decl_name); |
| 6736 | 6761 | return sema.analyzeDeclVal(block, src, decl); |
| 6737 | 6762 | } |
| ... | ... | @@ -6883,7 +6908,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6883 | 6908 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6884 | 6909 | else => |e| return e, |
| 6885 | 6910 | }; |
| 6886 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); | |
| 6911 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | |
| 6887 | 6912 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) { |
| 6888 | 6913 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"), |
| 6889 | 6914 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| ... | ... | @@ -6926,7 +6951,7 @@ fn popErrorReturnTrace( |
| 6926 | 6951 | try sema.resolveTypeFields(stack_trace_ty); |
| 6927 | 6952 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6928 | 6953 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6929 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); | |
| 6954 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | |
| 6930 | 6955 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6931 | 6956 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6932 | 6957 | } else if (is_non_error == null) { |
| ... | ... | @@ -6952,7 +6977,7 @@ fn popErrorReturnTrace( |
| 6952 | 6977 | try sema.resolveTypeFields(stack_trace_ty); |
| 6953 | 6978 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6954 | 6979 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6955 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); | |
| 6980 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | |
| 6956 | 6981 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6957 | 6982 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6958 | 6983 | _ = try then_block.addBr(cond_block_inst, .void_value); |
| ... | ... | @@ -7010,7 +7035,11 @@ fn zirCall( |
| 7010 | 7035 | .direct => .{ .direct = try sema.resolveInst(extra.data.callee) }, |
| 7011 | 7036 | .field => blk: { |
| 7012 | 7037 | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); |
| 7013 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.data.field_name_start)); | |
| 7038 | const field_name = try mod.intern_pool.getOrPutString( | |
| 7039 | sema.gpa, | |
| 7040 | sema.code.nullTerminatedString(extra.data.field_name_start), | |
| 7041 | .no_embedded_nulls, | |
| 7042 | ); | |
| 7014 | 7043 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 7015 | 7044 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); |
| 7016 | 7045 | }, |
| ... | ... | @@ -7073,7 +7102,7 @@ fn zirCall( |
| 7073 | 7102 | if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) { |
| 7074 | 7103 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7075 | 7104 | try sema.resolveTypeFields(stack_trace_ty); |
| 7076 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index"); | |
| 7105 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index", .no_embedded_nulls); | |
| 7077 | 7106 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); |
| 7078 | 7107 | |
| 7079 | 7108 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| ... | ... | @@ -8648,7 +8677,11 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8648 | 8677 | _ = block; |
| 8649 | 8678 | const mod = sema.mod; |
| 8650 | 8679 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 8651 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | |
| 8680 | const name = try mod.intern_pool.getOrPutString( | |
| 8681 | sema.gpa, | |
| 8682 | inst_data.get(sema.code), | |
| 8683 | .no_embedded_nulls, | |
| 8684 | ); | |
| 8652 | 8685 | _ = try mod.getErrorValue(name); |
| 8653 | 8686 | // Create an error set type with only this error value, and return the value. |
| 8654 | 8687 | const error_set_type = try mod.singleErrorSetType(name); |
| ... | ... | @@ -8804,7 +8837,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8804 | 8837 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 8805 | 8838 | const name = inst_data.get(sema.code); |
| 8806 | 8839 | return Air.internedToRef((try mod.intern(.{ |
| 8807 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name), | |
| 8840 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name, .no_embedded_nulls), | |
| 8808 | 8841 | }))); |
| 8809 | 8842 | } |
| 8810 | 8843 | |
| ... | ... | @@ -9761,7 +9794,7 @@ fn funcCommon( |
| 9761 | 9794 | const func_index = try ip.getExternFunc(gpa, .{ |
| 9762 | 9795 | .ty = func_ty, |
| 9763 | 9796 | .decl = sema.owner_decl_index, |
| 9764 | .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name), | |
| 9797 | .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name, .no_embedded_nulls), | |
| 9765 | 9798 | }); |
| 9766 | 9799 | return finishFunc( |
| 9767 | 9800 | sema, |
| ... | ... | @@ -10225,7 +10258,11 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10225 | 10258 | const src = inst_data.src(); |
| 10226 | 10259 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 10227 | 10260 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10228 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); | |
| 10261 | const field_name = try mod.intern_pool.getOrPutString( | |
| 10262 | sema.gpa, | |
| 10263 | sema.code.nullTerminatedString(extra.field_name_start), | |
| 10264 | .no_embedded_nulls, | |
| 10265 | ); | |
| 10229 | 10266 | const object = try sema.resolveInst(extra.lhs); |
| 10230 | 10267 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 10231 | 10268 | } |
| ... | ... | @@ -10239,7 +10276,11 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10239 | 10276 | const src = inst_data.src(); |
| 10240 | 10277 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 10241 | 10278 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10242 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); | |
| 10279 | const field_name = try mod.intern_pool.getOrPutString( | |
| 10280 | sema.gpa, | |
| 10281 | sema.code.nullTerminatedString(extra.field_name_start), | |
| 10282 | .no_embedded_nulls, | |
| 10283 | ); | |
| 10243 | 10284 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10244 | 10285 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 10245 | 10286 | } |
| ... | ... | @@ -10253,7 +10294,11 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 10253 | 10294 | const src = inst_data.src(); |
| 10254 | 10295 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; |
| 10255 | 10296 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10256 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); | |
| 10297 | const field_name = try mod.intern_pool.getOrPutString( | |
| 10298 | sema.gpa, | |
| 10299 | sema.code.nullTerminatedString(extra.field_name_start), | |
| 10300 | .no_embedded_nulls, | |
| 10301 | ); | |
| 10257 | 10302 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10258 | 10303 | const struct_ty = sema.typeOf(object_ptr).childType(mod); |
| 10259 | 10304 | switch (struct_ty.zigTypeTag(mod)) { |
| ... | ... | @@ -13759,8 +13804,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13759 | 13804 | switch (ip.indexToKey(ty.toIntern())) { |
| 13760 | 13805 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 13761 | 13806 | .Slice => { |
| 13762 | if (ip.stringEqlSlice(field_name, "ptr")) break :hf true; | |
| 13763 | if (ip.stringEqlSlice(field_name, "len")) break :hf true; | |
| 13807 | if (field_name.eqlSlice("ptr", ip)) break :hf true; | |
| 13808 | if (field_name.eqlSlice("len", ip)) break :hf true; | |
| 13764 | 13809 | break :hf false; |
| 13765 | 13810 | }, |
| 13766 | 13811 | else => {}, |
| ... | ... | @@ -13783,7 +13828,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13783 | 13828 | .enum_type => { |
| 13784 | 13829 | break :hf ip.loadEnumType(ty.toIntern()).nameIndex(ip, field_name) != null; |
| 13785 | 13830 | }, |
| 13786 | .array_type => break :hf ip.stringEqlSlice(field_name, "len"), | |
| 13831 | .array_type => break :hf field_name.eqlSlice("len", ip), | |
| 13787 | 13832 | else => {}, |
| 13788 | 13833 | } |
| 13789 | 13834 | return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{ |
| ... | ... | @@ -13885,7 +13930,11 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13885 | 13930 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13886 | 13931 | const mod = sema.mod; |
| 13887 | 13932 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 13888 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | |
| 13933 | const name = try mod.intern_pool.getOrPutString( | |
| 13934 | sema.gpa, | |
| 13935 | inst_data.get(sema.code), | |
| 13936 | .no_embedded_nulls, | |
| 13937 | ); | |
| 13889 | 13938 | _ = try mod.getErrorValue(name); |
| 13890 | 13939 | const error_set_type = try mod.singleErrorSetType(name); |
| 13891 | 13940 | return Air.internedToRef((try mod.intern(.{ .err = .{ |
| ... | ... | @@ -17552,11 +17601,9 @@ fn zirBuiltinSrc( |
| 17552 | 17601 | const gpa = sema.gpa; |
| 17553 | 17602 | |
| 17554 | 17603 | const func_name_val = v: { |
| 17555 | // This dupe prevents InternPool string pool memory from being reallocated | |
| 17556 | // while a reference exists. | |
| 17557 | const bytes = try sema.arena.dupe(u8, ip.stringToSlice(fn_owner_decl.name)); | |
| 17604 | const func_name_len = fn_owner_decl.name.length(ip); | |
| 17558 | 17605 | const array_ty = try ip.get(gpa, .{ .array_type = .{ |
| 17559 | .len = bytes.len, | |
| 17606 | .len = func_name_len, | |
| 17560 | 17607 | .sentinel = .zero_u8, |
| 17561 | 17608 | .child = .u8_type, |
| 17562 | 17609 | } }); |
| ... | ... | @@ -17568,19 +17615,19 @@ fn zirBuiltinSrc( |
| 17568 | 17615 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 17569 | 17616 | .val = try ip.get(gpa, .{ .aggregate = .{ |
| 17570 | 17617 | .ty = array_ty, |
| 17571 | .storage = .{ .bytes = bytes }, | |
| 17618 | .storage = .{ .bytes = fn_owner_decl.name.toString() }, | |
| 17572 | 17619 | } }), |
| 17573 | 17620 | } }, |
| 17574 | 17621 | } }), |
| 17575 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), | |
| 17622 | .len = (try mod.intValue(Type.usize, func_name_len)).toIntern(), | |
| 17576 | 17623 | } }); |
| 17577 | 17624 | }; |
| 17578 | 17625 | |
| 17579 | 17626 | const file_name_val = v: { |
| 17580 | 17627 | // The compiler must not call realpath anywhere. |
| 17581 | const bytes = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena); | |
| 17628 | const file_name = try fn_owner_decl.getFileScope(mod).fullPath(sema.arena); | |
| 17582 | 17629 | const array_ty = try ip.get(gpa, .{ .array_type = .{ |
| 17583 | .len = bytes.len, | |
| 17630 | .len = file_name.len, | |
| 17584 | 17631 | .sentinel = .zero_u8, |
| 17585 | 17632 | .child = .u8_type, |
| 17586 | 17633 | } }); |
| ... | ... | @@ -17592,11 +17639,13 @@ fn zirBuiltinSrc( |
| 17592 | 17639 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 17593 | 17640 | .val = try ip.get(gpa, .{ .aggregate = .{ |
| 17594 | 17641 | .ty = array_ty, |
| 17595 | .storage = .{ .bytes = bytes }, | |
| 17642 | .storage = .{ | |
| 17643 | .bytes = try ip.getOrPutString(gpa, file_name, .maybe_embedded_nulls), | |
| 17644 | }, | |
| 17596 | 17645 | } }), |
| 17597 | 17646 | } }, |
| 17598 | 17647 | } }), |
| 17599 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), | |
| 17648 | .len = (try mod.intValue(Type.usize, file_name.len)).toIntern(), | |
| 17600 | 17649 | } }); |
| 17601 | 17650 | }; |
| 17602 | 17651 | |
| ... | ... | @@ -17651,7 +17700,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17651 | 17700 | block, |
| 17652 | 17701 | src, |
| 17653 | 17702 | type_info_ty.getNamespaceIndex(mod), |
| 17654 | try ip.getOrPutString(gpa, "Fn"), | |
| 17703 | try ip.getOrPutString(gpa, "Fn", .no_embedded_nulls), | |
| 17655 | 17704 | )).?; |
| 17656 | 17705 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| 17657 | 17706 | const fn_info_decl = mod.declPtr(fn_info_decl_index); |
| ... | ... | @@ -17661,7 +17710,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17661 | 17710 | block, |
| 17662 | 17711 | src, |
| 17663 | 17712 | fn_info_ty.getNamespaceIndex(mod), |
| 17664 | try ip.getOrPutString(gpa, "Param"), | |
| 17713 | try ip.getOrPutString(gpa, "Param", .no_embedded_nulls), | |
| 17665 | 17714 | )).?; |
| 17666 | 17715 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| 17667 | 17716 | const param_info_decl = mod.declPtr(param_info_decl_index); |
| ... | ... | @@ -17762,7 +17811,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17762 | 17811 | block, |
| 17763 | 17812 | src, |
| 17764 | 17813 | type_info_ty.getNamespaceIndex(mod), |
| 17765 | try ip.getOrPutString(gpa, "Int"), | |
| 17814 | try ip.getOrPutString(gpa, "Int", .no_embedded_nulls), | |
| 17766 | 17815 | )).?; |
| 17767 | 17816 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| 17768 | 17817 | const int_info_decl = mod.declPtr(int_info_decl_index); |
| ... | ... | @@ -17790,7 +17839,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17790 | 17839 | block, |
| 17791 | 17840 | src, |
| 17792 | 17841 | type_info_ty.getNamespaceIndex(mod), |
| 17793 | try ip.getOrPutString(gpa, "Float"), | |
| 17842 | try ip.getOrPutString(gpa, "Float", .no_embedded_nulls), | |
| 17794 | 17843 | )).?; |
| 17795 | 17844 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| 17796 | 17845 | const float_info_decl = mod.declPtr(float_info_decl_index); |
| ... | ... | @@ -17822,7 +17871,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17822 | 17871 | block, |
| 17823 | 17872 | src, |
| 17824 | 17873 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 17825 | try ip.getOrPutString(gpa, "Pointer"), | |
| 17874 | try ip.getOrPutString(gpa, "Pointer", .no_embedded_nulls), | |
| 17826 | 17875 | )).?; |
| 17827 | 17876 | try sema.ensureDeclAnalyzed(decl_index); |
| 17828 | 17877 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -17833,7 +17882,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17833 | 17882 | block, |
| 17834 | 17883 | src, |
| 17835 | 17884 | pointer_ty.getNamespaceIndex(mod), |
| 17836 | try ip.getOrPutString(gpa, "Size"), | |
| 17885 | try ip.getOrPutString(gpa, "Size", .no_embedded_nulls), | |
| 17837 | 17886 | )).?; |
| 17838 | 17887 | try sema.ensureDeclAnalyzed(decl_index); |
| 17839 | 17888 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -17876,7 +17925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17876 | 17925 | block, |
| 17877 | 17926 | src, |
| 17878 | 17927 | type_info_ty.getNamespaceIndex(mod), |
| 17879 | try ip.getOrPutString(gpa, "Array"), | |
| 17928 | try ip.getOrPutString(gpa, "Array", .no_embedded_nulls), | |
| 17880 | 17929 | )).?; |
| 17881 | 17930 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| 17882 | 17931 | const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index); |
| ... | ... | @@ -17907,7 +17956,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17907 | 17956 | block, |
| 17908 | 17957 | src, |
| 17909 | 17958 | type_info_ty.getNamespaceIndex(mod), |
| 17910 | try ip.getOrPutString(gpa, "Vector"), | |
| 17959 | try ip.getOrPutString(gpa, "Vector", .no_embedded_nulls), | |
| 17911 | 17960 | )).?; |
| 17912 | 17961 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| 17913 | 17962 | const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index); |
| ... | ... | @@ -17936,7 +17985,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17936 | 17985 | block, |
| 17937 | 17986 | src, |
| 17938 | 17987 | type_info_ty.getNamespaceIndex(mod), |
| 17939 | try ip.getOrPutString(gpa, "Optional"), | |
| 17988 | try ip.getOrPutString(gpa, "Optional", .no_embedded_nulls), | |
| 17940 | 17989 | )).?; |
| 17941 | 17990 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| 17942 | 17991 | const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index); |
| ... | ... | @@ -17963,7 +18012,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17963 | 18012 | block, |
| 17964 | 18013 | src, |
| 17965 | 18014 | type_info_ty.getNamespaceIndex(mod), |
| 17966 | try ip.getOrPutString(gpa, "Error"), | |
| 18015 | try ip.getOrPutString(gpa, "Error", .no_embedded_nulls), | |
| 17967 | 18016 | )).?; |
| 17968 | 18017 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| 17969 | 18018 | const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index); |
| ... | ... | @@ -17980,18 +18029,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17980 | 18029 | else => |err_set_ty_index| blk: { |
| 17981 | 18030 | const names = ip.indexToKey(err_set_ty_index).error_set_type.names; |
| 17982 | 18031 | const vals = try sema.arena.alloc(InternPool.Index, names.len); |
| 17983 | for (vals, 0..) |*field_val, i| { | |
| 17984 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 17985 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(names.get(ip)[i])); | |
| 17986 | const name_val = v: { | |
| 18032 | for (vals, 0..) |*field_val, error_index| { | |
| 18033 | const error_name = names.get(ip)[error_index]; | |
| 18034 | const error_name_len = error_name.length(ip); | |
| 18035 | const error_name_val = v: { | |
| 17987 | 18036 | const new_decl_ty = try mod.arrayType(.{ |
| 17988 | .len = name.len, | |
| 18037 | .len = error_name_len, | |
| 17989 | 18038 | .sentinel = .zero_u8, |
| 17990 | 18039 | .child = .u8_type, |
| 17991 | 18040 | }); |
| 17992 | 18041 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17993 | 18042 | .ty = new_decl_ty.toIntern(), |
| 17994 | .storage = .{ .bytes = name }, | |
| 18043 | .storage = .{ .bytes = error_name.toString() }, | |
| 17995 | 18044 | } }); |
| 17996 | 18045 | break :v try mod.intern(.{ .slice = .{ |
| 17997 | 18046 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18002,13 +18051,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18002 | 18051 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 18003 | 18052 | } }, |
| 18004 | 18053 | } }), |
| 18005 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), | |
| 18054 | .len = (try mod.intValue(Type.usize, error_name_len)).toIntern(), | |
| 18006 | 18055 | } }); |
| 18007 | 18056 | }; |
| 18008 | 18057 | |
| 18009 | 18058 | const error_field_fields = .{ |
| 18010 | 18059 | // name: [:0]const u8, |
| 18011 | name_val, | |
| 18060 | error_name_val, | |
| 18012 | 18061 | }; |
| 18013 | 18062 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 18014 | 18063 | .ty = error_field_ty.toIntern(), |
| ... | ... | @@ -18069,7 +18118,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18069 | 18118 | block, |
| 18070 | 18119 | src, |
| 18071 | 18120 | type_info_ty.getNamespaceIndex(mod), |
| 18072 | try ip.getOrPutString(gpa, "ErrorUnion"), | |
| 18121 | try ip.getOrPutString(gpa, "ErrorUnion", .no_embedded_nulls), | |
| 18073 | 18122 | )).?; |
| 18074 | 18123 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); |
| 18075 | 18124 | const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index); |
| ... | ... | @@ -18099,7 +18148,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18099 | 18148 | block, |
| 18100 | 18149 | src, |
| 18101 | 18150 | type_info_ty.getNamespaceIndex(mod), |
| 18102 | try ip.getOrPutString(gpa, "EnumField"), | |
| 18151 | try ip.getOrPutString(gpa, "EnumField", .no_embedded_nulls), | |
| 18103 | 18152 | )).?; |
| 18104 | 18153 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| 18105 | 18154 | const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index); |
| ... | ... | @@ -18107,27 +18156,29 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18107 | 18156 | }; |
| 18108 | 18157 | |
| 18109 | 18158 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len); |
| 18110 | for (enum_field_vals, 0..) |*field_val, i| { | |
| 18159 | for (enum_field_vals, 0..) |*field_val, tag_index| { | |
| 18111 | 18160 | const enum_type = ip.loadEnumType(ty.toIntern()); |
| 18112 | 18161 | const value_val = if (enum_type.values.len > 0) |
| 18113 | 18162 | try mod.intern_pool.getCoercedInts( |
| 18114 | 18163 | mod.gpa, |
| 18115 | mod.intern_pool.indexToKey(enum_type.values.get(ip)[i]).int, | |
| 18164 | mod.intern_pool.indexToKey(enum_type.values.get(ip)[tag_index]).int, | |
| 18116 | 18165 | .comptime_int_type, |
| 18117 | 18166 | ) |
| 18118 | 18167 | else |
| 18119 | (try mod.intValue(Type.comptime_int, i)).toIntern(); | |
| 18168 | (try mod.intValue(Type.comptime_int, tag_index)).toIntern(); | |
| 18169 | ||
| 18120 | 18170 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 18121 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(enum_type.names.get(ip)[i])); | |
| 18122 | 18171 | const name_val = v: { |
| 18172 | const tag_name = enum_type.names.get(ip)[tag_index]; | |
| 18173 | const tag_name_len = tag_name.length(ip); | |
| 18123 | 18174 | const new_decl_ty = try mod.arrayType(.{ |
| 18124 | .len = name.len, | |
| 18175 | .len = tag_name_len, | |
| 18125 | 18176 | .sentinel = .zero_u8, |
| 18126 | 18177 | .child = .u8_type, |
| 18127 | 18178 | }); |
| 18128 | 18179 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 18129 | 18180 | .ty = new_decl_ty.toIntern(), |
| 18130 | .storage = .{ .bytes = name }, | |
| 18181 | .storage = .{ .bytes = tag_name.toString() }, | |
| 18131 | 18182 | } }); |
| 18132 | 18183 | break :v try mod.intern(.{ .slice = .{ |
| 18133 | 18184 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18138,7 +18189,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18138 | 18189 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 18139 | 18190 | } }, |
| 18140 | 18191 | } }), |
| 18141 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), | |
| 18192 | .len = (try mod.intValue(Type.usize, tag_name_len)).toIntern(), | |
| 18142 | 18193 | } }); |
| 18143 | 18194 | }; |
| 18144 | 18195 | |
| ... | ... | @@ -18191,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18191 | 18242 | block, |
| 18192 | 18243 | src, |
| 18193 | 18244 | type_info_ty.getNamespaceIndex(mod), |
| 18194 | try ip.getOrPutString(gpa, "Enum"), | |
| 18245 | try ip.getOrPutString(gpa, "Enum", .no_embedded_nulls), | |
| 18195 | 18246 | )).?; |
| 18196 | 18247 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); |
| 18197 | 18248 | const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index); |
| ... | ... | @@ -18223,7 +18274,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18223 | 18274 | block, |
| 18224 | 18275 | src, |
| 18225 | 18276 | type_info_ty.getNamespaceIndex(mod), |
| 18226 | try ip.getOrPutString(gpa, "Union"), | |
| 18277 | try ip.getOrPutString(gpa, "Union", .no_embedded_nulls), | |
| 18227 | 18278 | )).?; |
| 18228 | 18279 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); |
| 18229 | 18280 | const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index); |
| ... | ... | @@ -18235,7 +18286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18235 | 18286 | block, |
| 18236 | 18287 | src, |
| 18237 | 18288 | type_info_ty.getNamespaceIndex(mod), |
| 18238 | try ip.getOrPutString(gpa, "UnionField"), | |
| 18289 | try ip.getOrPutString(gpa, "UnionField", .no_embedded_nulls), | |
| 18239 | 18290 | )).?; |
| 18240 | 18291 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| 18241 | 18292 | const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index); |
| ... | ... | @@ -18250,18 +18301,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18250 | 18301 | const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len); |
| 18251 | 18302 | defer gpa.free(union_field_vals); |
| 18252 | 18303 | |
| 18253 | for (union_field_vals, 0..) |*field_val, i| { | |
| 18254 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 18255 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(tag_type.names.get(ip)[i])); | |
| 18304 | for (union_field_vals, 0..) |*field_val, field_index| { | |
| 18256 | 18305 | const name_val = v: { |
| 18306 | const field_name = tag_type.names.get(ip)[field_index]; | |
| 18307 | const field_name_len = field_name.length(ip); | |
| 18257 | 18308 | const new_decl_ty = try mod.arrayType(.{ |
| 18258 | .len = name.len, | |
| 18309 | .len = field_name_len, | |
| 18259 | 18310 | .sentinel = .zero_u8, |
| 18260 | 18311 | .child = .u8_type, |
| 18261 | 18312 | }); |
| 18262 | 18313 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 18263 | 18314 | .ty = new_decl_ty.toIntern(), |
| 18264 | .storage = .{ .bytes = name }, | |
| 18315 | .storage = .{ .bytes = field_name.toString() }, | |
| 18265 | 18316 | } }); |
| 18266 | 18317 | break :v try mod.intern(.{ .slice = .{ |
| 18267 | 18318 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18272,16 +18323,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18272 | 18323 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 18273 | 18324 | } }, |
| 18274 | 18325 | } }), |
| 18275 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), | |
| 18326 | .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(), | |
| 18276 | 18327 | } }); |
| 18277 | 18328 | }; |
| 18278 | 18329 | |
| 18279 | 18330 | const alignment = switch (layout) { |
| 18280 | .auto, .@"extern" => try sema.unionFieldAlignment(union_obj, @intCast(i)), | |
| 18331 | .auto, .@"extern" => try sema.unionFieldAlignment(union_obj, @intCast(field_index)), | |
| 18281 | 18332 | .@"packed" => .none, |
| 18282 | 18333 | }; |
| 18283 | 18334 | |
| 18284 | const field_ty = union_obj.field_types.get(ip)[i]; | |
| 18335 | const field_ty = union_obj.field_types.get(ip)[field_index]; | |
| 18285 | 18336 | const union_field_fields = .{ |
| 18286 | 18337 | // name: [:0]const u8, |
| 18287 | 18338 | name_val, |
| ... | ... | @@ -18338,7 +18389,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18338 | 18389 | block, |
| 18339 | 18390 | src, |
| 18340 | 18391 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18341 | try ip.getOrPutString(gpa, "ContainerLayout"), | |
| 18392 | try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls), | |
| 18342 | 18393 | )).?; |
| 18343 | 18394 | try sema.ensureDeclAnalyzed(decl_index); |
| 18344 | 18395 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -18371,7 +18422,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18371 | 18422 | block, |
| 18372 | 18423 | src, |
| 18373 | 18424 | type_info_ty.getNamespaceIndex(mod), |
| 18374 | try ip.getOrPutString(gpa, "Struct"), | |
| 18425 | try ip.getOrPutString(gpa, "Struct", .no_embedded_nulls), | |
| 18375 | 18426 | )).?; |
| 18376 | 18427 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); |
| 18377 | 18428 | const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index); |
| ... | ... | @@ -18383,7 +18434,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18383 | 18434 | block, |
| 18384 | 18435 | src, |
| 18385 | 18436 | type_info_ty.getNamespaceIndex(mod), |
| 18386 | try ip.getOrPutString(gpa, "StructField"), | |
| 18437 | try ip.getOrPutString(gpa, "StructField", .no_embedded_nulls), | |
| 18387 | 18438 | )).?; |
| 18388 | 18439 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| 18389 | 18440 | const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index); |
| ... | ... | @@ -18396,27 +18447,25 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18396 | 18447 | defer gpa.free(struct_field_vals); |
| 18397 | 18448 | fv: { |
| 18398 | 18449 | const struct_type = switch (ip.indexToKey(ty.toIntern())) { |
| 18399 | .anon_struct_type => |tuple| { | |
| 18400 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len); | |
| 18401 | for (struct_field_vals, 0..) |*struct_field_val, i| { | |
| 18402 | const anon_struct_type = ip.indexToKey(ty.toIntern()).anon_struct_type; | |
| 18403 | const field_ty = anon_struct_type.types.get(ip)[i]; | |
| 18404 | const field_val = anon_struct_type.values.get(ip)[i]; | |
| 18450 | .anon_struct_type => |anon_struct_type| { | |
| 18451 | struct_field_vals = try gpa.alloc(InternPool.Index, anon_struct_type.types.len); | |
| 18452 | for (struct_field_vals, 0..) |*struct_field_val, field_index| { | |
| 18453 | const field_ty = anon_struct_type.types.get(ip)[field_index]; | |
| 18454 | const field_val = anon_struct_type.values.get(ip)[field_index]; | |
| 18405 | 18455 | const name_val = v: { |
| 18406 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 18407 | const bytes = if (tuple.names.len != 0) | |
| 18408 | // https://github.com/ziglang/zig/issues/15709 | |
| 18409 | try sema.arena.dupeZ(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip)[i])) | |
| 18456 | const field_name = if (anon_struct_type.names.len != 0) | |
| 18457 | anon_struct_type.names.get(ip)[field_index] | |
| 18410 | 18458 | else |
| 18411 | try std.fmt.allocPrintZ(sema.arena, "{d}", .{i}); | |
| 18459 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | |
| 18460 | const field_name_len = field_name.length(ip); | |
| 18412 | 18461 | const new_decl_ty = try mod.arrayType(.{ |
| 18413 | .len = bytes.len, | |
| 18462 | .len = field_name_len, | |
| 18414 | 18463 | .sentinel = .zero_u8, |
| 18415 | 18464 | .child = .u8_type, |
| 18416 | 18465 | }); |
| 18417 | 18466 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 18418 | 18467 | .ty = new_decl_ty.toIntern(), |
| 18419 | .storage = .{ .bytes = bytes }, | |
| 18468 | .storage = .{ .bytes = field_name.toString() }, | |
| 18420 | 18469 | } }); |
| 18421 | 18470 | break :v try mod.intern(.{ .slice = .{ |
| 18422 | 18471 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18427,7 +18476,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18427 | 18476 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 18428 | 18477 | } }, |
| 18429 | 18478 | } }), |
| 18430 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), | |
| 18479 | .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(), | |
| 18431 | 18480 | } }); |
| 18432 | 18481 | }; |
| 18433 | 18482 | |
| ... | ... | @@ -18462,24 +18511,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18462 | 18511 | |
| 18463 | 18512 | try sema.resolveStructFieldInits(ty); |
| 18464 | 18513 | |
| 18465 | for (struct_field_vals, 0..) |*field_val, i| { | |
| 18466 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 18467 | const name = if (struct_type.fieldName(ip, i).unwrap()) |name_nts| | |
| 18468 | try sema.arena.dupeZ(u8, ip.stringToSlice(name_nts)) | |
| 18514 | for (struct_field_vals, 0..) |*field_val, field_index| { | |
| 18515 | const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name| | |
| 18516 | field_name | |
| 18469 | 18517 | else |
| 18470 | try std.fmt.allocPrintZ(sema.arena, "{d}", .{i}); | |
| 18471 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | |
| 18472 | const field_init = struct_type.fieldInit(ip, i); | |
| 18473 | const field_is_comptime = struct_type.fieldIsComptime(ip, i); | |
| 18518 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | |
| 18519 | const field_name_len = field_name.length(ip); | |
| 18520 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); | |
| 18521 | const field_init = struct_type.fieldInit(ip, field_index); | |
| 18522 | const field_is_comptime = struct_type.fieldIsComptime(ip, field_index); | |
| 18474 | 18523 | const name_val = v: { |
| 18475 | 18524 | const new_decl_ty = try mod.arrayType(.{ |
| 18476 | .len = name.len, | |
| 18525 | .len = field_name_len, | |
| 18477 | 18526 | .sentinel = .zero_u8, |
| 18478 | 18527 | .child = .u8_type, |
| 18479 | 18528 | }); |
| 18480 | 18529 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 18481 | 18530 | .ty = new_decl_ty.toIntern(), |
| 18482 | .storage = .{ .bytes = name }, | |
| 18531 | .storage = .{ .bytes = field_name.toString() }, | |
| 18483 | 18532 | } }); |
| 18484 | 18533 | break :v try mod.intern(.{ .slice = .{ |
| 18485 | 18534 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18490,7 +18539,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18490 | 18539 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 18491 | 18540 | } }, |
| 18492 | 18541 | } }), |
| 18493 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), | |
| 18542 | .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(), | |
| 18494 | 18543 | } }); |
| 18495 | 18544 | }; |
| 18496 | 18545 | |
| ... | ... | @@ -18499,7 +18548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18499 | 18548 | const alignment = switch (struct_type.layout) { |
| 18500 | 18549 | .@"packed" => .none, |
| 18501 | 18550 | else => try sema.structFieldAlignment( |
| 18502 | struct_type.fieldAlign(ip, i), | |
| 18551 | struct_type.fieldAlign(ip, field_index), | |
| 18503 | 18552 | field_ty, |
| 18504 | 18553 | struct_type.layout, |
| 18505 | 18554 | ), |
| ... | ... | @@ -18569,7 +18618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18569 | 18618 | block, |
| 18570 | 18619 | src, |
| 18571 | 18620 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18572 | try ip.getOrPutString(gpa, "ContainerLayout"), | |
| 18621 | try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls), | |
| 18573 | 18622 | )).?; |
| 18574 | 18623 | try sema.ensureDeclAnalyzed(decl_index); |
| 18575 | 18624 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -18605,7 +18654,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18605 | 18654 | block, |
| 18606 | 18655 | src, |
| 18607 | 18656 | type_info_ty.getNamespaceIndex(mod), |
| 18608 | try ip.getOrPutString(gpa, "Opaque"), | |
| 18657 | try ip.getOrPutString(gpa, "Opaque", .no_embedded_nulls), | |
| 18609 | 18658 | )).?; |
| 18610 | 18659 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| 18611 | 18660 | const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index); |
| ... | ... | @@ -18648,7 +18697,7 @@ fn typeInfoDecls( |
| 18648 | 18697 | block, |
| 18649 | 18698 | src, |
| 18650 | 18699 | type_info_ty.getNamespaceIndex(mod), |
| 18651 | try mod.intern_pool.getOrPutString(gpa, "Declaration"), | |
| 18700 | try mod.intern_pool.getOrPutString(gpa, "Declaration", .no_embedded_nulls), | |
| 18652 | 18701 | )).?; |
| 18653 | 18702 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| 18654 | 18703 | const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index); |
| ... | ... | @@ -18722,16 +18771,15 @@ fn typeInfoNamespaceDecls( |
| 18722 | 18771 | } |
| 18723 | 18772 | if (decl.kind != .named) continue; |
| 18724 | 18773 | const name_val = v: { |
| 18725 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 18726 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name)); | |
| 18774 | const decl_name_len = decl.name.length(ip); | |
| 18727 | 18775 | const new_decl_ty = try mod.arrayType(.{ |
| 18728 | .len = name.len, | |
| 18776 | .len = decl_name_len, | |
| 18729 | 18777 | .sentinel = .zero_u8, |
| 18730 | 18778 | .child = .u8_type, |
| 18731 | 18779 | }); |
| 18732 | 18780 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 18733 | 18781 | .ty = new_decl_ty.toIntern(), |
| 18734 | .storage = .{ .bytes = name }, | |
| 18782 | .storage = .{ .bytes = decl.name.toString() }, | |
| 18735 | 18783 | } }); |
| 18736 | 18784 | break :v try mod.intern(.{ .slice = .{ |
| 18737 | 18785 | .ty = .slice_const_u8_sentinel_0_type, |
| ... | ... | @@ -18742,7 +18790,7 @@ fn typeInfoNamespaceDecls( |
| 18742 | 18790 | .val = new_decl_val, |
| 18743 | 18791 | } }, |
| 18744 | 18792 | } }), |
| 18745 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), | |
| 18793 | .len = (try mod.intValue(Type.usize, decl_name_len)).toIntern(), | |
| 18746 | 18794 | } }); |
| 18747 | 18795 | }; |
| 18748 | 18796 | |
| ... | ... | @@ -19385,7 +19433,11 @@ fn zirRetErrValue( |
| 19385 | 19433 | ) CompileError!void { |
| 19386 | 19434 | const mod = sema.mod; |
| 19387 | 19435 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 19388 | const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | |
| 19436 | const err_name = try mod.intern_pool.getOrPutString( | |
| 19437 | sema.gpa, | |
| 19438 | inst_data.get(sema.code), | |
| 19439 | .no_embedded_nulls, | |
| 19440 | ); | |
| 19389 | 19441 | _ = try mod.getErrorValue(err_name); |
| 19390 | 19442 | const src = inst_data.src(); |
| 19391 | 19443 | // Return the error code from the function. |
| ... | ... | @@ -20072,7 +20124,11 @@ fn zirStructInit( |
| 20072 | 20124 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20073 | 20125 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 20074 | 20126 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20075 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); | |
| 20127 | const field_name = try ip.getOrPutString( | |
| 20128 | gpa, | |
| 20129 | sema.code.nullTerminatedString(field_type_extra.name_start), | |
| 20130 | .no_embedded_nulls, | |
| 20131 | ); | |
| 20076 | 20132 | const field_index = if (resolved_ty.isTuple(mod)) |
| 20077 | 20133 | try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src) |
| 20078 | 20134 | else |
| ... | ... | @@ -20109,7 +20165,11 @@ fn zirStructInit( |
| 20109 | 20165 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20110 | 20166 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 20111 | 20167 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20112 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); | |
| 20168 | const field_name = try ip.getOrPutString( | |
| 20169 | gpa, | |
| 20170 | sema.code.nullTerminatedString(field_type_extra.name_start), | |
| 20171 | .no_embedded_nulls, | |
| 20172 | ); | |
| 20113 | 20173 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); |
| 20114 | 20174 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); |
| 20115 | 20175 | const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index); |
| ... | ... | @@ -20417,8 +20477,7 @@ fn structInitAnon( |
| 20417 | 20477 | }, |
| 20418 | 20478 | }; |
| 20419 | 20479 | |
| 20420 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name); | |
| 20421 | field_name.* = name_ip; | |
| 20480 | field_name.* = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls); | |
| 20422 | 20481 | |
| 20423 | 20482 | const init = try sema.resolveInst(item.data.init); |
| 20424 | 20483 | field_ty.* = sema.typeOf(init).toIntern(); |
| ... | ... | @@ -20809,7 +20868,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 20809 | 20868 | }; |
| 20810 | 20869 | const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod); |
| 20811 | 20870 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); |
| 20812 | const field_name = try ip.getOrPutString(sema.gpa, zir_field_name); | |
| 20871 | const field_name = try ip.getOrPutString(sema.gpa, zir_field_name, .no_embedded_nulls); | |
| 20813 | 20872 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); |
| 20814 | 20873 | } |
| 20815 | 20874 | |
| ... | ... | @@ -20975,7 +21034,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20975 | 21034 | |
| 20976 | 21035 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { |
| 20977 | 21036 | const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 20978 | return sema.addStrLit(sema.mod.intern_pool.stringToSlice(err_name)); | |
| 21037 | return sema.addNullTerminatedStrLit(err_name); | |
| 20979 | 21038 | } |
| 20980 | 21039 | |
| 20981 | 21040 | // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass |
| ... | ... | @@ -21093,7 +21152,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21093 | 21152 | .EnumLiteral => { |
| 21094 | 21153 | const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined); |
| 21095 | 21154 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 21096 | return sema.addStrLit(ip.stringToSlice(tag_name)); | |
| 21155 | return sema.addNullTerminatedStrLit(tag_name); | |
| 21097 | 21156 | }, |
| 21098 | 21157 | .Enum => operand_ty, |
| 21099 | 21158 | .Union => operand_ty.unionTagType(mod) orelse |
| ... | ... | @@ -21127,7 +21186,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21127 | 21186 | }; |
| 21128 | 21187 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 21129 | 21188 | const field_name = enum_ty.enumFieldName(field_index, mod); |
| 21130 | return sema.addStrLit(ip.stringToSlice(field_name)); | |
| 21189 | return sema.addNullTerminatedStrLit(field_name); | |
| 21131 | 21190 | } |
| 21132 | 21191 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 21133 | 21192 | if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) { |
| ... | ... | @@ -21179,11 +21238,11 @@ fn zirReify( |
| 21179 | 21238 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21180 | 21239 | const signedness_val = try Value.fromInterned(union_val.val).fieldValue( |
| 21181 | 21240 | mod, |
| 21182 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?, | |
| 21241 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness", .no_embedded_nulls)).?, | |
| 21183 | 21242 | ); |
| 21184 | 21243 | const bits_val = try Value.fromInterned(union_val.val).fieldValue( |
| 21185 | 21244 | mod, |
| 21186 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?, | |
| 21245 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits", .no_embedded_nulls)).?, | |
| 21187 | 21246 | ); |
| 21188 | 21247 | |
| 21189 | 21248 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| ... | ... | @@ -21195,11 +21254,11 @@ fn zirReify( |
| 21195 | 21254 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21196 | 21255 | const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21197 | 21256 | ip, |
| 21198 | try ip.getOrPutString(gpa, "len"), | |
| 21257 | try ip.getOrPutString(gpa, "len", .no_embedded_nulls), | |
| 21199 | 21258 | ).?); |
| 21200 | 21259 | const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21201 | 21260 | ip, |
| 21202 | try ip.getOrPutString(gpa, "child"), | |
| 21261 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | |
| 21203 | 21262 | ).?); |
| 21204 | 21263 | |
| 21205 | 21264 | const len: u32 = @intCast(try len_val.toUnsignedIntAdvanced(sema)); |
| ... | ... | @@ -21217,7 +21276,7 @@ fn zirReify( |
| 21217 | 21276 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21218 | 21277 | const bits_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21219 | 21278 | ip, |
| 21220 | try ip.getOrPutString(gpa, "bits"), | |
| 21279 | try ip.getOrPutString(gpa, "bits", .no_embedded_nulls), | |
| 21221 | 21280 | ).?); |
| 21222 | 21281 | |
| 21223 | 21282 | const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema)); |
| ... | ... | @@ -21235,35 +21294,35 @@ fn zirReify( |
| 21235 | 21294 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21236 | 21295 | const size_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21237 | 21296 | ip, |
| 21238 | try ip.getOrPutString(gpa, "size"), | |
| 21297 | try ip.getOrPutString(gpa, "size", .no_embedded_nulls), | |
| 21239 | 21298 | ).?); |
| 21240 | 21299 | const is_const_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21241 | 21300 | ip, |
| 21242 | try ip.getOrPutString(gpa, "is_const"), | |
| 21301 | try ip.getOrPutString(gpa, "is_const", .no_embedded_nulls), | |
| 21243 | 21302 | ).?); |
| 21244 | 21303 | const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21245 | 21304 | ip, |
| 21246 | try ip.getOrPutString(gpa, "is_volatile"), | |
| 21305 | try ip.getOrPutString(gpa, "is_volatile", .no_embedded_nulls), | |
| 21247 | 21306 | ).?); |
| 21248 | 21307 | const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21249 | 21308 | ip, |
| 21250 | try ip.getOrPutString(gpa, "alignment"), | |
| 21309 | try ip.getOrPutString(gpa, "alignment", .no_embedded_nulls), | |
| 21251 | 21310 | ).?); |
| 21252 | 21311 | const address_space_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21253 | 21312 | ip, |
| 21254 | try ip.getOrPutString(gpa, "address_space"), | |
| 21313 | try ip.getOrPutString(gpa, "address_space", .no_embedded_nulls), | |
| 21255 | 21314 | ).?); |
| 21256 | 21315 | const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21257 | 21316 | ip, |
| 21258 | try ip.getOrPutString(gpa, "child"), | |
| 21317 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | |
| 21259 | 21318 | ).?); |
| 21260 | 21319 | const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21261 | 21320 | ip, |
| 21262 | try ip.getOrPutString(gpa, "is_allowzero"), | |
| 21321 | try ip.getOrPutString(gpa, "is_allowzero", .no_embedded_nulls), | |
| 21263 | 21322 | ).?); |
| 21264 | 21323 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21265 | 21324 | ip, |
| 21266 | try ip.getOrPutString(gpa, "sentinel"), | |
| 21325 | try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls), | |
| 21267 | 21326 | ).?); |
| 21268 | 21327 | |
| 21269 | 21328 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| ... | ... | @@ -21341,15 +21400,15 @@ fn zirReify( |
| 21341 | 21400 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21342 | 21401 | const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21343 | 21402 | ip, |
| 21344 | try ip.getOrPutString(gpa, "len"), | |
| 21403 | try ip.getOrPutString(gpa, "len", .no_embedded_nulls), | |
| 21345 | 21404 | ).?); |
| 21346 | 21405 | const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21347 | 21406 | ip, |
| 21348 | try ip.getOrPutString(gpa, "child"), | |
| 21407 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | |
| 21349 | 21408 | ).?); |
| 21350 | 21409 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21351 | 21410 | ip, |
| 21352 | try ip.getOrPutString(gpa, "sentinel"), | |
| 21411 | try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls), | |
| 21353 | 21412 | ).?); |
| 21354 | 21413 | |
| 21355 | 21414 | const len = try len_val.toUnsignedIntAdvanced(sema); |
| ... | ... | @@ -21370,7 +21429,7 @@ fn zirReify( |
| 21370 | 21429 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21371 | 21430 | const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21372 | 21431 | ip, |
| 21373 | try ip.getOrPutString(gpa, "child"), | |
| 21432 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | |
| 21374 | 21433 | ).?); |
| 21375 | 21434 | |
| 21376 | 21435 | const child_ty = child_val.toType(); |
| ... | ... | @@ -21382,11 +21441,11 @@ fn zirReify( |
| 21382 | 21441 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21383 | 21442 | const error_set_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21384 | 21443 | ip, |
| 21385 | try ip.getOrPutString(gpa, "error_set"), | |
| 21444 | try ip.getOrPutString(gpa, "error_set", .no_embedded_nulls), | |
| 21386 | 21445 | ).?); |
| 21387 | 21446 | const payload_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21388 | 21447 | ip, |
| 21389 | try ip.getOrPutString(gpa, "payload"), | |
| 21448 | try ip.getOrPutString(gpa, "payload", .no_embedded_nulls), | |
| 21390 | 21449 | ).?); |
| 21391 | 21450 | |
| 21392 | 21451 | const error_set_ty = error_set_val.toType(); |
| ... | ... | @@ -21415,7 +21474,7 @@ fn zirReify( |
| 21415 | 21474 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); |
| 21416 | 21475 | const name_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex( |
| 21417 | 21476 | ip, |
| 21418 | try ip.getOrPutString(gpa, "name"), | |
| 21477 | try ip.getOrPutString(gpa, "name", .no_embedded_nulls), | |
| 21419 | 21478 | ).?); |
| 21420 | 21479 | |
| 21421 | 21480 | const name = try sema.sliceToIpString(block, src, name_val, .{ |
| ... | ... | @@ -21437,23 +21496,23 @@ fn zirReify( |
| 21437 | 21496 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21438 | 21497 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21439 | 21498 | ip, |
| 21440 | try ip.getOrPutString(gpa, "layout"), | |
| 21499 | try ip.getOrPutString(gpa, "layout", .no_embedded_nulls), | |
| 21441 | 21500 | ).?); |
| 21442 | 21501 | const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21443 | 21502 | ip, |
| 21444 | try ip.getOrPutString(gpa, "backing_integer"), | |
| 21503 | try ip.getOrPutString(gpa, "backing_integer", .no_embedded_nulls), | |
| 21445 | 21504 | ).?); |
| 21446 | 21505 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21447 | 21506 | ip, |
| 21448 | try ip.getOrPutString(gpa, "fields"), | |
| 21507 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | |
| 21449 | 21508 | ).?); |
| 21450 | 21509 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21451 | 21510 | ip, |
| 21452 | try ip.getOrPutString(gpa, "decls"), | |
| 21511 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | |
| 21453 | 21512 | ).?); |
| 21454 | 21513 | const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21455 | 21514 | ip, |
| 21456 | try ip.getOrPutString(gpa, "is_tuple"), | |
| 21515 | try ip.getOrPutString(gpa, "is_tuple", .no_embedded_nulls), | |
| 21457 | 21516 | ).?); |
| 21458 | 21517 | |
| 21459 | 21518 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| ... | ... | @@ -21477,19 +21536,19 @@ fn zirReify( |
| 21477 | 21536 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21478 | 21537 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21479 | 21538 | ip, |
| 21480 | try ip.getOrPutString(gpa, "tag_type"), | |
| 21539 | try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls), | |
| 21481 | 21540 | ).?); |
| 21482 | 21541 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21483 | 21542 | ip, |
| 21484 | try ip.getOrPutString(gpa, "fields"), | |
| 21543 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | |
| 21485 | 21544 | ).?); |
| 21486 | 21545 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21487 | 21546 | ip, |
| 21488 | try ip.getOrPutString(gpa, "decls"), | |
| 21547 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | |
| 21489 | 21548 | ).?); |
| 21490 | 21549 | const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21491 | 21550 | ip, |
| 21492 | try ip.getOrPutString(gpa, "is_exhaustive"), | |
| 21551 | try ip.getOrPutString(gpa, "is_exhaustive", .no_embedded_nulls), | |
| 21493 | 21552 | ).?); |
| 21494 | 21553 | |
| 21495 | 21554 | if (try decls_val.sliceLen(sema) > 0) { |
| ... | ... | @@ -21506,7 +21565,7 @@ fn zirReify( |
| 21506 | 21565 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21507 | 21566 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21508 | 21567 | ip, |
| 21509 | try ip.getOrPutString(gpa, "decls"), | |
| 21568 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | |
| 21510 | 21569 | ).?); |
| 21511 | 21570 | |
| 21512 | 21571 | // Decls |
| ... | ... | @@ -21544,19 +21603,19 @@ fn zirReify( |
| 21544 | 21603 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21545 | 21604 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21546 | 21605 | ip, |
| 21547 | try ip.getOrPutString(gpa, "layout"), | |
| 21606 | try ip.getOrPutString(gpa, "layout", .no_embedded_nulls), | |
| 21548 | 21607 | ).?); |
| 21549 | 21608 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21550 | 21609 | ip, |
| 21551 | try ip.getOrPutString(gpa, "tag_type"), | |
| 21610 | try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls), | |
| 21552 | 21611 | ).?); |
| 21553 | 21612 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21554 | 21613 | ip, |
| 21555 | try ip.getOrPutString(gpa, "fields"), | |
| 21614 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | |
| 21556 | 21615 | ).?); |
| 21557 | 21616 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21558 | 21617 | ip, |
| 21559 | try ip.getOrPutString(gpa, "decls"), | |
| 21618 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | |
| 21560 | 21619 | ).?); |
| 21561 | 21620 | |
| 21562 | 21621 | if (try decls_val.sliceLen(sema) > 0) { |
| ... | ... | @@ -21574,23 +21633,23 @@ fn zirReify( |
| 21574 | 21633 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21575 | 21634 | const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21576 | 21635 | ip, |
| 21577 | try ip.getOrPutString(gpa, "calling_convention"), | |
| 21636 | try ip.getOrPutString(gpa, "calling_convention", .no_embedded_nulls), | |
| 21578 | 21637 | ).?); |
| 21579 | 21638 | const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21580 | 21639 | ip, |
| 21581 | try ip.getOrPutString(gpa, "is_generic"), | |
| 21640 | try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls), | |
| 21582 | 21641 | ).?); |
| 21583 | 21642 | const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21584 | 21643 | ip, |
| 21585 | try ip.getOrPutString(gpa, "is_var_args"), | |
| 21644 | try ip.getOrPutString(gpa, "is_var_args", .no_embedded_nulls), | |
| 21586 | 21645 | ).?); |
| 21587 | 21646 | const return_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21588 | 21647 | ip, |
| 21589 | try ip.getOrPutString(gpa, "return_type"), | |
| 21648 | try ip.getOrPutString(gpa, "return_type", .no_embedded_nulls), | |
| 21590 | 21649 | ).?); |
| 21591 | 21650 | const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex( |
| 21592 | 21651 | ip, |
| 21593 | try ip.getOrPutString(gpa, "params"), | |
| 21652 | try ip.getOrPutString(gpa, "params", .no_embedded_nulls), | |
| 21594 | 21653 | ).?); |
| 21595 | 21654 | |
| 21596 | 21655 | const is_generic = is_generic_val.toBool(); |
| ... | ... | @@ -21620,15 +21679,15 @@ fn zirReify( |
| 21620 | 21679 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); |
| 21621 | 21680 | const param_is_generic_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex( |
| 21622 | 21681 | ip, |
| 21623 | try ip.getOrPutString(gpa, "is_generic"), | |
| 21682 | try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls), | |
| 21624 | 21683 | ).?); |
| 21625 | 21684 | const param_is_noalias_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex( |
| 21626 | 21685 | ip, |
| 21627 | try ip.getOrPutString(gpa, "is_noalias"), | |
| 21686 | try ip.getOrPutString(gpa, "is_noalias", .no_embedded_nulls), | |
| 21628 | 21687 | ).?); |
| 21629 | 21688 | const opt_param_type_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex( |
| 21630 | 21689 | ip, |
| 21631 | try ip.getOrPutString(gpa, "type"), | |
| 21690 | try ip.getOrPutString(gpa, "type", .no_embedded_nulls), | |
| 21632 | 21691 | ).?); |
| 21633 | 21692 | |
| 21634 | 21693 | if (param_is_generic_val.toBool()) { |
| ... | ... | @@ -22366,13 +22425,14 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 22366 | 22425 | |
| 22367 | 22426 | fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22368 | 22427 | const mod = sema.mod; |
| 22428 | const ip = &mod.intern_pool; | |
| 22429 | ||
| 22369 | 22430 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 22370 | 22431 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22371 | 22432 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 22372 | 22433 | |
| 22373 | var bytes = std.ArrayList(u8).init(sema.arena); | |
| 22374 | try ty.print(bytes.writer(), mod); | |
| 22375 | return addStrLitNoAlias(sema, bytes.items); | |
| 22434 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls); | |
| 22435 | return sema.addNullTerminatedStrLit(type_name); | |
| 22376 | 22436 | } |
| 22377 | 22437 | |
| 22378 | 22438 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -23507,7 +23567,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 23507 | 23567 | } |
| 23508 | 23568 | |
| 23509 | 23569 | const field_index = if (ty.isTuple(mod)) blk: { |
| 23510 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 23570 | if (field_name.eqlSlice("len", ip)) { | |
| 23511 | 23571 | return sema.fail(block, src, "no offset available for 'len' field of tuple", .{}); |
| 23512 | 23572 | } |
| 23513 | 23573 | break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src); |
| ... | ... | @@ -23977,18 +24037,18 @@ fn resolveExportOptions( |
| 23977 | 24037 | const section_src = sema.maybeOptionsSrc(block, src, "section"); |
| 23978 | 24038 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 23979 | 24039 | |
| 23980 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | |
| 24040 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | |
| 23981 | 24041 | const name = try sema.toConstString(block, name_src, name_operand, .{ |
| 23982 | 24042 | .needed_comptime_reason = "name of exported value must be comptime-known", |
| 23983 | 24043 | }); |
| 23984 | 24044 | |
| 23985 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | |
| 24045 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src); | |
| 23986 | 24046 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ |
| 23987 | 24047 | .needed_comptime_reason = "linkage of exported value must be comptime-known", |
| 23988 | 24048 | }); |
| 23989 | 24049 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 23990 | 24050 | |
| 23991 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); | |
| 24051 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section", .no_embedded_nulls), section_src); | |
| 23992 | 24052 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ |
| 23993 | 24053 | .needed_comptime_reason = "linksection of exported value must be comptime-known", |
| 23994 | 24054 | }); |
| ... | ... | @@ -23999,7 +24059,7 @@ fn resolveExportOptions( |
| 23999 | 24059 | else |
| 24000 | 24060 | null; |
| 24001 | 24061 | |
| 24002 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); | |
| 24062 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility", .no_embedded_nulls), visibility_src); | |
| 24003 | 24063 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ |
| 24004 | 24064 | .needed_comptime_reason = "visibility of exported value must be comptime-known", |
| 24005 | 24065 | }); |
| ... | ... | @@ -24016,9 +24076,9 @@ fn resolveExportOptions( |
| 24016 | 24076 | } |
| 24017 | 24077 | |
| 24018 | 24078 | return .{ |
| 24019 | .name = try ip.getOrPutString(gpa, name), | |
| 24079 | .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls), | |
| 24020 | 24080 | .linkage = linkage, |
| 24021 | .section = try ip.getOrPutStringOpt(gpa, section), | |
| 24081 | .section = try ip.getOrPutStringOpt(gpa, section, .no_embedded_nulls), | |
| 24022 | 24082 | .visibility = visibility, |
| 24023 | 24083 | }; |
| 24024 | 24084 | } |
| ... | ... | @@ -24896,7 +24956,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins |
| 24896 | 24956 | const field_index = switch (parent_ty.zigTypeTag(mod)) { |
| 24897 | 24957 | .Struct => blk: { |
| 24898 | 24958 | if (parent_ty.isTuple(mod)) { |
| 24899 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 24959 | if (field_name.eqlSlice("len", ip)) { | |
| 24900 | 24960 | return sema.fail(block, inst_src, "cannot get @fieldParentPtr of 'len' field of tuple", .{}); |
| 24901 | 24961 | } |
| 24902 | 24962 | break :blk try sema.tupleFieldIndex(block, parent_ty, field_name, field_name_src); |
| ... | ... | @@ -25578,7 +25638,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25578 | 25638 | |
| 25579 | 25639 | const runtime_src = rs: { |
| 25580 | 25640 | const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src; |
| 25581 | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len"), dest_src); | |
| 25641 | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), dest_src); | |
| 25582 | 25642 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src; |
| 25583 | 25643 | const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?; |
| 25584 | 25644 | const len = try sema.usizeCast(block, dest_src, len_u64); |
| ... | ... | @@ -25708,7 +25768,7 @@ fn zirVarExtended( |
| 25708 | 25768 | .ty = var_ty.toIntern(), |
| 25709 | 25769 | .init = init_val, |
| 25710 | 25770 | .decl = sema.owner_decl_index, |
| 25711 | .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name), | |
| 25771 | .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name, .no_embedded_nulls), | |
| 25712 | 25772 | .is_extern = small.is_extern, |
| 25713 | 25773 | .is_const = small.is_const, |
| 25714 | 25774 | .is_threadlocal = small.is_threadlocal, |
| ... | ... | @@ -26076,17 +26136,17 @@ fn resolvePrefetchOptions( |
| 26076 | 26136 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); |
| 26077 | 26137 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 26078 | 26138 | |
| 26079 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); | |
| 26139 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); | |
| 26080 | 26140 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| 26081 | 26141 | .needed_comptime_reason = "prefetch read/write must be comptime-known", |
| 26082 | 26142 | }); |
| 26083 | 26143 | |
| 26084 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); | |
| 26144 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality", .no_embedded_nulls), locality_src); | |
| 26085 | 26145 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ |
| 26086 | 26146 | .needed_comptime_reason = "prefetch locality must be comptime-known", |
| 26087 | 26147 | }); |
| 26088 | 26148 | |
| 26089 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); | |
| 26149 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache", .no_embedded_nulls), cache_src); | |
| 26090 | 26150 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ |
| 26091 | 26151 | .needed_comptime_reason = "prefetch cache must be comptime-known", |
| 26092 | 26152 | }); |
| ... | ... | @@ -26155,23 +26215,23 @@ fn resolveExternOptions( |
| 26155 | 26215 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); |
| 26156 | 26216 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 26157 | 26217 | |
| 26158 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | |
| 26218 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | |
| 26159 | 26219 | const name = try sema.toConstString(block, name_src, name_ref, .{ |
| 26160 | 26220 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", |
| 26161 | 26221 | }); |
| 26162 | 26222 | |
| 26163 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); | |
| 26223 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name", .no_embedded_nulls), library_src); | |
| 26164 | 26224 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ |
| 26165 | 26225 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", |
| 26166 | 26226 | }); |
| 26167 | 26227 | |
| 26168 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | |
| 26228 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src); | |
| 26169 | 26229 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ |
| 26170 | 26230 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", |
| 26171 | 26231 | }); |
| 26172 | 26232 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 26173 | 26233 | |
| 26174 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); | |
| 26234 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local", .no_embedded_nulls), thread_local_src); | |
| 26175 | 26235 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ |
| 26176 | 26236 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", |
| 26177 | 26237 | }); |
| ... | ... | @@ -26196,8 +26256,8 @@ fn resolveExternOptions( |
| 26196 | 26256 | } |
| 26197 | 26257 | |
| 26198 | 26258 | return .{ |
| 26199 | .name = try ip.getOrPutString(gpa, name), | |
| 26200 | .library_name = try ip.getOrPutStringOpt(gpa, library_name), | |
| 26259 | .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls), | |
| 26260 | .library_name = try ip.getOrPutStringOpt(gpa, library_name, .no_embedded_nulls), | |
| 26201 | 26261 | .linkage = linkage, |
| 26202 | 26262 | .is_thread_local = is_thread_local_val.toBool(), |
| 26203 | 26263 | }; |
| ... | ... | @@ -26809,7 +26869,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 26809 | 26869 | block, |
| 26810 | 26870 | .unneeded, |
| 26811 | 26871 | panic_messages_ty.getNamespaceIndex(mod), |
| 26812 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)), | |
| 26872 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), | |
| 26813 | 26873 | ) catch |err| switch (err) { |
| 26814 | 26874 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), |
| 26815 | 26875 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| ... | ... | @@ -27129,9 +27189,9 @@ fn fieldVal( |
| 27129 | 27189 | |
| 27130 | 27190 | switch (inner_ty.zigTypeTag(mod)) { |
| 27131 | 27191 | .Array => { |
| 27132 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 27192 | if (field_name.eqlSlice("len", ip)) { | |
| 27133 | 27193 | return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern()); |
| 27134 | } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) { | |
| 27194 | } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) { | |
| 27135 | 27195 | const ptr_info = object_ty.ptrInfo(mod); |
| 27136 | 27196 | const result_ty = try sema.ptrType(.{ |
| 27137 | 27197 | .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(), |
| ... | ... | @@ -27160,13 +27220,13 @@ fn fieldVal( |
| 27160 | 27220 | .Pointer => { |
| 27161 | 27221 | const ptr_info = inner_ty.ptrInfo(mod); |
| 27162 | 27222 | if (ptr_info.flags.size == .Slice) { |
| 27163 | if (ip.stringEqlSlice(field_name, "ptr")) { | |
| 27223 | if (field_name.eqlSlice("ptr", ip)) { | |
| 27164 | 27224 | const slice = if (is_pointer_to) |
| 27165 | 27225 | try sema.analyzeLoad(block, src, object, object_src) |
| 27166 | 27226 | else |
| 27167 | 27227 | object; |
| 27168 | 27228 | return sema.analyzeSlicePtr(block, object_src, slice, inner_ty); |
| 27169 | } else if (ip.stringEqlSlice(field_name, "len")) { | |
| 27229 | } else if (field_name.eqlSlice("len", ip)) { | |
| 27170 | 27230 | const slice = if (is_pointer_to) |
| 27171 | 27231 | try sema.analyzeLoad(block, src, object, object_src) |
| 27172 | 27232 | else |
| ... | ... | @@ -27319,10 +27379,10 @@ fn fieldPtr( |
| 27319 | 27379 | |
| 27320 | 27380 | switch (inner_ty.zigTypeTag(mod)) { |
| 27321 | 27381 | .Array => { |
| 27322 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 27382 | if (field_name.eqlSlice("len", ip)) { | |
| 27323 | 27383 | const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod)); |
| 27324 | 27384 | return anonDeclRef(sema, int_val.toIntern()); |
| 27325 | } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) { | |
| 27385 | } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) { | |
| 27326 | 27386 | const ptr_info = object_ty.ptrInfo(mod); |
| 27327 | 27387 | const new_ptr_ty = try sema.ptrType(.{ |
| 27328 | 27388 | .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(), |
| ... | ... | @@ -27370,7 +27430,7 @@ fn fieldPtr( |
| 27370 | 27430 | |
| 27371 | 27431 | const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty; |
| 27372 | 27432 | |
| 27373 | if (ip.stringEqlSlice(field_name, "ptr")) { | |
| 27433 | if (field_name.eqlSlice("ptr", ip)) { | |
| 27374 | 27434 | const slice_ptr_ty = inner_ty.slicePtrFieldType(mod); |
| 27375 | 27435 | |
| 27376 | 27436 | const result_ty = try sema.ptrType(.{ |
| ... | ... | @@ -27396,7 +27456,7 @@ fn fieldPtr( |
| 27396 | 27456 | const field_ptr = try block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); |
| 27397 | 27457 | try sema.checkKnownAllocPtr(block, inner_ptr, field_ptr); |
| 27398 | 27458 | return field_ptr; |
| 27399 | } else if (ip.stringEqlSlice(field_name, "len")) { | |
| 27459 | } else if (field_name.eqlSlice("len", ip)) { | |
| 27400 | 27460 | const result_ty = try sema.ptrType(.{ |
| 27401 | 27461 | .child = .usize_type, |
| 27402 | 27462 | .flags = .{ |
| ... | ... | @@ -27584,7 +27644,7 @@ fn fieldCallBind( |
| 27584 | 27644 | |
| 27585 | 27645 | return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr); |
| 27586 | 27646 | } else if (concrete_ty.isTuple(mod)) { |
| 27587 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 27647 | if (field_name.eqlSlice("len", ip)) { | |
| 27588 | 27648 | return .{ .direct = try mod.intRef(Type.usize, concrete_ty.structFieldCount(mod)) }; |
| 27589 | 27649 | } |
| 27590 | 27650 | if (field_name.toUnsigned(ip)) |field_index| { |
| ... | ... | @@ -27808,7 +27868,7 @@ fn structFieldPtr( |
| 27808 | 27868 | try sema.resolveStructLayout(struct_ty); |
| 27809 | 27869 | |
| 27810 | 27870 | if (struct_ty.isTuple(mod)) { |
| 27811 | if (ip.stringEqlSlice(field_name, "len")) { | |
| 27871 | if (field_name.eqlSlice("len", ip)) { | |
| 27812 | 27872 | const len_inst = try mod.intRef(Type.usize, struct_ty.structFieldCount(mod)); |
| 27813 | 27873 | return sema.analyzeRef(block, src, len_inst); |
| 27814 | 27874 | } |
| ... | ... | @@ -28023,7 +28083,7 @@ fn tupleFieldVal( |
| 28023 | 28083 | tuple_ty: Type, |
| 28024 | 28084 | ) CompileError!Air.Inst.Ref { |
| 28025 | 28085 | const mod = sema.mod; |
| 28026 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { | |
| 28086 | if (field_name.eqlSlice("len", &mod.intern_pool)) { | |
| 28027 | 28087 | return mod.intRef(Type.usize, tuple_ty.structFieldCount(mod)); |
| 28028 | 28088 | } |
| 28029 | 28089 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); |
| ... | ... | @@ -28039,16 +28099,17 @@ fn tupleFieldIndex( |
| 28039 | 28099 | field_name_src: LazySrcLoc, |
| 28040 | 28100 | ) CompileError!u32 { |
| 28041 | 28101 | const mod = sema.mod; |
| 28042 | assert(!mod.intern_pool.stringEqlSlice(field_name, "len")); | |
| 28043 | if (field_name.toUnsigned(&mod.intern_pool)) |field_index| { | |
| 28102 | const ip = &mod.intern_pool; | |
| 28103 | assert(!field_name.eqlSlice("len", ip)); | |
| 28104 | if (field_name.toUnsigned(ip)) |field_index| { | |
| 28044 | 28105 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; |
| 28045 | 28106 | return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{ |
| 28046 | field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod), | |
| 28107 | field_name.fmt(ip), tuple_ty.fmt(mod), | |
| 28047 | 28108 | }); |
| 28048 | 28109 | } |
| 28049 | 28110 | |
| 28050 | 28111 | return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{ |
| 28051 | field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod), | |
| 28112 | field_name.fmt(ip), tuple_ty.fmt(mod), | |
| 28052 | 28113 | }); |
| 28053 | 28114 | } |
| 28054 | 28115 | |
| ... | ... | @@ -28076,7 +28137,7 @@ fn tupleFieldValByIndex( |
| 28076 | 28137 | return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) { |
| 28077 | 28138 | .undef => mod.undefRef(field_ty), |
| 28078 | 28139 | .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) { |
| 28079 | .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]), | |
| 28140 | .bytes => |bytes| try mod.intValue(Type.u8, bytes.at(field_index, &mod.intern_pool)), | |
| 28080 | 28141 | .elems => |elems| Value.fromInterned(elems[field_index]), |
| 28081 | 28142 | .repeated_elem => |elem| Value.fromInterned(elem), |
| 28082 | 28143 | }.toIntern()), |
| ... | ... | @@ -32266,38 +32327,36 @@ fn coerceTupleToStruct( |
| 32266 | 32327 | .struct_type => ip.loadStructType(inst_ty.toIntern()).field_types.len, |
| 32267 | 32328 | else => unreachable, |
| 32268 | 32329 | }; |
| 32269 | for (0..field_count) |field_index_usize| { | |
| 32270 | const field_i: u32 = @intCast(field_index_usize); | |
| 32330 | for (0..field_count) |tuple_field_index| { | |
| 32271 | 32331 | const field_src = inst_src; // TODO better source location |
| 32272 | // https://github.com/ziglang/zig/issues/15709 | |
| 32273 | 32332 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 32274 | 32333 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 32275 | anon_struct_type.names.get(ip)[field_i] | |
| 32334 | anon_struct_type.names.get(ip)[tuple_field_index] | |
| 32276 | 32335 | else |
| 32277 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), | |
| 32278 | .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[field_i], | |
| 32336 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{tuple_field_index}, .no_embedded_nulls), | |
| 32337 | .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[tuple_field_index], | |
| 32279 | 32338 | else => unreachable, |
| 32280 | 32339 | }; |
| 32281 | const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src); | |
| 32282 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); | |
| 32283 | const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i); | |
| 32284 | const coerced = try sema.coerce(block, field_ty, elem_ref, field_src); | |
| 32285 | field_refs[field_index] = coerced; | |
| 32286 | if (struct_type.fieldIsComptime(ip, field_index)) { | |
| 32340 | const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src); | |
| 32341 | const struct_field_ty = Type.fromInterned(struct_type.field_types.get(ip)[struct_field_index]); | |
| 32342 | const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, @intCast(tuple_field_index)); | |
| 32343 | const coerced = try sema.coerce(block, struct_field_ty, elem_ref, field_src); | |
| 32344 | field_refs[struct_field_index] = coerced; | |
| 32345 | if (struct_type.fieldIsComptime(ip, struct_field_index)) { | |
| 32287 | 32346 | const init_val = (try sema.resolveValue(coerced)) orelse { |
| 32288 | 32347 | return sema.failWithNeededComptime(block, field_src, .{ |
| 32289 | 32348 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 32290 | 32349 | }); |
| 32291 | 32350 | }; |
| 32292 | 32351 | |
| 32293 | const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[field_index]); | |
| 32294 | if (!init_val.eql(field_init, field_ty, sema.mod)) { | |
| 32295 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i); | |
| 32352 | const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[struct_field_index]); | |
| 32353 | if (!init_val.eql(field_init, struct_field_ty, sema.mod)) { | |
| 32354 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, tuple_field_index); | |
| 32296 | 32355 | } |
| 32297 | 32356 | } |
| 32298 | 32357 | if (runtime_src == null) { |
| 32299 | 32358 | if (try sema.resolveValue(coerced)) |field_val| { |
| 32300 | field_vals[field_index] = field_val.toIntern(); | |
| 32359 | field_vals[struct_field_index] = field_val.toIntern(); | |
| 32301 | 32360 | } else { |
| 32302 | 32361 | runtime_src = field_src; |
| 32303 | 32362 | } |
| ... | ... | @@ -32382,24 +32441,23 @@ fn coerceTupleToTuple( |
| 32382 | 32441 | for (0..dest_field_count) |field_index_usize| { |
| 32383 | 32442 | const field_i: u32 = @intCast(field_index_usize); |
| 32384 | 32443 | const field_src = inst_src; // TODO better source location |
| 32385 | // https://github.com/ziglang/zig/issues/15709 | |
| 32386 | 32444 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 32387 | 32445 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 32388 | 32446 | anon_struct_type.names.get(ip)[field_i] |
| 32389 | 32447 | else |
| 32390 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), | |
| 32448 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls), | |
| 32391 | 32449 | .struct_type => s: { |
| 32392 | 32450 | const struct_type = ip.loadStructType(inst_ty.toIntern()); |
| 32393 | 32451 | if (struct_type.field_names.len > 0) { |
| 32394 | 32452 | break :s struct_type.field_names.get(ip)[field_i]; |
| 32395 | 32453 | } else { |
| 32396 | break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}); | |
| 32454 | break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls); | |
| 32397 | 32455 | } |
| 32398 | 32456 | }, |
| 32399 | 32457 | else => unreachable, |
| 32400 | 32458 | }; |
| 32401 | 32459 | |
| 32402 | if (ip.stringEqlSlice(field_name, "len")) | |
| 32460 | if (field_name.eqlSlice("len", ip)) | |
| 32403 | 32461 | return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{}); |
| 32404 | 32462 | |
| 32405 | 32463 | const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| ... | ... | @@ -34196,7 +34254,7 @@ const PeerResolveResult = union(enum) { |
| 34196 | 34254 | /// There was an error when resolving the type of a struct or tuple field. |
| 34197 | 34255 | field_error: struct { |
| 34198 | 34256 | /// The name of the field which caused the failure. |
| 34199 | field_name: []const u8, | |
| 34257 | field_name: InternPool.NullTerminatedString, | |
| 34200 | 34258 | /// The type of this field in each peer. |
| 34201 | 34259 | field_types: []Type, |
| 34202 | 34260 | /// The error from resolving the field type. Guaranteed not to be `success`. |
| ... | ... | @@ -34237,8 +34295,8 @@ const PeerResolveResult = union(enum) { |
| 34237 | 34295 | }; |
| 34238 | 34296 | }, |
| 34239 | 34297 | .field_error => |field_error| { |
| 34240 | const fmt = "struct field '{s}' has conflicting types"; | |
| 34241 | const args = .{field_error.field_name}; | |
| 34298 | const fmt = "struct field '{}' has conflicting types"; | |
| 34299 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; | |
| 34242 | 34300 | if (opt_msg) |msg| { |
| 34243 | 34301 | try sema.errNote(block, src, msg, fmt, args); |
| 34244 | 34302 | } else { |
| ... | ... | @@ -35321,7 +35379,7 @@ fn resolvePeerTypesInner( |
| 35321 | 35379 | const sub_peer_tys = try sema.arena.alloc(?Type, peer_tys.len); |
| 35322 | 35380 | const sub_peer_vals = try sema.arena.alloc(?Value, peer_vals.len); |
| 35323 | 35381 | |
| 35324 | for (field_types, field_vals, 0..) |*field_ty, *field_val, field_idx| { | |
| 35382 | for (field_types, field_vals, 0..) |*field_ty, *field_val, field_index| { | |
| 35325 | 35383 | // Fill buffers with types and values of the field |
| 35326 | 35384 | for (peer_tys, peer_vals, sub_peer_tys, sub_peer_vals) |opt_ty, opt_val, *peer_field_ty, *peer_field_val| { |
| 35327 | 35385 | const ty = opt_ty orelse { |
| ... | ... | @@ -35329,8 +35387,8 @@ fn resolvePeerTypesInner( |
| 35329 | 35387 | peer_field_val.* = null; |
| 35330 | 35388 | continue; |
| 35331 | 35389 | }; |
| 35332 | peer_field_ty.* = ty.structFieldType(field_idx, mod); | |
| 35333 | peer_field_val.* = if (opt_val) |val| try val.fieldValue(mod, field_idx) else null; | |
| 35390 | peer_field_ty.* = ty.structFieldType(field_index, mod); | |
| 35391 | peer_field_val.* = if (opt_val) |val| try val.fieldValue(mod, field_index) else null; | |
| 35334 | 35392 | } |
| 35335 | 35393 | |
| 35336 | 35394 | // Resolve field type recursively |
| ... | ... | @@ -35339,9 +35397,10 @@ fn resolvePeerTypesInner( |
| 35339 | 35397 | else => |result| { |
| 35340 | 35398 | const result_buf = try sema.arena.create(PeerResolveResult); |
| 35341 | 35399 | result_buf.* = result; |
| 35342 | const field_name = if (is_tuple) name: { | |
| 35343 | break :name try std.fmt.allocPrint(sema.arena, "{d}", .{field_idx}); | |
| 35344 | } else try sema.arena.dupe(u8, ip.stringToSlice(field_names[field_idx])); | |
| 35400 | const field_name = if (is_tuple) | |
| 35401 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_index}, .no_embedded_nulls) | |
| 35402 | else | |
| 35403 | field_names[field_index]; | |
| 35345 | 35404 | |
| 35346 | 35405 | // The error info needs the field types, but we can't reuse sub_peer_tys |
| 35347 | 35406 | // since the recursive call may have clobbered it. |
| ... | ... | @@ -35350,7 +35409,7 @@ fn resolvePeerTypesInner( |
| 35350 | 35409 | // Already-resolved types won't be referenced by the error so it's fine |
| 35351 | 35410 | // to leave them undefined. |
| 35352 | 35411 | const ty = opt_ty orelse continue; |
| 35353 | peer_field_ty.* = ty.structFieldType(field_idx, mod); | |
| 35412 | peer_field_ty.* = ty.structFieldType(field_index, mod); | |
| 35354 | 35413 | } |
| 35355 | 35414 | |
| 35356 | 35415 | return .{ .field_error = .{ |
| ... | ... | @@ -35369,7 +35428,7 @@ fn resolvePeerTypesInner( |
| 35369 | 35428 | const struct_ty = opt_ty orelse continue; |
| 35370 | 35429 | try sema.resolveStructFieldInits(struct_ty); |
| 35371 | 35430 | |
| 35372 | const uncoerced_field_val = try struct_ty.structFieldValueComptime(mod, field_idx) orelse { | |
| 35431 | const uncoerced_field_val = try struct_ty.structFieldValueComptime(mod, field_index) orelse { | |
| 35373 | 35432 | comptime_val = null; |
| 35374 | 35433 | break; |
| 35375 | 35434 | }; |
| ... | ... | @@ -36811,7 +36870,7 @@ fn semaStructFields( |
| 36811 | 36870 | |
| 36812 | 36871 | // This string needs to outlive the ZIR code. |
| 36813 | 36872 | if (opt_field_name_zir) |field_name_zir| { |
| 36814 | const field_name = try ip.getOrPutString(gpa, field_name_zir); | |
| 36873 | const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | |
| 36815 | 36874 | assert(struct_type.addFieldName(ip, field_name) == null); |
| 36816 | 36875 | } |
| 36817 | 36876 | |
| ... | ... | @@ -37342,7 +37401,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 37342 | 37401 | } |
| 37343 | 37402 | |
| 37344 | 37403 | // This string needs to outlive the ZIR code. |
| 37345 | const field_name = try ip.getOrPutString(gpa, field_name_zir); | |
| 37404 | const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | |
| 37346 | 37405 | if (enum_field_names.len != 0) { |
| 37347 | 37406 | enum_field_names[field_i] = field_name; |
| 37348 | 37407 | } |
| ... | ... | @@ -37528,7 +37587,12 @@ fn generateUnionTagTypeNumbered( |
| 37528 | 37587 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); |
| 37529 | 37588 | errdefer mod.destroyDecl(new_decl_index); |
| 37530 | 37589 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 37531 | const name = try ip.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(ip)}); | |
| 37590 | const name = try ip.getOrPutStringFmt( | |
| 37591 | gpa, | |
| 37592 | "@typeInfo({}).Union.tag_type.?", | |
| 37593 | .{fqn.fmt(ip)}, | |
| 37594 | .no_embedded_nulls, | |
| 37595 | ); | |
| 37532 | 37596 | try mod.initNewAnonDecl( |
| 37533 | 37597 | new_decl_index, |
| 37534 | 37598 | src_decl.src_line, |
| ... | ... | @@ -37574,7 +37638,12 @@ fn generateUnionTagTypeSimple( |
| 37574 | 37638 | const src_decl = mod.declPtr(block.src_decl); |
| 37575 | 37639 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); |
| 37576 | 37640 | errdefer mod.destroyDecl(new_decl_index); |
| 37577 | const name = try ip.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(ip)}); | |
| 37641 | const name = try ip.getOrPutStringFmt( | |
| 37642 | gpa, | |
| 37643 | "@typeInfo({}).Union.tag_type.?", | |
| 37644 | .{fqn.fmt(ip)}, | |
| 37645 | .no_embedded_nulls, | |
| 37646 | ); | |
| 37578 | 37647 | try mod.initNewAnonDecl( |
| 37579 | 37648 | new_decl_index, |
| 37580 | 37649 | src_decl.src_line, |
| ... | ... | @@ -37638,7 +37707,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37638 | 37707 | block, |
| 37639 | 37708 | src, |
| 37640 | 37709 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace.toOptional(), |
| 37641 | try ip.getOrPutString(gpa, "builtin"), | |
| 37710 | try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls), | |
| 37642 | 37711 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 37643 | 37712 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src); |
| 37644 | 37713 | const builtin_ty = sema.analyzeAsType(block, src, builtin_inst) catch |err| switch (err) { |
| ... | ... | @@ -37649,7 +37718,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37649 | 37718 | block, |
| 37650 | 37719 | src, |
| 37651 | 37720 | builtin_ty.getNamespaceIndex(mod), |
| 37652 | try ip.getOrPutString(gpa, name), | |
| 37721 | try ip.getOrPutString(gpa, name, .no_embedded_nulls), | |
| 37653 | 37722 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 37654 | 37723 | return decl_index; |
| 37655 | 37724 | } |
| ... | ... | @@ -38820,7 +38889,7 @@ fn intFitsInType( |
| 38820 | 38889 | .aggregate => |aggregate| { |
| 38821 | 38890 | assert(ty.zigTypeTag(mod) == .Vector); |
| 38822 | 38891 | return switch (aggregate.storage) { |
| 38823 | .bytes => |bytes| for (bytes, 0..) |byte, i| { | |
| 38892 | .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(mod), &mod.intern_pool), 0..) |byte, i| { | |
| 38824 | 38893 | if (byte == 0) continue; |
| 38825 | 38894 | const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed); |
| 38826 | 38895 | if (info.bits >= actual_needed_bits) continue; |
src/Value.zig+95-85| ... | ... | @@ -52,30 +52,31 @@ pub fn toIpString(val: Value, ty: Type, mod: *Module) !InternPool.NullTerminated |
| 52 | 52 | assert(ty.zigTypeTag(mod) == .Array); |
| 53 | 53 | assert(ty.childType(mod).toIntern() == .u8_type); |
| 54 | 54 | const ip = &mod.intern_pool; |
| 55 | return switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) { | |
| 56 | .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes), | |
| 57 | .elems => try arrayToIpString(val, ty.arrayLen(mod), mod), | |
| 55 | switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) { | |
| 56 | .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(mod), ip), | |
| 57 | .elems => return arrayToIpString(val, ty.arrayLen(mod), mod), | |
| 58 | 58 | .repeated_elem => |elem| { |
| 59 | const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod))); | |
| 60 | const len = @as(usize, @intCast(ty.arrayLen(mod))); | |
| 59 | const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(mod)); | |
| 60 | const len: usize = @intCast(ty.arrayLen(mod)); | |
| 61 | 61 | try ip.string_bytes.appendNTimes(mod.gpa, byte, len); |
| 62 | return ip.getOrPutTrailingString(mod.gpa, len); | |
| 62 | return ip.getOrPutTrailingString(mod.gpa, len, .no_embedded_nulls); | |
| 63 | 63 | }, |
| 64 | }; | |
| 64 | } | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /// Asserts that the value is representable as an array of bytes. |
| 68 | 68 | /// Copies the value into a freshly allocated slice of memory, which is owned by the caller. |
| 69 | 69 | pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 { |
| 70 | return switch (mod.intern_pool.indexToKey(val.toIntern())) { | |
| 71 | .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)), | |
| 70 | const ip = &mod.intern_pool; | |
| 71 | return switch (ip.indexToKey(val.toIntern())) { | |
| 72 | .enum_literal => |enum_literal| allocator.dupe(u8, enum_literal.toSlice(ip)), | |
| 72 | 73 | .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(mod), allocator, mod), |
| 73 | 74 | .aggregate => |aggregate| switch (aggregate.storage) { |
| 74 | .bytes => |bytes| try allocator.dupe(u8, bytes), | |
| 75 | .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(mod), ip)), | |
| 75 | 76 | .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod), |
| 76 | 77 | .repeated_elem => |elem| { |
| 77 | const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod))); | |
| 78 | const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod)))); | |
| 78 | const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(mod)); | |
| 79 | const result = try allocator.alloc(u8, @intCast(ty.arrayLen(mod))); | |
| 79 | 80 | @memset(result, byte); |
| 80 | 81 | return result; |
| 81 | 82 | }, |
| ... | ... | @@ -85,10 +86,10 @@ pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module |
| 85 | 86 | } |
| 86 | 87 | |
| 87 | 88 | fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 { |
| 88 | const result = try allocator.alloc(u8, @as(usize, @intCast(len))); | |
| 89 | const result = try allocator.alloc(u8, @intCast(len)); | |
| 89 | 90 | for (result, 0..) |*elem, i| { |
| 90 | 91 | const elem_val = try val.elemValue(mod, i); |
| 91 | elem.* = @as(u8, @intCast(elem_val.toUnsignedInt(mod))); | |
| 92 | elem.* = @intCast(elem_val.toUnsignedInt(mod)); | |
| 92 | 93 | } |
| 93 | 94 | return result; |
| 94 | 95 | } |
| ... | ... | @@ -96,7 +97,7 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Modul |
| 96 | 97 | fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString { |
| 97 | 98 | const gpa = mod.gpa; |
| 98 | 99 | const ip = &mod.intern_pool; |
| 99 | const len = @as(usize, @intCast(len_u64)); | |
| 100 | const len: usize = @intCast(len_u64); | |
| 100 | 101 | try ip.string_bytes.ensureUnusedCapacity(gpa, len); |
| 101 | 102 | for (0..len) |i| { |
| 102 | 103 | // I don't think elemValue has the possibility to affect ip.string_bytes. Let's |
| ... | ... | @@ -104,10 +105,10 @@ fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTermi |
| 104 | 105 | const prev = ip.string_bytes.items.len; |
| 105 | 106 | const elem_val = try val.elemValue(mod, i); |
| 106 | 107 | assert(ip.string_bytes.items.len == prev); |
| 107 | const byte = @as(u8, @intCast(elem_val.toUnsignedInt(mod))); | |
| 108 | const byte: u8 = @intCast(elem_val.toUnsignedInt(mod)); | |
| 108 | 109 | ip.string_bytes.appendAssumeCapacity(byte); |
| 109 | 110 | } |
| 110 | return ip.getOrPutTrailingString(gpa, len); | |
| 111 | return ip.getOrPutTrailingString(gpa, len, .no_embedded_nulls); | |
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | pub fn fromInterned(i: InternPool.Index) Value { |
| ... | ... | @@ -256,7 +257,7 @@ pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 |
| 256 | 257 | const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null; |
| 257 | 258 | const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod); |
| 258 | 259 | if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty); |
| 259 | return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod); | |
| 260 | return base_addr + struct_ty.structFieldOffset(@intCast(field.index), mod); | |
| 260 | 261 | }, |
| 261 | 262 | else => null, |
| 262 | 263 | }, |
| ... | ... | @@ -351,17 +352,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ |
| 351 | 352 | bigint.writeTwosComplement(buffer[0..byte_count], endian); |
| 352 | 353 | }, |
| 353 | 354 | .Float => switch (ty.floatBits(target)) { |
| 354 | 16 => std.mem.writeInt(u16, buffer[0..2], @as(u16, @bitCast(val.toFloat(f16, mod))), endian), | |
| 355 | 32 => std.mem.writeInt(u32, buffer[0..4], @as(u32, @bitCast(val.toFloat(f32, mod))), endian), | |
| 356 | 64 => std.mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(val.toFloat(f64, mod))), endian), | |
| 357 | 80 => std.mem.writeInt(u80, buffer[0..10], @as(u80, @bitCast(val.toFloat(f80, mod))), endian), | |
| 358 | 128 => std.mem.writeInt(u128, buffer[0..16], @as(u128, @bitCast(val.toFloat(f128, mod))), endian), | |
| 355 | 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, mod)), endian), | |
| 356 | 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, mod)), endian), | |
| 357 | 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, mod)), endian), | |
| 358 | 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, mod)), endian), | |
| 359 | 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, mod)), endian), | |
| 359 | 360 | else => unreachable, |
| 360 | 361 | }, |
| 361 | 362 | .Array => { |
| 362 | 363 | const len = ty.arrayLen(mod); |
| 363 | 364 | const elem_ty = ty.childType(mod); |
| 364 | const elem_size = @as(usize, @intCast(elem_ty.abiSize(mod))); | |
| 365 | const elem_size: usize = @intCast(elem_ty.abiSize(mod)); | |
| 365 | 366 | var elem_i: usize = 0; |
| 366 | 367 | var buf_off: usize = 0; |
| 367 | 368 | while (elem_i < len) : (elem_i += 1) { |
| ... | ... | @@ -380,17 +381,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ |
| 380 | 381 | const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout; |
| 381 | 382 | switch (struct_type.layout) { |
| 382 | 383 | .auto => return error.IllDefinedMemoryLayout, |
| 383 | .@"extern" => for (0..struct_type.field_types.len) |i| { | |
| 384 | const off: usize = @intCast(ty.structFieldOffset(i, mod)); | |
| 384 | .@"extern" => for (0..struct_type.field_types.len) |field_index| { | |
| 385 | const off: usize = @intCast(ty.structFieldOffset(field_index, mod)); | |
| 385 | 386 | const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 386 | 387 | .bytes => |bytes| { |
| 387 | buffer[off] = bytes[i]; | |
| 388 | buffer[off] = bytes.at(field_index, ip); | |
| 388 | 389 | continue; |
| 389 | 390 | }, |
| 390 | .elems => |elems| elems[i], | |
| 391 | .elems => |elems| elems[field_index], | |
| 391 | 392 | .repeated_elem => |elem| elem, |
| 392 | 393 | }); |
| 393 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | |
| 394 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); | |
| 394 | 395 | try writeToMemory(field_val, field_ty, mod, buffer[off..]); |
| 395 | 396 | }, |
| 396 | 397 | .@"packed" => { |
| ... | ... | @@ -423,7 +424,7 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ |
| 423 | 424 | const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?; |
| 424 | 425 | const field_type = Type.fromInterned(union_obj.field_types.get(&mod.intern_pool)[field_index]); |
| 425 | 426 | const field_val = try val.fieldValue(mod, field_index); |
| 426 | const byte_count = @as(usize, @intCast(field_type.abiSize(mod))); | |
| 427 | const byte_count: usize = @intCast(field_type.abiSize(mod)); | |
| 427 | 428 | return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]); |
| 428 | 429 | } else { |
| 429 | 430 | const backing_ty = try ty.unionBackingType(mod); |
| ... | ... | @@ -471,7 +472,7 @@ pub fn writeToPackedMemory( |
| 471 | 472 | const target = mod.getTarget(); |
| 472 | 473 | const endian = target.cpu.arch.endian(); |
| 473 | 474 | if (val.isUndef(mod)) { |
| 474 | const bit_size = @as(usize, @intCast(ty.bitSize(mod))); | |
| 475 | const bit_size: usize = @intCast(ty.bitSize(mod)); | |
| 475 | 476 | std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian); |
| 476 | 477 | return; |
| 477 | 478 | } |
| ... | ... | @@ -507,17 +508,17 @@ pub fn writeToPackedMemory( |
| 507 | 508 | } |
| 508 | 509 | }, |
| 509 | 510 | .Float => switch (ty.floatBits(target)) { |
| 510 | 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @as(u16, @bitCast(val.toFloat(f16, mod))), endian), | |
| 511 | 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @as(u32, @bitCast(val.toFloat(f32, mod))), endian), | |
| 512 | 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @as(u64, @bitCast(val.toFloat(f64, mod))), endian), | |
| 513 | 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @as(u80, @bitCast(val.toFloat(f80, mod))), endian), | |
| 514 | 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @as(u128, @bitCast(val.toFloat(f128, mod))), endian), | |
| 511 | 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, mod)), endian), | |
| 512 | 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, mod)), endian), | |
| 513 | 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, mod)), endian), | |
| 514 | 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, mod)), endian), | |
| 515 | 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, mod)), endian), | |
| 515 | 516 | else => unreachable, |
| 516 | 517 | }, |
| 517 | 518 | .Vector => { |
| 518 | 519 | const elem_ty = ty.childType(mod); |
| 519 | const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod))); | |
| 520 | const len = @as(usize, @intCast(ty.arrayLen(mod))); | |
| 520 | const elem_bit_size: u16 = @intCast(elem_ty.bitSize(mod)); | |
| 521 | const len: usize = @intCast(ty.arrayLen(mod)); | |
| 521 | 522 | |
| 522 | 523 | var bits: u16 = 0; |
| 523 | 524 | var elem_i: usize = 0; |
| ... | ... | @@ -644,22 +645,22 @@ pub fn readFromMemory( |
| 644 | 645 | .Float => return Value.fromInterned((try mod.intern(.{ .float = .{ |
| 645 | 646 | .ty = ty.toIntern(), |
| 646 | 647 | .storage = switch (ty.floatBits(target)) { |
| 647 | 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) }, | |
| 648 | 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readInt(u32, buffer[0..4], endian))) }, | |
| 649 | 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readInt(u64, buffer[0..8], endian))) }, | |
| 650 | 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readInt(u80, buffer[0..10], endian))) }, | |
| 651 | 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) }, | |
| 648 | 16 => .{ .f16 = @bitCast(std.mem.readInt(u16, buffer[0..2], endian)) }, | |
| 649 | 32 => .{ .f32 = @bitCast(std.mem.readInt(u32, buffer[0..4], endian)) }, | |
| 650 | 64 => .{ .f64 = @bitCast(std.mem.readInt(u64, buffer[0..8], endian)) }, | |
| 651 | 80 => .{ .f80 = @bitCast(std.mem.readInt(u80, buffer[0..10], endian)) }, | |
| 652 | 128 => .{ .f128 = @bitCast(std.mem.readInt(u128, buffer[0..16], endian)) }, | |
| 652 | 653 | else => unreachable, |
| 653 | 654 | }, |
| 654 | 655 | } }))), |
| 655 | 656 | .Array => { |
| 656 | 657 | const elem_ty = ty.childType(mod); |
| 657 | 658 | const elem_size = elem_ty.abiSize(mod); |
| 658 | const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod)))); | |
| 659 | const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod))); | |
| 659 | 660 | var offset: usize = 0; |
| 660 | 661 | for (elems) |*elem| { |
| 661 | 662 | elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern(); |
| 662 | offset += @as(usize, @intCast(elem_size)); | |
| 663 | offset += @intCast(elem_size); | |
| 663 | 664 | } |
| 664 | 665 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ |
| 665 | 666 | .ty = ty.toIntern(), |
| ... | ... | @@ -795,7 +796,7 @@ pub fn readFromPackedMemory( |
| 795 | 796 | }; |
| 796 | 797 | |
| 797 | 798 | // Slow path, we have to construct a big-int |
| 798 | const abi_size = @as(usize, @intCast(ty.abiSize(mod))); | |
| 799 | const abi_size: usize = @intCast(ty.abiSize(mod)); | |
| 799 | 800 | const Limb = std.math.big.Limb; |
| 800 | 801 | const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb); |
| 801 | 802 | const limbs_buffer = try arena.alloc(Limb, limb_count); |
| ... | ... | @@ -812,20 +813,20 @@ pub fn readFromPackedMemory( |
| 812 | 813 | .Float => return Value.fromInterned((try mod.intern(.{ .float = .{ |
| 813 | 814 | .ty = ty.toIntern(), |
| 814 | 815 | .storage = switch (ty.floatBits(target)) { |
| 815 | 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) }, | |
| 816 | 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian))) }, | |
| 817 | 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian))) }, | |
| 818 | 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian))) }, | |
| 819 | 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) }, | |
| 816 | 16 => .{ .f16 = @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian)) }, | |
| 817 | 32 => .{ .f32 = @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian)) }, | |
| 818 | 64 => .{ .f64 = @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian)) }, | |
| 819 | 80 => .{ .f80 = @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian)) }, | |
| 820 | 128 => .{ .f128 = @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian)) }, | |
| 820 | 821 | else => unreachable, |
| 821 | 822 | }, |
| 822 | 823 | } }))), |
| 823 | 824 | .Vector => { |
| 824 | 825 | const elem_ty = ty.childType(mod); |
| 825 | const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod)))); | |
| 826 | const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod))); | |
| 826 | 827 | |
| 827 | 828 | var bits: u16 = 0; |
| 828 | const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod))); | |
| 829 | const elem_bit_size: u16 = @intCast(elem_ty.bitSize(mod)); | |
| 829 | 830 | for (elems, 0..) |_, i| { |
| 830 | 831 | // On big-endian systems, LLVM reverses the element order of vectors by default |
| 831 | 832 | const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i; |
| ... | ... | @@ -909,7 +910,7 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 { |
| 909 | 910 | var i: usize = limbs.len; |
| 910 | 911 | while (i != 0) { |
| 911 | 912 | i -= 1; |
| 912 | const limb: f128 = @as(f128, @floatFromInt(limbs[i])); | |
| 913 | const limb: f128 = @floatFromInt(limbs[i]); | |
| 913 | 914 | result = @mulAdd(f128, base, result, limb); |
| 914 | 915 | } |
| 915 | 916 | if (positive) { |
| ... | ... | @@ -934,7 +935,7 @@ pub fn ctz(val: Value, ty: Type, mod: *Module) u64 { |
| 934 | 935 | pub fn popCount(val: Value, ty: Type, mod: *Module) u64 { |
| 935 | 936 | var bigint_buf: BigIntSpace = undefined; |
| 936 | 937 | const bigint = val.toBigInt(&bigint_buf, mod); |
| 937 | return @as(u64, @intCast(bigint.popCount(ty.intInfo(mod).bits))); | |
| 938 | return @intCast(bigint.popCount(ty.intInfo(mod).bits)); | |
| 938 | 939 | } |
| 939 | 940 | |
| 940 | 941 | pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value { |
| ... | ... | @@ -1191,7 +1192,7 @@ pub fn compareAllWithZeroAdvancedExtra( |
| 1191 | 1192 | inline else => |x| if (std.math.isNan(x)) return op == .neq, |
| 1192 | 1193 | }, |
| 1193 | 1194 | .aggregate => |aggregate| return switch (aggregate.storage) { |
| 1194 | .bytes => |bytes| for (bytes) |byte| { | |
| 1195 | .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(mod).arrayLenIncludingSentinel(mod), &mod.intern_pool)) |byte| { | |
| 1195 | 1196 | if (!std.math.order(byte, 0).compare(op)) break false; |
| 1196 | 1197 | } else true, |
| 1197 | 1198 | .elems => |elems| for (elems) |elem| { |
| ... | ... | @@ -1279,7 +1280,7 @@ pub fn elemValue(val: Value, zcu: *Zcu, index: usize) Allocator.Error!Value { |
| 1279 | 1280 | if (index < len) return Value.fromInterned(switch (aggregate.storage) { |
| 1280 | 1281 | .bytes => |bytes| try zcu.intern(.{ .int = .{ |
| 1281 | 1282 | .ty = .u8_type, |
| 1282 | .storage = .{ .u64 = bytes[index] }, | |
| 1283 | .storage = .{ .u64 = bytes.at(index, ip) }, | |
| 1283 | 1284 | } }), |
| 1284 | 1285 | .elems => |elems| elems[index], |
| 1285 | 1286 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1318,28 +1319,37 @@ pub fn sliceArray( |
| 1318 | 1319 | start: usize, |
| 1319 | 1320 | end: usize, |
| 1320 | 1321 | ) error{OutOfMemory}!Value { |
| 1321 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 1322 | 1322 | const mod = sema.mod; |
| 1323 | const aggregate = mod.intern_pool.indexToKey(val.toIntern()).aggregate; | |
| 1324 | return Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 1325 | .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) { | |
| 1326 | .array_type => |array_type| try mod.arrayType(.{ | |
| 1327 | .len = @as(u32, @intCast(end - start)), | |
| 1328 | .child = array_type.child, | |
| 1329 | .sentinel = if (end == array_type.len) array_type.sentinel else .none, | |
| 1330 | }), | |
| 1331 | .vector_type => |vector_type| try mod.vectorType(.{ | |
| 1332 | .len = @as(u32, @intCast(end - start)), | |
| 1333 | .child = vector_type.child, | |
| 1334 | }), | |
| 1335 | else => unreachable, | |
| 1336 | }.toIntern(), | |
| 1337 | .storage = switch (aggregate.storage) { | |
| 1338 | .bytes => .{ .bytes = try sema.arena.dupe(u8, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.bytes[start..end]) }, | |
| 1339 | .elems => .{ .elems = try sema.arena.dupe(InternPool.Index, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.elems[start..end]) }, | |
| 1340 | .repeated_elem => |elem| .{ .repeated_elem = elem }, | |
| 1323 | const ip = &mod.intern_pool; | |
| 1324 | return Value.fromInterned(try mod.intern(.{ | |
| 1325 | .aggregate = .{ | |
| 1326 | .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) { | |
| 1327 | .array_type => |array_type| try mod.arrayType(.{ | |
| 1328 | .len = @intCast(end - start), | |
| 1329 | .child = array_type.child, | |
| 1330 | .sentinel = if (end == array_type.len) array_type.sentinel else .none, | |
| 1331 | }), | |
| 1332 | .vector_type => |vector_type| try mod.vectorType(.{ | |
| 1333 | .len = @intCast(end - start), | |
| 1334 | .child = vector_type.child, | |
| 1335 | }), | |
| 1336 | else => unreachable, | |
| 1337 | }.toIntern(), | |
| 1338 | .storage = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { | |
| 1339 | .bytes => |bytes| storage: { | |
| 1340 | try ip.string_bytes.ensureUnusedCapacity(sema.gpa, end - start + 1); | |
| 1341 | break :storage .{ .bytes = try ip.getOrPutString( | |
| 1342 | sema.gpa, | |
| 1343 | bytes.toSlice(end, ip)[start..], | |
| 1344 | .maybe_embedded_nulls, | |
| 1345 | ) }; | |
| 1346 | }, | |
| 1347 | // TODO: write something like getCoercedInts to avoid needing to dupe | |
| 1348 | .elems => |elems| .{ .elems = try sema.arena.dupe(InternPool.Index, elems[start..end]) }, | |
| 1349 | .repeated_elem => |elem| .{ .repeated_elem = elem }, | |
| 1350 | }, | |
| 1341 | 1351 | }, |
| 1342 | } })); | |
| 1352 | })); | |
| 1343 | 1353 | } |
| 1344 | 1354 | |
| 1345 | 1355 | pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value { |
| ... | ... | @@ -1350,7 +1360,7 @@ pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value { |
| 1350 | 1360 | .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) { |
| 1351 | 1361 | .bytes => |bytes| try mod.intern(.{ .int = .{ |
| 1352 | 1362 | .ty = .u8_type, |
| 1353 | .storage = .{ .u64 = bytes[index] }, | |
| 1363 | .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) }, | |
| 1354 | 1364 | } }), |
| 1355 | 1365 | .elems => |elems| elems[index], |
| 1356 | 1366 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1461,7 +1471,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi |
| 1461 | 1471 | |
| 1462 | 1472 | pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt { |
| 1463 | 1473 | return if (getErrorName(val, mod).unwrap()) |err_name| |
| 1464 | @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(err_name).?)) | |
| 1474 | @intCast(mod.global_error_set.getIndex(err_name).?) | |
| 1465 | 1475 | else |
| 1466 | 1476 | 0; |
| 1467 | 1477 | } |
| ... | ... | @@ -2413,14 +2423,14 @@ pub fn intTruncBitsAsValue( |
| 2413 | 2423 | for (result_data, 0..) |*scalar, i| { |
| 2414 | 2424 | const elem_val = try val.elemValue(mod, i); |
| 2415 | 2425 | const bits_elem = try bits.elemValue(mod, i); |
| 2416 | scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).toIntern(); | |
| 2426 | scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(bits_elem.toUnsignedInt(mod)), mod)).toIntern(); | |
| 2417 | 2427 | } |
| 2418 | 2428 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ |
| 2419 | 2429 | .ty = ty.toIntern(), |
| 2420 | 2430 | .storage = .{ .elems = result_data }, |
| 2421 | 2431 | } }))); |
| 2422 | 2432 | } |
| 2423 | return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod); | |
| 2433 | return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(mod)), mod); | |
| 2424 | 2434 | } |
| 2425 | 2435 | |
| 2426 | 2436 | pub fn intTruncScalar( |
| ... | ... | @@ -2468,7 +2478,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M |
| 2468 | 2478 | // resorting to BigInt first. |
| 2469 | 2479 | var lhs_space: Value.BigIntSpace = undefined; |
| 2470 | 2480 | const lhs_bigint = lhs.toBigInt(&lhs_space, mod); |
| 2471 | const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod))); | |
| 2481 | const shift: usize = @intCast(rhs.toUnsignedInt(mod)); | |
| 2472 | 2482 | const limbs = try allocator.alloc( |
| 2473 | 2483 | std.math.big.Limb, |
| 2474 | 2484 | lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1, |
| ... | ... | @@ -2530,7 +2540,7 @@ pub fn shlWithOverflowScalar( |
| 2530 | 2540 | const info = ty.intInfo(mod); |
| 2531 | 2541 | var lhs_space: Value.BigIntSpace = undefined; |
| 2532 | 2542 | const lhs_bigint = lhs.toBigInt(&lhs_space, mod); |
| 2533 | const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod))); | |
| 2543 | const shift: usize = @intCast(rhs.toUnsignedInt(mod)); | |
| 2534 | 2544 | const limbs = try allocator.alloc( |
| 2535 | 2545 | std.math.big.Limb, |
| 2536 | 2546 | lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1, |
| ... | ... | @@ -2587,7 +2597,7 @@ pub fn shlSatScalar( |
| 2587 | 2597 | |
| 2588 | 2598 | var lhs_space: Value.BigIntSpace = undefined; |
| 2589 | 2599 | const lhs_bigint = lhs.toBigInt(&lhs_space, mod); |
| 2590 | const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod))); | |
| 2600 | const shift: usize = @intCast(rhs.toUnsignedInt(mod)); | |
| 2591 | 2601 | const limbs = try arena.alloc( |
| 2592 | 2602 | std.math.big.Limb, |
| 2593 | 2603 | std.math.big.int.calcTwosCompLimbCount(info.bits) + 1, |
| ... | ... | @@ -2659,7 +2669,7 @@ pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M |
| 2659 | 2669 | // resorting to BigInt first. |
| 2660 | 2670 | var lhs_space: Value.BigIntSpace = undefined; |
| 2661 | 2671 | const lhs_bigint = lhs.toBigInt(&lhs_space, mod); |
| 2662 | const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod))); | |
| 2672 | const shift: usize = @intCast(rhs.toUnsignedInt(mod)); | |
| 2663 | 2673 | |
| 2664 | 2674 | const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8)); |
| 2665 | 2675 | if (result_limbs == 0) { |
src/arch/aarch64/CodeGen.zig+2-2| ... | ... | @@ -4345,8 +4345,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4345 | 4345 | .data = .{ .reg = .x30 }, |
| 4346 | 4346 | }); |
| 4347 | 4347 | } else if (func_value.getExternFunc(mod)) |extern_func| { |
| 4348 | const decl_name = mod.intern_pool.stringToSlice(mod.declPtr(extern_func.decl).name); | |
| 4349 | const lib_name = mod.intern_pool.stringToSliceUnwrap(extern_func.lib_name); | |
| 4348 | const decl_name = mod.declPtr(extern_func.decl).name.toSlice(&mod.intern_pool); | |
| 4349 | const lib_name = extern_func.lib_name.toSlice(&mod.intern_pool); | |
| 4350 | 4350 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 4351 | 4351 | _ = macho_file; |
| 4352 | 4352 | @panic("TODO airCall"); |
src/arch/wasm/CodeGen.zig+10-9| ... | ... | @@ -2199,9 +2199,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 2199 | 2199 | const atom = func.bin_file.getAtomPtr(atom_index); |
| 2200 | 2200 | const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type); |
| 2201 | 2201 | try func.bin_file.addOrUpdateImport( |
| 2202 | mod.intern_pool.stringToSlice(ext_decl.name), | |
| 2202 | ext_decl.name.toSlice(&mod.intern_pool), | |
| 2203 | 2203 | atom.sym_index, |
| 2204 | mod.intern_pool.stringToSliceUnwrap(ext_decl.getOwnedExternFunc(mod).?.lib_name), | |
| 2204 | ext_decl.getOwnedExternFunc(mod).?.lib_name.toSlice(&mod.intern_pool), | |
| 2205 | 2205 | type_index, |
| 2206 | 2206 | ); |
| 2207 | 2207 | break :blk extern_func.decl; |
| ... | ... | @@ -7236,8 +7236,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7236 | 7236 | defer arena_allocator.deinit(); |
| 7237 | 7237 | const arena = arena_allocator.allocator(); |
| 7238 | 7238 | |
| 7239 | const fqn = ip.stringToSlice(try mod.declPtr(enum_decl_index).fullyQualifiedName(mod)); | |
| 7240 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn}); | |
| 7239 | const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(mod); | |
| 7240 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)}); | |
| 7241 | 7241 | |
| 7242 | 7242 | // check if we already generated code for this. |
| 7243 | 7243 | if (func.bin_file.findGlobalSymbol(func_name)) |loc| { |
| ... | ... | @@ -7268,17 +7268,18 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7268 | 7268 | // generate an if-else chain for each tag value as well as constant. |
| 7269 | 7269 | const tag_names = enum_ty.enumFields(mod); |
| 7270 | 7270 | for (0..tag_names.len) |tag_index| { |
| 7271 | const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]); | |
| 7271 | const tag_name = tag_names.get(ip)[tag_index]; | |
| 7272 | const tag_name_len = tag_name.length(ip); | |
| 7272 | 7273 | // for each tag name, create an unnamed const, |
| 7273 | 7274 | // and then get a pointer to its value. |
| 7274 | 7275 | const name_ty = try mod.arrayType(.{ |
| 7275 | .len = tag_name.len, | |
| 7276 | .len = tag_name_len, | |
| 7276 | 7277 | .child = .u8_type, |
| 7277 | 7278 | .sentinel = .zero_u8, |
| 7278 | 7279 | }); |
| 7279 | 7280 | const name_val = try mod.intern(.{ .aggregate = .{ |
| 7280 | 7281 | .ty = name_ty.toIntern(), |
| 7281 | .storage = .{ .bytes = tag_name }, | |
| 7282 | .storage = .{ .bytes = tag_name.toString() }, | |
| 7282 | 7283 | } }); |
| 7283 | 7284 | const tag_sym_index = try func.bin_file.lowerUnnamedConst( |
| 7284 | 7285 | Value.fromInterned(name_val), |
| ... | ... | @@ -7338,7 +7339,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7338 | 7339 | |
| 7339 | 7340 | // store length |
| 7340 | 7341 | try writer.writeByte(std.wasm.opcode(.i32_const)); |
| 7341 | try leb.writeULEB128(writer, @as(u32, @intCast(tag_name.len))); | |
| 7342 | try leb.writeULEB128(writer, @as(u32, @intCast(tag_name_len))); | |
| 7342 | 7343 | try writer.writeByte(std.wasm.opcode(.i32_store)); |
| 7343 | 7344 | try leb.writeULEB128(writer, encoded_alignment); |
| 7344 | 7345 | try leb.writeULEB128(writer, @as(u32, 4)); |
| ... | ... | @@ -7359,7 +7360,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7359 | 7360 | |
| 7360 | 7361 | // store length |
| 7361 | 7362 | try writer.writeByte(std.wasm.opcode(.i64_const)); |
| 7362 | try leb.writeULEB128(writer, @as(u64, @intCast(tag_name.len))); | |
| 7363 | try leb.writeULEB128(writer, @as(u64, @intCast(tag_name_len))); | |
| 7363 | 7364 | try writer.writeByte(std.wasm.opcode(.i64_store)); |
| 7364 | 7365 | try leb.writeULEB128(writer, encoded_alignment); |
| 7365 | 7366 | try leb.writeULEB128(writer, @as(u32, 8)); |
src/arch/x86_64/CodeGen.zig+3-3| ... | ... | @@ -2247,7 +2247,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2247 | 2247 | var data_off: i32 = 0; |
| 2248 | 2248 | const tag_names = enum_ty.enumFields(mod); |
| 2249 | 2249 | for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| { |
| 2250 | const tag_name_len = ip.stringToSlice(tag_names.get(ip)[tag_index]).len; | |
| 2250 | const tag_name_len = tag_names.get(ip)[tag_index].length(ip); | |
| 2251 | 2251 | const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 2252 | 2252 | const tag_mcv = try self.genTypedValue(tag_val); |
| 2253 | 2253 | try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv); |
| ... | ... | @@ -12314,8 +12314,8 @@ fn genCall(self: *Self, info: union(enum) { |
| 12314 | 12314 | }, |
| 12315 | 12315 | .extern_func => |extern_func| { |
| 12316 | 12316 | const owner_decl = mod.declPtr(extern_func.decl); |
| 12317 | const lib_name = mod.intern_pool.stringToSliceUnwrap(extern_func.lib_name); | |
| 12318 | const decl_name = mod.intern_pool.stringToSlice(owner_decl.name); | |
| 12317 | const lib_name = extern_func.lib_name.toSlice(&mod.intern_pool); | |
| 12318 | const decl_name = owner_decl.name.toSlice(&mod.intern_pool); | |
| 12319 | 12319 | try self.genExternSymbolRef(.call, lib_name, decl_name); |
| 12320 | 12320 | }, |
| 12321 | 12321 | else => return self.fail("TODO implement calling bitcasted functions", .{}), |
src/codegen.zig+50-57| ... | ... | @@ -97,7 +97,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian |
| 97 | 97 | _ = target; |
| 98 | 98 | const bits = @typeInfo(F).Float.bits; |
| 99 | 99 | const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } }); |
| 100 | const int = @as(Int, @bitCast(f)); | |
| 100 | const int: Int = @bitCast(f); | |
| 101 | 101 | mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian); |
| 102 | 102 | } |
| 103 | 103 | |
| ... | ... | @@ -136,24 +136,24 @@ pub fn generateLazySymbol( |
| 136 | 136 | if (lazy_sym.ty.isAnyError(zcu)) { |
| 137 | 137 | alignment.* = .@"4"; |
| 138 | 138 | const err_names = zcu.global_error_set.keys(); |
| 139 | mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(err_names.len)), endian); | |
| 139 | mem.writeInt(u32, try code.addManyAsArray(4), @intCast(err_names.len), endian); | |
| 140 | 140 | var offset = code.items.len; |
| 141 | 141 | try code.resize((1 + err_names.len + 1) * 4); |
| 142 | 142 | for (err_names) |err_name_nts| { |
| 143 | const err_name = zcu.intern_pool.stringToSlice(err_name_nts); | |
| 144 | mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian); | |
| 143 | const err_name = err_name_nts.toSlice(ip); | |
| 144 | mem.writeInt(u32, code.items[offset..][0..4], @intCast(code.items.len), endian); | |
| 145 | 145 | offset += 4; |
| 146 | 146 | try code.ensureUnusedCapacity(err_name.len + 1); |
| 147 | 147 | code.appendSliceAssumeCapacity(err_name); |
| 148 | 148 | code.appendAssumeCapacity(0); |
| 149 | 149 | } |
| 150 | mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian); | |
| 150 | mem.writeInt(u32, code.items[offset..][0..4], @intCast(code.items.len), endian); | |
| 151 | 151 | return Result.ok; |
| 152 | 152 | } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) { |
| 153 | 153 | alignment.* = .@"1"; |
| 154 | 154 | const tag_names = lazy_sym.ty.enumFields(zcu); |
| 155 | 155 | for (0..tag_names.len) |tag_index| { |
| 156 | const tag_name = zcu.intern_pool.stringToSlice(tag_names.get(ip)[tag_index]); | |
| 156 | const tag_name = tag_names.get(ip)[tag_index].toSlice(ip); | |
| 157 | 157 | try code.ensureUnusedCapacity(tag_name.len + 1); |
| 158 | 158 | code.appendSliceAssumeCapacity(tag_name); |
| 159 | 159 | code.appendAssumeCapacity(0); |
| ... | ... | @@ -241,13 +241,13 @@ pub fn generateSymbol( |
| 241 | 241 | }, |
| 242 | 242 | .err => |err| { |
| 243 | 243 | const int = try mod.getErrorValue(err.name); |
| 244 | try code.writer().writeInt(u16, @as(u16, @intCast(int)), endian); | |
| 244 | try code.writer().writeInt(u16, @intCast(int), endian); | |
| 245 | 245 | }, |
| 246 | 246 | .error_union => |error_union| { |
| 247 | 247 | const payload_ty = ty.errorUnionPayload(mod); |
| 248 | const err_val = switch (error_union.val) { | |
| 249 | .err_name => |err_name| @as(u16, @intCast(try mod.getErrorValue(err_name))), | |
| 250 | .payload => @as(u16, 0), | |
| 248 | const err_val: u16 = switch (error_union.val) { | |
| 249 | .err_name => |err_name| @intCast(try mod.getErrorValue(err_name)), | |
| 250 | .payload => 0, | |
| 251 | 251 | }; |
| 252 | 252 | |
| 253 | 253 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | ... | @@ -357,15 +357,13 @@ pub fn generateSymbol( |
| 357 | 357 | }, |
| 358 | 358 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { |
| 359 | 359 | .array_type => |array_type| switch (aggregate.storage) { |
| 360 | .bytes => |bytes| try code.appendSlice(bytes), | |
| 360 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(array_type.lenIncludingSentinel(), ip)), | |
| 361 | 361 | .elems, .repeated_elem => { |
| 362 | 362 | var index: u64 = 0; |
| 363 | const len_including_sentinel = | |
| 364 | array_type.len + @intFromBool(array_type.sentinel != .none); | |
| 365 | while (index < len_including_sentinel) : (index += 1) { | |
| 363 | while (index < array_type.lenIncludingSentinel()) : (index += 1) { | |
| 366 | 364 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) { |
| 367 | 365 | .bytes => unreachable, |
| 368 | .elems => |elems| elems[@as(usize, @intCast(index))], | |
| 366 | .elems => |elems| elems[@intCast(index)], | |
| 369 | 367 | .repeated_elem => |elem| if (index < array_type.len) |
| 370 | 368 | elem |
| 371 | 369 | else |
| ... | ... | @@ -399,7 +397,7 @@ pub fn generateSymbol( |
| 399 | 397 | }) { |
| 400 | 398 | .bool_true => true, |
| 401 | 399 | .bool_false => false, |
| 402 | else => |elem| switch (mod.intern_pool.indexToKey(elem)) { | |
| 400 | else => |elem| switch (ip.indexToKey(elem)) { | |
| 403 | 401 | .undef => continue, |
| 404 | 402 | .int => |int| switch (int.storage) { |
| 405 | 403 | .u64 => |x| switch (x) { |
| ... | ... | @@ -420,7 +418,7 @@ pub fn generateSymbol( |
| 420 | 418 | } |
| 421 | 419 | } else { |
| 422 | 420 | switch (aggregate.storage) { |
| 423 | .bytes => |bytes| try code.appendSlice(bytes), | |
| 421 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(vector_type.len, ip)), | |
| 424 | 422 | .elems, .repeated_elem => { |
| 425 | 423 | var index: u64 = 0; |
| 426 | 424 | while (index < vector_type.len) : (index += 1) { |
| ... | ... | @@ -457,7 +455,7 @@ pub fn generateSymbol( |
| 457 | 455 | const field_val = switch (aggregate.storage) { |
| 458 | 456 | .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{ |
| 459 | 457 | .ty = field_ty, |
| 460 | .storage = .{ .u64 = bytes[index] }, | |
| 458 | .storage = .{ .u64 = bytes.at(index, ip) }, | |
| 461 | 459 | } }), |
| 462 | 460 | .elems => |elems| elems[index], |
| 463 | 461 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -493,7 +491,7 @@ pub fn generateSymbol( |
| 493 | 491 | const field_val = switch (aggregate.storage) { |
| 494 | 492 | .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{ |
| 495 | 493 | .ty = field_ty, |
| 496 | .storage = .{ .u64 = bytes[index] }, | |
| 494 | .storage = .{ .u64 = bytes.at(index, ip) }, | |
| 497 | 495 | } }), |
| 498 | 496 | .elems => |elems| elems[index], |
| 499 | 497 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -513,7 +511,7 @@ pub fn generateSymbol( |
| 513 | 511 | } else { |
| 514 | 512 | Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), mod, code.items[current_pos..], bits) catch unreachable; |
| 515 | 513 | } |
| 516 | bits += @as(u16, @intCast(Type.fromInterned(field_ty).bitSize(mod))); | |
| 514 | bits += @intCast(Type.fromInterned(field_ty).bitSize(mod)); | |
| 517 | 515 | } |
| 518 | 516 | }, |
| 519 | 517 | .auto, .@"extern" => { |
| ... | ... | @@ -529,7 +527,7 @@ pub fn generateSymbol( |
| 529 | 527 | const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 530 | 528 | .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{ |
| 531 | 529 | .ty = field_ty, |
| 532 | .storage = .{ .u64 = bytes[field_index] }, | |
| 530 | .storage = .{ .u64 = bytes.at(field_index, ip) }, | |
| 533 | 531 | } }), |
| 534 | 532 | .elems => |elems| elems[field_index], |
| 535 | 533 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -625,7 +623,8 @@ fn lowerParentPtr( |
| 625 | 623 | reloc_info: RelocInfo, |
| 626 | 624 | ) CodeGenError!Result { |
| 627 | 625 | const mod = bin_file.comp.module.?; |
| 628 | const ptr = mod.intern_pool.indexToKey(parent_ptr).ptr; | |
| 626 | const ip = &mod.intern_pool; | |
| 627 | const ptr = ip.indexToKey(parent_ptr).ptr; | |
| 629 | 628 | return switch (ptr.addr) { |
| 630 | 629 | .decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info), |
| 631 | 630 | .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info), |
| ... | ... | @@ -636,10 +635,10 @@ fn lowerParentPtr( |
| 636 | 635 | eu_payload, |
| 637 | 636 | code, |
| 638 | 637 | debug_output, |
| 639 | reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset( | |
| 640 | Type.fromInterned(mod.intern_pool.typeOf(eu_payload)), | |
| 638 | reloc_info.offset(@intCast(errUnionPayloadOffset( | |
| 639 | Type.fromInterned(ip.typeOf(eu_payload)), | |
| 641 | 640 | mod, |
| 642 | )))), | |
| 641 | ))), | |
| 643 | 642 | ), |
| 644 | 643 | .opt_payload => |opt_payload| try lowerParentPtr( |
| 645 | 644 | bin_file, |
| ... | ... | @@ -655,19 +654,19 @@ fn lowerParentPtr( |
| 655 | 654 | elem.base, |
| 656 | 655 | code, |
| 657 | 656 | debug_output, |
| 658 | reloc_info.offset(@as(u32, @intCast(elem.index * | |
| 659 | Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))), | |
| 657 | reloc_info.offset(@intCast(elem.index * | |
| 658 | Type.fromInterned(ip.typeOf(elem.base)).elemType2(mod).abiSize(mod))), | |
| 660 | 659 | ), |
| 661 | 660 | .field => |field| { |
| 662 | const base_ptr_ty = mod.intern_pool.typeOf(field.base); | |
| 663 | const base_ty = mod.intern_pool.indexToKey(base_ptr_ty).ptr_type.child; | |
| 661 | const base_ptr_ty = ip.typeOf(field.base); | |
| 662 | const base_ty = ip.indexToKey(base_ptr_ty).ptr_type.child; | |
| 664 | 663 | return lowerParentPtr( |
| 665 | 664 | bin_file, |
| 666 | 665 | src_loc, |
| 667 | 666 | field.base, |
| 668 | 667 | code, |
| 669 | 668 | debug_output, |
| 670 | reloc_info.offset(switch (mod.intern_pool.indexToKey(base_ty)) { | |
| 669 | reloc_info.offset(switch (ip.indexToKey(base_ty)) { | |
| 671 | 670 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 672 | 671 | .One, .Many, .C => unreachable, |
| 673 | 672 | .Slice => switch (field.index) { |
| ... | ... | @@ -723,11 +722,12 @@ fn lowerAnonDeclRef( |
| 723 | 722 | ) CodeGenError!Result { |
| 724 | 723 | _ = debug_output; |
| 725 | 724 | const zcu = lf.comp.module.?; |
| 725 | const ip = &zcu.intern_pool; | |
| 726 | 726 | const target = lf.comp.root_mod.resolved_target.result; |
| 727 | 727 | |
| 728 | 728 | const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8); |
| 729 | 729 | const decl_val = anon_decl.val; |
| 730 | const decl_ty = Type.fromInterned(zcu.intern_pool.typeOf(decl_val)); | |
| 730 | const decl_ty = Type.fromInterned(ip.typeOf(decl_val)); | |
| 731 | 731 | log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(zcu)}); |
| 732 | 732 | const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn; |
| 733 | 733 | if (!is_fn_body and !decl_ty.hasRuntimeBits(zcu)) { |
| ... | ... | @@ -735,7 +735,7 @@ fn lowerAnonDeclRef( |
| 735 | 735 | return Result.ok; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | const decl_align = zcu.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment; | |
| 738 | const decl_align = ip.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment; | |
| 739 | 739 | const res = try lf.lowerAnonDecl(decl_val, decl_align, src_loc); |
| 740 | 740 | switch (res) { |
| 741 | 741 | .ok => {}, |
| ... | ... | @@ -787,8 +787,8 @@ fn lowerDeclRef( |
| 787 | 787 | }); |
| 788 | 788 | const endian = target.cpu.arch.endian(); |
| 789 | 789 | switch (ptr_width) { |
| 790 | 16 => mem.writeInt(u16, try code.addManyAsArray(2), @as(u16, @intCast(vaddr)), endian), | |
| 791 | 32 => mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(vaddr)), endian), | |
| 790 | 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian), | |
| 791 | 32 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian), | |
| 792 | 792 | 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian), |
| 793 | 793 | else => unreachable, |
| 794 | 794 | } |
| ... | ... | @@ -859,6 +859,7 @@ fn genDeclRef( |
| 859 | 859 | ptr_decl_index: InternPool.DeclIndex, |
| 860 | 860 | ) CodeGenError!GenResult { |
| 861 | 861 | const zcu = lf.comp.module.?; |
| 862 | const ip = &zcu.intern_pool; | |
| 862 | 863 | const ty = val.typeOf(zcu); |
| 863 | 864 | log.debug("genDeclRef: val = {}", .{val.fmtValue(zcu)}); |
| 864 | 865 | |
| ... | ... | @@ -869,7 +870,7 @@ fn genDeclRef( |
| 869 | 870 | const ptr_bits = target.ptrBitWidth(); |
| 870 | 871 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); |
| 871 | 872 | |
| 872 | const decl_index = switch (zcu.intern_pool.indexToKey(ptr_decl.val.toIntern())) { | |
| 873 | const decl_index = switch (ip.indexToKey(ptr_decl.val.toIntern())) { | |
| 873 | 874 | .func => |func| func.owner_decl, |
| 874 | 875 | .extern_func => |extern_func| extern_func.decl, |
| 875 | 876 | else => ptr_decl_index, |
| ... | ... | @@ -909,12 +910,9 @@ fn genDeclRef( |
| 909 | 910 | |
| 910 | 911 | if (lf.cast(link.File.Elf)) |elf_file| { |
| 911 | 912 | if (is_extern) { |
| 912 | const name = zcu.intern_pool.stringToSlice(decl.name); | |
| 913 | const name = decl.name.toSlice(ip); | |
| 913 | 914 | // TODO audit this |
| 914 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| | |
| 915 | zcu.intern_pool.stringToSliceUnwrap(ov.lib_name) | |
| 916 | else | |
| 917 | null; | |
| 915 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null; | |
| 918 | 916 | const sym_index = try elf_file.getGlobalSymbol(name, lib_name); |
| 919 | 917 | elf_file.symbol(elf_file.zigObjectPtr().?.symbol(sym_index)).flags.needs_got = true; |
| 920 | 918 | return GenResult.mcv(.{ .load_symbol = sym_index }); |
| ... | ... | @@ -927,11 +925,8 @@ fn genDeclRef( |
| 927 | 925 | return GenResult.mcv(.{ .load_symbol = sym.esym_index }); |
| 928 | 926 | } else if (lf.cast(link.File.MachO)) |macho_file| { |
| 929 | 927 | if (is_extern) { |
| 930 | const name = zcu.intern_pool.stringToSlice(decl.name); | |
| 931 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| | |
| 932 | zcu.intern_pool.stringToSliceUnwrap(ov.lib_name) | |
| 933 | else | |
| 934 | null; | |
| 928 | const name = decl.name.toSlice(ip); | |
| 929 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null; | |
| 935 | 930 | const sym_index = try macho_file.getGlobalSymbol(name, lib_name); |
| 936 | 931 | macho_file.getSymbol(macho_file.getZigObject().?.symbols.items[sym_index]).flags.needs_got = true; |
| 937 | 932 | return GenResult.mcv(.{ .load_symbol = sym_index }); |
| ... | ... | @@ -944,12 +939,9 @@ fn genDeclRef( |
| 944 | 939 | return GenResult.mcv(.{ .load_symbol = sym.nlist_idx }); |
| 945 | 940 | } else if (lf.cast(link.File.Coff)) |coff_file| { |
| 946 | 941 | if (is_extern) { |
| 947 | const name = zcu.intern_pool.stringToSlice(decl.name); | |
| 942 | const name = decl.name.toSlice(ip); | |
| 948 | 943 | // TODO audit this |
| 949 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| | |
| 950 | zcu.intern_pool.stringToSliceUnwrap(ov.lib_name) | |
| 951 | else | |
| 952 | null; | |
| 944 | const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null; | |
| 953 | 945 | const global_index = try coff_file.getGlobalSymbol(name, lib_name); |
| 954 | 946 | try coff_file.need_got_table.put(gpa, global_index, {}); // needs GOT |
| 955 | 947 | return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index }); |
| ... | ... | @@ -1012,6 +1004,7 @@ pub fn genTypedValue( |
| 1012 | 1004 | owner_decl_index: InternPool.DeclIndex, |
| 1013 | 1005 | ) CodeGenError!GenResult { |
| 1014 | 1006 | const zcu = lf.comp.module.?; |
| 1007 | const ip = &zcu.intern_pool; | |
| 1015 | 1008 | const ty = val.typeOf(zcu); |
| 1016 | 1009 | |
| 1017 | 1010 | log.debug("genTypedValue: val = {}", .{val.fmtValue(zcu)}); |
| ... | ... | @@ -1024,7 +1017,7 @@ pub fn genTypedValue( |
| 1024 | 1017 | const target = namespace.file_scope.mod.resolved_target.result; |
| 1025 | 1018 | const ptr_bits = target.ptrBitWidth(); |
| 1026 | 1019 | |
| 1027 | if (!ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(val.toIntern())) { | |
| 1020 | if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) { | |
| 1028 | 1021 | .ptr => |ptr| switch (ptr.addr) { |
| 1029 | 1022 | .decl => |decl| return genDeclRef(lf, src_loc, val, decl), |
| 1030 | 1023 | else => {}, |
| ... | ... | @@ -1041,7 +1034,7 @@ pub fn genTypedValue( |
| 1041 | 1034 | return GenResult.mcv(.{ .immediate = 0 }); |
| 1042 | 1035 | }, |
| 1043 | 1036 | .none => {}, |
| 1044 | else => switch (zcu.intern_pool.indexToKey(val.toIntern())) { | |
| 1037 | else => switch (ip.indexToKey(val.toIntern())) { | |
| 1045 | 1038 | .int => { |
| 1046 | 1039 | return GenResult.mcv(.{ .immediate = val.toUnsignedInt(zcu) }); |
| 1047 | 1040 | }, |
| ... | ... | @@ -1052,8 +1045,8 @@ pub fn genTypedValue( |
| 1052 | 1045 | .Int => { |
| 1053 | 1046 | const info = ty.intInfo(zcu); |
| 1054 | 1047 | if (info.bits <= ptr_bits) { |
| 1055 | const unsigned = switch (info.signedness) { | |
| 1056 | .signed => @as(u64, @bitCast(val.toSignedInt(zcu))), | |
| 1048 | const unsigned: u64 = switch (info.signedness) { | |
| 1049 | .signed => @bitCast(val.toSignedInt(zcu)), | |
| 1057 | 1050 | .unsigned => val.toUnsignedInt(zcu), |
| 1058 | 1051 | }; |
| 1059 | 1052 | return GenResult.mcv(.{ .immediate = unsigned }); |
| ... | ... | @@ -1075,7 +1068,7 @@ pub fn genTypedValue( |
| 1075 | 1068 | } |
| 1076 | 1069 | }, |
| 1077 | 1070 | .Enum => { |
| 1078 | const enum_tag = zcu.intern_pool.indexToKey(val.toIntern()).enum_tag; | |
| 1071 | const enum_tag = ip.indexToKey(val.toIntern()).enum_tag; | |
| 1079 | 1072 | return genTypedValue( |
| 1080 | 1073 | lf, |
| 1081 | 1074 | src_loc, |
| ... | ... | @@ -1084,7 +1077,7 @@ pub fn genTypedValue( |
| 1084 | 1077 | ); |
| 1085 | 1078 | }, |
| 1086 | 1079 | .ErrorSet => { |
| 1087 | const err_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name; | |
| 1080 | const err_name = ip.indexToKey(val.toIntern()).err.name; | |
| 1088 | 1081 | const error_index = zcu.global_error_set.getIndex(err_name).?; |
| 1089 | 1082 | return GenResult.mcv(.{ .immediate = error_index }); |
| 1090 | 1083 | }, |
| ... | ... | @@ -1094,7 +1087,7 @@ pub fn genTypedValue( |
| 1094 | 1087 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1095 | 1088 | // We use the error type directly as the type. |
| 1096 | 1089 | const err_int_ty = try zcu.errorIntType(); |
| 1097 | switch (zcu.intern_pool.indexToKey(val.toIntern()).error_union.val) { | |
| 1090 | switch (ip.indexToKey(val.toIntern()).error_union.val) { | |
| 1098 | 1091 | .err_name => |err_name| return genTypedValue( |
| 1099 | 1092 | lf, |
| 1100 | 1093 | src_loc, |
src/codegen/c.zig+73-105| ... | ... | @@ -505,7 +505,7 @@ pub const Function = struct { |
| 505 | 505 | .never_inline, |
| 506 | 506 | => |owner_decl| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{ |
| 507 | 507 | @tagName(key), |
| 508 | fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(owner_decl).name)), | |
| 508 | fmtIdent(zcu.declPtr(owner_decl).name.toSlice(&zcu.intern_pool)), | |
| 509 | 509 | @intFromEnum(owner_decl), |
| 510 | 510 | }), |
| 511 | 511 | }, |
| ... | ... | @@ -822,19 +822,6 @@ pub const DeclGen = struct { |
| 822 | 822 | try dg.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset), .Other), |
| 823 | 823 | }); |
| 824 | 824 | }, |
| 825 | .end => { | |
| 826 | const ptr_base_ctype = try dg.ctypeFromType(ptr_base_ty, .complete); | |
| 827 | if (!ptr_ctype.eql(ptr_base_ctype)) { | |
| 828 | try writer.writeByte('('); | |
| 829 | try dg.renderCType(writer, ptr_ctype); | |
| 830 | try writer.writeByte(')'); | |
| 831 | } | |
| 832 | try writer.writeAll("(("); | |
| 833 | try dg.renderParentPtr(writer, field.base, location); | |
| 834 | try writer.print(") + {})", .{ | |
| 835 | try dg.fmtIntLiteral(try zcu.intValue(Type.usize, 1), .Other), | |
| 836 | }); | |
| 837 | }, | |
| 838 | 825 | } |
| 839 | 826 | }, |
| 840 | 827 | .comptime_field, .comptime_alloc => unreachable, |
| ... | ... | @@ -911,7 +898,7 @@ pub const DeclGen = struct { |
| 911 | 898 | }, |
| 912 | 899 | }, |
| 913 | 900 | .err => |err| try writer.print("zig_error_{}", .{ |
| 914 | fmtIdent(ip.stringToSlice(err.name)), | |
| 901 | fmtIdent(err.name.toSlice(ip)), | |
| 915 | 902 | }), |
| 916 | 903 | .error_union => |error_union| { |
| 917 | 904 | const payload_ty = ty.errorUnionPayload(zcu); |
| ... | ... | @@ -1191,7 +1178,7 @@ pub const DeclGen = struct { |
| 1191 | 1178 | switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 1192 | 1179 | .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{ |
| 1193 | 1180 | .ty = field_ty.toIntern(), |
| 1194 | .storage = .{ .u64 = bytes[field_index] }, | |
| 1181 | .storage = .{ .u64 = bytes.at(field_index, ip) }, | |
| 1195 | 1182 | } }), |
| 1196 | 1183 | .elems => |elems| elems[field_index], |
| 1197 | 1184 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1225,7 +1212,7 @@ pub const DeclGen = struct { |
| 1225 | 1212 | const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 1226 | 1213 | .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{ |
| 1227 | 1214 | .ty = field_ty.toIntern(), |
| 1228 | .storage = .{ .u64 = bytes[field_index] }, | |
| 1215 | .storage = .{ .u64 = bytes.at(field_index, ip) }, | |
| 1229 | 1216 | } }), |
| 1230 | 1217 | .elems => |elems| elems[field_index], |
| 1231 | 1218 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1271,7 +1258,7 @@ pub const DeclGen = struct { |
| 1271 | 1258 | const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 1272 | 1259 | .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{ |
| 1273 | 1260 | .ty = field_ty.toIntern(), |
| 1274 | .storage = .{ .u64 = bytes[field_index] }, | |
| 1261 | .storage = .{ .u64 = bytes.at(field_index, ip) }, | |
| 1275 | 1262 | } }), |
| 1276 | 1263 | .elems => |elems| elems[field_index], |
| 1277 | 1264 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1312,7 +1299,7 @@ pub const DeclGen = struct { |
| 1312 | 1299 | const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { |
| 1313 | 1300 | .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{ |
| 1314 | 1301 | .ty = field_ty.toIntern(), |
| 1315 | .storage = .{ .u64 = bytes[field_index] }, | |
| 1302 | .storage = .{ .u64 = bytes.at(field_index, ip) }, | |
| 1316 | 1303 | } }), |
| 1317 | 1304 | .elems => |elems| elems[field_index], |
| 1318 | 1305 | .repeated_elem => |elem| elem, |
| ... | ... | @@ -1405,7 +1392,7 @@ pub const DeclGen = struct { |
| 1405 | 1392 | try writer.writeAll(" .payload = {"); |
| 1406 | 1393 | } |
| 1407 | 1394 | if (field_ty.hasRuntimeBits(zcu)) { |
| 1408 | try writer.print(" .{ } = ", .{fmtIdent(ip.stringToSlice(field_name))}); | |
| 1395 | try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))}); | |
| 1409 | 1396 | try dg.renderValue(writer, Value.fromInterned(un.val), initializer_type); |
| 1410 | 1397 | try writer.writeByte(' '); |
| 1411 | 1398 | } else for (0..loaded_union.field_types.len) |this_field_index| { |
| ... | ... | @@ -1754,14 +1741,12 @@ pub const DeclGen = struct { |
| 1754 | 1741 | switch (name) { |
| 1755 | 1742 | .export_index => |export_index| mangled: { |
| 1756 | 1743 | const maybe_exports = zcu.decl_exports.get(fn_decl_index); |
| 1757 | const external_name = ip.stringToSlice( | |
| 1758 | if (maybe_exports) |exports| | |
| 1759 | exports.items[export_index].opts.name | |
| 1760 | else if (fn_decl.isExtern(zcu)) | |
| 1761 | fn_decl.name | |
| 1762 | else | |
| 1763 | break :mangled, | |
| 1764 | ); | |
| 1744 | const external_name = (if (maybe_exports) |exports| | |
| 1745 | exports.items[export_index].opts.name | |
| 1746 | else if (fn_decl.isExtern(zcu)) | |
| 1747 | fn_decl.name | |
| 1748 | else | |
| 1749 | break :mangled).toSlice(ip); | |
| 1765 | 1750 | const is_mangled = isMangledIdent(external_name, true); |
| 1766 | 1751 | const is_export = export_index > 0; |
| 1767 | 1752 | if (is_mangled and is_export) { |
| ... | ... | @@ -1769,7 +1754,7 @@ pub const DeclGen = struct { |
| 1769 | 1754 | fmtIdent(external_name), |
| 1770 | 1755 | fmtStringLiteral(external_name, null), |
| 1771 | 1756 | fmtStringLiteral( |
| 1772 | ip.stringToSlice(maybe_exports.?.items[0].opts.name), | |
| 1757 | maybe_exports.?.items[0].opts.name.toSlice(ip), | |
| 1773 | 1758 | null, |
| 1774 | 1759 | ), |
| 1775 | 1760 | }); |
| ... | ... | @@ -1780,7 +1765,7 @@ pub const DeclGen = struct { |
| 1780 | 1765 | } else if (is_export) { |
| 1781 | 1766 | try w.print(" zig_export({s}, {s})", .{ |
| 1782 | 1767 | fmtStringLiteral( |
| 1783 | ip.stringToSlice(maybe_exports.?.items[0].opts.name), | |
| 1768 | maybe_exports.?.items[0].opts.name.toSlice(ip), | |
| 1784 | 1769 | null, |
| 1785 | 1770 | ), |
| 1786 | 1771 | fmtStringLiteral(external_name, null), |
| ... | ... | @@ -2088,12 +2073,12 @@ pub const DeclGen = struct { |
| 2088 | 2073 | .complete, |
| 2089 | 2074 | ); |
| 2090 | 2075 | mangled: { |
| 2091 | const external_name = zcu.intern_pool.stringToSlice(if (maybe_exports) |exports| | |
| 2076 | const external_name = (if (maybe_exports) |exports| | |
| 2092 | 2077 | exports.items[0].opts.name |
| 2093 | 2078 | else if (variable.is_extern) |
| 2094 | 2079 | decl.name |
| 2095 | 2080 | else |
| 2096 | break :mangled); | |
| 2081 | break :mangled).toSlice(&zcu.intern_pool); | |
| 2097 | 2082 | if (isMangledIdent(external_name, true)) { |
| 2098 | 2083 | try fwd.print(" zig_mangled_{s}({ }, {s})", .{ |
| 2099 | 2084 | @tagName(fwd_kind), |
| ... | ... | @@ -2107,15 +2092,16 @@ pub const DeclGen = struct { |
| 2107 | 2092 | |
| 2108 | 2093 | fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void { |
| 2109 | 2094 | const zcu = dg.zcu; |
| 2095 | const ip = &zcu.intern_pool; | |
| 2110 | 2096 | const decl = zcu.declPtr(decl_index); |
| 2111 | 2097 | |
| 2112 | 2098 | if (zcu.decl_exports.get(decl_index)) |exports| { |
| 2113 | 2099 | try writer.print("{ }", .{ |
| 2114 | fmtIdent(zcu.intern_pool.stringToSlice(exports.items[export_index].opts.name)), | |
| 2100 | fmtIdent(exports.items[export_index].opts.name.toSlice(ip)), | |
| 2115 | 2101 | }); |
| 2116 | 2102 | } else if (decl.getExternDecl(zcu).unwrap()) |extern_decl_index| { |
| 2117 | 2103 | try writer.print("{ }", .{ |
| 2118 | fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(extern_decl_index).name)), | |
| 2104 | fmtIdent(zcu.declPtr(extern_decl_index).name.toSlice(ip)), | |
| 2119 | 2105 | }); |
| 2120 | 2106 | } else { |
| 2121 | 2107 | // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case), |
| ... | ... | @@ -2239,7 +2225,7 @@ fn renderFwdDeclTypeName( |
| 2239 | 2225 | switch (fwd_decl.name) { |
| 2240 | 2226 | .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}), |
| 2241 | 2227 | .owner_decl => |owner_decl| try w.print("{}__{d}", .{ |
| 2242 | fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(owner_decl).name)), | |
| 2228 | fmtIdent(zcu.declPtr(owner_decl).name.toSlice(&zcu.intern_pool)), | |
| 2243 | 2229 | @intFromEnum(owner_decl), |
| 2244 | 2230 | }), |
| 2245 | 2231 | } |
| ... | ... | @@ -2561,7 +2547,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2561 | 2547 | try writer.writeAll("enum {\n"); |
| 2562 | 2548 | o.indent_writer.pushIndent(); |
| 2563 | 2549 | for (zcu.global_error_set.keys()[1..], 1..) |name_nts, value| { |
| 2564 | const name = ip.stringToSlice(name_nts); | |
| 2550 | const name = name_nts.toSlice(ip); | |
| 2565 | 2551 | max_name_len = @max(name.len, max_name_len); |
| 2566 | 2552 | const err_val = try zcu.intern(.{ .err = .{ |
| 2567 | 2553 | .ty = .anyerror_type, |
| ... | ... | @@ -2579,19 +2565,19 @@ pub fn genErrDecls(o: *Object) !void { |
| 2579 | 2565 | defer o.dg.gpa.free(name_buf); |
| 2580 | 2566 | |
| 2581 | 2567 | @memcpy(name_buf[0..name_prefix.len], name_prefix); |
| 2582 | for (zcu.global_error_set.keys()) |name_ip| { | |
| 2583 | const name = ip.stringToSlice(name_ip); | |
| 2584 | @memcpy(name_buf[name_prefix.len..][0..name.len], name); | |
| 2585 | const identifier = name_buf[0 .. name_prefix.len + name.len]; | |
| 2568 | for (zcu.global_error_set.keys()) |name| { | |
| 2569 | const name_slice = name.toSlice(ip); | |
| 2570 | @memcpy(name_buf[name_prefix.len..][0..name_slice.len], name_slice); | |
| 2571 | const identifier = name_buf[0 .. name_prefix.len + name_slice.len]; | |
| 2586 | 2572 | |
| 2587 | 2573 | const name_ty = try zcu.arrayType(.{ |
| 2588 | .len = name.len, | |
| 2574 | .len = name_slice.len, | |
| 2589 | 2575 | .child = .u8_type, |
| 2590 | 2576 | .sentinel = .zero_u8, |
| 2591 | 2577 | }); |
| 2592 | 2578 | const name_val = try zcu.intern(.{ .aggregate = .{ |
| 2593 | 2579 | .ty = name_ty.toIntern(), |
| 2594 | .storage = .{ .bytes = name }, | |
| 2580 | .storage = .{ .bytes = name.toString() }, | |
| 2595 | 2581 | } }); |
| 2596 | 2582 | |
| 2597 | 2583 | try writer.writeAll("static "); |
| ... | ... | @@ -2624,7 +2610,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2624 | 2610 | ); |
| 2625 | 2611 | try writer.writeAll(" = {"); |
| 2626 | 2612 | for (zcu.global_error_set.keys(), 0..) |name_nts, value| { |
| 2627 | const name = ip.stringToSlice(name_nts); | |
| 2613 | const name = name_nts.toSlice(ip); | |
| 2628 | 2614 | if (value != 0) try writer.writeByte(','); |
| 2629 | 2615 | try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{ |
| 2630 | 2616 | fmtIdent(name), |
| ... | ... | @@ -2672,7 +2658,7 @@ fn genExports(o: *Object) !void { |
| 2672 | 2658 | for (exports.items[1..]) |@"export"| { |
| 2673 | 2659 | try fwd.writeAll("zig_extern "); |
| 2674 | 2660 | if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage "); |
| 2675 | const export_name = ip.stringToSlice(@"export".opts.name); | |
| 2661 | const export_name = @"export".opts.name.toSlice(ip); | |
| 2676 | 2662 | try o.dg.renderTypeAndName( |
| 2677 | 2663 | fwd, |
| 2678 | 2664 | decl.typeOf(zcu), |
| ... | ... | @@ -2685,11 +2671,11 @@ fn genExports(o: *Object) !void { |
| 2685 | 2671 | try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{ |
| 2686 | 2672 | fmtIdent(export_name), |
| 2687 | 2673 | fmtStringLiteral(export_name, null), |
| 2688 | fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null), | |
| 2674 | fmtStringLiteral(exports.items[0].opts.name.toSlice(ip), null), | |
| 2689 | 2675 | }); |
| 2690 | 2676 | } else { |
| 2691 | 2677 | try fwd.print(" zig_export({s}, {s})", .{ |
| 2692 | fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null), | |
| 2678 | fmtStringLiteral(exports.items[0].opts.name.toSlice(ip), null), | |
| 2693 | 2679 | fmtStringLiteral(export_name, null), |
| 2694 | 2680 | }); |
| 2695 | 2681 | } |
| ... | ... | @@ -2719,17 +2705,18 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn |
| 2719 | 2705 | try w.writeAll(") {\n switch (tag) {\n"); |
| 2720 | 2706 | const tag_names = enum_ty.enumFields(zcu); |
| 2721 | 2707 | for (0..tag_names.len) |tag_index| { |
| 2722 | const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]); | |
| 2708 | const tag_name = tag_names.get(ip)[tag_index]; | |
| 2709 | const tag_name_len = tag_name.length(ip); | |
| 2723 | 2710 | const tag_val = try zcu.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 2724 | 2711 | |
| 2725 | 2712 | const name_ty = try zcu.arrayType(.{ |
| 2726 | .len = tag_name.len, | |
| 2713 | .len = tag_name_len, | |
| 2727 | 2714 | .child = .u8_type, |
| 2728 | 2715 | .sentinel = .zero_u8, |
| 2729 | 2716 | }); |
| 2730 | 2717 | const name_val = try zcu.intern(.{ .aggregate = .{ |
| 2731 | 2718 | .ty = name_ty.toIntern(), |
| 2732 | .storage = .{ .bytes = tag_name }, | |
| 2719 | .storage = .{ .bytes = tag_name.toString() }, | |
| 2733 | 2720 | } }); |
| 2734 | 2721 | |
| 2735 | 2722 | try w.print(" case {}: {{\n static ", .{ |
| ... | ... | @@ -2742,7 +2729,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn |
| 2742 | 2729 | try o.dg.renderType(w, name_slice_ty); |
| 2743 | 2730 | try w.print("){{{}, {}}};\n", .{ |
| 2744 | 2731 | fmtIdent("name"), |
| 2745 | try o.dg.fmtIntLiteral(try zcu.intValue(Type.usize, tag_name.len), .Other), | |
| 2732 | try o.dg.fmtIntLiteral(try zcu.intValue(Type.usize, tag_name_len), .Other), | |
| 2746 | 2733 | }); |
| 2747 | 2734 | |
| 2748 | 2735 | try w.writeAll(" }\n"); |
| ... | ... | @@ -2810,7 +2797,7 @@ pub fn genFunc(f: *Function) !void { |
| 2810 | 2797 | |
| 2811 | 2798 | try o.indent_writer.insertNewline(); |
| 2812 | 2799 | if (!is_global) try o.writer().writeAll("static "); |
| 2813 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s| | |
| 2800 | if (decl.@"linksection".toSlice(&zcu.intern_pool)) |s| | |
| 2814 | 2801 | try o.writer().print("zig_linksection_fn({s}) ", .{fmtStringLiteral(s, null)}); |
| 2815 | 2802 | try o.dg.renderFunctionSignature(o.writer(), decl_index, .complete, .{ .export_index = 0 }); |
| 2816 | 2803 | try o.writer().writeByte(' '); |
| ... | ... | @@ -2900,7 +2887,7 @@ pub fn genDecl(o: *Object) !void { |
| 2900 | 2887 | if (!is_global) try w.writeAll("static "); |
| 2901 | 2888 | if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage "); |
| 2902 | 2889 | if (variable.is_threadlocal and !o.dg.mod.single_threaded) try w.writeAll("zig_threadlocal "); |
| 2903 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s| | |
| 2890 | if (decl.@"linksection".toSlice(&zcu.intern_pool)) |s| | |
| 2904 | 2891 | try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)}); |
| 2905 | 2892 | const decl_c_value = .{ .decl = decl_index }; |
| 2906 | 2893 | try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete); |
| ... | ... | @@ -2933,7 +2920,7 @@ pub fn genDeclValue( |
| 2933 | 2920 | switch (o.dg.pass) { |
| 2934 | 2921 | .decl => |decl_index| { |
| 2935 | 2922 | if (zcu.decl_exports.get(decl_index)) |exports| { |
| 2936 | const export_name = zcu.intern_pool.stringToSlice(exports.items[0].opts.name); | |
| 2923 | const export_name = exports.items[0].opts.name.toSlice(&zcu.intern_pool); | |
| 2937 | 2924 | if (isMangledIdent(export_name, true)) { |
| 2938 | 2925 | try fwd_decl_writer.print(" zig_mangled_final({ }, {s})", .{ |
| 2939 | 2926 | fmtIdent(export_name), fmtStringLiteral(export_name, null), |
| ... | ... | @@ -2949,7 +2936,7 @@ pub fn genDeclValue( |
| 2949 | 2936 | |
| 2950 | 2937 | const w = o.writer(); |
| 2951 | 2938 | if (!is_global) try w.writeAll("static "); |
| 2952 | if (zcu.intern_pool.stringToSliceUnwrap(@"linksection")) |s| | |
| 2939 | if (@"linksection".toSlice(&zcu.intern_pool)) |s| | |
| 2953 | 2940 | try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)}); |
| 2954 | 2941 | try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete); |
| 2955 | 2942 | try w.writeAll(" = "); |
| ... | ... | @@ -5453,49 +5440,39 @@ fn fieldLocation( |
| 5453 | 5440 | ) union(enum) { |
| 5454 | 5441 | begin: void, |
| 5455 | 5442 | field: CValue, |
| 5456 | byte_offset: u32, | |
| 5457 | end: void, | |
| 5443 | byte_offset: u64, | |
| 5458 | 5444 | } { |
| 5459 | 5445 | const ip = &zcu.intern_pool; |
| 5460 | 5446 | const container_ty = Type.fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child); |
| 5461 | 5447 | switch (ip.indexToKey(container_ty.toIntern())) { |
| 5462 | 5448 | .struct_type => { |
| 5463 | 5449 | const loaded_struct = ip.loadStructType(container_ty.toIntern()); |
| 5464 | switch (loaded_struct.layout) { | |
| 5465 | .auto, .@"extern" => { | |
| 5466 | var field_it = loaded_struct.iterateRuntimeOrder(ip); | |
| 5467 | var before = true; | |
| 5468 | while (field_it.next()) |next_field_index| { | |
| 5469 | if (next_field_index == field_index) before = false; | |
| 5470 | if (before) continue; | |
| 5471 | const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[next_field_index]); | |
| 5472 | if (!field_type.hasRuntimeBitsIgnoreComptime(zcu)) continue; | |
| 5473 | return .{ .field = if (loaded_struct.fieldName(ip, next_field_index).unwrap()) |field_name| | |
| 5474 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 5475 | else | |
| 5476 | .{ .field = next_field_index } }; | |
| 5477 | } | |
| 5478 | return if (container_ty.hasRuntimeBitsIgnoreComptime(zcu)) .end else .begin; | |
| 5479 | }, | |
| 5480 | .@"packed" => return if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0) | |
| 5450 | return switch (loaded_struct.layout) { | |
| 5451 | .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu)) | |
| 5452 | .begin | |
| 5453 | else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu)) | |
| 5454 | .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] } | |
| 5455 | else | |
| 5456 | .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| | |
| 5457 | .{ .identifier = field_name.toSlice(ip) } | |
| 5458 | else | |
| 5459 | .{ .field = field_index } }, | |
| 5460 | .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0) | |
| 5481 | 5461 | .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) + |
| 5482 | 5462 | container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) } |
| 5483 | 5463 | else |
| 5484 | 5464 | .begin, |
| 5485 | } | |
| 5486 | }, | |
| 5487 | .anon_struct_type => |anon_struct_info| { | |
| 5488 | for (field_index..anon_struct_info.types.len) |next_field_index| { | |
| 5489 | if (anon_struct_info.values.get(ip)[next_field_index] != .none) continue; | |
| 5490 | const field_type = Type.fromInterned(anon_struct_info.types.get(ip)[next_field_index]); | |
| 5491 | if (!field_type.hasRuntimeBitsIgnoreComptime(zcu)) continue; | |
| 5492 | return .{ .field = if (anon_struct_info.fieldName(ip, next_field_index).unwrap()) |field_name| | |
| 5493 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 5494 | else | |
| 5495 | .{ .field = next_field_index } }; | |
| 5496 | } | |
| 5497 | return if (container_ty.hasRuntimeBitsIgnoreComptime(zcu)) .end else .begin; | |
| 5465 | }; | |
| 5498 | 5466 | }, |
| 5467 | .anon_struct_type => |anon_struct_info| return if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu)) | |
| 5468 | .begin | |
| 5469 | else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu)) | |
| 5470 | .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) } | |
| 5471 | else | |
| 5472 | .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name| | |
| 5473 | .{ .identifier = field_name.toSlice(ip) } | |
| 5474 | else | |
| 5475 | .{ .field = field_index } }, | |
| 5499 | 5476 | .union_type => { |
| 5500 | 5477 | const loaded_union = ip.loadUnionType(container_ty.toIntern()); |
| 5501 | 5478 | switch (loaded_union.getLayout(ip)) { |
| ... | ... | @@ -5508,9 +5485,9 @@ fn fieldLocation( |
| 5508 | 5485 | .begin; |
| 5509 | 5486 | const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index]; |
| 5510 | 5487 | return .{ .field = if (loaded_union.hasTag(ip)) |
| 5511 | .{ .payload_identifier = ip.stringToSlice(field_name) } | |
| 5488 | .{ .payload_identifier = field_name.toSlice(ip) } | |
| 5512 | 5489 | else |
| 5513 | .{ .identifier = ip.stringToSlice(field_name) } }; | |
| 5490 | .{ .identifier = field_name.toSlice(ip) } }; | |
| 5514 | 5491 | }, |
| 5515 | 5492 | .@"packed" => return .begin, |
| 5516 | 5493 | } |
| ... | ... | @@ -5591,10 +5568,6 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5591 | 5568 | try f.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset)), |
| 5592 | 5569 | }); |
| 5593 | 5570 | }, |
| 5594 | .end => { | |
| 5595 | try f.writeCValue(writer, field_ptr_val, .Other); | |
| 5596 | try writer.print(" - {}", .{try f.fmtIntLiteral(try zcu.intValue(Type.usize, 1))}); | |
| 5597 | }, | |
| 5598 | 5571 | } |
| 5599 | 5572 | |
| 5600 | 5573 | try writer.writeAll(";\n"); |
| ... | ... | @@ -5639,11 +5612,6 @@ fn fieldPtr( |
| 5639 | 5612 | try f.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset)), |
| 5640 | 5613 | }); |
| 5641 | 5614 | }, |
| 5642 | .end => { | |
| 5643 | try writer.writeByte('('); | |
| 5644 | try f.writeCValue(writer, container_ptr_val, .Other); | |
| 5645 | try writer.print(" + {})", .{try f.fmtIntLiteral(try zcu.intValue(Type.usize, 1))}); | |
| 5646 | }, | |
| 5647 | 5615 | } |
| 5648 | 5616 | |
| 5649 | 5617 | try writer.writeAll(";\n"); |
| ... | ... | @@ -5675,7 +5643,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5675 | 5643 | const loaded_struct = ip.loadStructType(struct_ty.toIntern()); |
| 5676 | 5644 | switch (loaded_struct.layout) { |
| 5677 | 5645 | .auto, .@"extern" => break :field_name if (loaded_struct.fieldName(ip, extra.field_index).unwrap()) |field_name| |
| 5678 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 5646 | .{ .identifier = field_name.toSlice(ip) } | |
| 5679 | 5647 | else |
| 5680 | 5648 | .{ .field = extra.field_index }, |
| 5681 | 5649 | .@"packed" => { |
| ... | ... | @@ -5733,7 +5701,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5733 | 5701 | } |
| 5734 | 5702 | }, |
| 5735 | 5703 | .anon_struct_type => |anon_struct_info| if (anon_struct_info.fieldName(ip, extra.field_index).unwrap()) |field_name| |
| 5736 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 5704 | .{ .identifier = field_name.toSlice(ip) } | |
| 5737 | 5705 | else |
| 5738 | 5706 | .{ .field = extra.field_index }, |
| 5739 | 5707 | .union_type => field_name: { |
| ... | ... | @@ -5742,9 +5710,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5742 | 5710 | .auto, .@"extern" => { |
| 5743 | 5711 | const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index]; |
| 5744 | 5712 | break :field_name if (loaded_union.hasTag(ip)) |
| 5745 | .{ .payload_identifier = ip.stringToSlice(name) } | |
| 5713 | .{ .payload_identifier = name.toSlice(ip) } | |
| 5746 | 5714 | else |
| 5747 | .{ .identifier = ip.stringToSlice(name) }; | |
| 5715 | .{ .identifier = name.toSlice(ip) }; | |
| 5748 | 5716 | }, |
| 5749 | 5717 | .@"packed" => { |
| 5750 | 5718 | const operand_lval = if (struct_byval == .constant) blk: { |
| ... | ... | @@ -7094,7 +7062,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7094 | 7062 | |
| 7095 | 7063 | const a = try Assignment.start(f, writer, field_ty); |
| 7096 | 7064 | try f.writeCValueMember(writer, local, if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| |
| 7097 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 7065 | .{ .identifier = field_name.toSlice(ip) } | |
| 7098 | 7066 | else |
| 7099 | 7067 | .{ .field = field_index }); |
| 7100 | 7068 | try a.assign(f, writer); |
| ... | ... | @@ -7174,7 +7142,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7174 | 7142 | |
| 7175 | 7143 | const a = try Assignment.start(f, writer, field_ty); |
| 7176 | 7144 | try f.writeCValueMember(writer, local, if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name| |
| 7177 | .{ .identifier = ip.stringToSlice(field_name) } | |
| 7145 | .{ .identifier = field_name.toSlice(ip) } | |
| 7178 | 7146 | else |
| 7179 | 7147 | .{ .field = field_index }); |
| 7180 | 7148 | try a.assign(f, writer); |
| ... | ... | @@ -7222,8 +7190,8 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7222 | 7190 | try writer.print("{}", .{try f.fmtIntLiteral(try tag_val.intFromEnum(tag_ty, zcu))}); |
| 7223 | 7191 | try a.end(f, writer); |
| 7224 | 7192 | } |
| 7225 | break :field .{ .payload_identifier = ip.stringToSlice(field_name) }; | |
| 7226 | } else .{ .identifier = ip.stringToSlice(field_name) }; | |
| 7193 | break :field .{ .payload_identifier = field_name.toSlice(ip) }; | |
| 7194 | } else .{ .identifier = field_name.toSlice(ip) }; | |
| 7227 | 7195 | |
| 7228 | 7196 | const a = try Assignment.start(f, writer, payload_ty); |
| 7229 | 7197 | try f.writeCValueMember(writer, local, field); |
src/codegen/c/Type.zig+5-5| ... | ... | @@ -1465,7 +1465,7 @@ pub const Pool = struct { |
| 1465 | 1465 | }, |
| 1466 | 1466 | }, |
| 1467 | 1467 | .array_type => |array_info| { |
| 1468 | const len = array_info.len + @intFromBool(array_info.sentinel != .none); | |
| 1468 | const len = array_info.lenIncludingSentinel(); | |
| 1469 | 1469 | if (len == 0) return .{ .index = .void }; |
| 1470 | 1470 | const elem_type = Type.fromInterned(array_info.child); |
| 1471 | 1471 | const elem_ctype = try pool.fromType( |
| ... | ... | @@ -1479,7 +1479,7 @@ pub const Pool = struct { |
| 1479 | 1479 | if (elem_ctype.index == .void) return .{ .index = .void }; |
| 1480 | 1480 | const array_ctype = try pool.getArray(allocator, .{ |
| 1481 | 1481 | .elem_ctype = elem_ctype, |
| 1482 | .len = array_info.len + @intFromBool(array_info.sentinel != .none), | |
| 1482 | .len = len, | |
| 1483 | 1483 | }); |
| 1484 | 1484 | if (!kind.isParameter()) return array_ctype; |
| 1485 | 1485 | var fields = [_]Info.Field{ |
| ... | ... | @@ -1625,7 +1625,7 @@ pub const Pool = struct { |
| 1625 | 1625 | if (field_ctype.index == .void) continue; |
| 1626 | 1626 | const field_name = if (loaded_struct.fieldName(ip, field_index) |
| 1627 | 1627 | .unwrap()) |field_name| |
| 1628 | try pool.string(allocator, ip.stringToSlice(field_name)) | |
| 1628 | try pool.string(allocator, field_name.toSlice(ip)) | |
| 1629 | 1629 | else |
| 1630 | 1630 | try pool.fmt(allocator, "f{d}", .{field_index}); |
| 1631 | 1631 | const field_alignas = AlignAs.fromAlignment(.{ |
| ... | ... | @@ -1685,7 +1685,7 @@ pub const Pool = struct { |
| 1685 | 1685 | if (field_ctype.index == .void) continue; |
| 1686 | 1686 | const field_name = if (anon_struct_info.fieldName(ip, @intCast(field_index)) |
| 1687 | 1687 | .unwrap()) |field_name| |
| 1688 | try pool.string(allocator, ip.stringToSlice(field_name)) | |
| 1688 | try pool.string(allocator, field_name.toSlice(ip)) | |
| 1689 | 1689 | else |
| 1690 | 1690 | try pool.fmt(allocator, "f{d}", .{field_index}); |
| 1691 | 1691 | pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{ |
| ... | ... | @@ -1766,7 +1766,7 @@ pub const Pool = struct { |
| 1766 | 1766 | if (field_ctype.index == .void) continue; |
| 1767 | 1767 | const field_name = try pool.string( |
| 1768 | 1768 | allocator, |
| 1769 | ip.stringToSlice(loaded_tag.names.get(ip)[field_index]), | |
| 1769 | loaded_tag.names.get(ip)[field_index].toSlice(ip), | |
| 1770 | 1770 | ); |
| 1771 | 1771 | const field_alignas = AlignAs.fromAlignment(.{ |
| 1772 | 1772 | .@"align" = loaded_union.fieldAlign(ip, @intCast(field_index)), |
src/codegen/llvm.zig+53-60| ... | ... | @@ -1011,7 +1011,7 @@ pub const Object = struct { |
| 1011 | 1011 | |
| 1012 | 1012 | llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty); |
| 1013 | 1013 | for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| { |
| 1014 | const name_string = try o.builder.stringNull(mod.intern_pool.stringToSlice(name)); | |
| 1014 | const name_string = try o.builder.stringNull(name.toSlice(&mod.intern_pool)); | |
| 1015 | 1015 | const name_init = try o.builder.stringConst(name_string); |
| 1016 | 1016 | const name_variable_index = |
| 1017 | 1017 | try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default); |
| ... | ... | @@ -1086,7 +1086,7 @@ pub const Object = struct { |
| 1086 | 1086 | for (object.extern_collisions.keys()) |decl_index| { |
| 1087 | 1087 | const global = object.decl_map.get(decl_index) orelse continue; |
| 1088 | 1088 | // Same logic as below but for externs instead of exports. |
| 1089 | const decl_name = object.builder.strtabStringIfExists(mod.intern_pool.stringToSlice(mod.declPtr(decl_index).name)) orelse continue; | |
| 1089 | const decl_name = object.builder.strtabStringIfExists(mod.declPtr(decl_index).name.toSlice(&mod.intern_pool)) orelse continue; | |
| 1090 | 1090 | const other_global = object.builder.getGlobal(decl_name) orelse continue; |
| 1091 | 1091 | if (other_global.toConst().getBase(&object.builder) == |
| 1092 | 1092 | global.toConst().getBase(&object.builder)) continue; |
| ... | ... | @@ -1116,7 +1116,7 @@ pub const Object = struct { |
| 1116 | 1116 | for (export_list) |exp| { |
| 1117 | 1117 | // Detect if the LLVM global has already been created as an extern. In such |
| 1118 | 1118 | // case, we need to replace all uses of it with this exported global. |
| 1119 | const exp_name = object.builder.strtabStringIfExists(mod.intern_pool.stringToSlice(exp.opts.name)) orelse continue; | |
| 1119 | const exp_name = object.builder.strtabStringIfExists(exp.opts.name.toSlice(&mod.intern_pool)) orelse continue; | |
| 1120 | 1120 | |
| 1121 | 1121 | const other_global = object.builder.getGlobal(exp_name) orelse continue; |
| 1122 | 1122 | if (other_global.toConst().getBase(&object.builder) == global_base) continue; |
| ... | ... | @@ -1442,7 +1442,7 @@ pub const Object = struct { |
| 1442 | 1442 | } }, &o.builder); |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | if (ip.stringToSliceUnwrap(decl.@"linksection")) |section| | |
| 1445 | if (decl.@"linksection".toSlice(ip)) |section| | |
| 1446 | 1446 | function_index.setSection(try o.builder.string(section), &o.builder); |
| 1447 | 1447 | |
| 1448 | 1448 | var deinit_wip = true; |
| ... | ... | @@ -1662,7 +1662,7 @@ pub const Object = struct { |
| 1662 | 1662 | |
| 1663 | 1663 | const subprogram = try o.builder.debugSubprogram( |
| 1664 | 1664 | file, |
| 1665 | try o.builder.metadataString(ip.stringToSlice(decl.name)), | |
| 1665 | try o.builder.metadataString(decl.name.toSlice(ip)), | |
| 1666 | 1666 | try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)), |
| 1667 | 1667 | line_number, |
| 1668 | 1668 | line_number + func.lbrace_line, |
| ... | ... | @@ -1752,6 +1752,7 @@ pub const Object = struct { |
| 1752 | 1752 | .value => |val| return updateExportedValue(self, mod, val, exports), |
| 1753 | 1753 | }; |
| 1754 | 1754 | const gpa = mod.gpa; |
| 1755 | const ip = &mod.intern_pool; | |
| 1755 | 1756 | // If the module does not already have the function, we ignore this function call |
| 1756 | 1757 | // because we call `updateExports` at the end of `updateFunc` and `updateDecl`. |
| 1757 | 1758 | const global_index = self.decl_map.get(decl_index) orelse return; |
| ... | ... | @@ -1759,17 +1760,14 @@ pub const Object = struct { |
| 1759 | 1760 | const comp = mod.comp; |
| 1760 | 1761 | if (decl.isExtern(mod)) { |
| 1761 | 1762 | const decl_name = decl_name: { |
| 1762 | const decl_name = mod.intern_pool.stringToSlice(decl.name); | |
| 1763 | ||
| 1764 | 1763 | if (mod.getTarget().isWasm() and decl.val.typeOf(mod).zigTypeTag(mod) == .Fn) { |
| 1765 | if (mod.intern_pool.stringToSliceUnwrap(decl.getOwnedExternFunc(mod).?.lib_name)) |lib_name| { | |
| 1764 | if (decl.getOwnedExternFunc(mod).?.lib_name.toSlice(ip)) |lib_name| { | |
| 1766 | 1765 | if (!std.mem.eql(u8, lib_name, "c")) { |
| 1767 | break :decl_name try self.builder.strtabStringFmt("{s}|{s}", .{ decl_name, lib_name }); | |
| 1766 | break :decl_name try self.builder.strtabStringFmt("{}|{s}", .{ decl.name.fmt(ip), lib_name }); | |
| 1768 | 1767 | } |
| 1769 | 1768 | } |
| 1770 | 1769 | } |
| 1771 | ||
| 1772 | break :decl_name try self.builder.strtabString(decl_name); | |
| 1770 | break :decl_name try self.builder.strtabString(decl.name.toSlice(ip)); | |
| 1773 | 1771 | }; |
| 1774 | 1772 | |
| 1775 | 1773 | if (self.builder.getGlobal(decl_name)) |other_global| { |
| ... | ... | @@ -1792,9 +1790,7 @@ pub const Object = struct { |
| 1792 | 1790 | if (decl_var.is_weak_linkage) global_index.setLinkage(.extern_weak, &self.builder); |
| 1793 | 1791 | } |
| 1794 | 1792 | } else if (exports.len != 0) { |
| 1795 | const main_exp_name = try self.builder.strtabString( | |
| 1796 | mod.intern_pool.stringToSlice(exports[0].opts.name), | |
| 1797 | ); | |
| 1793 | const main_exp_name = try self.builder.strtabString(exports[0].opts.name.toSlice(ip)); | |
| 1798 | 1794 | try global_index.rename(main_exp_name, &self.builder); |
| 1799 | 1795 | |
| 1800 | 1796 | if (decl.val.getVariable(mod)) |decl_var| if (decl_var.is_threadlocal) |
| ... | ... | @@ -1803,9 +1799,7 @@ pub const Object = struct { |
| 1803 | 1799 | |
| 1804 | 1800 | return updateExportedGlobal(self, mod, global_index, exports); |
| 1805 | 1801 | } else { |
| 1806 | const fqn = try self.builder.strtabString( | |
| 1807 | mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)), | |
| 1808 | ); | |
| 1802 | const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(mod)).toSlice(ip)); | |
| 1809 | 1803 | try global_index.rename(fqn, &self.builder); |
| 1810 | 1804 | global_index.setLinkage(.internal, &self.builder); |
| 1811 | 1805 | if (comp.config.dll_export_fns) |
| ... | ... | @@ -1832,9 +1826,8 @@ pub const Object = struct { |
| 1832 | 1826 | exports: []const *Module.Export, |
| 1833 | 1827 | ) link.File.UpdateExportsError!void { |
| 1834 | 1828 | const gpa = mod.gpa; |
| 1835 | const main_exp_name = try o.builder.strtabString( | |
| 1836 | mod.intern_pool.stringToSlice(exports[0].opts.name), | |
| 1837 | ); | |
| 1829 | const ip = &mod.intern_pool; | |
| 1830 | const main_exp_name = try o.builder.strtabString(exports[0].opts.name.toSlice(ip)); | |
| 1838 | 1831 | const global_index = i: { |
| 1839 | 1832 | const gop = try o.anon_decl_map.getOrPut(gpa, exported_value); |
| 1840 | 1833 | if (gop.found_existing) { |
| ... | ... | @@ -1845,7 +1838,7 @@ pub const Object = struct { |
| 1845 | 1838 | const llvm_addr_space = toLlvmAddressSpace(.generic, o.target); |
| 1846 | 1839 | const variable_index = try o.builder.addVariable( |
| 1847 | 1840 | main_exp_name, |
| 1848 | try o.lowerType(Type.fromInterned(mod.intern_pool.typeOf(exported_value))), | |
| 1841 | try o.lowerType(Type.fromInterned(ip.typeOf(exported_value))), | |
| 1849 | 1842 | llvm_addr_space, |
| 1850 | 1843 | ); |
| 1851 | 1844 | const global_index = variable_index.ptrConst(&o.builder).global; |
| ... | ... | @@ -1867,8 +1860,9 @@ pub const Object = struct { |
| 1867 | 1860 | global_index: Builder.Global.Index, |
| 1868 | 1861 | exports: []const *Module.Export, |
| 1869 | 1862 | ) link.File.UpdateExportsError!void { |
| 1870 | global_index.setUnnamedAddr(.default, &o.builder); | |
| 1871 | 1863 | const comp = mod.comp; |
| 1864 | const ip = &mod.intern_pool; | |
| 1865 | global_index.setUnnamedAddr(.default, &o.builder); | |
| 1872 | 1866 | if (comp.config.dll_export_fns) |
| 1873 | 1867 | global_index.setDllStorageClass(.dllexport, &o.builder); |
| 1874 | 1868 | global_index.setLinkage(switch (exports[0].opts.linkage) { |
| ... | ... | @@ -1882,7 +1876,7 @@ pub const Object = struct { |
| 1882 | 1876 | .hidden => .hidden, |
| 1883 | 1877 | .protected => .protected, |
| 1884 | 1878 | }, &o.builder); |
| 1885 | if (mod.intern_pool.stringToSliceUnwrap(exports[0].opts.section)) |section| | |
| 1879 | if (exports[0].opts.section.toSlice(ip)) |section| | |
| 1886 | 1880 | switch (global_index.ptrConst(&o.builder).kind) { |
| 1887 | 1881 | .variable => |impl_index| impl_index.setSection( |
| 1888 | 1882 | try o.builder.string(section), |
| ... | ... | @@ -1900,7 +1894,7 @@ pub const Object = struct { |
| 1900 | 1894 | // Until then we iterate over existing aliases and make them point |
| 1901 | 1895 | // to the correct decl, or otherwise add a new alias. Old aliases are leaked. |
| 1902 | 1896 | for (exports[1..]) |exp| { |
| 1903 | const exp_name = try o.builder.strtabString(mod.intern_pool.stringToSlice(exp.opts.name)); | |
| 1897 | const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip)); | |
| 1904 | 1898 | if (o.builder.getGlobal(exp_name)) |global| { |
| 1905 | 1899 | switch (global.ptrConst(&o.builder).kind) { |
| 1906 | 1900 | .alias => |alias| { |
| ... | ... | @@ -2013,7 +2007,7 @@ pub const Object = struct { |
| 2013 | 2007 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); |
| 2014 | 2008 | |
| 2015 | 2009 | enumerators[i] = try o.builder.debugEnumerator( |
| 2016 | try o.builder.metadataString(ip.stringToSlice(field_name_ip)), | |
| 2010 | try o.builder.metadataString(field_name_ip.toSlice(ip)), | |
| 2017 | 2011 | int_info.signedness == .unsigned, |
| 2018 | 2012 | int_info.bits, |
| 2019 | 2013 | bigint, |
| ... | ... | @@ -2473,7 +2467,7 @@ pub const Object = struct { |
| 2473 | 2467 | offset = field_offset + field_size; |
| 2474 | 2468 | |
| 2475 | 2469 | const field_name = if (tuple.names.len != 0) |
| 2476 | ip.stringToSlice(tuple.names.get(ip)[i]) | |
| 2470 | tuple.names.get(ip)[i].toSlice(ip) | |
| 2477 | 2471 | else |
| 2478 | 2472 | try std.fmt.allocPrintZ(gpa, "{d}", .{i}); |
| 2479 | 2473 | defer if (tuple.names.len == 0) gpa.free(field_name); |
| ... | ... | @@ -2557,10 +2551,10 @@ pub const Object = struct { |
| 2557 | 2551 | const field_offset = ty.structFieldOffset(field_index, mod); |
| 2558 | 2552 | |
| 2559 | 2553 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2560 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}); | |
| 2554 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | |
| 2561 | 2555 | |
| 2562 | 2556 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2563 | try o.builder.metadataString(ip.stringToSlice(field_name)), | |
| 2557 | try o.builder.metadataString(field_name.toSlice(ip)), | |
| 2564 | 2558 | .none, // File |
| 2565 | 2559 | debug_fwd_ref, |
| 2566 | 2560 | 0, // Line |
| ... | ... | @@ -2655,7 +2649,7 @@ pub const Object = struct { |
| 2655 | 2649 | |
| 2656 | 2650 | const field_name = tag_type.names.get(ip)[field_index]; |
| 2657 | 2651 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2658 | try o.builder.metadataString(ip.stringToSlice(field_name)), | |
| 2652 | try o.builder.metadataString(field_name.toSlice(ip)), | |
| 2659 | 2653 | .none, // File |
| 2660 | 2654 | debug_union_fwd_ref, |
| 2661 | 2655 | 0, // Line |
| ... | ... | @@ -2827,7 +2821,7 @@ pub const Object = struct { |
| 2827 | 2821 | const mod = o.module; |
| 2828 | 2822 | const decl = mod.declPtr(decl_index); |
| 2829 | 2823 | return o.builder.debugStructType( |
| 2830 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // TODO use fully qualified name | |
| 2824 | try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name | |
| 2831 | 2825 | try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope), |
| 2832 | 2826 | try o.namespaceToDebugScope(decl.src_namespace), |
| 2833 | 2827 | decl.src_line + 1, |
| ... | ... | @@ -2844,11 +2838,11 @@ pub const Object = struct { |
| 2844 | 2838 | const std_mod = mod.std_mod; |
| 2845 | 2839 | const std_file = (mod.importPkg(std_mod) catch unreachable).file; |
| 2846 | 2840 | |
| 2847 | const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin"); | |
| 2841 | const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin", .no_embedded_nulls); | |
| 2848 | 2842 | const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace); |
| 2849 | 2843 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?; |
| 2850 | 2844 | |
| 2851 | const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace"); | |
| 2845 | const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace", .no_embedded_nulls); | |
| 2852 | 2846 | // buffer is only used for int_type, `builtin` is a struct. |
| 2853 | 2847 | const builtin_ty = mod.declPtr(builtin_decl).val.toType(); |
| 2854 | 2848 | const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?; |
| ... | ... | @@ -2892,10 +2886,10 @@ pub const Object = struct { |
| 2892 | 2886 | const is_extern = decl.isExtern(zcu); |
| 2893 | 2887 | const function_index = try o.builder.addFunction( |
| 2894 | 2888 | try o.lowerType(zig_fn_type), |
| 2895 | try o.builder.strtabString(ip.stringToSlice(if (is_extern) | |
| 2889 | try o.builder.strtabString((if (is_extern) | |
| 2896 | 2890 | decl.name |
| 2897 | 2891 | else |
| 2898 | try decl.fullyQualifiedName(zcu))), | |
| 2892 | try decl.fullyQualifiedName(zcu)).toSlice(ip)), | |
| 2899 | 2893 | toLlvmAddressSpace(decl.@"addrspace", target), |
| 2900 | 2894 | ); |
| 2901 | 2895 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; |
| ... | ... | @@ -2910,9 +2904,9 @@ pub const Object = struct { |
| 2910 | 2904 | if (target.isWasm()) { |
| 2911 | 2905 | try attributes.addFnAttr(.{ .string = .{ |
| 2912 | 2906 | .kind = try o.builder.string("wasm-import-name"), |
| 2913 | .value = try o.builder.string(ip.stringToSlice(decl.name)), | |
| 2907 | .value = try o.builder.string(decl.name.toSlice(ip)), | |
| 2914 | 2908 | } }, &o.builder); |
| 2915 | if (ip.stringToSliceUnwrap(decl.getOwnedExternFunc(zcu).?.lib_name)) |lib_name| { | |
| 2909 | if (decl.getOwnedExternFunc(zcu).?.lib_name.toSlice(ip)) |lib_name| { | |
| 2916 | 2910 | if (!std.mem.eql(u8, lib_name, "c")) try attributes.addFnAttr(.{ .string = .{ |
| 2917 | 2911 | .kind = try o.builder.string("wasm-import-module"), |
| 2918 | 2912 | .value = try o.builder.string(lib_name), |
| ... | ... | @@ -3108,9 +3102,10 @@ pub const Object = struct { |
| 3108 | 3102 | const is_extern = decl.isExtern(mod); |
| 3109 | 3103 | |
| 3110 | 3104 | const variable_index = try o.builder.addVariable( |
| 3111 | try o.builder.strtabString(mod.intern_pool.stringToSlice( | |
| 3112 | if (is_extern) decl.name else try decl.fullyQualifiedName(mod), | |
| 3113 | )), | |
| 3105 | try o.builder.strtabString((if (is_extern) | |
| 3106 | decl.name | |
| 3107 | else | |
| 3108 | try decl.fullyQualifiedName(mod)).toSlice(&mod.intern_pool)), | |
| 3114 | 3109 | try o.lowerType(decl.typeOf(mod)), |
| 3115 | 3110 | toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()), |
| 3116 | 3111 | ); |
| ... | ... | @@ -3258,7 +3253,7 @@ pub const Object = struct { |
| 3258 | 3253 | }; |
| 3259 | 3254 | }, |
| 3260 | 3255 | .array_type => |array_type| o.builder.arrayType( |
| 3261 | array_type.len + @intFromBool(array_type.sentinel != .none), | |
| 3256 | array_type.lenIncludingSentinel(), | |
| 3262 | 3257 | try o.lowerType(Type.fromInterned(array_type.child)), |
| 3263 | 3258 | ), |
| 3264 | 3259 | .vector_type => |vector_type| o.builder.vectorType( |
| ... | ... | @@ -3335,9 +3330,7 @@ pub const Object = struct { |
| 3335 | 3330 | return int_ty; |
| 3336 | 3331 | } |
| 3337 | 3332 | |
| 3338 | const name = try o.builder.string(ip.stringToSlice( | |
| 3339 | try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod), | |
| 3340 | )); | |
| 3333 | const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod); | |
| 3341 | 3334 | |
| 3342 | 3335 | var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){}; |
| 3343 | 3336 | defer llvm_field_types.deinit(o.gpa); |
| ... | ... | @@ -3402,7 +3395,7 @@ pub const Object = struct { |
| 3402 | 3395 | ); |
| 3403 | 3396 | } |
| 3404 | 3397 | |
| 3405 | const ty = try o.builder.opaqueType(name); | |
| 3398 | const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); | |
| 3406 | 3399 | try o.type_map.put(o.gpa, t.toIntern(), ty); |
| 3407 | 3400 | |
| 3408 | 3401 | o.builder.namedTypeSetBody( |
| ... | ... | @@ -3491,9 +3484,7 @@ pub const Object = struct { |
| 3491 | 3484 | return enum_tag_ty; |
| 3492 | 3485 | } |
| 3493 | 3486 | |
| 3494 | const name = try o.builder.string(ip.stringToSlice( | |
| 3495 | try mod.declPtr(union_obj.decl).fullyQualifiedName(mod), | |
| 3496 | )); | |
| 3487 | const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(mod); | |
| 3497 | 3488 | |
| 3498 | 3489 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); |
| 3499 | 3490 | const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty); |
| ... | ... | @@ -3513,7 +3504,7 @@ pub const Object = struct { |
| 3513 | 3504 | }; |
| 3514 | 3505 | |
| 3515 | 3506 | if (layout.tag_size == 0) { |
| 3516 | const ty = try o.builder.opaqueType(name); | |
| 3507 | const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); | |
| 3517 | 3508 | try o.type_map.put(o.gpa, t.toIntern(), ty); |
| 3518 | 3509 | |
| 3519 | 3510 | o.builder.namedTypeSetBody( |
| ... | ... | @@ -3541,7 +3532,7 @@ pub const Object = struct { |
| 3541 | 3532 | llvm_fields_len += 1; |
| 3542 | 3533 | } |
| 3543 | 3534 | |
| 3544 | const ty = try o.builder.opaqueType(name); | |
| 3535 | const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); | |
| 3545 | 3536 | try o.type_map.put(o.gpa, t.toIntern(), ty); |
| 3546 | 3537 | |
| 3547 | 3538 | o.builder.namedTypeSetBody( |
| ... | ... | @@ -3554,8 +3545,8 @@ pub const Object = struct { |
| 3554 | 3545 | const gop = try o.type_map.getOrPut(o.gpa, t.toIntern()); |
| 3555 | 3546 | if (!gop.found_existing) { |
| 3556 | 3547 | const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl); |
| 3557 | const name = try o.builder.string(ip.stringToSlice(try decl.fullyQualifiedName(mod))); | |
| 3558 | gop.value_ptr.* = try o.builder.opaqueType(name); | |
| 3548 | const fqn = try decl.fullyQualifiedName(mod); | |
| 3549 | gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); | |
| 3559 | 3550 | } |
| 3560 | 3551 | return gop.value_ptr.*; |
| 3561 | 3552 | }, |
| ... | ... | @@ -3859,7 +3850,9 @@ pub const Object = struct { |
| 3859 | 3850 | }, |
| 3860 | 3851 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { |
| 3861 | 3852 | .array_type => |array_type| switch (aggregate.storage) { |
| 3862 | .bytes => |bytes| try o.builder.stringConst(try o.builder.string(bytes)), | |
| 3853 | .bytes => |bytes| try o.builder.stringConst(try o.builder.string( | |
| 3854 | bytes.toSlice(array_type.lenIncludingSentinel(), ip), | |
| 3855 | )), | |
| 3863 | 3856 | .elems => |elems| { |
| 3864 | 3857 | const array_ty = try o.lowerType(ty); |
| 3865 | 3858 | const elem_ty = array_ty.childType(&o.builder); |
| ... | ... | @@ -3892,8 +3885,7 @@ pub const Object = struct { |
| 3892 | 3885 | }, |
| 3893 | 3886 | .repeated_elem => |elem| { |
| 3894 | 3887 | const len: usize = @intCast(array_type.len); |
| 3895 | const len_including_sentinel: usize = | |
| 3896 | @intCast(len + @intFromBool(array_type.sentinel != .none)); | |
| 3888 | const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel()); | |
| 3897 | 3889 | const array_ty = try o.lowerType(ty); |
| 3898 | 3890 | const elem_ty = array_ty.childType(&o.builder); |
| 3899 | 3891 | |
| ... | ... | @@ -3942,7 +3934,7 @@ pub const Object = struct { |
| 3942 | 3934 | defer allocator.free(vals); |
| 3943 | 3935 | |
| 3944 | 3936 | switch (aggregate.storage) { |
| 3945 | .bytes => |bytes| for (vals, bytes) |*result_val, byte| { | |
| 3937 | .bytes => |bytes| for (vals, bytes.toSlice(vector_type.len, ip)) |*result_val, byte| { | |
| 3946 | 3938 | result_val.* = try o.builder.intConst(.i8, byte); |
| 3947 | 3939 | }, |
| 3948 | 3940 | .elems => |elems| for (vals, elems) |*result_val, elem| { |
| ... | ... | @@ -4633,7 +4625,7 @@ pub const Object = struct { |
| 4633 | 4625 | defer wip_switch.finish(&wip); |
| 4634 | 4626 | |
| 4635 | 4627 | for (0..enum_type.names.len) |field_index| { |
| 4636 | const name = try o.builder.stringNull(ip.stringToSlice(enum_type.names.get(ip)[field_index])); | |
| 4628 | const name = try o.builder.stringNull(enum_type.names.get(ip)[field_index].toSlice(ip)); | |
| 4637 | 4629 | const name_init = try o.builder.stringConst(name); |
| 4638 | 4630 | const name_variable_index = |
| 4639 | 4631 | try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default); |
| ... | ... | @@ -4693,6 +4685,7 @@ pub const DeclGen = struct { |
| 4693 | 4685 | fn genDecl(dg: *DeclGen) !void { |
| 4694 | 4686 | const o = dg.object; |
| 4695 | 4687 | const zcu = o.module; |
| 4688 | const ip = &zcu.intern_pool; | |
| 4696 | 4689 | const decl = dg.decl; |
| 4697 | 4690 | const decl_index = dg.decl_index; |
| 4698 | 4691 | assert(decl.has_tv); |
| ... | ... | @@ -4705,7 +4698,7 @@ pub const DeclGen = struct { |
| 4705 | 4698 | decl.getAlignment(zcu).toLlvm(), |
| 4706 | 4699 | &o.builder, |
| 4707 | 4700 | ); |
| 4708 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| | |
| 4701 | if (decl.@"linksection".toSlice(ip)) |section| | |
| 4709 | 4702 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4710 | 4703 | assert(decl.has_tv); |
| 4711 | 4704 | const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: { |
| ... | ... | @@ -4728,7 +4721,7 @@ pub const DeclGen = struct { |
| 4728 | 4721 | const debug_file = try o.getDebugFile(namespace.file_scope); |
| 4729 | 4722 | |
| 4730 | 4723 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4731 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), // Name | |
| 4724 | try o.builder.metadataString(decl.name.toSlice(ip)), // Name | |
| 4732 | 4725 | try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name |
| 4733 | 4726 | debug_file, // File |
| 4734 | 4727 | debug_file, // Scope |
| ... | ... | @@ -5156,8 +5149,8 @@ pub const FuncGen = struct { |
| 5156 | 5149 | |
| 5157 | 5150 | self.scope = try o.builder.debugSubprogram( |
| 5158 | 5151 | self.file, |
| 5159 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), | |
| 5160 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(fqn)), | |
| 5152 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), | |
| 5153 | try o.builder.metadataString(fqn.toSlice(&zcu.intern_pool)), | |
| 5161 | 5154 | line_number, |
| 5162 | 5155 | line_number + func.lbrace_line, |
| 5163 | 5156 | try o.lowerDebugType(fn_ty), |
src/codegen/spirv.zig+17-26| ... | ... | @@ -1028,39 +1028,30 @@ const DeclGen = struct { |
| 1028 | 1028 | inline .array_type, .vector_type => |array_type, tag| { |
| 1029 | 1029 | const elem_ty = Type.fromInterned(array_type.child); |
| 1030 | 1030 | |
| 1031 | const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod)))); | |
| 1031 | const constituents = try self.gpa.alloc(IdRef, @intCast(ty.arrayLenIncludingSentinel(mod))); | |
| 1032 | 1032 | defer self.gpa.free(constituents); |
| 1033 | 1033 | |
| 1034 | 1034 | switch (aggregate.storage) { |
| 1035 | 1035 | .bytes => |bytes| { |
| 1036 | 1036 | // TODO: This is really space inefficient, perhaps there is a better |
| 1037 | 1037 | // way to do it? |
| 1038 | for (bytes, 0..) |byte, i| { | |
| 1039 | constituents[i] = try self.constInt(elem_ty, byte, .indirect); | |
| 1038 | for (constituents, bytes.toSlice(constituents.len, ip)) |*constituent, byte| { | |
| 1039 | constituent.* = try self.constInt(elem_ty, byte, .indirect); | |
| 1040 | 1040 | } |
| 1041 | 1041 | }, |
| 1042 | 1042 | .elems => |elems| { |
| 1043 | for (0..@as(usize, @intCast(array_type.len))) |i| { | |
| 1044 | constituents[i] = try self.constant(elem_ty, Value.fromInterned(elems[i]), .indirect); | |
| 1043 | for (constituents, elems) |*constituent, elem| { | |
| 1044 | constituent.* = try self.constant(elem_ty, Value.fromInterned(elem), .indirect); | |
| 1045 | 1045 | } |
| 1046 | 1046 | }, |
| 1047 | 1047 | .repeated_elem => |elem| { |
| 1048 | const val_id = try self.constant(elem_ty, Value.fromInterned(elem), .indirect); | |
| 1049 | for (0..@as(usize, @intCast(array_type.len))) |i| { | |
| 1050 | constituents[i] = val_id; | |
| 1051 | } | |
| 1048 | @memset(constituents, try self.constant(elem_ty, Value.fromInterned(elem), .indirect)); | |
| 1052 | 1049 | }, |
| 1053 | 1050 | } |
| 1054 | 1051 | |
| 1055 | 1052 | switch (tag) { |
| 1056 | inline .array_type => { | |
| 1057 | if (array_type.sentinel != .none) { | |
| 1058 | const sentinel = Value.fromInterned(array_type.sentinel); | |
| 1059 | constituents[constituents.len - 1] = try self.constant(elem_ty, sentinel, .indirect); | |
| 1060 | } | |
| 1061 | return self.constructArray(ty, constituents); | |
| 1062 | }, | |
| 1063 | inline .vector_type => return self.constructVector(ty, constituents), | |
| 1053 | .array_type => return self.constructArray(ty, constituents), | |
| 1054 | .vector_type => return self.constructVector(ty, constituents), | |
| 1064 | 1055 | else => unreachable, |
| 1065 | 1056 | } |
| 1066 | 1057 | }, |
| ... | ... | @@ -1683,9 +1674,9 @@ const DeclGen = struct { |
| 1683 | 1674 | } |
| 1684 | 1675 | |
| 1685 | 1676 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 1686 | try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index}); | |
| 1677 | try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index}, .no_embedded_nulls); | |
| 1687 | 1678 | try member_types.append(try self.resolveType(field_ty, .indirect)); |
| 1688 | try member_names.append(ip.stringToSlice(field_name)); | |
| 1679 | try member_names.append(field_name.toSlice(ip)); | |
| 1689 | 1680 | } |
| 1690 | 1681 | |
| 1691 | 1682 | const result_id = try self.spv.structType(member_types.items, member_names.items); |
| ... | ... | @@ -2123,12 +2114,12 @@ const DeclGen = struct { |
| 2123 | 2114 | // Append the actual code into the functions section. |
| 2124 | 2115 | try self.spv.addFunction(spv_decl_index, self.func); |
| 2125 | 2116 | |
| 2126 | const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module)); | |
| 2127 | try self.spv.debugName(result_id, fqn); | |
| 2117 | const fqn = try decl.fullyQualifiedName(self.module); | |
| 2118 | try self.spv.debugName(result_id, fqn.toSlice(ip)); | |
| 2128 | 2119 | |
| 2129 | 2120 | // Temporarily generate a test kernel declaration if this is a test function. |
| 2130 | 2121 | if (self.module.test_functions.contains(self.decl_index)) { |
| 2131 | try self.generateTestEntryPoint(fqn, spv_decl_index); | |
| 2122 | try self.generateTestEntryPoint(fqn.toSlice(ip), spv_decl_index); | |
| 2132 | 2123 | } |
| 2133 | 2124 | }, |
| 2134 | 2125 | .global => { |
| ... | ... | @@ -2152,8 +2143,8 @@ const DeclGen = struct { |
| 2152 | 2143 | .storage_class = final_storage_class, |
| 2153 | 2144 | }); |
| 2154 | 2145 | |
| 2155 | const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module)); | |
| 2156 | try self.spv.debugName(result_id, fqn); | |
| 2146 | const fqn = try decl.fullyQualifiedName(self.module); | |
| 2147 | try self.spv.debugName(result_id, fqn.toSlice(ip)); | |
| 2157 | 2148 | try self.spv.declareDeclDeps(spv_decl_index, &.{}); |
| 2158 | 2149 | }, |
| 2159 | 2150 | .invocation_global => { |
| ... | ... | @@ -2197,8 +2188,8 @@ const DeclGen = struct { |
| 2197 | 2188 | try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {}); |
| 2198 | 2189 | try self.spv.addFunction(spv_decl_index, self.func); |
| 2199 | 2190 | |
| 2200 | const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module)); | |
| 2201 | try self.spv.debugNameFmt(initializer_id, "initializer of {s}", .{fqn}); | |
| 2191 | const fqn = try decl.fullyQualifiedName(self.module); | |
| 2192 | try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)}); | |
| 2202 | 2193 | |
| 2203 | 2194 | try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{ |
| 2204 | 2195 | .id_result_type = ptr_ty_id, |
src/link/Coff.zig+23-25| ... | ... | @@ -1176,9 +1176,9 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd |
| 1176 | 1176 | gop.value_ptr.* = .{}; |
| 1177 | 1177 | } |
| 1178 | 1178 | const unnamed_consts = gop.value_ptr; |
| 1179 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1179 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1180 | 1180 | const index = unnamed_consts.items.len; |
| 1181 | const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); | |
| 1181 | const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | |
| 1182 | 1182 | defer gpa.free(sym_name); |
| 1183 | 1183 | const ty = val.typeOf(mod); |
| 1184 | 1184 | const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) { |
| ... | ... | @@ -1257,8 +1257,8 @@ pub fn updateDecl( |
| 1257 | 1257 | if (decl.isExtern(mod)) { |
| 1258 | 1258 | // TODO make this part of getGlobalSymbol |
| 1259 | 1259 | const variable = decl.getOwnedVariable(mod).?; |
| 1260 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 1261 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); | |
| 1260 | const name = decl.name.toSlice(&mod.intern_pool); | |
| 1261 | const lib_name = variable.lib_name.toSlice(&mod.intern_pool); | |
| 1262 | 1262 | const global_index = try self.getGlobalSymbol(name, lib_name); |
| 1263 | 1263 | try self.need_got_table.put(gpa, global_index, {}); |
| 1264 | 1264 | return; |
| ... | ... | @@ -1425,9 +1425,9 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com |
| 1425 | 1425 | const mod = self.base.comp.module.?; |
| 1426 | 1426 | const decl = mod.declPtr(decl_index); |
| 1427 | 1427 | |
| 1428 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1428 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1429 | 1429 | |
| 1430 | log.debug("updateDeclCode {s}{*}", .{ decl_name, decl }); | |
| 1430 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 1431 | 1431 | const required_alignment: u32 = @intCast(decl.getAlignment(mod).toByteUnits() orelse 0); |
| 1432 | 1432 | |
| 1433 | 1433 | const decl_metadata = self.decls.get(decl_index).?; |
| ... | ... | @@ -1439,7 +1439,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com |
| 1439 | 1439 | |
| 1440 | 1440 | if (atom.size != 0) { |
| 1441 | 1441 | const sym = atom.getSymbolPtr(self); |
| 1442 | try self.setSymbolName(sym, decl_name); | |
| 1442 | try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool)); | |
| 1443 | 1443 | sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1)); |
| 1444 | 1444 | sym.type = .{ .complex_type = complex_type, .base_type = .NULL }; |
| 1445 | 1445 | |
| ... | ... | @@ -1447,7 +1447,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com |
| 1447 | 1447 | const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment); |
| 1448 | 1448 | if (need_realloc) { |
| 1449 | 1449 | const vaddr = try self.growAtom(atom_index, code_len, required_alignment); |
| 1450 | log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, sym.value, vaddr }); | |
| 1450 | log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), sym.value, vaddr }); | |
| 1451 | 1451 | log.debug(" (required alignment 0x{x}", .{required_alignment}); |
| 1452 | 1452 | |
| 1453 | 1453 | if (vaddr != sym.value) { |
| ... | ... | @@ -1463,13 +1463,13 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com |
| 1463 | 1463 | self.getAtomPtr(atom_index).size = code_len; |
| 1464 | 1464 | } else { |
| 1465 | 1465 | const sym = atom.getSymbolPtr(self); |
| 1466 | try self.setSymbolName(sym, decl_name); | |
| 1466 | try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool)); | |
| 1467 | 1467 | sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1)); |
| 1468 | 1468 | sym.type = .{ .complex_type = complex_type, .base_type = .NULL }; |
| 1469 | 1469 | |
| 1470 | 1470 | const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment); |
| 1471 | 1471 | errdefer self.freeAtom(atom_index); |
| 1472 | log.debug("allocated atom for {s} at 0x{x}", .{ decl_name, vaddr }); | |
| 1472 | log.debug("allocated atom for {} at 0x{x}", .{ decl_name.fmt(&mod.intern_pool), vaddr }); | |
| 1473 | 1473 | self.getAtomPtr(atom_index).size = code_len; |
| 1474 | 1474 | sym.value = vaddr; |
| 1475 | 1475 | |
| ... | ... | @@ -1534,20 +1534,18 @@ pub fn updateExports( |
| 1534 | 1534 | else => std.builtin.CallingConvention.C, |
| 1535 | 1535 | }; |
| 1536 | 1536 | const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod); |
| 1537 | if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and | |
| 1538 | comp.config.link_libc) | |
| 1539 | { | |
| 1537 | if (decl_cc == .C and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) { | |
| 1540 | 1538 | mod.stage1_flags.have_c_main = true; |
| 1541 | 1539 | } else if (decl_cc == winapi_cc and target.os.tag == .windows) { |
| 1542 | if (ip.stringEqlSlice(exp.opts.name, "WinMain")) { | |
| 1540 | if (exp.opts.name.eqlSlice("WinMain", ip)) { | |
| 1543 | 1541 | mod.stage1_flags.have_winmain = true; |
| 1544 | } else if (ip.stringEqlSlice(exp.opts.name, "wWinMain")) { | |
| 1542 | } else if (exp.opts.name.eqlSlice("wWinMain", ip)) { | |
| 1545 | 1543 | mod.stage1_flags.have_wwinmain = true; |
| 1546 | } else if (ip.stringEqlSlice(exp.opts.name, "WinMainCRTStartup")) { | |
| 1544 | } else if (exp.opts.name.eqlSlice("WinMainCRTStartup", ip)) { | |
| 1547 | 1545 | mod.stage1_flags.have_winmain_crt_startup = true; |
| 1548 | } else if (ip.stringEqlSlice(exp.opts.name, "wWinMainCRTStartup")) { | |
| 1546 | } else if (exp.opts.name.eqlSlice("wWinMainCRTStartup", ip)) { | |
| 1549 | 1547 | mod.stage1_flags.have_wwinmain_crt_startup = true; |
| 1550 | } else if (ip.stringEqlSlice(exp.opts.name, "DllMainCRTStartup")) { | |
| 1548 | } else if (exp.opts.name.eqlSlice("DllMainCRTStartup", ip)) { | |
| 1551 | 1549 | mod.stage1_flags.have_dllmain_crt_startup = true; |
| 1552 | 1550 | } |
| 1553 | 1551 | } |
| ... | ... | @@ -1585,7 +1583,7 @@ pub fn updateExports( |
| 1585 | 1583 | for (exports) |exp| { |
| 1586 | 1584 | log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)}); |
| 1587 | 1585 | |
| 1588 | if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section_name| { | |
| 1586 | if (exp.opts.section.toSlice(&mod.intern_pool)) |section_name| { | |
| 1589 | 1587 | if (!mem.eql(u8, section_name, ".text")) { |
| 1590 | 1588 | try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create( |
| 1591 | 1589 | gpa, |
| ... | ... | @@ -1607,7 +1605,7 @@ pub fn updateExports( |
| 1607 | 1605 | continue; |
| 1608 | 1606 | } |
| 1609 | 1607 | |
| 1610 | const exp_name = mod.intern_pool.stringToSlice(exp.opts.name); | |
| 1608 | const exp_name = exp.opts.name.toSlice(&mod.intern_pool); | |
| 1611 | 1609 | const sym_index = metadata.getExport(self, exp_name) orelse blk: { |
| 1612 | 1610 | const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: { |
| 1613 | 1611 | const global = self.globals.items[global_index]; |
| ... | ... | @@ -1646,18 +1644,18 @@ pub fn updateExports( |
| 1646 | 1644 | pub fn deleteDeclExport( |
| 1647 | 1645 | self: *Coff, |
| 1648 | 1646 | decl_index: InternPool.DeclIndex, |
| 1649 | name_ip: InternPool.NullTerminatedString, | |
| 1647 | name: InternPool.NullTerminatedString, | |
| 1650 | 1648 | ) void { |
| 1651 | 1649 | if (self.llvm_object) |_| return; |
| 1652 | 1650 | const metadata = self.decls.getPtr(decl_index) orelse return; |
| 1653 | 1651 | const mod = self.base.comp.module.?; |
| 1654 | const name = mod.intern_pool.stringToSlice(name_ip); | |
| 1655 | const sym_index = metadata.getExportPtr(self, name) orelse return; | |
| 1652 | const name_slice = name.toSlice(&mod.intern_pool); | |
| 1653 | const sym_index = metadata.getExportPtr(self, name_slice) orelse return; | |
| 1656 | 1654 | |
| 1657 | 1655 | const gpa = self.base.comp.gpa; |
| 1658 | 1656 | const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null }; |
| 1659 | 1657 | const sym = self.getSymbolPtr(sym_loc); |
| 1660 | log.debug("deleting export '{s}'", .{name}); | |
| 1658 | log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)}); | |
| 1661 | 1659 | assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED); |
| 1662 | 1660 | sym.* = .{ |
| 1663 | 1661 | .name = [_]u8{0} ** 8, |
| ... | ... | @@ -1669,7 +1667,7 @@ pub fn deleteDeclExport( |
| 1669 | 1667 | }; |
| 1670 | 1668 | self.locals_free_list.append(gpa, sym_index.*) catch {}; |
| 1671 | 1669 | |
| 1672 | if (self.resolver.fetchRemove(name)) |entry| { | |
| 1670 | if (self.resolver.fetchRemove(name_slice)) |entry| { | |
| 1673 | 1671 | defer gpa.free(entry.key); |
| 1674 | 1672 | self.globals_free_list.append(gpa, entry.value) catch {}; |
| 1675 | 1673 | self.globals.items[entry.value] = .{ |
src/link/Dwarf.zig+17-20| ... | ... | @@ -339,15 +339,14 @@ pub const DeclState = struct { |
| 339 | 339 | struct_type.field_names.get(ip), |
| 340 | 340 | struct_type.field_types.get(ip), |
| 341 | 341 | struct_type.offsets.get(ip), |
| 342 | ) |field_name_ip, field_ty, field_off| { | |
| 342 | ) |field_name, field_ty, field_off| { | |
| 343 | 343 | if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; |
| 344 | const field_name = ip.stringToSlice(field_name_ip); | |
| 344 | const field_name_slice = field_name.toSlice(ip); | |
| 345 | 345 | // DW.AT.member |
| 346 | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2); | |
| 346 | try dbg_info_buffer.ensureUnusedCapacity(field_name_slice.len + 2); | |
| 347 | 347 | dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.struct_member)); |
| 348 | 348 | // DW.AT.name, DW.FORM.string |
| 349 | dbg_info_buffer.appendSliceAssumeCapacity(field_name); | |
| 350 | dbg_info_buffer.appendAssumeCapacity(0); | |
| 349 | dbg_info_buffer.appendSliceAssumeCapacity(field_name_slice[0 .. field_name_slice.len + 1]); | |
| 351 | 350 | // DW.AT.type, DW.FORM.ref4 |
| 352 | 351 | const index = dbg_info_buffer.items.len; |
| 353 | 352 | try dbg_info_buffer.appendNTimes(0, 4); |
| ... | ... | @@ -374,14 +373,13 @@ pub const DeclState = struct { |
| 374 | 373 | try dbg_info_buffer.append(0); |
| 375 | 374 | |
| 376 | 375 | const enum_type = ip.loadEnumType(ty.ip_index); |
| 377 | for (enum_type.names.get(ip), 0..) |field_name_index, field_i| { | |
| 378 | const field_name = ip.stringToSlice(field_name_index); | |
| 376 | for (enum_type.names.get(ip), 0..) |field_name, field_i| { | |
| 377 | const field_name_slice = field_name.toSlice(ip); | |
| 379 | 378 | // DW.AT.enumerator |
| 380 | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2 + @sizeOf(u64)); | |
| 379 | try dbg_info_buffer.ensureUnusedCapacity(field_name_slice.len + 2 + @sizeOf(u64)); | |
| 381 | 380 | dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant)); |
| 382 | 381 | // DW.AT.name, DW.FORM.string |
| 383 | dbg_info_buffer.appendSliceAssumeCapacity(field_name); | |
| 384 | dbg_info_buffer.appendAssumeCapacity(0); | |
| 382 | dbg_info_buffer.appendSliceAssumeCapacity(field_name_slice[0 .. field_name_slice.len + 1]); | |
| 385 | 383 | // DW.AT.const_value, DW.FORM.data8 |
| 386 | 384 | const value: u64 = value: { |
| 387 | 385 | if (enum_type.values.len == 0) break :value field_i; // auto-numbered |
| ... | ... | @@ -443,11 +441,11 @@ pub const DeclState = struct { |
| 443 | 441 | |
| 444 | 442 | for (union_obj.field_types.get(ip), union_obj.loadTagType(ip).names.get(ip)) |field_ty, field_name| { |
| 445 | 443 | if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; |
| 444 | const field_name_slice = field_name.toSlice(ip); | |
| 446 | 445 | // DW.AT.member |
| 447 | 446 | try dbg_info_buffer.append(@intFromEnum(AbbrevCode.struct_member)); |
| 448 | 447 | // DW.AT.name, DW.FORM.string |
| 449 | try dbg_info_buffer.appendSlice(ip.stringToSlice(field_name)); | |
| 450 | try dbg_info_buffer.append(0); | |
| 448 | try dbg_info_buffer.appendSlice(field_name_slice[0 .. field_name_slice.len + 1]); | |
| 451 | 449 | // DW.AT.type, DW.FORM.ref4 |
| 452 | 450 | const index = dbg_info_buffer.items.len; |
| 453 | 451 | try dbg_info_buffer.appendNTimes(0, 4); |
| ... | ... | @@ -1155,8 +1153,8 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde |
| 1155 | 1153 | dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy); |
| 1156 | 1154 | |
| 1157 | 1155 | // .debug_info subprogram |
| 1158 | const decl_name_slice = mod.intern_pool.stringToSlice(decl.name); | |
| 1159 | const decl_linkage_name_slice = mod.intern_pool.stringToSlice(decl_linkage_name); | |
| 1156 | const decl_name_slice = decl.name.toSlice(&mod.intern_pool); | |
| 1157 | const decl_linkage_name_slice = decl_linkage_name.toSlice(&mod.intern_pool); | |
| 1160 | 1158 | try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 + |
| 1161 | 1159 | (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1)); |
| 1162 | 1160 | |
| ... | ... | @@ -2866,15 +2864,14 @@ fn addDbgInfoErrorSetNames( |
| 2866 | 2864 | // DW.AT.const_value, DW.FORM.data8 |
| 2867 | 2865 | mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), 0, target_endian); |
| 2868 | 2866 | |
| 2869 | for (error_names) |error_name_ip| { | |
| 2870 | const int = try mod.getErrorValue(error_name_ip); | |
| 2871 | const error_name = mod.intern_pool.stringToSlice(error_name_ip); | |
| 2867 | for (error_names) |error_name| { | |
| 2868 | const int = try mod.getErrorValue(error_name); | |
| 2869 | const error_name_slice = error_name.toSlice(&mod.intern_pool); | |
| 2872 | 2870 | // DW.AT.enumerator |
| 2873 | try dbg_info_buffer.ensureUnusedCapacity(error_name.len + 2 + @sizeOf(u64)); | |
| 2871 | try dbg_info_buffer.ensureUnusedCapacity(error_name_slice.len + 2 + @sizeOf(u64)); | |
| 2874 | 2872 | dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant)); |
| 2875 | 2873 | // DW.AT.name, DW.FORM.string |
| 2876 | dbg_info_buffer.appendSliceAssumeCapacity(error_name); | |
| 2877 | dbg_info_buffer.appendAssumeCapacity(0); | |
| 2874 | dbg_info_buffer.appendSliceAssumeCapacity(error_name_slice[0 .. error_name_slice.len + 1]); | |
| 2878 | 2875 | // DW.AT.const_value, DW.FORM.data8 |
| 2879 | 2876 | mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), int, target_endian); |
| 2880 | 2877 | } |
src/link/Elf.zig+21-8| ... | ... | @@ -1517,7 +1517,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1517 | 1517 | |
| 1518 | 1518 | if (self.base.isStatic()) { |
| 1519 | 1519 | try argv.append("-static"); |
| 1520 | } else if (self.base.isDynLib()) { | |
| 1520 | } else if (self.isEffectivelyDynLib()) { | |
| 1521 | 1521 | try argv.append("-shared"); |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| ... | ... | @@ -1997,7 +1997,7 @@ fn markImportsExports(self: *Elf) void { |
| 1997 | 1997 | } |
| 1998 | 1998 | if (file_ptr.index() == file_index) { |
| 1999 | 1999 | global.flags.@"export" = true; |
| 2000 | if (elf_file.base.isDynLib() and vis != .PROTECTED) { | |
| 2000 | if (elf_file.isEffectivelyDynLib() and vis != .PROTECTED) { | |
| 2001 | 2001 | global.flags.import = true; |
| 2002 | 2002 | } |
| 2003 | 2003 | } |
| ... | ... | @@ -2005,7 +2005,7 @@ fn markImportsExports(self: *Elf) void { |
| 2005 | 2005 | } |
| 2006 | 2006 | }.mark; |
| 2007 | 2007 | |
| 2008 | if (!self.base.isDynLib()) { | |
| 2008 | if (!self.isEffectivelyDynLib()) { | |
| 2009 | 2009 | for (self.shared_objects.items) |index| { |
| 2010 | 2010 | for (self.file(index).?.globals()) |global_index| { |
| 2011 | 2011 | const global = self.symbol(global_index); |
| ... | ... | @@ -2469,7 +2469,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi |
| 2469 | 2469 | } else { |
| 2470 | 2470 | try argv.append("-static"); |
| 2471 | 2471 | } |
| 2472 | } else if (is_dyn_lib) { | |
| 2472 | } else if (switch (target.os.tag) { | |
| 2473 | else => is_dyn_lib, | |
| 2474 | .haiku => is_exe_or_dyn_lib, | |
| 2475 | }) { | |
| 2473 | 2476 | try argv.append("-shared"); |
| 2474 | 2477 | } |
| 2475 | 2478 | |
| ... | ... | @@ -2925,7 +2928,7 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 2925 | 2928 | const output_mode = comp.config.output_mode; |
| 2926 | 2929 | const link_mode = comp.config.link_mode; |
| 2927 | 2930 | const elf_type: elf.ET = switch (output_mode) { |
| 2928 | .Exe => if (comp.config.pie) .DYN else .EXEC, | |
| 2931 | .Exe => if (comp.config.pie or target.os.tag == .haiku) .DYN else .EXEC, | |
| 2929 | 2932 | .Obj => .REL, |
| 2930 | 2933 | .Lib => switch (link_mode) { |
| 2931 | 2934 | .static => @as(elf.ET, .REL), |
| ... | ... | @@ -3114,7 +3117,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { |
| 3114 | 3117 | } |
| 3115 | 3118 | } |
| 3116 | 3119 | |
| 3117 | if (self.getTarget().cpu.arch == .riscv64 and self.base.isDynLib()) { | |
| 3120 | if (self.getTarget().cpu.arch == .riscv64 and self.isEffectivelyDynLib()) { | |
| 3118 | 3121 | self.global_pointer_index = try linker_defined.addGlobal("__global_pointer$", self); |
| 3119 | 3122 | } |
| 3120 | 3123 | |
| ... | ... | @@ -3420,7 +3423,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3420 | 3423 | }); |
| 3421 | 3424 | } |
| 3422 | 3425 | |
| 3423 | if (self.base.isDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { | |
| 3426 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { | |
| 3424 | 3427 | self.dynstrtab_section_index = try self.addSection(.{ |
| 3425 | 3428 | .name = ".dynstr", |
| 3426 | 3429 | .flags = elf.SHF_ALLOC, |
| ... | ... | @@ -3657,7 +3660,7 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { |
| 3657 | 3660 | try self.dynamic.addNeeded(shared_object, self); |
| 3658 | 3661 | } |
| 3659 | 3662 | |
| 3660 | if (self.base.isDynLib()) { | |
| 3663 | if (self.isEffectivelyDynLib()) { | |
| 3661 | 3664 | if (self.soname) |soname| { |
| 3662 | 3665 | try self.dynamic.setSoname(soname, self); |
| 3663 | 3666 | } |
| ... | ... | @@ -5246,6 +5249,16 @@ const CsuObjects = struct { |
| 5246 | 5249 | } |
| 5247 | 5250 | }; |
| 5248 | 5251 | |
| 5252 | /// If a target compiles other output modes as dynamic libraries, | |
| 5253 | /// this function returns true for those too. | |
| 5254 | pub fn isEffectivelyDynLib(self: Elf) bool { | |
| 5255 | if (self.base.isDynLib()) return true; | |
| 5256 | return switch (self.getTarget().os.tag) { | |
| 5257 | .haiku => self.base.isExe(), | |
| 5258 | else => false, | |
| 5259 | }; | |
| 5260 | } | |
| 5261 | ||
| 5249 | 5262 | pub fn isZigSection(self: Elf, shndx: u32) bool { |
| 5250 | 5263 | inline for (&[_]?u32{ |
| 5251 | 5264 | self.zig_text_section_index, |
src/link/Elf/Atom.zig+2-2| ... | ... | @@ -1054,7 +1054,7 @@ const x86_64 = struct { |
| 1054 | 1054 | it: *RelocsIterator, |
| 1055 | 1055 | ) !void { |
| 1056 | 1056 | const is_static = elf_file.base.isStatic(); |
| 1057 | const is_dyn_lib = elf_file.base.isDynLib(); | |
| 1057 | const is_dyn_lib = elf_file.isEffectivelyDynLib(); | |
| 1058 | 1058 | |
| 1059 | 1059 | const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type()); |
| 1060 | 1060 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; |
| ... | ... | @@ -1599,7 +1599,7 @@ const aarch64 = struct { |
| 1599 | 1599 | _ = it; |
| 1600 | 1600 | |
| 1601 | 1601 | const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); |
| 1602 | const is_dyn_lib = elf_file.base.isDynLib(); | |
| 1602 | const is_dyn_lib = elf_file.isEffectivelyDynLib(); | |
| 1603 | 1603 | |
| 1604 | 1604 | switch (r_type) { |
| 1605 | 1605 | .ABS64 => { |
src/link/Elf/Object.zig+1-1| ... | ... | @@ -568,7 +568,7 @@ pub fn claimUnresolved(self: *Object, elf_file: *Elf) void { |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | const is_import = blk: { |
| 571 | if (!elf_file.base.isDynLib()) break :blk false; | |
| 571 | if (!elf_file.isEffectivelyDynLib()) break :blk false; | |
| 572 | 572 | const vis = @as(elf.STV, @enumFromInt(esym.st_other)); |
| 573 | 573 | if (vis == .HIDDEN) break :blk false; |
| 574 | 574 | break :blk true; |
src/link/Elf/Symbol.zig+24| ... | ... | @@ -105,6 +105,29 @@ pub fn address(symbol: Symbol, opts: struct { plt: bool = true }, elf_file: *Elf |
| 105 | 105 | return symbol.pltAddress(elf_file); |
| 106 | 106 | } |
| 107 | 107 | if (symbol.atom(elf_file)) |atom_ptr| { |
| 108 | if (!atom_ptr.flags.alive) { | |
| 109 | if (mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame")) { | |
| 110 | const sym_name = symbol.name(elf_file); | |
| 111 | if (mem.startsWith(u8, sym_name, "__EH_FRAME_BEGIN__") or | |
| 112 | mem.startsWith(u8, sym_name, "__EH_FRAME_LIST__") or | |
| 113 | mem.startsWith(u8, sym_name, ".eh_frame_seg") or | |
| 114 | symbol.elfSym(elf_file).st_type() == elf.STT_SECTION) | |
| 115 | { | |
| 116 | return elf_file.shdrs.items[elf_file.eh_frame_section_index.?].sh_addr; | |
| 117 | } | |
| 118 | ||
| 119 | if (mem.startsWith(u8, sym_name, "__FRAME_END__") or | |
| 120 | mem.startsWith(u8, sym_name, "__EH_FRAME_LIST_END__")) | |
| 121 | { | |
| 122 | const shdr = elf_file.shdrs.items[elf_file.eh_frame_section_index.?]; | |
| 123 | return shdr.sh_addr + shdr.sh_size; | |
| 124 | } | |
| 125 | ||
| 126 | // TODO I think we potentially should error here | |
| 127 | } | |
| 128 | ||
| 129 | return 0; | |
| 130 | } | |
| 108 | 131 | return atom_ptr.address(elf_file) + symbol.value; |
| 109 | 132 | } |
| 110 | 133 | return symbol.value; |
| ... | ... | @@ -432,6 +455,7 @@ pub const Index = u32; |
| 432 | 455 | |
| 433 | 456 | const assert = std.debug.assert; |
| 434 | 457 | const elf = std.elf; |
| 458 | const mem = std.mem; | |
| 435 | 459 | const std = @import("std"); |
| 436 | 460 | const synthetic_sections = @import("synthetic_sections.zig"); |
| 437 | 461 |
src/link/Elf/ZigObject.zig+17-17| ... | ... | @@ -367,7 +367,7 @@ pub fn claimUnresolved(self: ZigObject, elf_file: *Elf) void { |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | const is_import = blk: { |
| 370 | if (!elf_file.base.isDynLib()) break :blk false; | |
| 370 | if (!elf_file.isEffectivelyDynLib()) break :blk false; | |
| 371 | 371 | const vis = @as(elf.STV, @enumFromInt(esym.st_other)); |
| 372 | 372 | if (vis == .HIDDEN) break :blk false; |
| 373 | 373 | break :blk true; |
| ... | ... | @@ -902,9 +902,9 @@ fn updateDeclCode( |
| 902 | 902 | const gpa = elf_file.base.comp.gpa; |
| 903 | 903 | const mod = elf_file.base.comp.module.?; |
| 904 | 904 | const decl = mod.declPtr(decl_index); |
| 905 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 905 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 906 | 906 | |
| 907 | log.debug("updateDeclCode {s}{*}", .{ decl_name, decl }); | |
| 907 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 908 | 908 | |
| 909 | 909 | const required_alignment = decl.getAlignment(mod); |
| 910 | 910 | |
| ... | ... | @@ -915,7 +915,7 @@ fn updateDeclCode( |
| 915 | 915 | sym.output_section_index = shdr_index; |
| 916 | 916 | atom_ptr.output_section_index = shdr_index; |
| 917 | 917 | |
| 918 | sym.name_offset = try self.strtab.insert(gpa, decl_name); | |
| 918 | sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool)); | |
| 919 | 919 | atom_ptr.flags.alive = true; |
| 920 | 920 | atom_ptr.name_offset = sym.name_offset; |
| 921 | 921 | esym.st_name = sym.name_offset; |
| ... | ... | @@ -932,7 +932,7 @@ fn updateDeclCode( |
| 932 | 932 | const need_realloc = code.len > capacity or !required_alignment.check(atom_ptr.value); |
| 933 | 933 | if (need_realloc) { |
| 934 | 934 | try atom_ptr.grow(elf_file); |
| 935 | log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, old_vaddr, atom_ptr.value }); | |
| 935 | log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom_ptr.value }); | |
| 936 | 936 | if (old_vaddr != atom_ptr.value) { |
| 937 | 937 | sym.value = 0; |
| 938 | 938 | esym.st_value = 0; |
| ... | ... | @@ -1000,9 +1000,9 @@ fn updateTlv( |
| 1000 | 1000 | const gpa = elf_file.base.comp.gpa; |
| 1001 | 1001 | const mod = elf_file.base.comp.module.?; |
| 1002 | 1002 | const decl = mod.declPtr(decl_index); |
| 1003 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1003 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1004 | 1004 | |
| 1005 | log.debug("updateTlv {s} ({*})", .{ decl_name, decl }); | |
| 1005 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 1006 | 1006 | |
| 1007 | 1007 | const required_alignment = decl.getAlignment(mod); |
| 1008 | 1008 | |
| ... | ... | @@ -1014,7 +1014,7 @@ fn updateTlv( |
| 1014 | 1014 | sym.output_section_index = shndx; |
| 1015 | 1015 | atom_ptr.output_section_index = shndx; |
| 1016 | 1016 | |
| 1017 | sym.name_offset = try self.strtab.insert(gpa, decl_name); | |
| 1017 | sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool)); | |
| 1018 | 1018 | atom_ptr.flags.alive = true; |
| 1019 | 1019 | atom_ptr.name_offset = sym.name_offset; |
| 1020 | 1020 | esym.st_value = 0; |
| ... | ... | @@ -1136,8 +1136,8 @@ pub fn updateDecl( |
| 1136 | 1136 | if (decl.isExtern(mod)) { |
| 1137 | 1137 | // Extern variable gets a .got entry only. |
| 1138 | 1138 | const variable = decl.getOwnedVariable(mod).?; |
| 1139 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 1140 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); | |
| 1139 | const name = decl.name.toSlice(&mod.intern_pool); | |
| 1140 | const lib_name = variable.lib_name.toSlice(&mod.intern_pool); | |
| 1141 | 1141 | const esym_index = try self.getGlobalSymbol(elf_file, name, lib_name); |
| 1142 | 1142 | elf_file.symbol(self.symbol(esym_index)).flags.needs_got = true; |
| 1143 | 1143 | return; |
| ... | ... | @@ -1293,9 +1293,9 @@ pub fn lowerUnnamedConst( |
| 1293 | 1293 | } |
| 1294 | 1294 | const unnamed_consts = gop.value_ptr; |
| 1295 | 1295 | const decl = mod.declPtr(decl_index); |
| 1296 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1296 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1297 | 1297 | const index = unnamed_consts.items.len; |
| 1298 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); | |
| 1298 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | |
| 1299 | 1299 | defer gpa.free(name); |
| 1300 | 1300 | const ty = val.typeOf(mod); |
| 1301 | 1301 | const sym_index = switch (try self.lowerConst( |
| ... | ... | @@ -1418,7 +1418,7 @@ pub fn updateExports( |
| 1418 | 1418 | |
| 1419 | 1419 | for (exports) |exp| { |
| 1420 | 1420 | if (exp.opts.section.unwrap()) |section_name| { |
| 1421 | if (!mod.intern_pool.stringEqlSlice(section_name, ".text")) { | |
| 1421 | if (!section_name.eqlSlice(".text", &mod.intern_pool)) { | |
| 1422 | 1422 | try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); |
| 1423 | 1423 | mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create( |
| 1424 | 1424 | gpa, |
| ... | ... | @@ -1445,7 +1445,7 @@ pub fn updateExports( |
| 1445 | 1445 | }, |
| 1446 | 1446 | }; |
| 1447 | 1447 | const stt_bits: u8 = @as(u4, @truncate(esym.st_info)); |
| 1448 | const exp_name = mod.intern_pool.stringToSlice(exp.opts.name); | |
| 1448 | const exp_name = exp.opts.name.toSlice(&mod.intern_pool); | |
| 1449 | 1449 | const name_off = try self.strtab.insert(gpa, exp_name); |
| 1450 | 1450 | const global_esym_index = if (metadata.@"export"(self, exp_name)) |exp_index| |
| 1451 | 1451 | exp_index.* |
| ... | ... | @@ -1476,9 +1476,9 @@ pub fn updateDeclLineNumber( |
| 1476 | 1476 | defer tracy.end(); |
| 1477 | 1477 | |
| 1478 | 1478 | const decl = mod.declPtr(decl_index); |
| 1479 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1479 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1480 | 1480 | |
| 1481 | log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl }); | |
| 1481 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 1482 | 1482 | |
| 1483 | 1483 | if (self.dwarf) |*dw| { |
| 1484 | 1484 | try dw.updateDeclLineNumber(mod, decl_index); |
| ... | ... | @@ -1493,7 +1493,7 @@ pub fn deleteDeclExport( |
| 1493 | 1493 | ) void { |
| 1494 | 1494 | const metadata = self.decls.getPtr(decl_index) orelse return; |
| 1495 | 1495 | const mod = elf_file.base.comp.module.?; |
| 1496 | const exp_name = mod.intern_pool.stringToSlice(name); | |
| 1496 | const exp_name = name.toSlice(&mod.intern_pool); | |
| 1497 | 1497 | const esym_index = metadata.@"export"(self, exp_name) orelse return; |
| 1498 | 1498 | log.debug("deleting export '{s}'", .{exp_name}); |
| 1499 | 1499 | const esym = &self.global_esyms.items(.elf_sym)[esym_index.*]; |
src/link/Elf/synthetic_sections.zig+12-12| ... | ... | @@ -89,7 +89,7 @@ pub const DynamicSection = struct { |
| 89 | 89 | if (elf_file.verneed_section_index != null) nentries += 2; // VERNEED |
| 90 | 90 | if (dt.getFlags(elf_file) != null) nentries += 1; // FLAGS |
| 91 | 91 | if (dt.getFlags1(elf_file) != null) nentries += 1; // FLAGS_1 |
| 92 | if (!elf_file.base.isDynLib()) nentries += 1; // DEBUG | |
| 92 | if (!elf_file.isEffectivelyDynLib()) nentries += 1; // DEBUG | |
| 93 | 93 | nentries += 1; // NULL |
| 94 | 94 | return nentries * @sizeOf(elf.Elf64_Dyn); |
| 95 | 95 | } |
| ... | ... | @@ -216,7 +216,7 @@ pub const DynamicSection = struct { |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // DEBUG |
| 219 | if (!elf_file.base.isDynLib()) try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_DEBUG, .d_val = 0 }); | |
| 219 | if (!elf_file.isEffectivelyDynLib()) try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_DEBUG, .d_val = 0 }); | |
| 220 | 220 | |
| 221 | 221 | // NULL |
| 222 | 222 | try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_NULL, .d_val = 0 }); |
| ... | ... | @@ -256,7 +256,7 @@ pub const ZigGotSection = struct { |
| 256 | 256 | entry.* = sym_index; |
| 257 | 257 | const symbol = elf_file.symbol(sym_index); |
| 258 | 258 | symbol.flags.has_zig_got = true; |
| 259 | if (elf_file.base.isDynLib() or (elf_file.base.isExe() and comp.config.pie)) { | |
| 259 | if (elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) { | |
| 260 | 260 | zig_got.flags.needs_rela = true; |
| 261 | 261 | } |
| 262 | 262 | if (symbol.extra(elf_file)) |extra| { |
| ... | ... | @@ -495,7 +495,7 @@ pub const GotSection = struct { |
| 495 | 495 | const symbol = elf_file.symbol(sym_index); |
| 496 | 496 | symbol.flags.has_got = true; |
| 497 | 497 | if (symbol.flags.import or symbol.isIFunc(elf_file) or |
| 498 | ((elf_file.base.isDynLib() or (elf_file.base.isExe() and comp.config.pie)) and !symbol.isAbs(elf_file))) | |
| 498 | ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and !symbol.isAbs(elf_file))) | |
| 499 | 499 | { |
| 500 | 500 | got.flags.needs_rela = true; |
| 501 | 501 | } |
| ... | ... | @@ -528,7 +528,7 @@ pub const GotSection = struct { |
| 528 | 528 | entry.symbol_index = sym_index; |
| 529 | 529 | const symbol = elf_file.symbol(sym_index); |
| 530 | 530 | symbol.flags.has_tlsgd = true; |
| 531 | if (symbol.flags.import or elf_file.base.isDynLib()) got.flags.needs_rela = true; | |
| 531 | if (symbol.flags.import or elf_file.isEffectivelyDynLib()) got.flags.needs_rela = true; | |
| 532 | 532 | if (symbol.extra(elf_file)) |extra| { |
| 533 | 533 | var new_extra = extra; |
| 534 | 534 | new_extra.tlsgd = index; |
| ... | ... | @@ -545,7 +545,7 @@ pub const GotSection = struct { |
| 545 | 545 | entry.symbol_index = sym_index; |
| 546 | 546 | const symbol = elf_file.symbol(sym_index); |
| 547 | 547 | symbol.flags.has_gottp = true; |
| 548 | if (symbol.flags.import or elf_file.base.isDynLib()) got.flags.needs_rela = true; | |
| 548 | if (symbol.flags.import or elf_file.isEffectivelyDynLib()) got.flags.needs_rela = true; | |
| 549 | 549 | if (symbol.extra(elf_file)) |extra| { |
| 550 | 550 | var new_extra = extra; |
| 551 | 551 | new_extra.gottp = index; |
| ... | ... | @@ -580,7 +580,7 @@ pub const GotSection = struct { |
| 580 | 580 | |
| 581 | 581 | pub fn write(got: GotSection, elf_file: *Elf, writer: anytype) !void { |
| 582 | 582 | const comp = elf_file.base.comp; |
| 583 | const is_dyn_lib = elf_file.base.isDynLib(); | |
| 583 | const is_dyn_lib = elf_file.isEffectivelyDynLib(); | |
| 584 | 584 | const apply_relocs = true; // TODO add user option for this |
| 585 | 585 | |
| 586 | 586 | for (got.entries.items) |entry| { |
| ... | ... | @@ -595,7 +595,7 @@ pub const GotSection = struct { |
| 595 | 595 | if (symbol.?.flags.import) break :blk 0; |
| 596 | 596 | if (symbol.?.isIFunc(elf_file)) |
| 597 | 597 | break :blk if (apply_relocs) value else 0; |
| 598 | if ((elf_file.base.isDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 598 | if ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 599 | 599 | !symbol.?.isAbs(elf_file)) |
| 600 | 600 | { |
| 601 | 601 | break :blk if (apply_relocs) value else 0; |
| ... | ... | @@ -653,7 +653,7 @@ pub const GotSection = struct { |
| 653 | 653 | pub fn addRela(got: GotSection, elf_file: *Elf) !void { |
| 654 | 654 | const comp = elf_file.base.comp; |
| 655 | 655 | const gpa = comp.gpa; |
| 656 | const is_dyn_lib = elf_file.base.isDynLib(); | |
| 656 | const is_dyn_lib = elf_file.isEffectivelyDynLib(); | |
| 657 | 657 | const cpu_arch = elf_file.getTarget().cpu.arch; |
| 658 | 658 | try elf_file.rela_dyn.ensureUnusedCapacity(gpa, got.numRela(elf_file)); |
| 659 | 659 | |
| ... | ... | @@ -683,7 +683,7 @@ pub const GotSection = struct { |
| 683 | 683 | }); |
| 684 | 684 | continue; |
| 685 | 685 | } |
| 686 | if ((elf_file.base.isDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 686 | if ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 687 | 687 | !symbol.?.isAbs(elf_file)) |
| 688 | 688 | { |
| 689 | 689 | elf_file.addRelaDynAssumeCapacity(.{ |
| ... | ... | @@ -758,7 +758,7 @@ pub const GotSection = struct { |
| 758 | 758 | |
| 759 | 759 | pub fn numRela(got: GotSection, elf_file: *Elf) usize { |
| 760 | 760 | const comp = elf_file.base.comp; |
| 761 | const is_dyn_lib = elf_file.base.isDynLib(); | |
| 761 | const is_dyn_lib = elf_file.isEffectivelyDynLib(); | |
| 762 | 762 | var num: usize = 0; |
| 763 | 763 | for (got.entries.items) |entry| { |
| 764 | 764 | const symbol = switch (entry.tag) { |
| ... | ... | @@ -767,7 +767,7 @@ pub const GotSection = struct { |
| 767 | 767 | }; |
| 768 | 768 | switch (entry.tag) { |
| 769 | 769 | .got => if (symbol.?.flags.import or symbol.?.isIFunc(elf_file) or |
| 770 | ((elf_file.base.isDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 770 | ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and | |
| 771 | 771 | !symbol.?.isAbs(elf_file))) |
| 772 | 772 | { |
| 773 | 773 | num += 1; |
src/link/MachO/ZigObject.zig+19-19| ... | ... | @@ -716,8 +716,8 @@ pub fn updateDecl( |
| 716 | 716 | if (decl.isExtern(mod)) { |
| 717 | 717 | // Extern variable gets a __got entry only |
| 718 | 718 | const variable = decl.getOwnedVariable(mod).?; |
| 719 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 720 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); | |
| 719 | const name = decl.name.toSlice(&mod.intern_pool); | |
| 720 | const lib_name = variable.lib_name.toSlice(&mod.intern_pool); | |
| 721 | 721 | const index = try self.getGlobalSymbol(macho_file, name, lib_name); |
| 722 | 722 | const actual_index = self.symbols.items[index]; |
| 723 | 723 | macho_file.getSymbol(actual_index).flags.needs_got = true; |
| ... | ... | @@ -786,9 +786,9 @@ fn updateDeclCode( |
| 786 | 786 | const gpa = macho_file.base.comp.gpa; |
| 787 | 787 | const mod = macho_file.base.comp.module.?; |
| 788 | 788 | const decl = mod.declPtr(decl_index); |
| 789 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 789 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 790 | 790 | |
| 791 | log.debug("updateDeclCode {s}{*}", .{ decl_name, decl }); | |
| 791 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 792 | 792 | |
| 793 | 793 | const required_alignment = decl.getAlignment(mod); |
| 794 | 794 | |
| ... | ... | @@ -800,7 +800,7 @@ fn updateDeclCode( |
| 800 | 800 | sym.out_n_sect = sect_index; |
| 801 | 801 | atom.out_n_sect = sect_index; |
| 802 | 802 | |
| 803 | sym.name = try self.strtab.insert(gpa, decl_name); | |
| 803 | sym.name = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool)); | |
| 804 | 804 | atom.flags.alive = true; |
| 805 | 805 | atom.name = sym.name; |
| 806 | 806 | nlist.n_strx = sym.name; |
| ... | ... | @@ -819,7 +819,7 @@ fn updateDeclCode( |
| 819 | 819 | |
| 820 | 820 | if (need_realloc) { |
| 821 | 821 | try atom.grow(macho_file); |
| 822 | log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, old_vaddr, atom.value }); | |
| 822 | log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom.value }); | |
| 823 | 823 | if (old_vaddr != atom.value) { |
| 824 | 824 | sym.value = 0; |
| 825 | 825 | nlist.n_value = 0; |
| ... | ... | @@ -870,23 +870,24 @@ fn updateTlv( |
| 870 | 870 | ) !void { |
| 871 | 871 | const mod = macho_file.base.comp.module.?; |
| 872 | 872 | const decl = mod.declPtr(decl_index); |
| 873 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 873 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 874 | 874 | |
| 875 | log.debug("updateTlv {s} ({*})", .{ decl_name, decl }); | |
| 875 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 876 | 876 | |
| 877 | const decl_name_slice = decl_name.toSlice(&mod.intern_pool); | |
| 877 | 878 | const required_alignment = decl.getAlignment(mod); |
| 878 | 879 | |
| 879 | 880 | // 1. Lower TLV initializer |
| 880 | 881 | const init_sym_index = try self.createTlvInitializer( |
| 881 | 882 | macho_file, |
| 882 | decl_name, | |
| 883 | decl_name_slice, | |
| 883 | 884 | required_alignment, |
| 884 | 885 | sect_index, |
| 885 | 886 | code, |
| 886 | 887 | ); |
| 887 | 888 | |
| 888 | 889 | // 2. Create TLV descriptor |
| 889 | try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl_name); | |
| 890 | try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl_name_slice); | |
| 890 | 891 | } |
| 891 | 892 | |
| 892 | 893 | fn createTlvInitializer( |
| ... | ... | @@ -1073,9 +1074,9 @@ pub fn lowerUnnamedConst( |
| 1073 | 1074 | } |
| 1074 | 1075 | const unnamed_consts = gop.value_ptr; |
| 1075 | 1076 | const decl = mod.declPtr(decl_index); |
| 1076 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1077 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1077 | 1078 | const index = unnamed_consts.items.len; |
| 1078 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); | |
| 1079 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | |
| 1079 | 1080 | defer gpa.free(name); |
| 1080 | 1081 | const sym_index = switch (try self.lowerConst( |
| 1081 | 1082 | macho_file, |
| ... | ... | @@ -1199,7 +1200,7 @@ pub fn updateExports( |
| 1199 | 1200 | |
| 1200 | 1201 | for (exports) |exp| { |
| 1201 | 1202 | if (exp.opts.section.unwrap()) |section_name| { |
| 1202 | if (!mod.intern_pool.stringEqlSlice(section_name, "__text")) { | |
| 1203 | if (!section_name.eqlSlice("__text", &mod.intern_pool)) { | |
| 1203 | 1204 | try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); |
| 1204 | 1205 | mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create( |
| 1205 | 1206 | gpa, |
| ... | ... | @@ -1220,7 +1221,7 @@ pub fn updateExports( |
| 1220 | 1221 | continue; |
| 1221 | 1222 | } |
| 1222 | 1223 | |
| 1223 | const exp_name = mod.intern_pool.stringToSlice(exp.opts.name); | |
| 1224 | const exp_name = exp.opts.name.toSlice(&mod.intern_pool); | |
| 1224 | 1225 | const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index| |
| 1225 | 1226 | exp_index.* |
| 1226 | 1227 | else blk: { |
| ... | ... | @@ -1349,13 +1350,12 @@ pub fn deleteDeclExport( |
| 1349 | 1350 | decl_index: InternPool.DeclIndex, |
| 1350 | 1351 | name: InternPool.NullTerminatedString, |
| 1351 | 1352 | ) void { |
| 1352 | const metadata = self.decls.getPtr(decl_index) orelse return; | |
| 1353 | ||
| 1354 | 1353 | const mod = macho_file.base.comp.module.?; |
| 1355 | const exp_name = mod.intern_pool.stringToSlice(name); | |
| 1356 | const nlist_index = metadata.@"export"(self, exp_name) orelse return; | |
| 1357 | 1354 | |
| 1358 | log.debug("deleting export '{s}'", .{exp_name}); | |
| 1355 | const metadata = self.decls.getPtr(decl_index) orelse return; | |
| 1356 | const nlist_index = metadata.@"export"(self, name.toSlice(&mod.intern_pool)) orelse return; | |
| 1357 | ||
| 1358 | log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)}); | |
| 1359 | 1359 | |
| 1360 | 1360 | const nlist = &self.symtab.items(.nlist)[nlist_index.*]; |
| 1361 | 1361 | self.symtab.items(.size)[nlist_index.*] = 0; |
src/link/Plan9.zig+23-19| ... | ... | @@ -477,11 +477,11 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn |
| 477 | 477 | } |
| 478 | 478 | const unnamed_consts = gop.value_ptr; |
| 479 | 479 | |
| 480 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 480 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 481 | 481 | |
| 482 | 482 | const index = unnamed_consts.items.len; |
| 483 | 483 | // name is freed when the unnamed const is freed |
| 484 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); | |
| 484 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | |
| 485 | 485 | |
| 486 | 486 | const sym_index = try self.allocateSymbolIndex(); |
| 487 | 487 | const new_atom_idx = try self.createAtom(); |
| ... | ... | @@ -529,7 +529,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) |
| 529 | 529 | const decl = mod.declPtr(decl_index); |
| 530 | 530 | |
| 531 | 531 | if (decl.isExtern(mod)) { |
| 532 | log.debug("found extern decl: {s}", .{mod.intern_pool.stringToSlice(decl.name)}); | |
| 532 | log.debug("found extern decl: {}", .{decl.name.fmt(&mod.intern_pool)}); | |
| 533 | 533 | return; |
| 534 | 534 | } |
| 535 | 535 | const atom_idx = try self.seeDecl(decl_index); |
| ... | ... | @@ -573,7 +573,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void { |
| 573 | 573 | const sym: aout.Sym = .{ |
| 574 | 574 | .value = undefined, // the value of stuff gets filled in in flushModule |
| 575 | 575 | .type = atom.type, |
| 576 | .name = try gpa.dupe(u8, mod.intern_pool.stringToSlice(decl.name)), | |
| 576 | .name = try gpa.dupe(u8, decl.name.toSlice(&mod.intern_pool)), | |
| 577 | 577 | }; |
| 578 | 578 | |
| 579 | 579 | if (atom.sym_index) |s| { |
| ... | ... | @@ -1013,10 +1013,12 @@ fn addDeclExports( |
| 1013 | 1013 | const atom = self.getAtom(metadata.index); |
| 1014 | 1014 | |
| 1015 | 1015 | for (exports) |exp| { |
| 1016 | const exp_name = mod.intern_pool.stringToSlice(exp.opts.name); | |
| 1016 | const exp_name = exp.opts.name.toSlice(&mod.intern_pool); | |
| 1017 | 1017 | // plan9 does not support custom sections |
| 1018 | 1018 | if (exp.opts.section.unwrap()) |section_name| { |
| 1019 | if (!mod.intern_pool.stringEqlSlice(section_name, ".text") and !mod.intern_pool.stringEqlSlice(section_name, ".data")) { | |
| 1019 | if (!section_name.eqlSlice(".text", &mod.intern_pool) and | |
| 1020 | !section_name.eqlSlice(".data", &mod.intern_pool)) | |
| 1021 | { | |
| 1020 | 1022 | try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create( |
| 1021 | 1023 | gpa, |
| 1022 | 1024 | mod.declPtr(decl_index).srcLoc(mod), |
| ... | ... | @@ -1129,19 +1131,21 @@ pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index { |
| 1129 | 1131 | // handle externs here because they might not get updateDecl called on them |
| 1130 | 1132 | const mod = self.base.comp.module.?; |
| 1131 | 1133 | const decl = mod.declPtr(decl_index); |
| 1132 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 1133 | 1134 | if (decl.isExtern(mod)) { |
| 1134 | 1135 | // this is a "phantom atom" - it is never actually written to disk, just convenient for us to store stuff about externs |
| 1135 | if (std.mem.eql(u8, name, "etext")) { | |
| 1136 | if (decl.name.eqlSlice("etext", &mod.intern_pool)) { | |
| 1136 | 1137 | self.etext_edata_end_atom_indices[0] = atom_idx; |
| 1137 | } else if (std.mem.eql(u8, name, "edata")) { | |
| 1138 | } else if (decl.name.eqlSlice("edata", &mod.intern_pool)) { | |
| 1138 | 1139 | self.etext_edata_end_atom_indices[1] = atom_idx; |
| 1139 | } else if (std.mem.eql(u8, name, "end")) { | |
| 1140 | } else if (decl.name.eqlSlice("end", &mod.intern_pool)) { | |
| 1140 | 1141 | self.etext_edata_end_atom_indices[2] = atom_idx; |
| 1141 | 1142 | } |
| 1142 | 1143 | try self.updateFinish(decl_index); |
| 1143 | log.debug("seeDecl(extern) for {s} (got_addr=0x{x})", .{ name, self.getAtom(atom_idx).getOffsetTableAddress(self) }); | |
| 1144 | } else log.debug("seeDecl for {s}", .{name}); | |
| 1144 | log.debug("seeDecl(extern) for {} (got_addr=0x{x})", .{ | |
| 1145 | decl.name.fmt(&mod.intern_pool), | |
| 1146 | self.getAtom(atom_idx).getOffsetTableAddress(self), | |
| 1147 | }); | |
| 1148 | } else log.debug("seeDecl for {}", .{decl.name.fmt(&mod.intern_pool)}); | |
| 1145 | 1149 | return atom_idx; |
| 1146 | 1150 | } |
| 1147 | 1151 | |
| ... | ... | @@ -1393,7 +1397,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { |
| 1393 | 1397 | const sym = self.syms.items[atom.sym_index.?]; |
| 1394 | 1398 | try self.writeSym(writer, sym); |
| 1395 | 1399 | if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| { |
| 1396 | for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| { | |
| 1400 | for (exports.items) |e| if (decl_metadata.getExport(self, e.opts.name.toSlice(ip))) |exp_i| { | |
| 1397 | 1401 | try self.writeSym(writer, self.syms.items[exp_i]); |
| 1398 | 1402 | }; |
| 1399 | 1403 | } |
| ... | ... | @@ -1440,7 +1444,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { |
| 1440 | 1444 | const sym = self.syms.items[atom.sym_index.?]; |
| 1441 | 1445 | try self.writeSym(writer, sym); |
| 1442 | 1446 | if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| { |
| 1443 | for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| { | |
| 1447 | for (exports.items) |e| if (decl_metadata.getExport(self, e.opts.name.toSlice(ip))) |exp_i| { | |
| 1444 | 1448 | const s = self.syms.items[exp_i]; |
| 1445 | 1449 | if (mem.eql(u8, s.name, "_start")) |
| 1446 | 1450 | self.entry_val = s.value; |
| ... | ... | @@ -1483,25 +1487,25 @@ pub fn getDeclVAddr( |
| 1483 | 1487 | reloc_info: link.File.RelocInfo, |
| 1484 | 1488 | ) !u64 { |
| 1485 | 1489 | const mod = self.base.comp.module.?; |
| 1490 | const ip = &mod.intern_pool; | |
| 1486 | 1491 | const decl = mod.declPtr(decl_index); |
| 1487 | log.debug("getDeclVAddr for {s}", .{mod.intern_pool.stringToSlice(decl.name)}); | |
| 1492 | log.debug("getDeclVAddr for {}", .{decl.name.fmt(ip)}); | |
| 1488 | 1493 | if (decl.isExtern(mod)) { |
| 1489 | const extern_name = mod.intern_pool.stringToSlice(decl.name); | |
| 1490 | if (std.mem.eql(u8, extern_name, "etext")) { | |
| 1494 | if (decl.name.eqlSlice("etext", ip)) { | |
| 1491 | 1495 | try self.addReloc(reloc_info.parent_atom_index, .{ |
| 1492 | 1496 | .target = undefined, |
| 1493 | 1497 | .offset = reloc_info.offset, |
| 1494 | 1498 | .addend = reloc_info.addend, |
| 1495 | 1499 | .type = .special_etext, |
| 1496 | 1500 | }); |
| 1497 | } else if (std.mem.eql(u8, extern_name, "edata")) { | |
| 1501 | } else if (decl.name.eqlSlice("edata", ip)) { | |
| 1498 | 1502 | try self.addReloc(reloc_info.parent_atom_index, .{ |
| 1499 | 1503 | .target = undefined, |
| 1500 | 1504 | .offset = reloc_info.offset, |
| 1501 | 1505 | .addend = reloc_info.addend, |
| 1502 | 1506 | .type = .special_edata, |
| 1503 | 1507 | }); |
| 1504 | } else if (std.mem.eql(u8, extern_name, "end")) { | |
| 1508 | } else if (decl.name.eqlSlice("end", ip)) { | |
| 1505 | 1509 | try self.addReloc(reloc_info.parent_atom_index, .{ |
| 1506 | 1510 | .target = undefined, |
| 1507 | 1511 | .offset = reloc_info.offset, |
src/link/SpirV.zig+5-6| ... | ... | @@ -130,7 +130,7 @@ pub fn updateFunc(self: *SpirV, module: *Module, func_index: InternPool.Index, a |
| 130 | 130 | |
| 131 | 131 | const func = module.funcInfo(func_index); |
| 132 | 132 | const decl = module.declPtr(func.owner_decl); |
| 133 | log.debug("lowering function {s}", .{module.intern_pool.stringToSlice(decl.name)}); | |
| 133 | log.debug("lowering function {}", .{decl.name.fmt(&module.intern_pool)}); | |
| 134 | 134 | |
| 135 | 135 | try self.object.updateFunc(module, func_index, air, liveness); |
| 136 | 136 | } |
| ... | ... | @@ -141,7 +141,7 @@ pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclInde |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | const decl = module.declPtr(decl_index); |
| 144 | log.debug("lowering declaration {s}", .{module.intern_pool.stringToSlice(decl.name)}); | |
| 144 | log.debug("lowering declaration {}", .{decl.name.fmt(&module.intern_pool)}); | |
| 145 | 145 | |
| 146 | 146 | try self.object.updateDecl(module, decl_index); |
| 147 | 147 | } |
| ... | ... | @@ -178,7 +178,7 @@ pub fn updateExports( |
| 178 | 178 | for (exports) |exp| { |
| 179 | 179 | try self.object.spv.declareEntryPoint( |
| 180 | 180 | spv_decl_index, |
| 181 | mod.intern_pool.stringToSlice(exp.opts.name), | |
| 181 | exp.opts.name.toSlice(&mod.intern_pool), | |
| 182 | 182 | execution_model, |
| 183 | 183 | ); |
| 184 | 184 | } |
| ... | ... | @@ -227,14 +227,13 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node |
| 227 | 227 | |
| 228 | 228 | try error_info.appendSlice("zig_errors"); |
| 229 | 229 | const mod = self.base.comp.module.?; |
| 230 | for (mod.global_error_set.keys()) |name_nts| { | |
| 231 | const name = mod.intern_pool.stringToSlice(name_nts); | |
| 230 | for (mod.global_error_set.keys()) |name| { | |
| 232 | 231 | // Errors can contain pretty much any character - to encode them in a string we must escape |
| 233 | 232 | // them somehow. Easiest here is to use some established scheme, one which also preseves the |
| 234 | 233 | // name if it contains no strange characters is nice for debugging. URI encoding fits the bill. |
| 235 | 234 | // We're using : as separator, which is a reserved character. |
| 236 | 235 | |
| 237 | const escaped_name = try std.Uri.escapeString(gpa, name); | |
| 236 | const escaped_name = try std.Uri.escapeString(gpa, name.toSlice(&mod.intern_pool)); | |
| 238 | 237 | defer gpa.free(escaped_name); |
| 239 | 238 | try error_info.writer().print(":{s}", .{escaped_name}); |
| 240 | 239 | } |
src/link/Wasm/ZigObject.zig+22-26| ... | ... | @@ -258,8 +258,8 @@ pub fn updateDecl( |
| 258 | 258 | |
| 259 | 259 | if (decl.isExtern(mod)) { |
| 260 | 260 | const variable = decl.getOwnedVariable(mod).?; |
| 261 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 262 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); | |
| 261 | const name = decl.name.toSlice(&mod.intern_pool); | |
| 262 | const lib_name = variable.lib_name.toSlice(&mod.intern_pool); | |
| 263 | 263 | return zig_object.addOrUpdateImport(wasm_file, name, atom.sym_index, lib_name, null); |
| 264 | 264 | } |
| 265 | 265 | const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| ... | ... | @@ -341,8 +341,8 @@ fn finishUpdateDecl( |
| 341 | 341 | const atom_index = decl_info.atom; |
| 342 | 342 | const atom = wasm_file.getAtomPtr(atom_index); |
| 343 | 343 | const sym = zig_object.symbol(atom.sym_index); |
| 344 | const full_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 345 | sym.name = try zig_object.string_table.insert(gpa, full_name); | |
| 344 | const full_name = try decl.fullyQualifiedName(mod); | |
| 345 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool)); | |
| 346 | 346 | try atom.code.appendSlice(gpa, code); |
| 347 | 347 | atom.size = @intCast(code.len); |
| 348 | 348 | |
| ... | ... | @@ -382,7 +382,7 @@ fn finishUpdateDecl( |
| 382 | 382 | // Will be freed upon freeing of decl or after cleanup of Wasm binary. |
| 383 | 383 | const full_segment_name = try std.mem.concat(gpa, u8, &.{ |
| 384 | 384 | segment_name, |
| 385 | full_name, | |
| 385 | full_name.toSlice(&mod.intern_pool), | |
| 386 | 386 | }); |
| 387 | 387 | errdefer gpa.free(full_segment_name); |
| 388 | 388 | sym.tag = .data; |
| ... | ... | @@ -427,9 +427,9 @@ pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_ind |
| 427 | 427 | gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) }; |
| 428 | 428 | const mod = wasm_file.base.comp.module.?; |
| 429 | 429 | const decl = mod.declPtr(decl_index); |
| 430 | const full_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 430 | const full_name = try decl.fullyQualifiedName(mod); | |
| 431 | 431 | const sym = zig_object.symbol(sym_index); |
| 432 | sym.name = try zig_object.string_table.insert(gpa, full_name); | |
| 432 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool)); | |
| 433 | 433 | } |
| 434 | 434 | return gop.value_ptr.atom; |
| 435 | 435 | } |
| ... | ... | @@ -478,9 +478,9 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d |
| 478 | 478 | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| 479 | 479 | const parent_atom = wasm_file.getAtom(parent_atom_index); |
| 480 | 480 | const local_index = parent_atom.locals.items.len; |
| 481 | const fqn = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 482 | const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{s}_{d}", .{ | |
| 483 | fqn, local_index, | |
| 481 | const fqn = try decl.fullyQualifiedName(mod); | |
| 482 | const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{ | |
| 483 | fqn.fmt(&mod.intern_pool), local_index, | |
| 484 | 484 | }); |
| 485 | 485 | defer gpa.free(name); |
| 486 | 486 | |
| ... | ... | @@ -623,11 +623,11 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void { |
| 623 | 623 | // Addend for each relocation to the table |
| 624 | 624 | var addend: u32 = 0; |
| 625 | 625 | const mod = wasm_file.base.comp.module.?; |
| 626 | for (mod.global_error_set.keys()) |error_name_nts| { | |
| 626 | for (mod.global_error_set.keys()) |error_name| { | |
| 627 | 627 | const atom = wasm_file.getAtomPtr(atom_index); |
| 628 | 628 | |
| 629 | const error_name = mod.intern_pool.stringToSlice(error_name_nts); | |
| 630 | const len: u32 = @intCast(error_name.len + 1); // names are 0-terminated | |
| 629 | const error_name_slice = error_name.toSlice(&mod.intern_pool); | |
| 630 | const len: u32 = @intCast(error_name_slice.len + 1); // names are 0-terminated | |
| 631 | 631 | |
| 632 | 632 | const slice_ty = Type.slice_const_u8_sentinel_0; |
| 633 | 633 | const offset = @as(u32, @intCast(atom.code.items.len)); |
| ... | ... | @@ -646,10 +646,9 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void { |
| 646 | 646 | |
| 647 | 647 | // as we updated the error name table, we now store the actual name within the names atom |
| 648 | 648 | try names_atom.code.ensureUnusedCapacity(gpa, len); |
| 649 | names_atom.code.appendSliceAssumeCapacity(error_name); | |
| 650 | names_atom.code.appendAssumeCapacity(0); | |
| 649 | names_atom.code.appendSliceAssumeCapacity(error_name_slice[0..len]); | |
| 651 | 650 | |
| 652 | log.debug("Populated error name: '{s}'", .{error_name}); | |
| 651 | log.debug("Populated error name: '{}'", .{error_name.fmt(&mod.intern_pool)}); | |
| 653 | 652 | } |
| 654 | 653 | names_atom.size = addend; |
| 655 | 654 | zig_object.error_names_atom = names_atom_index; |
| ... | ... | @@ -833,8 +832,7 @@ pub fn deleteDeclExport( |
| 833 | 832 | ) void { |
| 834 | 833 | const mod = wasm_file.base.comp.module.?; |
| 835 | 834 | const decl_info = zig_object.decls_map.getPtr(decl_index) orelse return; |
| 836 | const export_name = mod.intern_pool.stringToSlice(name); | |
| 837 | if (decl_info.@"export"(zig_object, export_name)) |sym_index| { | |
| 835 | if (decl_info.@"export"(zig_object, name.toSlice(&mod.intern_pool))) |sym_index| { | |
| 838 | 836 | const sym = zig_object.symbol(sym_index); |
| 839 | 837 | decl_info.deleteExport(sym_index); |
| 840 | 838 | std.debug.assert(zig_object.global_syms.remove(sym.name)); |
| ... | ... | @@ -864,10 +862,10 @@ pub fn updateExports( |
| 864 | 862 | const atom = wasm_file.getAtom(atom_index); |
| 865 | 863 | const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*; |
| 866 | 864 | const gpa = mod.gpa; |
| 867 | log.debug("Updating exports for decl '{s}'", .{mod.intern_pool.stringToSlice(decl.name)}); | |
| 865 | log.debug("Updating exports for decl '{}'", .{decl.name.fmt(&mod.intern_pool)}); | |
| 868 | 866 | |
| 869 | 867 | for (exports) |exp| { |
| 870 | if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section| { | |
| 868 | if (exp.opts.section.toSlice(&mod.intern_pool)) |section| { | |
| 871 | 869 | try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create( |
| 872 | 870 | gpa, |
| 873 | 871 | decl.srcLoc(mod), |
| ... | ... | @@ -877,10 +875,8 @@ pub fn updateExports( |
| 877 | 875 | continue; |
| 878 | 876 | } |
| 879 | 877 | |
| 880 | const export_string = mod.intern_pool.stringToSlice(exp.opts.name); | |
| 881 | const sym_index = if (decl_info.@"export"(zig_object, export_string)) |idx| | |
| 882 | idx | |
| 883 | else index: { | |
| 878 | const export_string = exp.opts.name.toSlice(&mod.intern_pool); | |
| 879 | const sym_index = if (decl_info.@"export"(zig_object, export_string)) |idx| idx else index: { | |
| 884 | 880 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 885 | 881 | try decl_info.appendExport(gpa, sym_index); |
| 886 | 882 | break :index sym_index; |
| ... | ... | @@ -1089,9 +1085,9 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde |
| 1089 | 1085 | pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void { |
| 1090 | 1086 | if (zig_object.dwarf) |*dw| { |
| 1091 | 1087 | const decl = mod.declPtr(decl_index); |
| 1092 | const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)); | |
| 1088 | const decl_name = try decl.fullyQualifiedName(mod); | |
| 1093 | 1089 | |
| 1094 | log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl }); | |
| 1090 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | |
| 1095 | 1091 | try dw.updateDeclLineNumber(mod, decl_index); |
| 1096 | 1092 | } |
| 1097 | 1093 | } |
src/mutable_value.zig+6-6| ... | ... | @@ -73,7 +73,7 @@ pub const MutableValue = union(enum) { |
| 73 | 73 | } }), |
| 74 | 74 | .bytes => |b| try ip.get(gpa, .{ .aggregate = .{ |
| 75 | 75 | .ty = b.ty, |
| 76 | .storage = .{ .bytes = b.data }, | |
| 76 | .storage = .{ .bytes = try ip.getOrPutString(gpa, b.data, .maybe_embedded_nulls) }, | |
| 77 | 77 | } }), |
| 78 | 78 | .aggregate => |a| { |
| 79 | 79 | const elems = try arena.alloc(InternPool.Index, a.elems.len); |
| ... | ... | @@ -158,18 +158,18 @@ pub const MutableValue = union(enum) { |
| 158 | 158 | }, |
| 159 | 159 | .aggregate => |agg| switch (agg.storage) { |
| 160 | 160 | .bytes => |bytes| { |
| 161 | assert(bytes.len == ip.aggregateTypeLenIncludingSentinel(agg.ty)); | |
| 161 | const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(agg.ty)); | |
| 162 | 162 | assert(ip.childType(agg.ty) == .u8_type); |
| 163 | 163 | if (allow_bytes) { |
| 164 | const arena_bytes = try arena.alloc(u8, bytes.len); | |
| 165 | @memcpy(arena_bytes, bytes); | |
| 164 | const arena_bytes = try arena.alloc(u8, len); | |
| 165 | @memcpy(arena_bytes, bytes.toSlice(len, ip)); | |
| 166 | 166 | mv.* = .{ .bytes = .{ |
| 167 | 167 | .ty = agg.ty, |
| 168 | 168 | .data = arena_bytes, |
| 169 | 169 | } }; |
| 170 | 170 | } else { |
| 171 | const mut_elems = try arena.alloc(MutableValue, bytes.len); | |
| 172 | for (bytes, mut_elems) |b, *mut_elem| { | |
| 171 | const mut_elems = try arena.alloc(MutableValue, len); | |
| 172 | for (bytes.toSlice(len, ip), mut_elems) |b, *mut_elem| { | |
| 173 | 173 | mut_elem.* = .{ .interned = try ip.get(gpa, .{ .int = .{ |
| 174 | 174 | .ty = .u8_type, |
| 175 | 175 | .storage = .{ .u64 = b }, |
src/print_value.zig+29-20| ... | ... | @@ -204,26 +204,35 @@ fn printAggregate( |
| 204 | 204 | try writer.writeAll(" }"); |
| 205 | 205 | return; |
| 206 | 206 | }, |
| 207 | .Array => if (aggregate.storage == .bytes and aggregate.storage.bytes.len > 0) { | |
| 208 | const skip_terminator = aggregate.storage.bytes[aggregate.storage.bytes.len - 1] == 0; | |
| 209 | const bytes = if (skip_terminator) b: { | |
| 210 | break :b aggregate.storage.bytes[0 .. aggregate.storage.bytes.len - 1]; | |
| 211 | } else aggregate.storage.bytes; | |
| 212 | try writer.print("\"{}\"", .{std.zig.fmtEscapes(bytes)}); | |
| 213 | if (!is_ref) try writer.writeAll(".*"); | |
| 214 | return; | |
| 215 | } else if (ty.arrayLen(zcu) == 0) { | |
| 216 | if (is_ref) try writer.writeByte('&'); | |
| 217 | return writer.writeAll(".{}"); | |
| 218 | } else if (ty.arrayLen(zcu) == 1) one_byte_str: { | |
| 219 | // The repr isn't `bytes`, but we might still be able to print this as a string | |
| 220 | if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str; | |
| 221 | const elem_val = Value.fromInterned(aggregate.storage.values()[0]); | |
| 222 | if (elem_val.isUndef(zcu)) break :one_byte_str; | |
| 223 | const byte = elem_val.toUnsignedInt(zcu); | |
| 224 | try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})}); | |
| 225 | if (!is_ref) try writer.writeAll(".*"); | |
| 226 | return; | |
| 207 | .Array => { | |
| 208 | switch (aggregate.storage) { | |
| 209 | .bytes => |bytes| string: { | |
| 210 | const len = ty.arrayLenIncludingSentinel(zcu); | |
| 211 | if (len == 0) break :string; | |
| 212 | const slice = bytes.toSlice(if (bytes.at(len - 1, ip) == 0) len - 1 else len, ip); | |
| 213 | try writer.print("\"{}\"", .{std.zig.fmtEscapes(slice)}); | |
| 214 | if (!is_ref) try writer.writeAll(".*"); | |
| 215 | return; | |
| 216 | }, | |
| 217 | .elems, .repeated_elem => {}, | |
| 218 | } | |
| 219 | switch (ty.arrayLen(zcu)) { | |
| 220 | 0 => { | |
| 221 | if (is_ref) try writer.writeByte('&'); | |
| 222 | return writer.writeAll(".{}"); | |
| 223 | }, | |
| 224 | 1 => one_byte_str: { | |
| 225 | // The repr isn't `bytes`, but we might still be able to print this as a string | |
| 226 | if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str; | |
| 227 | const elem_val = Value.fromInterned(aggregate.storage.values()[0]); | |
| 228 | if (elem_val.isUndef(zcu)) break :one_byte_str; | |
| 229 | const byte = elem_val.toUnsignedInt(zcu); | |
| 230 | try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})}); | |
| 231 | if (!is_ref) try writer.writeAll(".*"); | |
| 232 | return; | |
| 233 | }, | |
| 234 | else => {}, | |
| 235 | } | |
| 227 | 236 | }, |
| 228 | 237 | .Vector => if (ty.arrayLen(zcu) == 0) { |
| 229 | 238 | if (is_ref) try writer.writeByte('&'); |
src/target.zig+9-4| ... | ... | @@ -59,10 +59,15 @@ pub fn alwaysSingleThreaded(target: std.Target) bool { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | pub fn defaultSingleThreaded(target: std.Target) bool { |
| 62 | return switch (target.cpu.arch) { | |
| 63 | .wasm32, .wasm64 => true, | |
| 64 | else => false, | |
| 65 | }; | |
| 62 | switch (target.cpu.arch) { | |
| 63 | .wasm32, .wasm64 => return true, | |
| 64 | else => {}, | |
| 65 | } | |
| 66 | switch (target.os.tag) { | |
| 67 | .haiku => return true, | |
| 68 | else => {}, | |
| 69 | } | |
| 70 | return false; | |
| 66 | 71 | } |
| 67 | 72 | |
| 68 | 73 | /// Valgrind supports more, but Zig does not support them yet. |
src/type.zig+7-15| ... | ... | @@ -490,18 +490,10 @@ pub const Type = struct { |
| 490 | 490 | }; |
| 491 | 491 | }, |
| 492 | 492 | .anyframe_type => true, |
| 493 | .array_type => |array_type| { | |
| 494 | if (array_type.sentinel != .none) { | |
| 495 | return Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); | |
| 496 | } else { | |
| 497 | return array_type.len > 0 and | |
| 498 | try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); | |
| 499 | } | |
| 500 | }, | |
| 501 | .vector_type => |vector_type| { | |
| 502 | return vector_type.len > 0 and | |
| 503 | try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); | |
| 504 | }, | |
| 493 | .array_type => |array_type| return array_type.lenIncludingSentinel() > 0 and | |
| 494 | try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), | |
| 495 | .vector_type => |vector_type| return vector_type.len > 0 and | |
| 496 | try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), | |
| 505 | 497 | .opt_type => |child| { |
| 506 | 498 | const child_ty = Type.fromInterned(child); |
| 507 | 499 | if (child_ty.isNoReturn(mod)) { |
| ... | ... | @@ -1240,7 +1232,7 @@ pub const Type = struct { |
| 1240 | 1232 | .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) }, |
| 1241 | 1233 | |
| 1242 | 1234 | .array_type => |array_type| { |
| 1243 | const len = array_type.len + @intFromBool(array_type.sentinel != .none); | |
| 1235 | const len = array_type.lenIncludingSentinel(); | |
| 1244 | 1236 | if (len == 0) return .{ .scalar = 0 }; |
| 1245 | 1237 | switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) { |
| 1246 | 1238 | .scalar => |elem_size| return .{ .scalar = len * elem_size }, |
| ... | ... | @@ -1577,7 +1569,7 @@ pub const Type = struct { |
| 1577 | 1569 | .anyframe_type => return target.ptrBitWidth(), |
| 1578 | 1570 | |
| 1579 | 1571 | .array_type => |array_type| { |
| 1580 | const len = array_type.len + @intFromBool(array_type.sentinel != .none); | |
| 1572 | const len = array_type.lenIncludingSentinel(); | |
| 1581 | 1573 | if (len == 0) return 0; |
| 1582 | 1574 | const elem_ty = Type.fromInterned(array_type.child); |
| 1583 | 1575 | const elem_size = @max( |
| ... | ... | @@ -1731,7 +1723,7 @@ pub const Type = struct { |
| 1731 | 1723 | .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip), |
| 1732 | 1724 | .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip), |
| 1733 | 1725 | .array_type => |array_type| { |
| 1734 | if ((array_type.len + @intFromBool(array_type.sentinel != .none)) == 0) return true; | |
| 1726 | if (array_type.lenIncludingSentinel() == 0) return true; | |
| 1735 | 1727 | return Type.fromInterned(array_type.child).layoutIsResolved(mod); |
| 1736 | 1728 | }, |
| 1737 | 1729 | .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod), |
stage1/zig1.wasm| Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ |