authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-09 00:50:58-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-04-09 00:50:58-07:00
logac21ade667f0f42b8b1aec5831cbc99cbaed8565
treef66d847662b81eefe8c30de88dfedb0d93cdc524
parentd979df585d05de8d7385495fe6aee2b1d4e1380f
parentbc0e2089bc9408fa76716652a8ede5b5b44a817a
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19572 from jacobly0/haiku-bootstrap

haiku: get cmake bootstrap working

37 files changed, 2032 insertions(+), 1747 deletions(-)

build.zig+3
......@@ -747,6 +747,9 @@ fn addCmakeCfgOptionsToExe(
747747 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
748748 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
749749 },
750 .haiku => {
751 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
752 },
750753 else => {},
751754 }
752755 }
lib/std/Target.zig+7
......@@ -2740,6 +2740,13 @@ pub fn is_libc_lib_name(target: std.Target, name: []const u8) bool {
27402740 return true;
27412741 }
27422742
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
27432750 return false;
27442751}
27452752
lib/std/c/haiku.zig+808-681
......@@ -5,28 +5,18 @@ const maxInt = std.math.maxInt;
55const iovec = std.posix.iovec;
66const iovec_const = std.posix.iovec_const;
77
8extern "c" fn _errnop() *c_int;
8pub extern "root" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
99
10pub const _errno = _errnop;
11
12pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
10pub extern "root" fn find_thread(thread_name: ?*anyopaque) i32;
1311
14pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
12pub extern "root" fn get_system_info(system_info: *system_info) usize;
1513
16pub extern "c" fn get_system_info(system_info: *system_info) usize;
14pub extern "root" fn _get_team_info(team: i32, team_info: *team_info, size: usize) i32;
1715
18pub extern "c" fn _get_team_info(team: c_int, team_info: *team_info, size: usize) i32;
19
20pub extern "c" fn _get_next_area_info(team: c_int, cookie: *i64, area_info: *area_info, size: usize) i32;
16pub extern "root" fn _get_next_area_info(team: i32, cookie: *i64, area_info: *area_info, size: usize) i32;
2117
2218// TODO revisit if abi changes or better option becomes apparent
23pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info, size: usize) i32;
24
25pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
26
27pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, st: *Stat, stat_size: i32) usize;
28
29pub extern "c" fn _kern_get_current_team() i32;
19pub extern "root" fn _get_next_image_info(team: i32, cookie: *i32, image_info: *image_info, size: usize) i32;
3020
3121pub const sem_t = extern struct {
3222 type: i32,
......@@ -45,7 +35,7 @@ pub const pthread_attr_t = extern struct {
4535 __stack_address: ?*anyopaque,
4636};
4737
48pub const EAI = enum(c_int) {
38pub const EAI = enum(i32) {
4939 /// address family for hostname not supported
5040 ADDRFAMILY = 1,
5141
......@@ -99,11 +89,7 @@ pub const AI = struct {
9989
10090pub const AI_NUMERICSERV = AI.NUMERICSERV;
10191
102pub const fd_t = c_int;
103pub const pid_t = c_int;
104pub const uid_t = u32;
105pub const gid_t = u32;
106pub const mode_t = c_uint;
92pub const fd_t = i32;
10793
10894pub const socklen_t = u32;
10995
......@@ -129,8 +115,8 @@ pub const dl_phdr_info = extern struct {
129115};
130116
131117pub const Flock = extern struct {
132 type: c_short,
133 whence: c_short,
118 type: i16,
119 whence: i16,
134120 start: off_t,
135121 len: off_t,
136122 pid: pid_t,
......@@ -159,54 +145,6 @@ pub const msghdr = extern struct {
159145 msg_flags: i32,
160146};
161147
162pub const off_t = i64;
163pub const ino_t = u64;
164
165pub 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
196pub const timespec = extern struct {
197 tv_sec: isize,
198 tv_nsec: isize,
199};
200
201pub 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
210148pub const B_OS_NAME_LENGTH = 32; // OS.h
211149
212150pub const area_info = extern struct {
......@@ -354,17 +292,6 @@ pub const PROT = struct {
354292 pub const NONE = 0x00;
355293};
356294
357pub 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
368295pub const MSF = struct {
369296 pub const ASYNC = 1;
370297 pub const INVALIDATE = 2;
......@@ -404,159 +331,526 @@ pub const W = struct {
404331 }
405332};
406333
407// /system/develop/headers/posix/poll.h
408
409pub const nfds_t = usize;
334// access function
335pub const F_OK = 0; // test for existence of file
336pub const X_OK = 1; // test for execute or search permission
337pub const W_OK = 2; // test for write permission
338pub const R_OK = 4; // test for read permission
410339
411pub const pollfd = extern struct {
412 fd: i32,
413 events: i16,
414 revents: i16,
415};
340pub 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;
416346
417pub 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;
430351
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;
437355};
438356
439// /system/develop/headers/posix/signal.h
440
441pub const sigset_t = u64;
442pub const empty_sigset: sigset_t = 0;
443pub const filled_sigset = ~@as(sigset_t, 0);
444
445pub 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;
357pub const LOCK = struct {
358 pub const SH = 0x01;
359 pub const EX = 0x02;
360 pub const NB = 0x04;
361 pub const UN = 0x08;
489362};
490363
491pub const siginfo_t = extern struct {
492 signo: c_int,
493 code: c_int,
494 errno: c_int,
364pub const FD_CLOEXEC = 1;
495365
496 pid: pid_t,
497 uid: uid_t,
498 addr: *allowzero anyopaque,
366pub const SEEK = struct {
367 pub const SET = 0;
368 pub const CUR = 1;
369 pub const END = 2;
499370};
500371
501/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
502pub 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 },
372pub const SOCK = struct {
373 pub const STREAM = 1;
374 pub const DGRAM = 2;
375 pub const RAW = 3;
376 pub const SEQPACKET = 5;
511377
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};
514387
515 /// see signal options
516 flags: c_int,
388pub 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;
517399
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;
520411};
521412
522pub 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;
413pub const SOL = struct {
414 pub const SOCKET = -1;
533415};
534416
535pub const SS = struct {
536 pub const ONSTACK = 0x1;
537 pub const DISABLE = 0x2;
417pub 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;
538426};
539427
540pub const MINSIGSTKSZ = 8192;
541pub const SIGSTKSZ = 16384;
542
543pub const stack_t = extern struct {
544 sp: [*]u8,
545 size: isize,
546 flags: i32,
428pub 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;
547442};
548443
549pub const NSIG = 65;
444pub const DT = struct {};
550445
551pub const mcontext_t = vregs;
446/// add event to kq (implies enable)
447pub const EV_ADD = 0x0001;
552448
553pub 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
450pub const EV_DELETE = 0x0002;
451
452/// enable event
453pub const EV_ENABLE = 0x0004;
454
455/// disable event (not reported)
456pub const EV_DISABLE = 0x0008;
457
458/// only report one occurrence
459pub const EV_ONESHOT = 0x0010;
460
461/// clear event state after reporting
462pub 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
468pub const EV_RECEIPT = 0x0040;
469
470/// disable event after reporting
471pub const EV_DISPATCH = 0x0080;
472
473pub const EVFILT_READ = -1;
474pub const EVFILT_WRITE = -2;
475
476/// attached to aio requests
477pub const EVFILT_AIO = -3;
478
479/// attached to vnodes
480pub const EVFILT_VNODE = -4;
481
482/// attached to struct proc
483pub const EVFILT_PROC = -5;
484
485/// attached to struct proc
486pub const EVFILT_SIGNAL = -6;
487
488/// timers
489pub const EVFILT_TIMER = -7;
490
491/// Process descriptors
492pub const EVFILT_PROCDESC = -8;
493
494/// Filesystem events
495pub const EVFILT_FS = -9;
496
497pub const EVFILT_LIO = -10;
498
499/// User events
500pub const EVFILT_USER = -11;
501
502/// Sendfile events
503pub const EVFILT_SENDFILE = -12;
504
505pub const EVFILT_EMPTY = -13;
506
507pub 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
538pub const winsize = extern struct {
539 ws_row: u16,
540 ws_col: u16,
541 ws_xpixel: u16,
542 ws_ypixel: u16,
543};
544
545pub 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
606pub const HOST_NAME_MAX = 255;
607
608pub 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
619pub 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
639pub 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
651pub const rlim_t = i64;
652
653pub 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
661pub const rlimit = extern struct {
662 /// Soft limit
663 cur: rlim_t,
664 /// Hard limit
665 max: rlim_t,
666};
667
668pub 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
675pub const directory_which = enum(i32) {
676 B_USER_SETTINGS_DIRECTORY = 0xbbe,
677
678 _,
679};
680
681pub const MSG_NOSIGNAL = 0x0800;
682
683// /system/develop/headers/os/kernel/OS.h
684
685pub const area_id = i32;
686pub const port_id = i32;
687pub const sem_id = i32;
688pub const team_id = i32;
689pub const thread_id = i32;
690
691// /system/develop/headers/os/support/Errors.h
692
693pub 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 _,
558848};
559849
850// /system/develop/headers/os/support/SupportDefs.h
851
852pub const status_t = i32;
853
560854// /system/develop/headers/posix/arch/*/signal.h
561855
562856pub const vregs = switch (builtin.cpu.arch) {
......@@ -736,531 +1030,364 @@ pub const vregs = switch (builtin.cpu.arch) {
7361030 reserved2: u16,
7371031 mxcsr: u32,
7381032 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
826pub const F_OK = 0; // test for existence of file
827pub const X_OK = 1; // test for execute or search permission
828pub const W_OK = 2; // test for write permission
829pub const R_OK = 4; // test for read permission
830
831pub 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
848pub 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
855pub const FD_CLOEXEC = 1;
856
857pub const SEEK = struct {
858 pub const SET = 0;
859 pub const CUR = 1;
860 pub const END = 2;
861};
862
863pub 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
879pub 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 };
9031037
904pub 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 };
9071045
908pub 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 };
9181064
919pub 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 };
9341068
935pub 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,
9361078
937/// add event to kq (implies enable)
938pub const EV_ADD = 0x0001;
1079 fp_mmx: [8]fp_register,
1080 xmm: [16]xmm_register,
1081 reserved: [96]u8,
1082 };
9391083
940/// delete event from kq
941pub const EV_DELETE = 0x0002;
1084 pub const xstate_hdr = extern struct {
1085 bv: u64,
1086 xcomp_bv: u64,
1087 reserved: [48]u8,
1088 };
9421089
943/// enable event
944pub const EV_ENABLE = 0x0004;
1090 pub const savefpu = extern struct {
1091 fxsave: fpu_state,
1092 xstate: xstate_hdr,
1093 ymm: [16]xmm_register,
1094 };
9451095
946/// disable event (not reported)
947pub 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};
9481118
949/// only report one occurrence
950pub const EV_ONESHOT = 0x0010;
1119// /system/develop/headers/posix/dirent.h
1120
1121pub 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};
9511138
952/// clear event state after reporting
953pub const EV_CLEAR = 0x0020;
1139// /system/develop/headers/posix/errno.h
9541140
955/// force immediate event output
956/// ... with or without EV_ERROR
957/// ... use KEVENT_FLAG_ERROR_EVENTS
958/// on syscalls supporting flags
959pub const EV_RECEIPT = 0x0040;
1141extern "root" fn _errnop() *i32;
1142pub const _errno = _errnop;
9601143
961/// disable event after reporting
962pub const EV_DISPATCH = 0x0080;
1144// /system/develop/headers/posix/poll.h
9631145
964pub const EVFILT_READ = -1;
965pub const EVFILT_WRITE = -2;
1146pub const nfds_t = usize;
9661147
967/// attached to aio requests
968pub const EVFILT_AIO = -3;
1148pub const pollfd = extern struct {
1149 fd: i32,
1150 events: i16,
1151 revents: i16,
1152};
9691153
970/// attached to vnodes
971pub const EVFILT_VNODE = -4;
1154pub 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;
9721167
973/// attached to struct proc
974pub 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};
9751175
976/// attached to struct proc
977pub const EVFILT_SIGNAL = -6;
1176// /system/develop/headers/posix/signal.h
9781177
979/// timers
980pub const EVFILT_TIMER = -7;
1178pub const sigset_t = u64;
1179pub const empty_sigset: sigset_t = 0;
1180pub const filled_sigset = ~@as(sigset_t, 0);
9811181
982/// Process descriptors
983pub const EVFILT_PROCDESC = -8;
1182pub 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));
9841186
985/// Filesystem events
986pub const EVFILT_FS = -9;
1187 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
9871188
988pub 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;
9891222
990/// User events
991pub const EVFILT_USER = -11;
1223 pub const BLOCK = 1;
1224 pub const UNBLOCK = 2;
1225 pub const SETMASK = 3;
1226};
9921227
993/// Sendfile events
994pub const EVFILT_SENDFILE = -12;
1228pub const siginfo_t = extern struct {
1229 signo: i32,
1230 code: i32,
1231 errno: i32,
9951232
996pub const EVFILT_EMPTY = -13;
1233 pid: pid_t,
1234 uid: uid_t,
1235 addr: *allowzero anyopaque,
1236};
9971237
998pub 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.
1239pub 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;
10241242
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,
10271257};
10281258
1029pub const winsize = extern struct {
1030 ws_row: u16,
1031 ws_col: u16,
1032 ws_xpixel: u16,
1033 ws_ypixel: u16,
1259pub 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;
10341270};
10351271
1036const B_POSIX_ERROR_BASE = -2147454976;
1272pub const SS = struct {
1273 pub const ONSTACK = 0x1;
1274 pub const DISABLE = 0x2;
1275};
10371276
1038pub 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,
1277pub const MINSIGSTKSZ = 8192;
1278pub const SIGSTKSZ = 16384;
11011279
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 _,
1280pub const stack_t = extern struct {
1281 sp: [*]u8,
1282 size: isize,
1283 flags: i32,
11281284};
11291285
1130pub 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;
1286pub const NSIG = 65;
11571287
1158 pub fn ISREG(m: u32) bool {
1159 return m & IFMT == IFREG;
1160 }
1288pub const mcontext_t = vregs;
11611289
1162 pub fn ISLNK(m: u32) bool {
1163 return m & IFMT == IFLNK;
1164 }
1290pub const ucontext_t = extern struct {
1291 link: ?*ucontext_t,
1292 sigmask: sigset_t,
1293 stack: stack_t,
1294 mcontext: mcontext_t,
1295};
11651296
1166 pub fn ISBLK(m: u32) bool {
1167 return m & IFMT == IFBLK;
1168 }
1297// /system/develop/headers/posix/sys/stat.h
11691298
1170 pub fn ISDIR(m: u32) bool {
1171 return m & IFMT == IFDIR;
1172 }
1299pub 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,
11731315
1174 pub fn ISCHR(m: u32) bool {
1175 return m & IFMT == IFCHR;
1316 pub fn atime(self: @This()) timespec {
1317 return self.atim;
11761318 }
1177
1178 pub fn ISFIFO(m: u32) bool {
1179 return m & IFMT == IFIFO;
1319 pub fn mtime(self: @This()) timespec {
1320 return self.mtim;
11801321 }
1181
1182 pub fn ISSOCK(m: u32) bool {
1183 return m & IFMT == IFSOCK;
1322 pub fn ctime(self: @This()) timespec {
1323 return self.ctim;
11841324 }
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;
11881327 }
11891328};
11901329
1191pub const HOST_NAME_MAX = 255;
1330// /system/develop/headers/posix/sys/types.h
11921331
1193pub 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};
1332pub const blkcnt_t = i64;
1333pub const blksize_t = i32;
1334pub const fsblkcnt_t = i64;
1335pub const fsfilcnt_t = i64;
1336pub const off_t = i64;
1337pub const ino_t = i64;
1338pub const cnt_t = i32;
1339pub const dev_t = i32;
1340pub const pid_t = i32;
1341pub const id_t = i32;
12031342
1204pub 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};
1343pub const uid_t = u32;
1344pub const gid_t = u32;
1345pub const mode_t = u32;
1346pub const umode_t = u32;
1347pub const nlink_t = i32;
12231348
1224pub 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};
1349pub const clockid_t = i32;
1350pub const timer_t = *opaque {};
12351351
1236pub const rlim_t = i64;
1352// /system/develop/headers/posix/time.h
12371353
1238pub const RLIM = struct {
1239 /// No limit
1240 pub const INFINITY: rlim_t = (1 << 63) - 1;
1354pub const clock_t = i32;
1355pub const suseconds_t = i32;
1356pub const useconds_t = u32;
12411357
1242 pub const SAVED_MAX = INFINITY;
1243 pub const SAVED_CUR = INFINITY;
1244};
1358pub const time_t = isize;
12451359
1246pub const rlimit = extern struct {
1247 /// Soft limit
1248 cur: rlim_t,
1249 /// Hard limit
1250 max: rlim_t,
1251};
1360pub const CLOCKS_PER_SEC = 1_000_000;
1361pub const CLK_TCK = CLOCKS_PER_SEC;
1362pub const TIME_UTC = 1;
12521363
1253pub const SHUT = struct {
1254 pub const RD = 0;
1255 pub const WR = 1;
1256 pub const RDWR = 2;
1364pub 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;
12571373};
12581374
1259// TODO fill out if needed
1260pub const directory_which = enum(c_int) {
1261 B_USER_SETTINGS_DIRECTORY = 0xbbe,
1375pub const timespec = extern struct {
1376 /// seconds
1377 tv_sec: time_t,
1378 /// and nanoseconds
1379 tv_nsec: isize,
1380};
12621381
1263 _,
1382pub const itimerspec = extern struct {
1383 interval: timespec,
1384 value: timespec,
12641385};
12651386
1266pub const MSG_NOSIGNAL = 0x0800;
1387// /system/develop/headers/private/system/syscalls.h
1388
1389pub extern "root" fn _kern_get_current_team() team_id;
1390pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
1391pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
1392pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
1393pub 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) {
220220 },
221221 .haiku => struct {
222222 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,
224225 index: usize,
225226 end_index: usize,
226227 first_iter: bool,
227228
228229 const Self = @This();
230 const DirEnt = posix.system.DirEnt;
229231
230232 pub const Error = IteratorError;
231233
232234 /// Memory such as file names referenced in this returned entry becomes invalid
233235 /// with subsequent calls to `next`, as well as when this `Dir` is deinitialized.
234236 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) {
238238 if (self.index >= self.end_index) {
239239 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 }
241250 self.first_iter = false;
242251 }
243252 const rc = posix.system._kern_read_dir(
244253 self.dir.fd,
245254 &self.buf,
246255 self.buf.len,
247 HAIKU_MAX_COUNT,
256 self.buf.len / @sizeOf(DirEnt),
248257 );
249258 if (rc == 0) return null;
250259 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
253262 .FAULT => unreachable,
254263 .NOTDIR => unreachable,
255264 .INVAL => unreachable,
265 .OVERFLOW => unreachable,
266 .ACCES => return error.AccessDenied,
267 .PERM => return error.AccessDenied,
256268 else => |err| return posix.unexpectedErrno(err),
257269 }
258270 }
271 self.offset = 0;
259272 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);
269274 }
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;
270280
271281 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(
273283 self.dir.fd,
274 &haiku_entry.name,
284 name,
275285 false,
276286 &stat_info,
277287 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),
288300 }
289301 const statmode = stat_info.mode & posix.S.IFMT;
290302
......@@ -315,7 +327,7 @@ pub const Iterator = switch (native_os) {
315327 dir: Dir,
316328 // The if guard is solely there to prevent compile errors from missing `linux.dirent64`
317329 // 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)),
319331 index: usize,
320332 end_index: usize,
321333 first_iter: bool,
......@@ -599,13 +611,21 @@ fn iterateImpl(self: Dir, first_iter_start_value: bool) Iterator {
599611 .buf = undefined,
600612 .first_iter = first_iter_start_value,
601613 },
602 .linux, .haiku => return Iterator{
614 .linux => return Iterator{
603615 .dir = self,
604616 .index = 0,
605617 .end_index = 0,
606618 .buf = undefined,
607619 .first_iter = first_iter_start_value,
608620 },
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 },
609629 .windows => return Iterator{
610630 .dir = self,
611631 .index = 0,
......@@ -1429,6 +1449,27 @@ pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) Open
14291449 .wasi => {
14301450 return openDir(self, mem.sliceTo(sub_path_c, 0), args);
14311451 },
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 },
14321473 else => {
14331474 var symlink_flags: posix.O = .{
14341475 .ACCMODE = .RDONLY,
lib/std/zig/Zir.zig+2-6
......@@ -106,12 +106,8 @@ pub const NullTerminatedString = enum(u32) {
106106
107107/// Given an index into `string_bytes` returns the null-terminated string found there.
108108pub 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];
115111}
116112
117113pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
lib/std/zig/system.zig+7-3
......@@ -988,9 +988,13 @@ fn detectAbiAndDynamicLinker(
988988 // if it finds one, then instead of using /usr/bin/env as the ELF file to examine, it uses the file it references instead,
989989 // doing the same logic recursively in case it finds another shebang line.
990990
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 };
994998 // #! (2) + 255 (max length of shebang line since Linux 5.1) + \n (1)
995999 var buffer: [258]u8 = undefined;
9961000 while (true) {
lib/std/zig/system/NativePaths.zig+7
......@@ -105,6 +105,13 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
105105 return self;
106106 }
107107
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
108115 if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
109116 const triple = try native_target.linuxTriple(arena);
110117
src/Compilation.zig+3-4
......@@ -3159,7 +3159,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
31593159 const rt_file_path = try module_reference.src_loc.file_scope.fullPath(gpa);
31603160 defer gpa.free(rt_file_path);
31613161 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)),
31633163 .src_loc = try eb.addSourceLocation(.{
31643164 .src_path = try eb.addString(rt_file_path),
31653165 .span_start = span.start,
......@@ -4074,8 +4074,7 @@ fn workerCheckEmbedFile(
40744074fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void {
40754075 const mod = comp.module.?;
40764076 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), .{});
40794078 defer file.close();
40804079
40814080 const stat = try file.stat();
......@@ -4444,7 +4443,7 @@ fn reportRetryableEmbedFileError(
44444443 const ip = &mod.intern_pool;
44454444 const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
44464445 embed_file.owner.root,
4447 ip.stringToSlice(embed_file.sub_file_path),
4446 embed_file.sub_file_path.toSlice(ip),
44484447 @errorName(err),
44494448 });
44504449
src/InternPool.zig+190-164
......@@ -351,7 +351,7 @@ const KeyAdapter = struct {
351351 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {
352352 _ = b_void;
353353 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);
355355 }
356356
357357 pub fn hash(ctx: @This(), a: Key) u32 {
......@@ -385,7 +385,7 @@ pub const RuntimeIndex = enum(u32) {
385385 _,
386386
387387 pub fn increment(ri: *RuntimeIndex) void {
388 ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1));
388 ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
389389 }
390390};
391391
......@@ -418,12 +418,44 @@ pub const OptionalNamespaceIndex = enum(u32) {
418418
419419/// An index into `string_bytes`.
420420pub 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`.
441pub 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),
421445 _,
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 }
422454};
423455
424456/// An index into `string_bytes`.
425457pub const NullTerminatedString = enum(u32) {
426 /// This is distinct from `none` - it is a valid index that represents empty string.
458 /// An empty string.
427459 empty = 0,
428460 _,
429461
......@@ -447,6 +479,19 @@ pub const NullTerminatedString = enum(u32) {
447479 return @enumFromInt(@intFromEnum(self));
448480 }
449481
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
450495 const Adapter = struct {
451496 strings: []const NullTerminatedString,
452497
......@@ -467,11 +512,11 @@ pub const NullTerminatedString = enum(u32) {
467512 return @intFromEnum(a) < @intFromEnum(b);
468513 }
469514
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;
475520 }
476521
477522 const FormatData = struct {
......@@ -484,11 +529,11 @@ pub const NullTerminatedString = enum(u32) {
484529 _: std.fmt.FormatOptions,
485530 writer: anytype,
486531 ) @TypeOf(writer).Error!void {
487 const s = data.ip.stringToSlice(data.string);
532 const slice = data.string.toSlice(data.ip);
488533 if (comptime std.mem.eql(u8, specifier, "")) {
489 try writer.writeAll(s);
534 try writer.writeAll(slice);
490535 } 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)});
492537 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
493538 }
494539
......@@ -504,9 +549,12 @@ pub const OptionalNullTerminatedString = enum(u32) {
504549 none = std.math.maxInt(u32),
505550 _,
506551
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);
510558 }
511559};
512560
......@@ -690,6 +738,10 @@ pub const Key = union(enum) {
690738 len: u64,
691739 child: Index,
692740 sentinel: Index = .none,
741
742 pub fn lenIncludingSentinel(array_type: ArrayType) u64 {
743 return array_type.len + @intFromBool(array_type.sentinel != .none);
744 }
693745 };
694746
695747 /// Extern so that hashing can be done via memory reinterpreting.
......@@ -1043,7 +1095,7 @@ pub const Key = union(enum) {
10431095 storage: Storage,
10441096
10451097 pub const Storage = union(enum) {
1046 bytes: []const u8,
1098 bytes: String,
10471099 elems: []const Index,
10481100 repeated_elem: Index,
10491101
......@@ -1203,7 +1255,7 @@ pub const Key = union(enum) {
12031255
12041256 if (child == .u8_type) {
12051257 switch (aggregate.storage) {
1206 .bytes => |bytes| for (bytes[0..@intCast(len)]) |byte| {
1258 .bytes => |bytes| for (bytes.toSlice(len, ip)) |byte| {
12071259 std.hash.autoHash(&hasher, KeyTag.int);
12081260 std.hash.autoHash(&hasher, byte);
12091261 },
......@@ -1240,7 +1292,7 @@ pub const Key = union(enum) {
12401292
12411293 switch (aggregate.storage) {
12421294 .bytes => unreachable,
1243 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem|
1295 .elems => |elems| for (elems[0..@intCast(len)]) |elem|
12441296 std.hash.autoHash(&hasher, elem),
12451297 .repeated_elem => |elem| {
12461298 var remaining = len;
......@@ -1505,11 +1557,11 @@ pub const Key = union(enum) {
15051557 if (a_info.ty == .c_longdouble_type and a_info.storage != .f80) {
15061558 // These are strange: we'll sometimes represent them as f128, even if the
15071559 // 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))),
15101562 };
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))),
15131565 };
15141566 return a_val == b_val;
15151567 }
......@@ -1560,11 +1612,11 @@ pub const Key = union(enum) {
15601612 const len = ip.aggregateTypeLen(a_info.ty);
15611613 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;
15621614 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| {
15641616 const a_elem = switch (a_info.storage) {
15651617 .bytes => |bytes| ip.getIfExists(.{ .int = .{
15661618 .ty = .u8_type,
1567 .storage = .{ .u64 = bytes[elem_index] },
1619 .storage = .{ .u64 = bytes.at(elem_index, ip) },
15681620 } }) orelse return false,
15691621 .elems => |elems| elems[elem_index],
15701622 .repeated_elem => |elem| elem,
......@@ -1572,7 +1624,7 @@ pub const Key = union(enum) {
15721624 const b_elem = switch (b_info.storage) {
15731625 .bytes => |bytes| ip.getIfExists(.{ .int = .{
15741626 .ty = .u8_type,
1575 .storage = .{ .u64 = bytes[elem_index] },
1627 .storage = .{ .u64 = bytes.at(elem_index, ip) },
15761628 } }) orelse return false,
15771629 .elems => |elems| elems[elem_index],
15781630 .repeated_elem => |elem| elem,
......@@ -1585,18 +1637,15 @@ pub const Key = union(enum) {
15851637 switch (a_info.storage) {
15861638 .bytes => |a_bytes| {
15871639 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));
15931642 },
15941643 .elems => |a_elems| {
15951644 const b_elems = b_info.storage.elems;
15961645 return std.mem.eql(
15971646 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)],
16001649 );
16011650 },
16021651 .repeated_elem => |a_elem| {
......@@ -4175,10 +4224,10 @@ pub const Float64 = struct {
41754224 }
41764225
41774226 fn pack(val: f64) Float64 {
4178 const bits = @as(u64, @bitCast(val));
4227 const bits: u64 = @bitCast(val);
41794228 return .{
4180 .piece0 = @as(u32, @truncate(bits)),
4181 .piece1 = @as(u32, @truncate(bits >> 32)),
4229 .piece0 = @truncate(bits),
4230 .piece1 = @truncate(bits >> 32),
41824231 };
41834232 }
41844233};
......@@ -4197,11 +4246,11 @@ pub const Float80 = struct {
41974246 }
41984247
41994248 fn pack(val: f80) Float80 {
4200 const bits = @as(u80, @bitCast(val));
4249 const bits: u80 = @bitCast(val);
42014250 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),
42054254 };
42064255 }
42074256};
......@@ -4222,12 +4271,12 @@ pub const Float128 = struct {
42224271 }
42234272
42244273 fn pack(val: f128) Float128 {
4225 const bits = @as(u128, @bitCast(val));
4274 const bits: u128 = @bitCast(val);
42264275 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),
42314280 };
42324281 }
42334282};
......@@ -4244,7 +4293,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void {
42444293 assert(ip.items.len == 0);
42454294
42464295 // 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);
42484297
42494298 // So that we can use `catch unreachable` below.
42504299 try ip.items.ensureUnusedCapacity(gpa, static_keys.len);
......@@ -4329,13 +4378,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
43294378 .type_int_signed => .{
43304379 .int_type = .{
43314380 .signedness = .signed,
4332 .bits = @as(u16, @intCast(data)),
4381 .bits = @intCast(data),
43334382 },
43344383 },
43354384 .type_int_unsigned => .{
43364385 .int_type = .{
43374386 .signedness = .unsigned,
4338 .bits = @as(u16, @intCast(data)),
4387 .bits = @intCast(data),
43394388 },
43404389 },
43414390 .type_array_big => {
......@@ -4354,8 +4403,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
43544403 .sentinel = .none,
43554404 } };
43564405 },
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) },
43594408
43604409 .type_vector => {
43614410 const vector_info = ip.extraData(Vector, data);
......@@ -4506,9 +4555,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
45064555 } },
45074556 .type_function => .{ .func_type = ip.extraFuncType(data) },
45084557
4509 .undef => .{ .undef = @as(Index, @enumFromInt(data)) },
4558 .undef => .{ .undef = @enumFromInt(data) },
45104559 .opt_null => .{ .opt = .{
4511 .ty = @as(Index, @enumFromInt(data)),
4560 .ty = @enumFromInt(data),
45124561 .val = .none,
45134562 } },
45144563 .opt_payload => {
......@@ -4670,11 +4719,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
46704719 },
46714720 .float_f16 => .{ .float = .{
46724721 .ty = .f16_type,
4673 .storage = .{ .f16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },
4722 .storage = .{ .f16 = @bitCast(@as(u16, @intCast(data))) },
46744723 } },
46754724 .float_f32 => .{ .float = .{
46764725 .ty = .f32_type,
4677 .storage = .{ .f32 = @as(f32, @bitCast(data)) },
4726 .storage = .{ .f32 = @bitCast(data) },
46784727 } },
46794728 .float_f64 => .{ .float = .{
46804729 .ty = .f64_type,
......@@ -4771,10 +4820,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
47714820 },
47724821 .bytes => {
47734822 const extra = ip.extraData(Bytes, data);
4774 const len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(extra.ty));
47754823 return .{ .aggregate = .{
47764824 .ty = extra.ty,
4777 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] },
4825 .storage = .{ .bytes = extra.bytes },
47784826 } };
47794827 },
47804828 .aggregate => {
......@@ -4809,14 +4857,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
48094857 .val = .{ .payload = extra.val },
48104858 } };
48114859 },
4812 .enum_literal => .{ .enum_literal = @as(NullTerminatedString, @enumFromInt(data)) },
4860 .enum_literal => .{ .enum_literal = @enumFromInt(data) },
48134861 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },
48144862
48154863 .memoized_call => {
48164864 const extra = ip.extraDataTrail(MemoizedCall, data);
48174865 return .{ .memoized_call = .{
48184866 .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]),
48204868 .result = extra.data.result,
48214869 } };
48224870 },
......@@ -5596,9 +5644,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
55965644 switch (aggregate.storage) {
55975645 .bytes => |bytes| {
55985646 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);
56025649 }
56035650 },
56045651 .elems => |elems| {
......@@ -5641,11 +5688,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
56415688 switch (ty_key) {
56425689 .anon_struct_type => |anon_struct_type| opv: {
56435690 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 }
56495701 },
56505702 .elems => |elems| if (!std.mem.eql(
56515703 Index,
......@@ -5670,9 +5722,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
56705722
56715723 repeated: {
56725724 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|
56765728 if (elem != elems[0]) break :repeated,
56775729 .repeated_elem => {},
56785730 }
......@@ -5681,7 +5733,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
56815733 _ = ip.map.pop();
56825734 const elem = try ip.get(gpa, .{ .int = .{
56835735 .ty = .u8_type,
5684 .storage = .{ .u64 = bytes[0] },
5736 .storage = .{ .u64 = bytes.at(0, ip) },
56855737 } });
56865738 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
56875739 try ip.items.ensureUnusedCapacity(gpa, 1);
......@@ -5710,7 +5762,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
57105762 try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(len_including_sentinel + 1));
57115763 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
57125764 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)),
57145766 .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) {
57155767 .undef => {
57165768 ip.string_bytes.shrinkRetainingCapacity(string_bytes_index);
......@@ -5730,15 +5782,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
57305782 else => unreachable,
57315783 },
57325784 }
5733 const has_internal_null =
5734 std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null;
57355785 if (sentinel != .none) ip.string_bytes.appendAssumeCapacity(
57365786 @intCast(ip.indexToKey(sentinel).int.storage.u64),
57375787 );
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 );
57425793 ip.items.appendAssumeCapacity(.{
57435794 .tag = .bytes,
57445795 .data = ip.addExtraAssumeCapacity(Bytes{
......@@ -5780,7 +5831,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
57805831 .tag = .memoized_call,
57815832 .data = ip.addExtraAssumeCapacity(MemoizedCall{
57825833 .func = memoized_call.func,
5783 .args_len = @as(u32, @intCast(memoized_call.arg_values.len)),
5834 .args_len = @intCast(memoized_call.arg_values.len),
57845835 .result = memoized_call.result,
57855836 }),
57865837 });
......@@ -6753,7 +6804,7 @@ fn finishFuncInstance(
67536804 const decl = ip.declPtr(decl_index);
67546805 decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{
67556806 fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index),
6756 });
6807 }, .no_embedded_nulls);
67576808
67586809 return func_index;
67596810}
......@@ -7216,7 +7267,7 @@ pub fn remove(ip: *InternPool, index: Index) void {
72167267}
72177268
72187269fn 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);
72207271 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);
72217272 ip.items.appendAssumeCapacity(.{
72227273 .tag = tag,
......@@ -7235,7 +7286,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32
72357286}
72367287
72377288fn 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);
72397290 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
72407291 ip.extra.appendAssumeCapacity(switch (field.type) {
72417292 Index,
......@@ -7286,7 +7337,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
72867337 @sizeOf(u64) => {},
72877338 else => @compileError("unsupported host"),
72887339 }
7289 const result = @as(u32, @intCast(ip.limbs.items.len));
7340 const result: u32 = @intCast(ip.limbs.items.len);
72907341 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {
72917342 const new: u32 = switch (field.type) {
72927343 u32 => @field(extra, field.name),
......@@ -7374,7 +7425,7 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {
73747425
73757426 @field(result, field.name) = switch (field.type) {
73767427 u32 => int32,
7377 Index => @as(Index, @enumFromInt(int32)),
7428 Index => @enumFromInt(int32),
73787429 else => @compileError("bad field type: " ++ @typeName(field.type)),
73797430 };
73807431 }
......@@ -7410,8 +7461,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes
74107461 };
74117462 // TODO: https://github.com/ziglang/zig/issues/1738
74127463 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),
74157466 };
74167467}
74177468
......@@ -7683,7 +7734,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
76837734 .val = error_union.val,
76847735 } }),
76857736 .aggregate => |aggregate| {
7686 const new_len = @as(usize, @intCast(ip.aggregateTypeLen(new_ty)));
7737 const new_len: usize = @intCast(ip.aggregateTypeLen(new_ty));
76877738 direct: {
76887739 const old_ty_child = switch (ip.indexToKey(old_ty)) {
76897740 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
76967747 else => unreachable,
76977748 };
76987749 if (old_ty_child != new_ty_child) break :direct;
7699 // TODO: write something like getCoercedInts to avoid needing to dupe here
77007750 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 } }),
77097755 .elems => |elems| {
77107756 const elems_copy = try gpa.dupe(Index, elems[0..new_len]);
77117757 defer gpa.free(elems_copy);
......@@ -7729,14 +7775,13 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
77297775 // lifetime issues, since it'll allow us to avoid referencing `aggregate` after we
77307776 // begin interning elems.
77317777 switch (aggregate.storage) {
7732 .bytes => {
7778 .bytes => |bytes| {
77337779 // We have to intern each value here, so unfortunately we can't easily avoid
77347780 // 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| {
77377782 elem.* = try ip.get(gpa, .{ .int = .{
77387783 .ty = .u8_type,
7739 .storage = .{ .u64 = x },
7784 .storage = .{ .u64 = bytes.at(index, ip) },
77407785 } });
77417786 }
77427787 },
......@@ -8169,9 +8214,8 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
81698214
81708215 .bytes => b: {
81718216 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);
81758219 },
81768220 .aggregate => b: {
81778221 const info = ip.extraData(Tag.Aggregate, data);
......@@ -8434,15 +8478,35 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex)
84348478 };
84358479}
84368480
8481const 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
84378500pub fn getOrPutString(
84388501 ip: *InternPool,
84398502 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);
84448508 ip.string_bytes.appendAssumeCapacity(0);
8445 return ip.getOrPutTrailingString(gpa, s.len + 1);
8509 return ip.getOrPutTrailingString(gpa, slice.len + 1, embedded_nulls);
84468510}
84478511
84488512pub fn getOrPutStringFmt(
......@@ -8450,23 +8514,24 @@ pub fn getOrPutStringFmt(
84508514 gpa: Allocator,
84518515 comptime format: []const u8,
84528516 args: anytype,
8453) Allocator.Error!NullTerminatedString {
8517 comptime embedded_nulls: EmbeddedNulls,
8518) Allocator.Error!embedded_nulls.StringType() {
84548519 // ensure that references to string_bytes in args do not get invalidated
84558520 const len: usize = @intCast(std.fmt.count(format, args) + 1);
84568521 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
84578522 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
84588523 ip.string_bytes.appendAssumeCapacity(0);
8459 return ip.getOrPutTrailingString(gpa, len);
8524 return ip.getOrPutTrailingString(gpa, len, embedded_nulls);
84608525}
84618526
84628527pub fn getOrPutStringOpt(
84638528 ip: *InternPool,
84648529 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();
84708535}
84718536
84728537/// Uses the last len bytes of ip.string_bytes as the key.
......@@ -8474,7 +8539,8 @@ pub fn getOrPutTrailingString(
84748539 ip: *InternPool,
84758540 gpa: Allocator,
84768541 len: usize,
8477) Allocator.Error!NullTerminatedString {
8542 comptime embedded_nulls: EmbeddedNulls,
8543) Allocator.Error!embedded_nulls.StringType() {
84788544 const string_bytes = &ip.string_bytes;
84798545 const str_index: u32 = @intCast(string_bytes.items.len - len);
84808546 if (len > 0 and string_bytes.getLast() == 0) {
......@@ -8483,6 +8549,14 @@ pub fn getOrPutTrailingString(
84838549 try string_bytes.ensureUnusedCapacity(gpa, 1);
84848550 }
84858551 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 }
84868560 const gop = try ip.string_table.getOrPutContextAdapted(gpa, key, std.hash_map.StringIndexAdapter{
84878561 .bytes = string_bytes,
84888562 }, std.hash_map.StringIndexContext{
......@@ -8498,58 +8572,10 @@ pub fn getOrPutTrailingString(
84988572 }
84998573}
85008574
8501/// Uses the last len bytes of ip.string_bytes as the key.
8502pub 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
85298575pub 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{
85318577 .bytes = &ip.string_bytes,
8532 })) |index| {
8533 return @as(NullTerminatedString, @enumFromInt(index)).toOptional();
8534 } else {
8535 return .none;
8536 }
8537}
8538
8539pub 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
8547pub fn stringToSliceUnwrap(ip: *const InternPool, s: OptionalNullTerminatedString) ?[:0]const u8 {
8548 return ip.stringToSlice(s.unwrap() orelse return null);
8549}
8550
8551pub 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;
85538579}
85548580
85558581pub fn typeOf(ip: *const InternPool, index: Index) Index {
......@@ -8767,7 +8793,7 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 {
87678793 return switch (ip.indexToKey(ty)) {
87688794 .struct_type => ip.loadStructType(ty).field_types.len,
87698795 .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(),
87718797 .vector_type => |vector_type| vector_type.len,
87728798 else => unreachable,
87738799 };
src/Module.zig+63-50
......@@ -763,11 +763,11 @@ pub const Namespace = struct {
763763 ) !InternPool.NullTerminatedString {
764764 const ip = &zcu.intern_pool;
765765 const count = count: {
766 var count: usize = ip.stringToSlice(name).len + 1;
766 var count: usize = name.length(ip) + 1;
767767 var cur_ns = &ns;
768768 while (true) {
769769 const decl = zcu.declPtr(cur_ns.decl_index);
770 count += ip.stringToSlice(decl.name).len + 1;
770 count += decl.name.length(ip) + 1;
771771 cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse {
772772 count += ns.file_scope.sub_file_path.len;
773773 break :count count;
......@@ -793,7 +793,7 @@ pub const Namespace = struct {
793793 };
794794 }
795795
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);
797797 }
798798
799799 pub fn getType(ns: Namespace, zcu: *Zcu) Type {
......@@ -980,17 +980,13 @@ pub const File = struct {
980980 const ip = &mod.intern_pool;
981981 const start = ip.string_bytes.items.len;
982982 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);
984984 }
985985
986986 pub fn fullPath(file: File, ally: Allocator) ![]u8 {
987987 return file.mod.root.joinString(ally, file.sub_file_path);
988988 }
989989
990 pub fn fullPathZ(file: File, ally: Allocator) ![:0]u8 {
991 return file.mod.root.joinStringZ(ally, file.sub_file_path);
992 }
993
994990 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {
995991 const loc = std.zig.findLineColumn(file.source.bytes, src);
996992 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 {
25342530 const name_ip = try zcu.intern_pool.getOrPutString(
25352531 zcu.gpa,
25362532 old_zir.nullTerminatedString(name_zir),
2533 .no_embedded_nulls,
25372534 );
25382535 try old_names.put(zcu.gpa, name_ip, {});
25392536 }
......@@ -2551,6 +2548,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {
25512548 const name_ip = try zcu.intern_pool.getOrPutString(
25522549 zcu.gpa,
25532550 old_zir.nullTerminatedString(name_zir),
2551 .no_embedded_nulls,
25542552 );
25552553 if (!old_names.swapRemove(name_ip)) continue;
25562554 // Name added
......@@ -3555,37 +3553,46 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
35553553 const gpa = mod.gpa;
35563554 const zir = decl.getFileScope(mod).zir;
35573555
3558 const builtin_type_target_index: InternPool.Index = blk: {
3556 const builtin_type_target_index: InternPool.Index = ip_index: {
35593557 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;
35613559 // We're in the std module.
35623560 const std_file = (try mod.importPkg(std_mod)).file;
35633561 const std_decl = mod.declPtr(std_file.root_decl.unwrap().?);
35643562 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;
35693567 // 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;
35873594 }
3588 break :blk .none;
3595 break :ip_index .none;
35893596 };
35903597
35913598 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
......@@ -3725,8 +3732,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
37253732 } else if (bytes.len == 0) {
37263733 return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{});
37273734 }
3728 const section = try ip.getOrPutString(gpa, bytes);
3729 break :blk section.toOptional();
3735 break :blk try ip.getOrPutStringOpt(gpa, bytes, .no_embedded_nulls);
37303736 };
37313737 decl.@"addrspace" = blk: {
37323738 const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) {
......@@ -4101,7 +4107,10 @@ fn newEmbedFile(
41014107 .sentinel = .zero_u8,
41024108 .child = .u8_type,
41034109 } });
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 } });
41054114
41064115 const ptr_ty = (try mod.ptrType(.{
41074116 .child = array_ty,
......@@ -4111,7 +4120,6 @@ fn newEmbedFile(
41114120 .address_space = .generic,
41124121 },
41134122 })).toIntern();
4114
41154123 const ptr_val = try ip.get(gpa, .{ .ptr = .{
41164124 .ty = ptr_ty,
41174125 .addr = .{ .anon_decl = .{
......@@ -4122,7 +4130,7 @@ fn newEmbedFile(
41224130
41234131 result.* = new_file;
41244132 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),
41264134 .owner = pkg,
41274135 .stat = stat,
41284136 .val = ptr_val,
......@@ -4214,11 +4222,11 @@ const ScanDeclIter = struct {
42144222 const zcu = iter.zcu;
42154223 const gpa = zcu.gpa;
42164224 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);
42184226 var gop = try iter.seen_decls.getOrPut(gpa, name);
42194227 var next_suffix: u32 = 0;
42204228 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);
42224230 gop = try iter.seen_decls.getOrPut(gpa, name);
42234231 next_suffix += 1;
42244232 }
......@@ -4300,7 +4308,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
43004308 };
43014309 } else info: {
43024310 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 );
43044316 try iter.seen_decls.putNoClobber(gpa, name, {});
43054317 break :info .{
43064318 name,
......@@ -4362,9 +4374,10 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
43624374 if (!comp.config.is_test) break :a false;
43634375 if (decl_mod != zcu.main_mod) break :a false;
43644376 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);
43664379 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;
43684381 } else break :a false;
43694382 }
43704383 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
43774390 // `is_export` is unchanged. In this case, the incremental update mechanism will handle
43784391 // re-analysis for us if necessary.
43794392 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,
43824395 });
43834396 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
43844397 }
......@@ -5300,7 +5313,7 @@ pub fn populateTestFunctions(
53005313 const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;
53015314 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
53025315 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);
53045317 const decl_index = builtin_namespace.decls.getKeyAdapted(
53055318 test_functions_str,
53065319 DeclAdapter{ .zcu = mod },
......@@ -5327,16 +5340,16 @@ pub fn populateTestFunctions(
53275340
53285341 for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {
53295342 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);
53325345 const test_name_anon_decl: InternPool.Key.Ptr.Addr.AnonDecl = n: {
53335346 const test_name_ty = try mod.arrayType(.{
5334 .len = test_decl_name.len,
5347 .len = test_decl_name_len,
53355348 .child = .u8_type,
53365349 });
53375350 const test_name_val = try mod.intern(.{ .aggregate = .{
53385351 .ty = test_name_ty.toIntern(),
5339 .storage = .{ .bytes = test_decl_name },
5352 .storage = .{ .bytes = test_decl_name.toString() },
53405353 } });
53415354 break :n .{
53425355 .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(),
......@@ -5354,7 +5367,7 @@ pub fn populateTestFunctions(
53545367 } }),
53555368 .len = try mod.intern(.{ .int = .{
53565369 .ty = .usize_type,
5357 .storage = .{ .u64 = test_decl_name.len },
5370 .storage = .{ .u64 = test_decl_name_len },
53585371 } }),
53595372 } }),
53605373 // func
src/Sema.zig+325-256
......@@ -2059,12 +2059,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
20592059 const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty));
20602060
20612061 // 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);
20632063 const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true);
20642064 try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store);
20652065
20662066 // 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);
20682068 const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true);
20692069 try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store);
20702070
......@@ -2348,13 +2348,13 @@ fn failWithInvalidFieldAccess(
23482348fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool {
23492349 const ip = &mod.intern_pool;
23502350 switch (ty.zigTypeTag(mod)) {
2351 .Array => return ip.stringEqlSlice(field_name, "len"),
2351 .Array => return field_name.eqlSlice("len", ip),
23522352 .Pointer => {
23532353 const ptr_info = ty.ptrInfo(mod);
23542354 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);
23562356 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
2357 return ip.stringEqlSlice(field_name, "len");
2357 return field_name.eqlSlice("len", ip);
23582358 } else return false;
23592359 },
23602360 .Type, .Struct, .Union => return true,
......@@ -2703,12 +2703,20 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27032703 break :capture .{ .runtime = sema.typeOf(air_ref).toIntern() };
27042704 }),
27052705 .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 );
27072711 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
27082712 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
27092713 },
27102714 .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 );
27122720 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
27132721 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
27142722 },
......@@ -2882,7 +2890,7 @@ fn createAnonymousDeclTypeNamed(
28822890
28832891 const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
28842892 src_decl.name.fmt(&mod.intern_pool), anon_prefix, @intFromEnum(new_decl_index),
2885 }) catch unreachable;
2893 }, .no_embedded_nulls) catch unreachable;
28862894 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
28872895 return new_decl_index;
28882896 },
......@@ -2923,7 +2931,7 @@ fn createAnonymousDeclTypeNamed(
29232931 };
29242932
29252933 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);
29272935 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
29282936 return new_decl_index;
29292937 },
......@@ -2937,8 +2945,7 @@ fn createAnonymousDeclTypeNamed(
29372945
29382946 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{
29392947 src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code),
2940 });
2941
2948 }, .no_embedded_nulls);
29422949 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
29432950 return new_decl_index;
29442951 },
......@@ -3157,7 +3164,7 @@ fn zirEnumDecl(
31573164 const field_name_zir = sema.code.nullTerminatedString(field_name_index);
31583165 extra_index += 2; // field name, doc comment
31593166
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);
31613168
31623169 const tag_overflow = if (has_tag_value) overflow: {
31633170 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
......@@ -3462,7 +3469,7 @@ fn zirErrorSetDecl(
34623469 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
34633470 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
34643471 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);
34663473 _ = try mod.getErrorValue(name_ip);
34673474 const result = names.getOrPutAssumeCapacity(name_ip);
34683475 assert(!result.found_existing); // verified in AstGen
......@@ -3635,7 +3642,7 @@ fn indexablePtrLen(
36353642 const is_pointer_to = object_ty.isSinglePointer(mod);
36363643 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;
36373644 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);
36393646 return sema.fieldVal(block, src, object, field_name, src);
36403647}
36413648
......@@ -3649,7 +3656,7 @@ fn indexablePtrLenOrNone(
36493656 const operand_ty = sema.typeOf(operand);
36503657 try checkMemOperand(sema, block, src, operand_ty);
36513658 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);
36533660 return sema.fieldVal(block, src, operand, field_name, src);
36543661}
36553662
......@@ -4363,7 +4370,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43634370 }
43644371 if (!object_ty.indexableHasLen(mod)) continue;
43654372
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);
43674374 };
43684375 const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src);
43694376 if (len == .none) {
......@@ -4747,7 +4754,11 @@ fn validateUnionInit(
47474754 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
47484755 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
47494756 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 );
47514762 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
47524763 const air_tags = sema.air_instructions.items(.tag);
47534764 const air_datas = sema.air_instructions.items(.data);
......@@ -4890,6 +4901,7 @@ fn validateStructInit(
48904901 const field_name = try ip.getOrPutString(
48914902 gpa,
48924903 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
4904 .no_embedded_nulls,
48934905 );
48944906 field_index.* = if (struct_ty.isTuple(mod))
48954907 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
56725684
56735685fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
56745686 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 );
56765691}
56775692
5678fn 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);
5693fn addNullTerminatedStrLit(sema: *Sema, string: InternPool.NullTerminatedString) CompileError!Air.Inst.Ref {
5694 return sema.addStrLit(string.toString(), string.length(&sema.mod.intern_pool));
56815695}
56825696
5683/// Safe to call when `bytes` does not point into `InternPool`.
5684fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref {
5697fn addStrLit(sema: *Sema, string: InternPool.String, len: u64) CompileError!Air.Inst.Ref {
56855698 const mod = sema.mod;
56865699 const array_ty = try mod.arrayType(.{
5687 .len = bytes.len,
5700 .len = len,
56885701 .sentinel = .zero_u8,
56895702 .child = .u8_type,
56905703 });
56915704 const val = try mod.intern(.{ .aggregate = .{
56925705 .ty = array_ty.toIntern(),
5693 .storage = .{ .bytes = bytes },
5706 .storage = .{ .bytes = string },
56945707 } });
56955708 return anonDeclRef(sema, val);
56965709}
......@@ -6370,7 +6383,11 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
63706383 const src = inst_data.src();
63716384 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
63726385 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 );
63746391 const decl_index = if (extra.namespace != .none) index_blk: {
63756392 const container_ty = try sema.resolveType(block, operand_src, extra.namespace);
63766393 const container_namespace = container_ty.getNamespaceIndex(mod);
......@@ -6721,7 +6738,11 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
67216738 const mod = sema.mod;
67226739 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
67236740 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 );
67256746 const decl_index = try sema.lookupIdentifier(block, src, decl_name);
67266747 try sema.addReferencedBy(block, src, decl_index);
67276748 return sema.analyzeDeclRef(decl_index);
......@@ -6731,7 +6752,11 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
67316752 const mod = sema.mod;
67326753 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
67336754 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 );
67356760 const decl = try sema.lookupIdentifier(block, src, decl_name);
67366761 return sema.analyzeDeclVal(block, src, decl);
67376762}
......@@ -6883,7 +6908,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
68836908 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
68846909 else => |e| return e,
68856910 };
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);
68876912 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {
68886913 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),
68896914 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
......@@ -6926,7 +6951,7 @@ fn popErrorReturnTrace(
69266951 try sema.resolveTypeFields(stack_trace_ty);
69276952 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
69286953 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);
69306955 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);
69316956 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
69326957 } else if (is_non_error == null) {
......@@ -6952,7 +6977,7 @@ fn popErrorReturnTrace(
69526977 try sema.resolveTypeFields(stack_trace_ty);
69536978 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
69546979 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);
69566981 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
69576982 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
69586983 _ = try then_block.addBr(cond_block_inst, .void_value);
......@@ -7010,7 +7035,11 @@ fn zirCall(
70107035 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },
70117036 .field => blk: {
70127037 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 );
70147043 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
70157044 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
70167045 },
......@@ -7073,7 +7102,7 @@ fn zirCall(
70737102 if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) {
70747103 const stack_trace_ty = try sema.getBuiltinType("StackTrace");
70757104 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);
70777106 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);
70787107
70797108 // 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!
86488677 _ = block;
86498678 const mod = sema.mod;
86508679 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 );
86528685 _ = try mod.getErrorValue(name);
86538686 // Create an error set type with only this error value, and return the value.
86548687 const error_set_type = try mod.singleErrorSetType(name);
......@@ -8804,7 +8837,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88048837 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
88058838 const name = inst_data.get(sema.code);
88068839 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),
88088841 })));
88098842}
88108843
......@@ -9761,7 +9794,7 @@ fn funcCommon(
97619794 const func_index = try ip.getExternFunc(gpa, .{
97629795 .ty = func_ty,
97639796 .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),
97659798 });
97669799 return finishFunc(
97679800 sema,
......@@ -10225,7 +10258,11 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1022510258 const src = inst_data.src();
1022610259 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
1022710260 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 );
1022910266 const object = try sema.resolveInst(extra.lhs);
1023010267 return sema.fieldVal(block, src, object, field_name, field_name_src);
1023110268}
......@@ -10239,7 +10276,11 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1023910276 const src = inst_data.src();
1024010277 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
1024110278 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 );
1024310284 const object_ptr = try sema.resolveInst(extra.lhs);
1024410285 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false);
1024510286}
......@@ -10253,7 +10294,11 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1025310294 const src = inst_data.src();
1025410295 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
1025510296 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 );
1025710302 const object_ptr = try sema.resolveInst(extra.lhs);
1025810303 const struct_ty = sema.typeOf(object_ptr).childType(mod);
1025910304 switch (struct_ty.zigTypeTag(mod)) {
......@@ -13759,8 +13804,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1375913804 switch (ip.indexToKey(ty.toIntern())) {
1376013805 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1376113806 .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;
1376413809 break :hf false;
1376513810 },
1376613811 else => {},
......@@ -13783,7 +13828,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1378313828 .enum_type => {
1378413829 break :hf ip.loadEnumType(ty.toIntern()).nameIndex(ip, field_name) != null;
1378513830 },
13786 .array_type => break :hf ip.stringEqlSlice(field_name, "len"),
13831 .array_type => break :hf field_name.eqlSlice("len", ip),
1378713832 else => {},
1378813833 }
1378913834 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
1388513930fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1388613931 const mod = sema.mod;
1388713932 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 );
1388913938 _ = try mod.getErrorValue(name);
1389013939 const error_set_type = try mod.singleErrorSetType(name);
1389113940 return Air.internedToRef((try mod.intern(.{ .err = .{
......@@ -17552,11 +17601,9 @@ fn zirBuiltinSrc(
1755217601 const gpa = sema.gpa;
1755317602
1755417603 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);
1755817605 const array_ty = try ip.get(gpa, .{ .array_type = .{
17559 .len = bytes.len,
17606 .len = func_name_len,
1756017607 .sentinel = .zero_u8,
1756117608 .child = .u8_type,
1756217609 } });
......@@ -17568,19 +17615,19 @@ fn zirBuiltinSrc(
1756817615 .orig_ty = .slice_const_u8_sentinel_0_type,
1756917616 .val = try ip.get(gpa, .{ .aggregate = .{
1757017617 .ty = array_ty,
17571 .storage = .{ .bytes = bytes },
17618 .storage = .{ .bytes = fn_owner_decl.name.toString() },
1757217619 } }),
1757317620 } },
1757417621 } }),
17575 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
17622 .len = (try mod.intValue(Type.usize, func_name_len)).toIntern(),
1757617623 } });
1757717624 };
1757817625
1757917626 const file_name_val = v: {
1758017627 // 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);
1758217629 const array_ty = try ip.get(gpa, .{ .array_type = .{
17583 .len = bytes.len,
17630 .len = file_name.len,
1758417631 .sentinel = .zero_u8,
1758517632 .child = .u8_type,
1758617633 } });
......@@ -17592,11 +17639,13 @@ fn zirBuiltinSrc(
1759217639 .orig_ty = .slice_const_u8_sentinel_0_type,
1759317640 .val = try ip.get(gpa, .{ .aggregate = .{
1759417641 .ty = array_ty,
17595 .storage = .{ .bytes = bytes },
17642 .storage = .{
17643 .bytes = try ip.getOrPutString(gpa, file_name, .maybe_embedded_nulls),
17644 },
1759617645 } }),
1759717646 } },
1759817647 } }),
17599 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
17648 .len = (try mod.intValue(Type.usize, file_name.len)).toIntern(),
1760017649 } });
1760117650 };
1760217651
......@@ -17651,7 +17700,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1765117700 block,
1765217701 src,
1765317702 type_info_ty.getNamespaceIndex(mod),
17654 try ip.getOrPutString(gpa, "Fn"),
17703 try ip.getOrPutString(gpa, "Fn", .no_embedded_nulls),
1765517704 )).?;
1765617705 try sema.ensureDeclAnalyzed(fn_info_decl_index);
1765717706 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
1766117710 block,
1766217711 src,
1766317712 fn_info_ty.getNamespaceIndex(mod),
17664 try ip.getOrPutString(gpa, "Param"),
17713 try ip.getOrPutString(gpa, "Param", .no_embedded_nulls),
1766517714 )).?;
1766617715 try sema.ensureDeclAnalyzed(param_info_decl_index);
1766717716 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
1776217811 block,
1776317812 src,
1776417813 type_info_ty.getNamespaceIndex(mod),
17765 try ip.getOrPutString(gpa, "Int"),
17814 try ip.getOrPutString(gpa, "Int", .no_embedded_nulls),
1776617815 )).?;
1776717816 try sema.ensureDeclAnalyzed(int_info_decl_index);
1776817817 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
1779017839 block,
1779117840 src,
1779217841 type_info_ty.getNamespaceIndex(mod),
17793 try ip.getOrPutString(gpa, "Float"),
17842 try ip.getOrPutString(gpa, "Float", .no_embedded_nulls),
1779417843 )).?;
1779517844 try sema.ensureDeclAnalyzed(float_info_decl_index);
1779617845 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
1782217871 block,
1782317872 src,
1782417873 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
17825 try ip.getOrPutString(gpa, "Pointer"),
17874 try ip.getOrPutString(gpa, "Pointer", .no_embedded_nulls),
1782617875 )).?;
1782717876 try sema.ensureDeclAnalyzed(decl_index);
1782817877 const decl = mod.declPtr(decl_index);
......@@ -17833,7 +17882,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1783317882 block,
1783417883 src,
1783517884 pointer_ty.getNamespaceIndex(mod),
17836 try ip.getOrPutString(gpa, "Size"),
17885 try ip.getOrPutString(gpa, "Size", .no_embedded_nulls),
1783717886 )).?;
1783817887 try sema.ensureDeclAnalyzed(decl_index);
1783917888 const decl = mod.declPtr(decl_index);
......@@ -17876,7 +17925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1787617925 block,
1787717926 src,
1787817927 type_info_ty.getNamespaceIndex(mod),
17879 try ip.getOrPutString(gpa, "Array"),
17928 try ip.getOrPutString(gpa, "Array", .no_embedded_nulls),
1788017929 )).?;
1788117930 try sema.ensureDeclAnalyzed(array_field_ty_decl_index);
1788217931 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
1790717956 block,
1790817957 src,
1790917958 type_info_ty.getNamespaceIndex(mod),
17910 try ip.getOrPutString(gpa, "Vector"),
17959 try ip.getOrPutString(gpa, "Vector", .no_embedded_nulls),
1791117960 )).?;
1791217961 try sema.ensureDeclAnalyzed(vector_field_ty_decl_index);
1791317962 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
1793617985 block,
1793717986 src,
1793817987 type_info_ty.getNamespaceIndex(mod),
17939 try ip.getOrPutString(gpa, "Optional"),
17988 try ip.getOrPutString(gpa, "Optional", .no_embedded_nulls),
1794017989 )).?;
1794117990 try sema.ensureDeclAnalyzed(optional_field_ty_decl_index);
1794217991 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
1796318012 block,
1796418013 src,
1796518014 type_info_ty.getNamespaceIndex(mod),
17966 try ip.getOrPutString(gpa, "Error"),
18015 try ip.getOrPutString(gpa, "Error", .no_embedded_nulls),
1796718016 )).?;
1796818017 try sema.ensureDeclAnalyzed(set_field_ty_decl_index);
1796918018 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
1798018029 else => |err_set_ty_index| blk: {
1798118030 const names = ip.indexToKey(err_set_ty_index).error_set_type.names;
1798218031 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: {
1798718036 const new_decl_ty = try mod.arrayType(.{
17988 .len = name.len,
18037 .len = error_name_len,
1798918038 .sentinel = .zero_u8,
1799018039 .child = .u8_type,
1799118040 });
1799218041 const new_decl_val = try mod.intern(.{ .aggregate = .{
1799318042 .ty = new_decl_ty.toIntern(),
17994 .storage = .{ .bytes = name },
18043 .storage = .{ .bytes = error_name.toString() },
1799518044 } });
1799618045 break :v try mod.intern(.{ .slice = .{
1799718046 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18002,13 +18051,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1800218051 .orig_ty = .slice_const_u8_sentinel_0_type,
1800318052 } },
1800418053 } }),
18005 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
18054 .len = (try mod.intValue(Type.usize, error_name_len)).toIntern(),
1800618055 } });
1800718056 };
1800818057
1800918058 const error_field_fields = .{
1801018059 // name: [:0]const u8,
18011 name_val,
18060 error_name_val,
1801218061 };
1801318062 field_val.* = try mod.intern(.{ .aggregate = .{
1801418063 .ty = error_field_ty.toIntern(),
......@@ -18069,7 +18118,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1806918118 block,
1807018119 src,
1807118120 type_info_ty.getNamespaceIndex(mod),
18072 try ip.getOrPutString(gpa, "ErrorUnion"),
18121 try ip.getOrPutString(gpa, "ErrorUnion", .no_embedded_nulls),
1807318122 )).?;
1807418123 try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index);
1807518124 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
1809918148 block,
1810018149 src,
1810118150 type_info_ty.getNamespaceIndex(mod),
18102 try ip.getOrPutString(gpa, "EnumField"),
18151 try ip.getOrPutString(gpa, "EnumField", .no_embedded_nulls),
1810318152 )).?;
1810418153 try sema.ensureDeclAnalyzed(enum_field_ty_decl_index);
1810518154 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
1810718156 };
1810818157
1810918158 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| {
1811118160 const enum_type = ip.loadEnumType(ty.toIntern());
1811218161 const value_val = if (enum_type.values.len > 0)
1811318162 try mod.intern_pool.getCoercedInts(
1811418163 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,
1811618165 .comptime_int_type,
1811718166 )
1811818167 else
18119 (try mod.intValue(Type.comptime_int, i)).toIntern();
18168 (try mod.intValue(Type.comptime_int, tag_index)).toIntern();
18169
1812018170 // 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]));
1812218171 const name_val = v: {
18172 const tag_name = enum_type.names.get(ip)[tag_index];
18173 const tag_name_len = tag_name.length(ip);
1812318174 const new_decl_ty = try mod.arrayType(.{
18124 .len = name.len,
18175 .len = tag_name_len,
1812518176 .sentinel = .zero_u8,
1812618177 .child = .u8_type,
1812718178 });
1812818179 const new_decl_val = try mod.intern(.{ .aggregate = .{
1812918180 .ty = new_decl_ty.toIntern(),
18130 .storage = .{ .bytes = name },
18181 .storage = .{ .bytes = tag_name.toString() },
1813118182 } });
1813218183 break :v try mod.intern(.{ .slice = .{
1813318184 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18138,7 +18189,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1813818189 .orig_ty = .slice_const_u8_sentinel_0_type,
1813918190 } },
1814018191 } }),
18141 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
18192 .len = (try mod.intValue(Type.usize, tag_name_len)).toIntern(),
1814218193 } });
1814318194 };
1814418195
......@@ -18191,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1819118242 block,
1819218243 src,
1819318244 type_info_ty.getNamespaceIndex(mod),
18194 try ip.getOrPutString(gpa, "Enum"),
18245 try ip.getOrPutString(gpa, "Enum", .no_embedded_nulls),
1819518246 )).?;
1819618247 try sema.ensureDeclAnalyzed(type_enum_ty_decl_index);
1819718248 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
1822318274 block,
1822418275 src,
1822518276 type_info_ty.getNamespaceIndex(mod),
18226 try ip.getOrPutString(gpa, "Union"),
18277 try ip.getOrPutString(gpa, "Union", .no_embedded_nulls),
1822718278 )).?;
1822818279 try sema.ensureDeclAnalyzed(type_union_ty_decl_index);
1822918280 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
1823518286 block,
1823618287 src,
1823718288 type_info_ty.getNamespaceIndex(mod),
18238 try ip.getOrPutString(gpa, "UnionField"),
18289 try ip.getOrPutString(gpa, "UnionField", .no_embedded_nulls),
1823918290 )).?;
1824018291 try sema.ensureDeclAnalyzed(union_field_ty_decl_index);
1824118292 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
1825018301 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);
1825118302 defer gpa.free(union_field_vals);
1825218303
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| {
1825618305 const name_val = v: {
18306 const field_name = tag_type.names.get(ip)[field_index];
18307 const field_name_len = field_name.length(ip);
1825718308 const new_decl_ty = try mod.arrayType(.{
18258 .len = name.len,
18309 .len = field_name_len,
1825918310 .sentinel = .zero_u8,
1826018311 .child = .u8_type,
1826118312 });
1826218313 const new_decl_val = try mod.intern(.{ .aggregate = .{
1826318314 .ty = new_decl_ty.toIntern(),
18264 .storage = .{ .bytes = name },
18315 .storage = .{ .bytes = field_name.toString() },
1826518316 } });
1826618317 break :v try mod.intern(.{ .slice = .{
1826718318 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18272,16 +18323,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1827218323 .orig_ty = .slice_const_u8_sentinel_0_type,
1827318324 } },
1827418325 } }),
18275 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
18326 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
1827618327 } });
1827718328 };
1827818329
1827918330 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)),
1828118332 .@"packed" => .none,
1828218333 };
1828318334
18284 const field_ty = union_obj.field_types.get(ip)[i];
18335 const field_ty = union_obj.field_types.get(ip)[field_index];
1828518336 const union_field_fields = .{
1828618337 // name: [:0]const u8,
1828718338 name_val,
......@@ -18338,7 +18389,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1833818389 block,
1833918390 src,
1834018391 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
18341 try ip.getOrPutString(gpa, "ContainerLayout"),
18392 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
1834218393 )).?;
1834318394 try sema.ensureDeclAnalyzed(decl_index);
1834418395 const decl = mod.declPtr(decl_index);
......@@ -18371,7 +18422,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1837118422 block,
1837218423 src,
1837318424 type_info_ty.getNamespaceIndex(mod),
18374 try ip.getOrPutString(gpa, "Struct"),
18425 try ip.getOrPutString(gpa, "Struct", .no_embedded_nulls),
1837518426 )).?;
1837618427 try sema.ensureDeclAnalyzed(type_struct_ty_decl_index);
1837718428 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
1838318434 block,
1838418435 src,
1838518436 type_info_ty.getNamespaceIndex(mod),
18386 try ip.getOrPutString(gpa, "StructField"),
18437 try ip.getOrPutString(gpa, "StructField", .no_embedded_nulls),
1838718438 )).?;
1838818439 try sema.ensureDeclAnalyzed(struct_field_ty_decl_index);
1838918440 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
1839618447 defer gpa.free(struct_field_vals);
1839718448 fv: {
1839818449 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];
1840518455 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]
1841018458 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);
1841218461 const new_decl_ty = try mod.arrayType(.{
18413 .len = bytes.len,
18462 .len = field_name_len,
1841418463 .sentinel = .zero_u8,
1841518464 .child = .u8_type,
1841618465 });
1841718466 const new_decl_val = try mod.intern(.{ .aggregate = .{
1841818467 .ty = new_decl_ty.toIntern(),
18419 .storage = .{ .bytes = bytes },
18468 .storage = .{ .bytes = field_name.toString() },
1842018469 } });
1842118470 break :v try mod.intern(.{ .slice = .{
1842218471 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18427,7 +18476,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1842718476 .orig_ty = .slice_const_u8_sentinel_0_type,
1842818477 } },
1842918478 } }),
18430 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
18479 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
1843118480 } });
1843218481 };
1843318482
......@@ -18462,24 +18511,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1846218511
1846318512 try sema.resolveStructFieldInits(ty);
1846418513
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
1846918517 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);
1847418523 const name_val = v: {
1847518524 const new_decl_ty = try mod.arrayType(.{
18476 .len = name.len,
18525 .len = field_name_len,
1847718526 .sentinel = .zero_u8,
1847818527 .child = .u8_type,
1847918528 });
1848018529 const new_decl_val = try mod.intern(.{ .aggregate = .{
1848118530 .ty = new_decl_ty.toIntern(),
18482 .storage = .{ .bytes = name },
18531 .storage = .{ .bytes = field_name.toString() },
1848318532 } });
1848418533 break :v try mod.intern(.{ .slice = .{
1848518534 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18490,7 +18539,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1849018539 .orig_ty = .slice_const_u8_sentinel_0_type,
1849118540 } },
1849218541 } }),
18493 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
18542 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
1849418543 } });
1849518544 };
1849618545
......@@ -18499,7 +18548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1849918548 const alignment = switch (struct_type.layout) {
1850018549 .@"packed" => .none,
1850118550 else => try sema.structFieldAlignment(
18502 struct_type.fieldAlign(ip, i),
18551 struct_type.fieldAlign(ip, field_index),
1850318552 field_ty,
1850418553 struct_type.layout,
1850518554 ),
......@@ -18569,7 +18618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1856918618 block,
1857018619 src,
1857118620 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
18572 try ip.getOrPutString(gpa, "ContainerLayout"),
18621 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
1857318622 )).?;
1857418623 try sema.ensureDeclAnalyzed(decl_index);
1857518624 const decl = mod.declPtr(decl_index);
......@@ -18605,7 +18654,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1860518654 block,
1860618655 src,
1860718656 type_info_ty.getNamespaceIndex(mod),
18608 try ip.getOrPutString(gpa, "Opaque"),
18657 try ip.getOrPutString(gpa, "Opaque", .no_embedded_nulls),
1860918658 )).?;
1861018659 try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index);
1861118660 const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index);
......@@ -18648,7 +18697,7 @@ fn typeInfoDecls(
1864818697 block,
1864918698 src,
1865018699 type_info_ty.getNamespaceIndex(mod),
18651 try mod.intern_pool.getOrPutString(gpa, "Declaration"),
18700 try mod.intern_pool.getOrPutString(gpa, "Declaration", .no_embedded_nulls),
1865218701 )).?;
1865318702 try sema.ensureDeclAnalyzed(declaration_ty_decl_index);
1865418703 const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index);
......@@ -18722,16 +18771,15 @@ fn typeInfoNamespaceDecls(
1872218771 }
1872318772 if (decl.kind != .named) continue;
1872418773 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);
1872718775 const new_decl_ty = try mod.arrayType(.{
18728 .len = name.len,
18776 .len = decl_name_len,
1872918777 .sentinel = .zero_u8,
1873018778 .child = .u8_type,
1873118779 });
1873218780 const new_decl_val = try mod.intern(.{ .aggregate = .{
1873318781 .ty = new_decl_ty.toIntern(),
18734 .storage = .{ .bytes = name },
18782 .storage = .{ .bytes = decl.name.toString() },
1873518783 } });
1873618784 break :v try mod.intern(.{ .slice = .{
1873718785 .ty = .slice_const_u8_sentinel_0_type,
......@@ -18742,7 +18790,7 @@ fn typeInfoNamespaceDecls(
1874218790 .val = new_decl_val,
1874318791 } },
1874418792 } }),
18745 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
18793 .len = (try mod.intValue(Type.usize, decl_name_len)).toIntern(),
1874618794 } });
1874718795 };
1874818796
......@@ -19385,7 +19433,11 @@ fn zirRetErrValue(
1938519433) CompileError!void {
1938619434 const mod = sema.mod;
1938719435 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 );
1938919441 _ = try mod.getErrorValue(err_name);
1939019442 const src = inst_data.src();
1939119443 // Return the error code from the function.
......@@ -20072,7 +20124,11 @@ fn zirStructInit(
2007220124 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
2007320125 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
2007420126 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 );
2007620132 const field_index = if (resolved_ty.isTuple(mod))
2007720133 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)
2007820134 else
......@@ -20109,7 +20165,11 @@ fn zirStructInit(
2010920165 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
2011020166 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
2011120167 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 );
2011320173 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
2011420174 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
2011520175 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
......@@ -20417,8 +20477,7 @@ fn structInitAnon(
2041720477 },
2041820478 };
2041920479
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);
2042220481
2042320482 const init = try sema.resolveInst(item.data.init);
2042420483 field_ty.* = sema.typeOf(init).toIntern();
......@@ -20809,7 +20868,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2080920868 };
2081020869 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);
2081120870 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);
2081320872 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
2081420873}
2081520874
......@@ -20975,7 +21034,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2097521034
2097621035 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
2097721036 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);
2097921038 }
2098021039
2098121040 // 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
2109321152 .EnumLiteral => {
2109421153 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
2109521154 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
21096 return sema.addStrLit(ip.stringToSlice(tag_name));
21155 return sema.addNullTerminatedStrLit(tag_name);
2109721156 },
2109821157 .Enum => operand_ty,
2109921158 .Union => operand_ty.unionTagType(mod) orelse
......@@ -21127,7 +21186,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2112721186 };
2112821187 // TODO: write something like getCoercedInts to avoid needing to dupe
2112921188 const field_name = enum_ty.enumFieldName(field_index, mod);
21130 return sema.addStrLit(ip.stringToSlice(field_name));
21189 return sema.addNullTerminatedStrLit(field_name);
2113121190 }
2113221191 try sema.requireRuntimeBlock(block, src, operand_src);
2113321192 if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) {
......@@ -21179,11 +21238,11 @@ fn zirReify(
2117921238 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2118021239 const signedness_val = try Value.fromInterned(union_val.val).fieldValue(
2118121240 mod,
21182 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?,
21241 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness", .no_embedded_nulls)).?,
2118321242 );
2118421243 const bits_val = try Value.fromInterned(union_val.val).fieldValue(
2118521244 mod,
21186 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?,
21245 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits", .no_embedded_nulls)).?,
2118721246 );
2118821247
2118921248 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
......@@ -21195,11 +21254,11 @@ fn zirReify(
2119521254 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2119621255 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2119721256 ip,
21198 try ip.getOrPutString(gpa, "len"),
21257 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
2119921258 ).?);
2120021259 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2120121260 ip,
21202 try ip.getOrPutString(gpa, "child"),
21261 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
2120321262 ).?);
2120421263
2120521264 const len: u32 = @intCast(try len_val.toUnsignedIntAdvanced(sema));
......@@ -21217,7 +21276,7 @@ fn zirReify(
2121721276 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2121821277 const bits_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2121921278 ip,
21220 try ip.getOrPutString(gpa, "bits"),
21279 try ip.getOrPutString(gpa, "bits", .no_embedded_nulls),
2122121280 ).?);
2122221281
2122321282 const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema));
......@@ -21235,35 +21294,35 @@ fn zirReify(
2123521294 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2123621295 const size_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2123721296 ip,
21238 try ip.getOrPutString(gpa, "size"),
21297 try ip.getOrPutString(gpa, "size", .no_embedded_nulls),
2123921298 ).?);
2124021299 const is_const_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2124121300 ip,
21242 try ip.getOrPutString(gpa, "is_const"),
21301 try ip.getOrPutString(gpa, "is_const", .no_embedded_nulls),
2124321302 ).?);
2124421303 const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2124521304 ip,
21246 try ip.getOrPutString(gpa, "is_volatile"),
21305 try ip.getOrPutString(gpa, "is_volatile", .no_embedded_nulls),
2124721306 ).?);
2124821307 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2124921308 ip,
21250 try ip.getOrPutString(gpa, "alignment"),
21309 try ip.getOrPutString(gpa, "alignment", .no_embedded_nulls),
2125121310 ).?);
2125221311 const address_space_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2125321312 ip,
21254 try ip.getOrPutString(gpa, "address_space"),
21313 try ip.getOrPutString(gpa, "address_space", .no_embedded_nulls),
2125521314 ).?);
2125621315 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2125721316 ip,
21258 try ip.getOrPutString(gpa, "child"),
21317 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
2125921318 ).?);
2126021319 const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2126121320 ip,
21262 try ip.getOrPutString(gpa, "is_allowzero"),
21321 try ip.getOrPutString(gpa, "is_allowzero", .no_embedded_nulls),
2126321322 ).?);
2126421323 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2126521324 ip,
21266 try ip.getOrPutString(gpa, "sentinel"),
21325 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
2126721326 ).?);
2126821327
2126921328 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
......@@ -21341,15 +21400,15 @@ fn zirReify(
2134121400 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2134221401 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2134321402 ip,
21344 try ip.getOrPutString(gpa, "len"),
21403 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
2134521404 ).?);
2134621405 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2134721406 ip,
21348 try ip.getOrPutString(gpa, "child"),
21407 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
2134921408 ).?);
2135021409 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2135121410 ip,
21352 try ip.getOrPutString(gpa, "sentinel"),
21411 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
2135321412 ).?);
2135421413
2135521414 const len = try len_val.toUnsignedIntAdvanced(sema);
......@@ -21370,7 +21429,7 @@ fn zirReify(
2137021429 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2137121430 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2137221431 ip,
21373 try ip.getOrPutString(gpa, "child"),
21432 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
2137421433 ).?);
2137521434
2137621435 const child_ty = child_val.toType();
......@@ -21382,11 +21441,11 @@ fn zirReify(
2138221441 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2138321442 const error_set_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2138421443 ip,
21385 try ip.getOrPutString(gpa, "error_set"),
21444 try ip.getOrPutString(gpa, "error_set", .no_embedded_nulls),
2138621445 ).?);
2138721446 const payload_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2138821447 ip,
21389 try ip.getOrPutString(gpa, "payload"),
21448 try ip.getOrPutString(gpa, "payload", .no_embedded_nulls),
2139021449 ).?);
2139121450
2139221451 const error_set_ty = error_set_val.toType();
......@@ -21415,7 +21474,7 @@ fn zirReify(
2141521474 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
2141621475 const name_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
2141721476 ip,
21418 try ip.getOrPutString(gpa, "name"),
21477 try ip.getOrPutString(gpa, "name", .no_embedded_nulls),
2141921478 ).?);
2142021479
2142121480 const name = try sema.sliceToIpString(block, src, name_val, .{
......@@ -21437,23 +21496,23 @@ fn zirReify(
2143721496 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2143821497 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2143921498 ip,
21440 try ip.getOrPutString(gpa, "layout"),
21499 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
2144121500 ).?);
2144221501 const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2144321502 ip,
21444 try ip.getOrPutString(gpa, "backing_integer"),
21503 try ip.getOrPutString(gpa, "backing_integer", .no_embedded_nulls),
2144521504 ).?);
2144621505 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2144721506 ip,
21448 try ip.getOrPutString(gpa, "fields"),
21507 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
2144921508 ).?);
2145021509 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2145121510 ip,
21452 try ip.getOrPutString(gpa, "decls"),
21511 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
2145321512 ).?);
2145421513 const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2145521514 ip,
21456 try ip.getOrPutString(gpa, "is_tuple"),
21515 try ip.getOrPutString(gpa, "is_tuple", .no_embedded_nulls),
2145721516 ).?);
2145821517
2145921518 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
......@@ -21477,19 +21536,19 @@ fn zirReify(
2147721536 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2147821537 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2147921538 ip,
21480 try ip.getOrPutString(gpa, "tag_type"),
21539 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
2148121540 ).?);
2148221541 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2148321542 ip,
21484 try ip.getOrPutString(gpa, "fields"),
21543 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
2148521544 ).?);
2148621545 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2148721546 ip,
21488 try ip.getOrPutString(gpa, "decls"),
21547 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
2148921548 ).?);
2149021549 const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2149121550 ip,
21492 try ip.getOrPutString(gpa, "is_exhaustive"),
21551 try ip.getOrPutString(gpa, "is_exhaustive", .no_embedded_nulls),
2149321552 ).?);
2149421553
2149521554 if (try decls_val.sliceLen(sema) > 0) {
......@@ -21506,7 +21565,7 @@ fn zirReify(
2150621565 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2150721566 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2150821567 ip,
21509 try ip.getOrPutString(gpa, "decls"),
21568 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
2151021569 ).?);
2151121570
2151221571 // Decls
......@@ -21544,19 +21603,19 @@ fn zirReify(
2154421603 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2154521604 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2154621605 ip,
21547 try ip.getOrPutString(gpa, "layout"),
21606 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
2154821607 ).?);
2154921608 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2155021609 ip,
21551 try ip.getOrPutString(gpa, "tag_type"),
21610 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
2155221611 ).?);
2155321612 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2155421613 ip,
21555 try ip.getOrPutString(gpa, "fields"),
21614 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
2155621615 ).?);
2155721616 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2155821617 ip,
21559 try ip.getOrPutString(gpa, "decls"),
21618 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
2156021619 ).?);
2156121620
2156221621 if (try decls_val.sliceLen(sema) > 0) {
......@@ -21574,23 +21633,23 @@ fn zirReify(
2157421633 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2157521634 const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2157621635 ip,
21577 try ip.getOrPutString(gpa, "calling_convention"),
21636 try ip.getOrPutString(gpa, "calling_convention", .no_embedded_nulls),
2157821637 ).?);
2157921638 const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2158021639 ip,
21581 try ip.getOrPutString(gpa, "is_generic"),
21640 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
2158221641 ).?);
2158321642 const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2158421643 ip,
21585 try ip.getOrPutString(gpa, "is_var_args"),
21644 try ip.getOrPutString(gpa, "is_var_args", .no_embedded_nulls),
2158621645 ).?);
2158721646 const return_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2158821647 ip,
21589 try ip.getOrPutString(gpa, "return_type"),
21648 try ip.getOrPutString(gpa, "return_type", .no_embedded_nulls),
2159021649 ).?);
2159121650 const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2159221651 ip,
21593 try ip.getOrPutString(gpa, "params"),
21652 try ip.getOrPutString(gpa, "params", .no_embedded_nulls),
2159421653 ).?);
2159521654
2159621655 const is_generic = is_generic_val.toBool();
......@@ -21620,15 +21679,15 @@ fn zirReify(
2162021679 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
2162121680 const param_is_generic_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
2162221681 ip,
21623 try ip.getOrPutString(gpa, "is_generic"),
21682 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
2162421683 ).?);
2162521684 const param_is_noalias_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
2162621685 ip,
21627 try ip.getOrPutString(gpa, "is_noalias"),
21686 try ip.getOrPutString(gpa, "is_noalias", .no_embedded_nulls),
2162821687 ).?);
2162921688 const opt_param_type_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
2163021689 ip,
21631 try ip.getOrPutString(gpa, "type"),
21690 try ip.getOrPutString(gpa, "type", .no_embedded_nulls),
2163221691 ).?);
2163321692
2163421693 if (param_is_generic_val.toBool()) {
......@@ -22366,13 +22425,14 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2236622425
2236722426fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2236822427 const mod = sema.mod;
22428 const ip = &mod.intern_pool;
22429
2236922430 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2237022431 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2237122432 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2237222433
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);
2237622436}
2237722437
2237822438fn 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
2350723567 }
2350823568
2350923569 const field_index = if (ty.isTuple(mod)) blk: {
23510 if (ip.stringEqlSlice(field_name, "len")) {
23570 if (field_name.eqlSlice("len", ip)) {
2351123571 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});
2351223572 }
2351323573 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);
......@@ -23977,18 +24037,18 @@ fn resolveExportOptions(
2397724037 const section_src = sema.maybeOptionsSrc(block, src, "section");
2397824038 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2397924039
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);
2398124041 const name = try sema.toConstString(block, name_src, name_operand, .{
2398224042 .needed_comptime_reason = "name of exported value must be comptime-known",
2398324043 });
2398424044
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);
2398624046 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2398724047 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2398824048 });
2398924049 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2399024050
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);
2399224052 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2399324053 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2399424054 });
......@@ -23999,7 +24059,7 @@ fn resolveExportOptions(
2399924059 else
2400024060 null;
2400124061
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);
2400324063 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2400424064 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2400524065 });
......@@ -24016,9 +24076,9 @@ fn resolveExportOptions(
2401624076 }
2401724077
2401824078 return .{
24019 .name = try ip.getOrPutString(gpa, name),
24079 .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls),
2402024080 .linkage = linkage,
24021 .section = try ip.getOrPutStringOpt(gpa, section),
24081 .section = try ip.getOrPutStringOpt(gpa, section, .no_embedded_nulls),
2402224082 .visibility = visibility,
2402324083 };
2402424084}
......@@ -24896,7 +24956,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2489624956 const field_index = switch (parent_ty.zigTypeTag(mod)) {
2489724957 .Struct => blk: {
2489824958 if (parent_ty.isTuple(mod)) {
24899 if (ip.stringEqlSlice(field_name, "len")) {
24959 if (field_name.eqlSlice("len", ip)) {
2490024960 return sema.fail(block, inst_src, "cannot get @fieldParentPtr of 'len' field of tuple", .{});
2490124961 }
2490224962 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
2557825638
2557925639 const runtime_src = rs: {
2558025640 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);
2558225642 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;
2558325643 const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?;
2558425644 const len = try sema.usizeCast(block, dest_src, len_u64);
......@@ -25708,7 +25768,7 @@ fn zirVarExtended(
2570825768 .ty = var_ty.toIntern(),
2570925769 .init = init_val,
2571025770 .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),
2571225772 .is_extern = small.is_extern,
2571325773 .is_const = small.is_const,
2571425774 .is_threadlocal = small.is_threadlocal,
......@@ -26076,17 +26136,17 @@ fn resolvePrefetchOptions(
2607626136 const locality_src = sema.maybeOptionsSrc(block, src, "locality");
2607726137 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2607826138
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);
2608026140 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
2608126141 .needed_comptime_reason = "prefetch read/write must be comptime-known",
2608226142 });
2608326143
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);
2608526145 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{
2608626146 .needed_comptime_reason = "prefetch locality must be comptime-known",
2608726147 });
2608826148
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);
2609026150 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{
2609126151 .needed_comptime_reason = "prefetch cache must be comptime-known",
2609226152 });
......@@ -26155,23 +26215,23 @@ fn resolveExternOptions(
2615526215 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
2615626216 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2615726217
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);
2615926219 const name = try sema.toConstString(block, name_src, name_ref, .{
2616026220 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
2616126221 });
2616226222
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);
2616426224 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{
2616526225 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2616626226 });
2616726227
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);
2616926229 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2617026230 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2617126231 });
2617226232 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2617326233
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);
2617526235 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2617626236 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2617726237 });
......@@ -26196,8 +26256,8 @@ fn resolveExternOptions(
2619626256 }
2619726257
2619826258 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),
2620126261 .linkage = linkage,
2620226262 .is_thread_local = is_thread_local_val.toBool(),
2620326263 };
......@@ -26809,7 +26869,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
2680926869 block,
2681026870 .unneeded,
2681126871 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),
2681326873 ) catch |err| switch (err) {
2681426874 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),
2681526875 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
......@@ -27129,9 +27189,9 @@ fn fieldVal(
2712927189
2713027190 switch (inner_ty.zigTypeTag(mod)) {
2713127191 .Array => {
27132 if (ip.stringEqlSlice(field_name, "len")) {
27192 if (field_name.eqlSlice("len", ip)) {
2713327193 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) {
2713527195 const ptr_info = object_ty.ptrInfo(mod);
2713627196 const result_ty = try sema.ptrType(.{
2713727197 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
......@@ -27160,13 +27220,13 @@ fn fieldVal(
2716027220 .Pointer => {
2716127221 const ptr_info = inner_ty.ptrInfo(mod);
2716227222 if (ptr_info.flags.size == .Slice) {
27163 if (ip.stringEqlSlice(field_name, "ptr")) {
27223 if (field_name.eqlSlice("ptr", ip)) {
2716427224 const slice = if (is_pointer_to)
2716527225 try sema.analyzeLoad(block, src, object, object_src)
2716627226 else
2716727227 object;
2716827228 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)) {
2717027230 const slice = if (is_pointer_to)
2717127231 try sema.analyzeLoad(block, src, object, object_src)
2717227232 else
......@@ -27319,10 +27379,10 @@ fn fieldPtr(
2731927379
2732027380 switch (inner_ty.zigTypeTag(mod)) {
2732127381 .Array => {
27322 if (ip.stringEqlSlice(field_name, "len")) {
27382 if (field_name.eqlSlice("len", ip)) {
2732327383 const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod));
2732427384 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) {
2732627386 const ptr_info = object_ty.ptrInfo(mod);
2732727387 const new_ptr_ty = try sema.ptrType(.{
2732827388 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
......@@ -27370,7 +27430,7 @@ fn fieldPtr(
2737027430
2737127431 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;
2737227432
27373 if (ip.stringEqlSlice(field_name, "ptr")) {
27433 if (field_name.eqlSlice("ptr", ip)) {
2737427434 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
2737527435
2737627436 const result_ty = try sema.ptrType(.{
......@@ -27396,7 +27456,7 @@ fn fieldPtr(
2739627456 const field_ptr = try block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);
2739727457 try sema.checkKnownAllocPtr(block, inner_ptr, field_ptr);
2739827458 return field_ptr;
27399 } else if (ip.stringEqlSlice(field_name, "len")) {
27459 } else if (field_name.eqlSlice("len", ip)) {
2740027460 const result_ty = try sema.ptrType(.{
2740127461 .child = .usize_type,
2740227462 .flags = .{
......@@ -27584,7 +27644,7 @@ fn fieldCallBind(
2758427644
2758527645 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
2758627646 } else if (concrete_ty.isTuple(mod)) {
27587 if (ip.stringEqlSlice(field_name, "len")) {
27647 if (field_name.eqlSlice("len", ip)) {
2758827648 return .{ .direct = try mod.intRef(Type.usize, concrete_ty.structFieldCount(mod)) };
2758927649 }
2759027650 if (field_name.toUnsigned(ip)) |field_index| {
......@@ -27808,7 +27868,7 @@ fn structFieldPtr(
2780827868 try sema.resolveStructLayout(struct_ty);
2780927869
2781027870 if (struct_ty.isTuple(mod)) {
27811 if (ip.stringEqlSlice(field_name, "len")) {
27871 if (field_name.eqlSlice("len", ip)) {
2781227872 const len_inst = try mod.intRef(Type.usize, struct_ty.structFieldCount(mod));
2781327873 return sema.analyzeRef(block, src, len_inst);
2781427874 }
......@@ -28023,7 +28083,7 @@ fn tupleFieldVal(
2802328083 tuple_ty: Type,
2802428084) CompileError!Air.Inst.Ref {
2802528085 const mod = sema.mod;
28026 if (mod.intern_pool.stringEqlSlice(field_name, "len")) {
28086 if (field_name.eqlSlice("len", &mod.intern_pool)) {
2802728087 return mod.intRef(Type.usize, tuple_ty.structFieldCount(mod));
2802828088 }
2802928089 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
......@@ -28039,16 +28099,17 @@ fn tupleFieldIndex(
2803928099 field_name_src: LazySrcLoc,
2804028100) CompileError!u32 {
2804128101 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| {
2804428105 if (field_index < tuple_ty.structFieldCount(mod)) return field_index;
2804528106 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),
2804728108 });
2804828109 }
2804928110
2805028111 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),
2805228113 });
2805328114}
2805428115
......@@ -28076,7 +28137,7 @@ fn tupleFieldValByIndex(
2807628137 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {
2807728138 .undef => mod.undefRef(field_ty),
2807828139 .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)),
2808028141 .elems => |elems| Value.fromInterned(elems[field_index]),
2808128142 .repeated_elem => |elem| Value.fromInterned(elem),
2808228143 }.toIntern()),
......@@ -32266,38 +32327,36 @@ fn coerceTupleToStruct(
3226632327 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_types.len,
3226732328 else => unreachable,
3226832329 };
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| {
3227132331 const field_src = inst_src; // TODO better source location
32272 // https://github.com/ziglang/zig/issues/15709
3227332332 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
3227432333 .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]
3227632335 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],
3227932338 else => unreachable,
3228032339 };
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)) {
3228732346 const init_val = (try sema.resolveValue(coerced)) orelse {
3228832347 return sema.failWithNeededComptime(block, field_src, .{
3228932348 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
3229032349 });
3229132350 };
3229232351
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);
3229632355 }
3229732356 }
3229832357 if (runtime_src == null) {
3229932358 if (try sema.resolveValue(coerced)) |field_val| {
32300 field_vals[field_index] = field_val.toIntern();
32359 field_vals[struct_field_index] = field_val.toIntern();
3230132360 } else {
3230232361 runtime_src = field_src;
3230332362 }
......@@ -32382,24 +32441,23 @@ fn coerceTupleToTuple(
3238232441 for (0..dest_field_count) |field_index_usize| {
3238332442 const field_i: u32 = @intCast(field_index_usize);
3238432443 const field_src = inst_src; // TODO better source location
32385 // https://github.com/ziglang/zig/issues/15709
3238632444 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
3238732445 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)
3238832446 anon_struct_type.names.get(ip)[field_i]
3238932447 else
32390 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}),
32448 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls),
3239132449 .struct_type => s: {
3239232450 const struct_type = ip.loadStructType(inst_ty.toIntern());
3239332451 if (struct_type.field_names.len > 0) {
3239432452 break :s struct_type.field_names.get(ip)[field_i];
3239532453 } 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);
3239732455 }
3239832456 },
3239932457 else => unreachable,
3240032458 };
3240132459
32402 if (ip.stringEqlSlice(field_name, "len"))
32460 if (field_name.eqlSlice("len", ip))
3240332461 return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{});
3240432462
3240532463 const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) {
......@@ -34196,7 +34254,7 @@ const PeerResolveResult = union(enum) {
3419634254 /// There was an error when resolving the type of a struct or tuple field.
3419734255 field_error: struct {
3419834256 /// The name of the field which caused the failure.
34199 field_name: []const u8,
34257 field_name: InternPool.NullTerminatedString,
3420034258 /// The type of this field in each peer.
3420134259 field_types: []Type,
3420234260 /// The error from resolving the field type. Guaranteed not to be `success`.
......@@ -34237,8 +34295,8 @@ const PeerResolveResult = union(enum) {
3423734295 };
3423834296 },
3423934297 .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)};
3424234300 if (opt_msg) |msg| {
3424334301 try sema.errNote(block, src, msg, fmt, args);
3424434302 } else {
......@@ -35321,7 +35379,7 @@ fn resolvePeerTypesInner(
3532135379 const sub_peer_tys = try sema.arena.alloc(?Type, peer_tys.len);
3532235380 const sub_peer_vals = try sema.arena.alloc(?Value, peer_vals.len);
3532335381
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| {
3532535383 // Fill buffers with types and values of the field
3532635384 for (peer_tys, peer_vals, sub_peer_tys, sub_peer_vals) |opt_ty, opt_val, *peer_field_ty, *peer_field_val| {
3532735385 const ty = opt_ty orelse {
......@@ -35329,8 +35387,8 @@ fn resolvePeerTypesInner(
3532935387 peer_field_val.* = null;
3533035388 continue;
3533135389 };
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;
3533435392 }
3533535393
3533635394 // Resolve field type recursively
......@@ -35339,9 +35397,10 @@ fn resolvePeerTypesInner(
3533935397 else => |result| {
3534035398 const result_buf = try sema.arena.create(PeerResolveResult);
3534135399 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];
3534535404
3534635405 // The error info needs the field types, but we can't reuse sub_peer_tys
3534735406 // since the recursive call may have clobbered it.
......@@ -35350,7 +35409,7 @@ fn resolvePeerTypesInner(
3535035409 // Already-resolved types won't be referenced by the error so it's fine
3535135410 // to leave them undefined.
3535235411 const ty = opt_ty orelse continue;
35353 peer_field_ty.* = ty.structFieldType(field_idx, mod);
35412 peer_field_ty.* = ty.structFieldType(field_index, mod);
3535435413 }
3535535414
3535635415 return .{ .field_error = .{
......@@ -35369,7 +35428,7 @@ fn resolvePeerTypesInner(
3536935428 const struct_ty = opt_ty orelse continue;
3537035429 try sema.resolveStructFieldInits(struct_ty);
3537135430
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 {
3537335432 comptime_val = null;
3537435433 break;
3537535434 };
......@@ -36811,7 +36870,7 @@ fn semaStructFields(
3681136870
3681236871 // This string needs to outlive the ZIR code.
3681336872 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);
3681536874 assert(struct_type.addFieldName(ip, field_name) == null);
3681636875 }
3681736876
......@@ -37342,7 +37401,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3734237401 }
3734337402
3734437403 // 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);
3734637405 if (enum_field_names.len != 0) {
3734737406 enum_field_names[field_i] = field_name;
3734837407 }
......@@ -37528,7 +37587,12 @@ fn generateUnionTagTypeNumbered(
3752837587 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
3752937588 errdefer mod.destroyDecl(new_decl_index);
3753037589 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 );
3753237596 try mod.initNewAnonDecl(
3753337597 new_decl_index,
3753437598 src_decl.src_line,
......@@ -37574,7 +37638,12 @@ fn generateUnionTagTypeSimple(
3757437638 const src_decl = mod.declPtr(block.src_decl);
3757537639 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
3757637640 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 );
3757837647 try mod.initNewAnonDecl(
3757937648 new_decl_index,
3758037649 src_decl.src_line,
......@@ -37638,7 +37707,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
3763837707 block,
3763937708 src,
3764037709 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),
3764237711 )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");
3764337712 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src);
3764437713 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
3764937718 block,
3765037719 src,
3765137720 builtin_ty.getNamespaceIndex(mod),
37652 try ip.getOrPutString(gpa, name),
37721 try ip.getOrPutString(gpa, name, .no_embedded_nulls),
3765337722 )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name});
3765437723 return decl_index;
3765537724}
......@@ -38820,7 +38889,7 @@ fn intFitsInType(
3882038889 .aggregate => |aggregate| {
3882138890 assert(ty.zigTypeTag(mod) == .Vector);
3882238891 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| {
3882438893 if (byte == 0) continue;
3882538894 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);
3882638895 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
5252 assert(ty.zigTypeTag(mod) == .Array);
5353 assert(ty.childType(mod).toIntern() == .u8_type);
5454 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),
5858 .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));
6161 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);
6363 },
64 };
64 }
6565}
6666
6767/// Asserts that the value is representable as an array of bytes.
6868/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
6969pub 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)),
7273 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(mod), allocator, mod),
7374 .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)),
7576 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
7677 .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)));
7980 @memset(result, byte);
8081 return result;
8182 },
......@@ -85,10 +86,10 @@ pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module
8586}
8687
8788fn 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));
8990 for (result, 0..) |*elem, i| {
9091 const elem_val = try val.elemValue(mod, i);
91 elem.* = @as(u8, @intCast(elem_val.toUnsignedInt(mod)));
92 elem.* = @intCast(elem_val.toUnsignedInt(mod));
9293 }
9394 return result;
9495}
......@@ -96,7 +97,7 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Modul
9697fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {
9798 const gpa = mod.gpa;
9899 const ip = &mod.intern_pool;
99 const len = @as(usize, @intCast(len_u64));
100 const len: usize = @intCast(len_u64);
100101 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
101102 for (0..len) |i| {
102103 // 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
104105 const prev = ip.string_bytes.items.len;
105106 const elem_val = try val.elemValue(mod, i);
106107 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));
108109 ip.string_bytes.appendAssumeCapacity(byte);
109110 }
110 return ip.getOrPutTrailingString(gpa, len);
111 return ip.getOrPutTrailingString(gpa, len, .no_embedded_nulls);
111112}
112113
113114pub fn fromInterned(i: InternPool.Index) Value {
......@@ -256,7 +257,7 @@ pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64
256257 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
257258 const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod);
258259 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);
260261 },
261262 else => null,
262263 },
......@@ -351,17 +352,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
351352 bigint.writeTwosComplement(buffer[0..byte_count], endian);
352353 },
353354 .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),
359360 else => unreachable,
360361 },
361362 .Array => {
362363 const len = ty.arrayLen(mod);
363364 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));
365366 var elem_i: usize = 0;
366367 var buf_off: usize = 0;
367368 while (elem_i < len) : (elem_i += 1) {
......@@ -380,17 +381,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
380381 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
381382 switch (struct_type.layout) {
382383 .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));
385386 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
386387 .bytes => |bytes| {
387 buffer[off] = bytes[i];
388 buffer[off] = bytes.at(field_index, ip);
388389 continue;
389390 },
390 .elems => |elems| elems[i],
391 .elems => |elems| elems[field_index],
391392 .repeated_elem => |elem| elem,
392393 });
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]);
394395 try writeToMemory(field_val, field_ty, mod, buffer[off..]);
395396 },
396397 .@"packed" => {
......@@ -423,7 +424,7 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
423424 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
424425 const field_type = Type.fromInterned(union_obj.field_types.get(&mod.intern_pool)[field_index]);
425426 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));
427428 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);
428429 } else {
429430 const backing_ty = try ty.unionBackingType(mod);
......@@ -471,7 +472,7 @@ pub fn writeToPackedMemory(
471472 const target = mod.getTarget();
472473 const endian = target.cpu.arch.endian();
473474 if (val.isUndef(mod)) {
474 const bit_size = @as(usize, @intCast(ty.bitSize(mod)));
475 const bit_size: usize = @intCast(ty.bitSize(mod));
475476 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
476477 return;
477478 }
......@@ -507,17 +508,17 @@ pub fn writeToPackedMemory(
507508 }
508509 },
509510 .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),
515516 else => unreachable,
516517 },
517518 .Vector => {
518519 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));
521522
522523 var bits: u16 = 0;
523524 var elem_i: usize = 0;
......@@ -644,22 +645,22 @@ pub fn readFromMemory(
644645 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
645646 .ty = ty.toIntern(),
646647 .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)) },
652653 else => unreachable,
653654 },
654655 } }))),
655656 .Array => {
656657 const elem_ty = ty.childType(mod);
657658 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)));
659660 var offset: usize = 0;
660661 for (elems) |*elem| {
661662 elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern();
662 offset += @as(usize, @intCast(elem_size));
663 offset += @intCast(elem_size);
663664 }
664665 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
665666 .ty = ty.toIntern(),
......@@ -795,7 +796,7 @@ pub fn readFromPackedMemory(
795796 };
796797
797798 // 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));
799800 const Limb = std.math.big.Limb;
800801 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
801802 const limbs_buffer = try arena.alloc(Limb, limb_count);
......@@ -812,20 +813,20 @@ pub fn readFromPackedMemory(
812813 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
813814 .ty = ty.toIntern(),
814815 .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)) },
820821 else => unreachable,
821822 },
822823 } }))),
823824 .Vector => {
824825 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)));
826827
827828 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));
829830 for (elems, 0..) |_, i| {
830831 // On big-endian systems, LLVM reverses the element order of vectors by default
831832 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 {
909910 var i: usize = limbs.len;
910911 while (i != 0) {
911912 i -= 1;
912 const limb: f128 = @as(f128, @floatFromInt(limbs[i]));
913 const limb: f128 = @floatFromInt(limbs[i]);
913914 result = @mulAdd(f128, base, result, limb);
914915 }
915916 if (positive) {
......@@ -934,7 +935,7 @@ pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {
934935pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
935936 var bigint_buf: BigIntSpace = undefined;
936937 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));
938939}
939940
940941pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
......@@ -1191,7 +1192,7 @@ pub fn compareAllWithZeroAdvancedExtra(
11911192 inline else => |x| if (std.math.isNan(x)) return op == .neq,
11921193 },
11931194 .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| {
11951196 if (!std.math.order(byte, 0).compare(op)) break false;
11961197 } else true,
11971198 .elems => |elems| for (elems) |elem| {
......@@ -1279,7 +1280,7 @@ pub fn elemValue(val: Value, zcu: *Zcu, index: usize) Allocator.Error!Value {
12791280 if (index < len) return Value.fromInterned(switch (aggregate.storage) {
12801281 .bytes => |bytes| try zcu.intern(.{ .int = .{
12811282 .ty = .u8_type,
1282 .storage = .{ .u64 = bytes[index] },
1283 .storage = .{ .u64 = bytes.at(index, ip) },
12831284 } }),
12841285 .elems => |elems| elems[index],
12851286 .repeated_elem => |elem| elem,
......@@ -1318,28 +1319,37 @@ pub fn sliceArray(
13181319 start: usize,
13191320 end: usize,
13201321) error{OutOfMemory}!Value {
1321 // TODO: write something like getCoercedInts to avoid needing to dupe
13221322 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 },
13411351 },
1342 } }));
1352 }));
13431353}
13441354
13451355pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
......@@ -1350,7 +1360,7 @@ pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
13501360 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
13511361 .bytes => |bytes| try mod.intern(.{ .int = .{
13521362 .ty = .u8_type,
1353 .storage = .{ .u64 = bytes[index] },
1363 .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) },
13541364 } }),
13551365 .elems => |elems| elems[index],
13561366 .repeated_elem => |elem| elem,
......@@ -1461,7 +1471,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi
14611471
14621472pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
14631473 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).?)
14651475 else
14661476 0;
14671477}
......@@ -2413,14 +2423,14 @@ pub fn intTruncBitsAsValue(
24132423 for (result_data, 0..) |*scalar, i| {
24142424 const elem_val = try val.elemValue(mod, i);
24152425 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();
24172427 }
24182428 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
24192429 .ty = ty.toIntern(),
24202430 .storage = .{ .elems = result_data },
24212431 } })));
24222432 }
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);
24242434}
24252435
24262436pub fn intTruncScalar(
......@@ -2468,7 +2478,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M
24682478 // resorting to BigInt first.
24692479 var lhs_space: Value.BigIntSpace = undefined;
24702480 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));
24722482 const limbs = try allocator.alloc(
24732483 std.math.big.Limb,
24742484 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2530,7 +2540,7 @@ pub fn shlWithOverflowScalar(
25302540 const info = ty.intInfo(mod);
25312541 var lhs_space: Value.BigIntSpace = undefined;
25322542 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));
25342544 const limbs = try allocator.alloc(
25352545 std.math.big.Limb,
25362546 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2587,7 +2597,7 @@ pub fn shlSatScalar(
25872597
25882598 var lhs_space: Value.BigIntSpace = undefined;
25892599 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));
25912601 const limbs = try arena.alloc(
25922602 std.math.big.Limb,
25932603 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
26592669 // resorting to BigInt first.
26602670 var lhs_space: Value.BigIntSpace = undefined;
26612671 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));
26632673
26642674 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
26652675 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
43454345 .data = .{ .reg = .x30 },
43464346 });
43474347 } 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);
43504350 if (self.bin_file.cast(link.File.MachO)) |macho_file| {
43514351 _ = macho_file;
43524352 @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
21992199 const atom = func.bin_file.getAtomPtr(atom_index);
22002200 const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type);
22012201 try func.bin_file.addOrUpdateImport(
2202 mod.intern_pool.stringToSlice(ext_decl.name),
2202 ext_decl.name.toSlice(&mod.intern_pool),
22032203 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),
22052205 type_index,
22062206 );
22072207 break :blk extern_func.decl;
......@@ -7236,8 +7236,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72367236 defer arena_allocator.deinit();
72377237 const arena = arena_allocator.allocator();
72387238
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)});
72417241
72427242 // check if we already generated code for this.
72437243 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {
......@@ -7268,17 +7268,18 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72687268 // generate an if-else chain for each tag value as well as constant.
72697269 const tag_names = enum_ty.enumFields(mod);
72707270 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);
72727273 // for each tag name, create an unnamed const,
72737274 // and then get a pointer to its value.
72747275 const name_ty = try mod.arrayType(.{
7275 .len = tag_name.len,
7276 .len = tag_name_len,
72767277 .child = .u8_type,
72777278 .sentinel = .zero_u8,
72787279 });
72797280 const name_val = try mod.intern(.{ .aggregate = .{
72807281 .ty = name_ty.toIntern(),
7281 .storage = .{ .bytes = tag_name },
7282 .storage = .{ .bytes = tag_name.toString() },
72827283 } });
72837284 const tag_sym_index = try func.bin_file.lowerUnnamedConst(
72847285 Value.fromInterned(name_val),
......@@ -7338,7 +7339,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73387339
73397340 // store length
73407341 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)));
73427343 try writer.writeByte(std.wasm.opcode(.i32_store));
73437344 try leb.writeULEB128(writer, encoded_alignment);
73447345 try leb.writeULEB128(writer, @as(u32, 4));
......@@ -7359,7 +7360,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73597360
73607361 // store length
73617362 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)));
73637364 try writer.writeByte(std.wasm.opcode(.i64_store));
73647365 try leb.writeULEB128(writer, encoded_alignment);
73657366 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 {
22472247 var data_off: i32 = 0;
22482248 const tag_names = enum_ty.enumFields(mod);
22492249 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);
22512251 const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index));
22522252 const tag_mcv = try self.genTypedValue(tag_val);
22532253 try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv);
......@@ -12314,8 +12314,8 @@ fn genCall(self: *Self, info: union(enum) {
1231412314 },
1231512315 .extern_func => |extern_func| {
1231612316 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);
1231912319 try self.genExternSymbolRef(.call, lib_name, decl_name);
1232012320 },
1232112321 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
9797 _ = target;
9898 const bits = @typeInfo(F).Float.bits;
9999 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });
100 const int = @as(Int, @bitCast(f));
100 const int: Int = @bitCast(f);
101101 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);
102102}
103103
......@@ -136,24 +136,24 @@ pub fn generateLazySymbol(
136136 if (lazy_sym.ty.isAnyError(zcu)) {
137137 alignment.* = .@"4";
138138 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);
140140 var offset = code.items.len;
141141 try code.resize((1 + err_names.len + 1) * 4);
142142 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);
145145 offset += 4;
146146 try code.ensureUnusedCapacity(err_name.len + 1);
147147 code.appendSliceAssumeCapacity(err_name);
148148 code.appendAssumeCapacity(0);
149149 }
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);
151151 return Result.ok;
152152 } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) {
153153 alignment.* = .@"1";
154154 const tag_names = lazy_sym.ty.enumFields(zcu);
155155 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);
157157 try code.ensureUnusedCapacity(tag_name.len + 1);
158158 code.appendSliceAssumeCapacity(tag_name);
159159 code.appendAssumeCapacity(0);
......@@ -241,13 +241,13 @@ pub fn generateSymbol(
241241 },
242242 .err => |err| {
243243 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);
245245 },
246246 .error_union => |error_union| {
247247 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,
251251 };
252252
253253 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -357,15 +357,13 @@ pub fn generateSymbol(
357357 },
358358 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {
359359 .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)),
361361 .elems, .repeated_elem => {
362362 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) {
366364 switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) {
367365 .bytes => unreachable,
368 .elems => |elems| elems[@as(usize, @intCast(index))],
366 .elems => |elems| elems[@intCast(index)],
369367 .repeated_elem => |elem| if (index < array_type.len)
370368 elem
371369 else
......@@ -399,7 +397,7 @@ pub fn generateSymbol(
399397 }) {
400398 .bool_true => true,
401399 .bool_false => false,
402 else => |elem| switch (mod.intern_pool.indexToKey(elem)) {
400 else => |elem| switch (ip.indexToKey(elem)) {
403401 .undef => continue,
404402 .int => |int| switch (int.storage) {
405403 .u64 => |x| switch (x) {
......@@ -420,7 +418,7 @@ pub fn generateSymbol(
420418 }
421419 } else {
422420 switch (aggregate.storage) {
423 .bytes => |bytes| try code.appendSlice(bytes),
421 .bytes => |bytes| try code.appendSlice(bytes.toSlice(vector_type.len, ip)),
424422 .elems, .repeated_elem => {
425423 var index: u64 = 0;
426424 while (index < vector_type.len) : (index += 1) {
......@@ -457,7 +455,7 @@ pub fn generateSymbol(
457455 const field_val = switch (aggregate.storage) {
458456 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
459457 .ty = field_ty,
460 .storage = .{ .u64 = bytes[index] },
458 .storage = .{ .u64 = bytes.at(index, ip) },
461459 } }),
462460 .elems => |elems| elems[index],
463461 .repeated_elem => |elem| elem,
......@@ -493,7 +491,7 @@ pub fn generateSymbol(
493491 const field_val = switch (aggregate.storage) {
494492 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
495493 .ty = field_ty,
496 .storage = .{ .u64 = bytes[index] },
494 .storage = .{ .u64 = bytes.at(index, ip) },
497495 } }),
498496 .elems => |elems| elems[index],
499497 .repeated_elem => |elem| elem,
......@@ -513,7 +511,7 @@ pub fn generateSymbol(
513511 } else {
514512 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), mod, code.items[current_pos..], bits) catch unreachable;
515513 }
516 bits += @as(u16, @intCast(Type.fromInterned(field_ty).bitSize(mod)));
514 bits += @intCast(Type.fromInterned(field_ty).bitSize(mod));
517515 }
518516 },
519517 .auto, .@"extern" => {
......@@ -529,7 +527,7 @@ pub fn generateSymbol(
529527 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
530528 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
531529 .ty = field_ty,
532 .storage = .{ .u64 = bytes[field_index] },
530 .storage = .{ .u64 = bytes.at(field_index, ip) },
533531 } }),
534532 .elems => |elems| elems[field_index],
535533 .repeated_elem => |elem| elem,
......@@ -625,7 +623,8 @@ fn lowerParentPtr(
625623 reloc_info: RelocInfo,
626624) CodeGenError!Result {
627625 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;
629628 return switch (ptr.addr) {
630629 .decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info),
631630 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),
......@@ -636,10 +635,10 @@ fn lowerParentPtr(
636635 eu_payload,
637636 code,
638637 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)),
641640 mod,
642 )))),
641 ))),
643642 ),
644643 .opt_payload => |opt_payload| try lowerParentPtr(
645644 bin_file,
......@@ -655,19 +654,19 @@ fn lowerParentPtr(
655654 elem.base,
656655 code,
657656 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))),
660659 ),
661660 .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;
664663 return lowerParentPtr(
665664 bin_file,
666665 src_loc,
667666 field.base,
668667 code,
669668 debug_output,
670 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_ty)) {
669 reloc_info.offset(switch (ip.indexToKey(base_ty)) {
671670 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
672671 .One, .Many, .C => unreachable,
673672 .Slice => switch (field.index) {
......@@ -723,11 +722,12 @@ fn lowerAnonDeclRef(
723722) CodeGenError!Result {
724723 _ = debug_output;
725724 const zcu = lf.comp.module.?;
725 const ip = &zcu.intern_pool;
726726 const target = lf.comp.root_mod.resolved_target.result;
727727
728728 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
729729 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));
731731 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(zcu)});
732732 const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn;
733733 if (!is_fn_body and !decl_ty.hasRuntimeBits(zcu)) {
......@@ -735,7 +735,7 @@ fn lowerAnonDeclRef(
735735 return Result.ok;
736736 }
737737
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;
739739 const res = try lf.lowerAnonDecl(decl_val, decl_align, src_loc);
740740 switch (res) {
741741 .ok => {},
......@@ -787,8 +787,8 @@ fn lowerDeclRef(
787787 });
788788 const endian = target.cpu.arch.endian();
789789 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),
792792 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),
793793 else => unreachable,
794794 }
......@@ -859,6 +859,7 @@ fn genDeclRef(
859859 ptr_decl_index: InternPool.DeclIndex,
860860) CodeGenError!GenResult {
861861 const zcu = lf.comp.module.?;
862 const ip = &zcu.intern_pool;
862863 const ty = val.typeOf(zcu);
863864 log.debug("genDeclRef: val = {}", .{val.fmtValue(zcu)});
864865
......@@ -869,7 +870,7 @@ fn genDeclRef(
869870 const ptr_bits = target.ptrBitWidth();
870871 const ptr_bytes: u64 = @divExact(ptr_bits, 8);
871872
872 const decl_index = switch (zcu.intern_pool.indexToKey(ptr_decl.val.toIntern())) {
873 const decl_index = switch (ip.indexToKey(ptr_decl.val.toIntern())) {
873874 .func => |func| func.owner_decl,
874875 .extern_func => |extern_func| extern_func.decl,
875876 else => ptr_decl_index,
......@@ -909,12 +910,9 @@ fn genDeclRef(
909910
910911 if (lf.cast(link.File.Elf)) |elf_file| {
911912 if (is_extern) {
912 const name = zcu.intern_pool.stringToSlice(decl.name);
913 const name = decl.name.toSlice(ip);
913914 // 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;
918916 const sym_index = try elf_file.getGlobalSymbol(name, lib_name);
919917 elf_file.symbol(elf_file.zigObjectPtr().?.symbol(sym_index)).flags.needs_got = true;
920918 return GenResult.mcv(.{ .load_symbol = sym_index });
......@@ -927,11 +925,8 @@ fn genDeclRef(
927925 return GenResult.mcv(.{ .load_symbol = sym.esym_index });
928926 } else if (lf.cast(link.File.MachO)) |macho_file| {
929927 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;
935930 const sym_index = try macho_file.getGlobalSymbol(name, lib_name);
936931 macho_file.getSymbol(macho_file.getZigObject().?.symbols.items[sym_index]).flags.needs_got = true;
937932 return GenResult.mcv(.{ .load_symbol = sym_index });
......@@ -944,12 +939,9 @@ fn genDeclRef(
944939 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
945940 } else if (lf.cast(link.File.Coff)) |coff_file| {
946941 if (is_extern) {
947 const name = zcu.intern_pool.stringToSlice(decl.name);
942 const name = decl.name.toSlice(ip);
948943 // 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;
953945 const global_index = try coff_file.getGlobalSymbol(name, lib_name);
954946 try coff_file.need_got_table.put(gpa, global_index, {}); // needs GOT
955947 return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index });
......@@ -1012,6 +1004,7 @@ pub fn genTypedValue(
10121004 owner_decl_index: InternPool.DeclIndex,
10131005) CodeGenError!GenResult {
10141006 const zcu = lf.comp.module.?;
1007 const ip = &zcu.intern_pool;
10151008 const ty = val.typeOf(zcu);
10161009
10171010 log.debug("genTypedValue: val = {}", .{val.fmtValue(zcu)});
......@@ -1024,7 +1017,7 @@ pub fn genTypedValue(
10241017 const target = namespace.file_scope.mod.resolved_target.result;
10251018 const ptr_bits = target.ptrBitWidth();
10261019
1027 if (!ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1020 if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) {
10281021 .ptr => |ptr| switch (ptr.addr) {
10291022 .decl => |decl| return genDeclRef(lf, src_loc, val, decl),
10301023 else => {},
......@@ -1041,7 +1034,7 @@ pub fn genTypedValue(
10411034 return GenResult.mcv(.{ .immediate = 0 });
10421035 },
10431036 .none => {},
1044 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1037 else => switch (ip.indexToKey(val.toIntern())) {
10451038 .int => {
10461039 return GenResult.mcv(.{ .immediate = val.toUnsignedInt(zcu) });
10471040 },
......@@ -1052,8 +1045,8 @@ pub fn genTypedValue(
10521045 .Int => {
10531046 const info = ty.intInfo(zcu);
10541047 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)),
10571050 .unsigned => val.toUnsignedInt(zcu),
10581051 };
10591052 return GenResult.mcv(.{ .immediate = unsigned });
......@@ -1075,7 +1068,7 @@ pub fn genTypedValue(
10751068 }
10761069 },
10771070 .Enum => {
1078 const enum_tag = zcu.intern_pool.indexToKey(val.toIntern()).enum_tag;
1071 const enum_tag = ip.indexToKey(val.toIntern()).enum_tag;
10791072 return genTypedValue(
10801073 lf,
10811074 src_loc,
......@@ -1084,7 +1077,7 @@ pub fn genTypedValue(
10841077 );
10851078 },
10861079 .ErrorSet => {
1087 const err_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name;
1080 const err_name = ip.indexToKey(val.toIntern()).err.name;
10881081 const error_index = zcu.global_error_set.getIndex(err_name).?;
10891082 return GenResult.mcv(.{ .immediate = error_index });
10901083 },
......@@ -1094,7 +1087,7 @@ pub fn genTypedValue(
10941087 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
10951088 // We use the error type directly as the type.
10961089 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) {
10981091 .err_name => |err_name| return genTypedValue(
10991092 lf,
11001093 src_loc,
src/codegen/c.zig+73-105
......@@ -505,7 +505,7 @@ pub const Function = struct {
505505 .never_inline,
506506 => |owner_decl| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
507507 @tagName(key),
508 fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(owner_decl).name)),
508 fmtIdent(zcu.declPtr(owner_decl).name.toSlice(&zcu.intern_pool)),
509509 @intFromEnum(owner_decl),
510510 }),
511511 },
......@@ -822,19 +822,6 @@ pub const DeclGen = struct {
822822 try dg.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset), .Other),
823823 });
824824 },
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 },
838825 }
839826 },
840827 .comptime_field, .comptime_alloc => unreachable,
......@@ -911,7 +898,7 @@ pub const DeclGen = struct {
911898 },
912899 },
913900 .err => |err| try writer.print("zig_error_{}", .{
914 fmtIdent(ip.stringToSlice(err.name)),
901 fmtIdent(err.name.toSlice(ip)),
915902 }),
916903 .error_union => |error_union| {
917904 const payload_ty = ty.errorUnionPayload(zcu);
......@@ -1191,7 +1178,7 @@ pub const DeclGen = struct {
11911178 switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
11921179 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
11931180 .ty = field_ty.toIntern(),
1194 .storage = .{ .u64 = bytes[field_index] },
1181 .storage = .{ .u64 = bytes.at(field_index, ip) },
11951182 } }),
11961183 .elems => |elems| elems[field_index],
11971184 .repeated_elem => |elem| elem,
......@@ -1225,7 +1212,7 @@ pub const DeclGen = struct {
12251212 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
12261213 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
12271214 .ty = field_ty.toIntern(),
1228 .storage = .{ .u64 = bytes[field_index] },
1215 .storage = .{ .u64 = bytes.at(field_index, ip) },
12291216 } }),
12301217 .elems => |elems| elems[field_index],
12311218 .repeated_elem => |elem| elem,
......@@ -1271,7 +1258,7 @@ pub const DeclGen = struct {
12711258 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
12721259 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
12731260 .ty = field_ty.toIntern(),
1274 .storage = .{ .u64 = bytes[field_index] },
1261 .storage = .{ .u64 = bytes.at(field_index, ip) },
12751262 } }),
12761263 .elems => |elems| elems[field_index],
12771264 .repeated_elem => |elem| elem,
......@@ -1312,7 +1299,7 @@ pub const DeclGen = struct {
13121299 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
13131300 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
13141301 .ty = field_ty.toIntern(),
1315 .storage = .{ .u64 = bytes[field_index] },
1302 .storage = .{ .u64 = bytes.at(field_index, ip) },
13161303 } }),
13171304 .elems => |elems| elems[field_index],
13181305 .repeated_elem => |elem| elem,
......@@ -1405,7 +1392,7 @@ pub const DeclGen = struct {
14051392 try writer.writeAll(" .payload = {");
14061393 }
14071394 if (field_ty.hasRuntimeBits(zcu)) {
1408 try writer.print(" .{ } = ", .{fmtIdent(ip.stringToSlice(field_name))});
1395 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
14091396 try dg.renderValue(writer, Value.fromInterned(un.val), initializer_type);
14101397 try writer.writeByte(' ');
14111398 } else for (0..loaded_union.field_types.len) |this_field_index| {
......@@ -1754,14 +1741,12 @@ pub const DeclGen = struct {
17541741 switch (name) {
17551742 .export_index => |export_index| mangled: {
17561743 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);
17651750 const is_mangled = isMangledIdent(external_name, true);
17661751 const is_export = export_index > 0;
17671752 if (is_mangled and is_export) {
......@@ -1769,7 +1754,7 @@ pub const DeclGen = struct {
17691754 fmtIdent(external_name),
17701755 fmtStringLiteral(external_name, null),
17711756 fmtStringLiteral(
1772 ip.stringToSlice(maybe_exports.?.items[0].opts.name),
1757 maybe_exports.?.items[0].opts.name.toSlice(ip),
17731758 null,
17741759 ),
17751760 });
......@@ -1780,7 +1765,7 @@ pub const DeclGen = struct {
17801765 } else if (is_export) {
17811766 try w.print(" zig_export({s}, {s})", .{
17821767 fmtStringLiteral(
1783 ip.stringToSlice(maybe_exports.?.items[0].opts.name),
1768 maybe_exports.?.items[0].opts.name.toSlice(ip),
17841769 null,
17851770 ),
17861771 fmtStringLiteral(external_name, null),
......@@ -2088,12 +2073,12 @@ pub const DeclGen = struct {
20882073 .complete,
20892074 );
20902075 mangled: {
2091 const external_name = zcu.intern_pool.stringToSlice(if (maybe_exports) |exports|
2076 const external_name = (if (maybe_exports) |exports|
20922077 exports.items[0].opts.name
20932078 else if (variable.is_extern)
20942079 decl.name
20952080 else
2096 break :mangled);
2081 break :mangled).toSlice(&zcu.intern_pool);
20972082 if (isMangledIdent(external_name, true)) {
20982083 try fwd.print(" zig_mangled_{s}({ }, {s})", .{
20992084 @tagName(fwd_kind),
......@@ -2107,15 +2092,16 @@ pub const DeclGen = struct {
21072092
21082093 fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {
21092094 const zcu = dg.zcu;
2095 const ip = &zcu.intern_pool;
21102096 const decl = zcu.declPtr(decl_index);
21112097
21122098 if (zcu.decl_exports.get(decl_index)) |exports| {
21132099 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)),
21152101 });
21162102 } else if (decl.getExternDecl(zcu).unwrap()) |extern_decl_index| {
21172103 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)),
21192105 });
21202106 } else {
21212107 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
......@@ -2239,7 +2225,7 @@ fn renderFwdDeclTypeName(
22392225 switch (fwd_decl.name) {
22402226 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),
22412227 .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)),
22432229 @intFromEnum(owner_decl),
22442230 }),
22452231 }
......@@ -2561,7 +2547,7 @@ pub fn genErrDecls(o: *Object) !void {
25612547 try writer.writeAll("enum {\n");
25622548 o.indent_writer.pushIndent();
25632549 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);
25652551 max_name_len = @max(name.len, max_name_len);
25662552 const err_val = try zcu.intern(.{ .err = .{
25672553 .ty = .anyerror_type,
......@@ -2579,19 +2565,19 @@ pub fn genErrDecls(o: *Object) !void {
25792565 defer o.dg.gpa.free(name_buf);
25802566
25812567 @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];
25862572
25872573 const name_ty = try zcu.arrayType(.{
2588 .len = name.len,
2574 .len = name_slice.len,
25892575 .child = .u8_type,
25902576 .sentinel = .zero_u8,
25912577 });
25922578 const name_val = try zcu.intern(.{ .aggregate = .{
25932579 .ty = name_ty.toIntern(),
2594 .storage = .{ .bytes = name },
2580 .storage = .{ .bytes = name.toString() },
25952581 } });
25962582
25972583 try writer.writeAll("static ");
......@@ -2624,7 +2610,7 @@ pub fn genErrDecls(o: *Object) !void {
26242610 );
26252611 try writer.writeAll(" = {");
26262612 for (zcu.global_error_set.keys(), 0..) |name_nts, value| {
2627 const name = ip.stringToSlice(name_nts);
2613 const name = name_nts.toSlice(ip);
26282614 if (value != 0) try writer.writeByte(',');
26292615 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
26302616 fmtIdent(name),
......@@ -2672,7 +2658,7 @@ fn genExports(o: *Object) !void {
26722658 for (exports.items[1..]) |@"export"| {
26732659 try fwd.writeAll("zig_extern ");
26742660 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);
26762662 try o.dg.renderTypeAndName(
26772663 fwd,
26782664 decl.typeOf(zcu),
......@@ -2685,11 +2671,11 @@ fn genExports(o: *Object) !void {
26852671 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
26862672 fmtIdent(export_name),
26872673 fmtStringLiteral(export_name, null),
2688 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
2674 fmtStringLiteral(exports.items[0].opts.name.toSlice(ip), null),
26892675 });
26902676 } else {
26912677 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),
26932679 fmtStringLiteral(export_name, null),
26942680 });
26952681 }
......@@ -2719,17 +2705,18 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
27192705 try w.writeAll(") {\n switch (tag) {\n");
27202706 const tag_names = enum_ty.enumFields(zcu);
27212707 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);
27232710 const tag_val = try zcu.enumValueFieldIndex(enum_ty, @intCast(tag_index));
27242711
27252712 const name_ty = try zcu.arrayType(.{
2726 .len = tag_name.len,
2713 .len = tag_name_len,
27272714 .child = .u8_type,
27282715 .sentinel = .zero_u8,
27292716 });
27302717 const name_val = try zcu.intern(.{ .aggregate = .{
27312718 .ty = name_ty.toIntern(),
2732 .storage = .{ .bytes = tag_name },
2719 .storage = .{ .bytes = tag_name.toString() },
27332720 } });
27342721
27352722 try w.print(" case {}: {{\n static ", .{
......@@ -2742,7 +2729,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
27422729 try o.dg.renderType(w, name_slice_ty);
27432730 try w.print("){{{}, {}}};\n", .{
27442731 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),
27462733 });
27472734
27482735 try w.writeAll(" }\n");
......@@ -2810,7 +2797,7 @@ pub fn genFunc(f: *Function) !void {
28102797
28112798 try o.indent_writer.insertNewline();
28122799 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|
28142801 try o.writer().print("zig_linksection_fn({s}) ", .{fmtStringLiteral(s, null)});
28152802 try o.dg.renderFunctionSignature(o.writer(), decl_index, .complete, .{ .export_index = 0 });
28162803 try o.writer().writeByte(' ');
......@@ -2900,7 +2887,7 @@ pub fn genDecl(o: *Object) !void {
29002887 if (!is_global) try w.writeAll("static ");
29012888 if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage ");
29022889 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|
29042891 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});
29052892 const decl_c_value = .{ .decl = decl_index };
29062893 try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete);
......@@ -2933,7 +2920,7 @@ pub fn genDeclValue(
29332920 switch (o.dg.pass) {
29342921 .decl => |decl_index| {
29352922 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);
29372924 if (isMangledIdent(export_name, true)) {
29382925 try fwd_decl_writer.print(" zig_mangled_final({ }, {s})", .{
29392926 fmtIdent(export_name), fmtStringLiteral(export_name, null),
......@@ -2949,7 +2936,7 @@ pub fn genDeclValue(
29492936
29502937 const w = o.writer();
29512938 if (!is_global) try w.writeAll("static ");
2952 if (zcu.intern_pool.stringToSliceUnwrap(@"linksection")) |s|
2939 if (@"linksection".toSlice(&zcu.intern_pool)) |s|
29532940 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});
29542941 try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete);
29552942 try w.writeAll(" = ");
......@@ -5453,49 +5440,39 @@ fn fieldLocation(
54535440) union(enum) {
54545441 begin: void,
54555442 field: CValue,
5456 byte_offset: u32,
5457 end: void,
5443 byte_offset: u64,
54585444} {
54595445 const ip = &zcu.intern_pool;
54605446 const container_ty = Type.fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child);
54615447 switch (ip.indexToKey(container_ty.toIntern())) {
54625448 .struct_type => {
54635449 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)
54815461 .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) +
54825462 container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) }
54835463 else
54845464 .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 };
54985466 },
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 } },
54995476 .union_type => {
55005477 const loaded_union = ip.loadUnionType(container_ty.toIntern());
55015478 switch (loaded_union.getLayout(ip)) {
......@@ -5508,9 +5485,9 @@ fn fieldLocation(
55085485 .begin;
55095486 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
55105487 return .{ .field = if (loaded_union.hasTag(ip))
5511 .{ .payload_identifier = ip.stringToSlice(field_name) }
5488 .{ .payload_identifier = field_name.toSlice(ip) }
55125489 else
5513 .{ .identifier = ip.stringToSlice(field_name) } };
5490 .{ .identifier = field_name.toSlice(ip) } };
55145491 },
55155492 .@"packed" => return .begin,
55165493 }
......@@ -5591,10 +5568,6 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
55915568 try f.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset)),
55925569 });
55935570 },
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 },
55985571 }
55995572
56005573 try writer.writeAll(";\n");
......@@ -5639,11 +5612,6 @@ fn fieldPtr(
56395612 try f.fmtIntLiteral(try zcu.intValue(Type.usize, byte_offset)),
56405613 });
56415614 },
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 },
56475615 }
56485616
56495617 try writer.writeAll(";\n");
......@@ -5675,7 +5643,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
56755643 const loaded_struct = ip.loadStructType(struct_ty.toIntern());
56765644 switch (loaded_struct.layout) {
56775645 .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) }
56795647 else
56805648 .{ .field = extra.field_index },
56815649 .@"packed" => {
......@@ -5733,7 +5701,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57335701 }
57345702 },
57355703 .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) }
57375705 else
57385706 .{ .field = extra.field_index },
57395707 .union_type => field_name: {
......@@ -5742,9 +5710,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57425710 .auto, .@"extern" => {
57435711 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
57445712 break :field_name if (loaded_union.hasTag(ip))
5745 .{ .payload_identifier = ip.stringToSlice(name) }
5713 .{ .payload_identifier = name.toSlice(ip) }
57465714 else
5747 .{ .identifier = ip.stringToSlice(name) };
5715 .{ .identifier = name.toSlice(ip) };
57485716 },
57495717 .@"packed" => {
57505718 const operand_lval = if (struct_byval == .constant) blk: {
......@@ -7094,7 +7062,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
70947062
70957063 const a = try Assignment.start(f, writer, field_ty);
70967064 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) }
70987066 else
70997067 .{ .field = field_index });
71007068 try a.assign(f, writer);
......@@ -7174,7 +7142,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
71747142
71757143 const a = try Assignment.start(f, writer, field_ty);
71767144 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) }
71787146 else
71797147 .{ .field = field_index });
71807148 try a.assign(f, writer);
......@@ -7222,8 +7190,8 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
72227190 try writer.print("{}", .{try f.fmtIntLiteral(try tag_val.intFromEnum(tag_ty, zcu))});
72237191 try a.end(f, writer);
72247192 }
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) };
72277195
72287196 const a = try Assignment.start(f, writer, payload_ty);
72297197 try f.writeCValueMember(writer, local, field);
src/codegen/c/Type.zig+5-5
......@@ -1465,7 +1465,7 @@ pub const Pool = struct {
14651465 },
14661466 },
14671467 .array_type => |array_info| {
1468 const len = array_info.len + @intFromBool(array_info.sentinel != .none);
1468 const len = array_info.lenIncludingSentinel();
14691469 if (len == 0) return .{ .index = .void };
14701470 const elem_type = Type.fromInterned(array_info.child);
14711471 const elem_ctype = try pool.fromType(
......@@ -1479,7 +1479,7 @@ pub const Pool = struct {
14791479 if (elem_ctype.index == .void) return .{ .index = .void };
14801480 const array_ctype = try pool.getArray(allocator, .{
14811481 .elem_ctype = elem_ctype,
1482 .len = array_info.len + @intFromBool(array_info.sentinel != .none),
1482 .len = len,
14831483 });
14841484 if (!kind.isParameter()) return array_ctype;
14851485 var fields = [_]Info.Field{
......@@ -1625,7 +1625,7 @@ pub const Pool = struct {
16251625 if (field_ctype.index == .void) continue;
16261626 const field_name = if (loaded_struct.fieldName(ip, field_index)
16271627 .unwrap()) |field_name|
1628 try pool.string(allocator, ip.stringToSlice(field_name))
1628 try pool.string(allocator, field_name.toSlice(ip))
16291629 else
16301630 try pool.fmt(allocator, "f{d}", .{field_index});
16311631 const field_alignas = AlignAs.fromAlignment(.{
......@@ -1685,7 +1685,7 @@ pub const Pool = struct {
16851685 if (field_ctype.index == .void) continue;
16861686 const field_name = if (anon_struct_info.fieldName(ip, @intCast(field_index))
16871687 .unwrap()) |field_name|
1688 try pool.string(allocator, ip.stringToSlice(field_name))
1688 try pool.string(allocator, field_name.toSlice(ip))
16891689 else
16901690 try pool.fmt(allocator, "f{d}", .{field_index});
16911691 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
......@@ -1766,7 +1766,7 @@ pub const Pool = struct {
17661766 if (field_ctype.index == .void) continue;
17671767 const field_name = try pool.string(
17681768 allocator,
1769 ip.stringToSlice(loaded_tag.names.get(ip)[field_index]),
1769 loaded_tag.names.get(ip)[field_index].toSlice(ip),
17701770 );
17711771 const field_alignas = AlignAs.fromAlignment(.{
17721772 .@"align" = loaded_union.fieldAlign(ip, @intCast(field_index)),
src/codegen/llvm.zig+53-60
......@@ -1011,7 +1011,7 @@ pub const Object = struct {
10111011
10121012 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
10131013 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));
10151015 const name_init = try o.builder.stringConst(name_string);
10161016 const name_variable_index =
10171017 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
......@@ -1086,7 +1086,7 @@ pub const Object = struct {
10861086 for (object.extern_collisions.keys()) |decl_index| {
10871087 const global = object.decl_map.get(decl_index) orelse continue;
10881088 // 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;
10901090 const other_global = object.builder.getGlobal(decl_name) orelse continue;
10911091 if (other_global.toConst().getBase(&object.builder) ==
10921092 global.toConst().getBase(&object.builder)) continue;
......@@ -1116,7 +1116,7 @@ pub const Object = struct {
11161116 for (export_list) |exp| {
11171117 // Detect if the LLVM global has already been created as an extern. In such
11181118 // 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;
11201120
11211121 const other_global = object.builder.getGlobal(exp_name) orelse continue;
11221122 if (other_global.toConst().getBase(&object.builder) == global_base) continue;
......@@ -1442,7 +1442,7 @@ pub const Object = struct {
14421442 } }, &o.builder);
14431443 }
14441444
1445 if (ip.stringToSliceUnwrap(decl.@"linksection")) |section|
1445 if (decl.@"linksection".toSlice(ip)) |section|
14461446 function_index.setSection(try o.builder.string(section), &o.builder);
14471447
14481448 var deinit_wip = true;
......@@ -1662,7 +1662,7 @@ pub const Object = struct {
16621662
16631663 const subprogram = try o.builder.debugSubprogram(
16641664 file,
1665 try o.builder.metadataString(ip.stringToSlice(decl.name)),
1665 try o.builder.metadataString(decl.name.toSlice(ip)),
16661666 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),
16671667 line_number,
16681668 line_number + func.lbrace_line,
......@@ -1752,6 +1752,7 @@ pub const Object = struct {
17521752 .value => |val| return updateExportedValue(self, mod, val, exports),
17531753 };
17541754 const gpa = mod.gpa;
1755 const ip = &mod.intern_pool;
17551756 // If the module does not already have the function, we ignore this function call
17561757 // because we call `updateExports` at the end of `updateFunc` and `updateDecl`.
17571758 const global_index = self.decl_map.get(decl_index) orelse return;
......@@ -1759,17 +1760,14 @@ pub const Object = struct {
17591760 const comp = mod.comp;
17601761 if (decl.isExtern(mod)) {
17611762 const decl_name = decl_name: {
1762 const decl_name = mod.intern_pool.stringToSlice(decl.name);
1763
17641763 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| {
17661765 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 });
17681767 }
17691768 }
17701769 }
1771
1772 break :decl_name try self.builder.strtabString(decl_name);
1770 break :decl_name try self.builder.strtabString(decl.name.toSlice(ip));
17731771 };
17741772
17751773 if (self.builder.getGlobal(decl_name)) |other_global| {
......@@ -1792,9 +1790,7 @@ pub const Object = struct {
17921790 if (decl_var.is_weak_linkage) global_index.setLinkage(.extern_weak, &self.builder);
17931791 }
17941792 } 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));
17981794 try global_index.rename(main_exp_name, &self.builder);
17991795
18001796 if (decl.val.getVariable(mod)) |decl_var| if (decl_var.is_threadlocal)
......@@ -1803,9 +1799,7 @@ pub const Object = struct {
18031799
18041800 return updateExportedGlobal(self, mod, global_index, exports);
18051801 } 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));
18091803 try global_index.rename(fqn, &self.builder);
18101804 global_index.setLinkage(.internal, &self.builder);
18111805 if (comp.config.dll_export_fns)
......@@ -1832,9 +1826,8 @@ pub const Object = struct {
18321826 exports: []const *Module.Export,
18331827 ) link.File.UpdateExportsError!void {
18341828 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));
18381831 const global_index = i: {
18391832 const gop = try o.anon_decl_map.getOrPut(gpa, exported_value);
18401833 if (gop.found_existing) {
......@@ -1845,7 +1838,7 @@ pub const Object = struct {
18451838 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
18461839 const variable_index = try o.builder.addVariable(
18471840 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))),
18491842 llvm_addr_space,
18501843 );
18511844 const global_index = variable_index.ptrConst(&o.builder).global;
......@@ -1867,8 +1860,9 @@ pub const Object = struct {
18671860 global_index: Builder.Global.Index,
18681861 exports: []const *Module.Export,
18691862 ) link.File.UpdateExportsError!void {
1870 global_index.setUnnamedAddr(.default, &o.builder);
18711863 const comp = mod.comp;
1864 const ip = &mod.intern_pool;
1865 global_index.setUnnamedAddr(.default, &o.builder);
18721866 if (comp.config.dll_export_fns)
18731867 global_index.setDllStorageClass(.dllexport, &o.builder);
18741868 global_index.setLinkage(switch (exports[0].opts.linkage) {
......@@ -1882,7 +1876,7 @@ pub const Object = struct {
18821876 .hidden => .hidden,
18831877 .protected => .protected,
18841878 }, &o.builder);
1885 if (mod.intern_pool.stringToSliceUnwrap(exports[0].opts.section)) |section|
1879 if (exports[0].opts.section.toSlice(ip)) |section|
18861880 switch (global_index.ptrConst(&o.builder).kind) {
18871881 .variable => |impl_index| impl_index.setSection(
18881882 try o.builder.string(section),
......@@ -1900,7 +1894,7 @@ pub const Object = struct {
19001894 // Until then we iterate over existing aliases and make them point
19011895 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
19021896 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));
19041898 if (o.builder.getGlobal(exp_name)) |global| {
19051899 switch (global.ptrConst(&o.builder).kind) {
19061900 .alias => |alias| {
......@@ -2013,7 +2007,7 @@ pub const Object = struct {
20132007 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
20142008
20152009 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)),
20172011 int_info.signedness == .unsigned,
20182012 int_info.bits,
20192013 bigint,
......@@ -2473,7 +2467,7 @@ pub const Object = struct {
24732467 offset = field_offset + field_size;
24742468
24752469 const field_name = if (tuple.names.len != 0)
2476 ip.stringToSlice(tuple.names.get(ip)[i])
2470 tuple.names.get(ip)[i].toSlice(ip)
24772471 else
24782472 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
24792473 defer if (tuple.names.len == 0) gpa.free(field_name);
......@@ -2557,10 +2551,10 @@ pub const Object = struct {
25572551 const field_offset = ty.structFieldOffset(field_index, mod);
25582552
25592553 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);
25612555
25622556 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2563 try o.builder.metadataString(ip.stringToSlice(field_name)),
2557 try o.builder.metadataString(field_name.toSlice(ip)),
25642558 .none, // File
25652559 debug_fwd_ref,
25662560 0, // Line
......@@ -2655,7 +2649,7 @@ pub const Object = struct {
26552649
26562650 const field_name = tag_type.names.get(ip)[field_index];
26572651 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2658 try o.builder.metadataString(ip.stringToSlice(field_name)),
2652 try o.builder.metadataString(field_name.toSlice(ip)),
26592653 .none, // File
26602654 debug_union_fwd_ref,
26612655 0, // Line
......@@ -2827,7 +2821,7 @@ pub const Object = struct {
28272821 const mod = o.module;
28282822 const decl = mod.declPtr(decl_index);
28292823 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
28312825 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
28322826 try o.namespaceToDebugScope(decl.src_namespace),
28332827 decl.src_line + 1,
......@@ -2844,11 +2838,11 @@ pub const Object = struct {
28442838 const std_mod = mod.std_mod;
28452839 const std_file = (mod.importPkg(std_mod) catch unreachable).file;
28462840
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);
28482842 const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);
28492843 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?;
28502844
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);
28522846 // buffer is only used for int_type, `builtin` is a struct.
28532847 const builtin_ty = mod.declPtr(builtin_decl).val.toType();
28542848 const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?;
......@@ -2892,10 +2886,10 @@ pub const Object = struct {
28922886 const is_extern = decl.isExtern(zcu);
28932887 const function_index = try o.builder.addFunction(
28942888 try o.lowerType(zig_fn_type),
2895 try o.builder.strtabString(ip.stringToSlice(if (is_extern)
2889 try o.builder.strtabString((if (is_extern)
28962890 decl.name
28972891 else
2898 try decl.fullyQualifiedName(zcu))),
2892 try decl.fullyQualifiedName(zcu)).toSlice(ip)),
28992893 toLlvmAddressSpace(decl.@"addrspace", target),
29002894 );
29012895 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
......@@ -2910,9 +2904,9 @@ pub const Object = struct {
29102904 if (target.isWasm()) {
29112905 try attributes.addFnAttr(.{ .string = .{
29122906 .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)),
29142908 } }, &o.builder);
2915 if (ip.stringToSliceUnwrap(decl.getOwnedExternFunc(zcu).?.lib_name)) |lib_name| {
2909 if (decl.getOwnedExternFunc(zcu).?.lib_name.toSlice(ip)) |lib_name| {
29162910 if (!std.mem.eql(u8, lib_name, "c")) try attributes.addFnAttr(.{ .string = .{
29172911 .kind = try o.builder.string("wasm-import-module"),
29182912 .value = try o.builder.string(lib_name),
......@@ -3108,9 +3102,10 @@ pub const Object = struct {
31083102 const is_extern = decl.isExtern(mod);
31093103
31103104 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)),
31143109 try o.lowerType(decl.typeOf(mod)),
31153110 toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
31163111 );
......@@ -3258,7 +3253,7 @@ pub const Object = struct {
32583253 };
32593254 },
32603255 .array_type => |array_type| o.builder.arrayType(
3261 array_type.len + @intFromBool(array_type.sentinel != .none),
3256 array_type.lenIncludingSentinel(),
32623257 try o.lowerType(Type.fromInterned(array_type.child)),
32633258 ),
32643259 .vector_type => |vector_type| o.builder.vectorType(
......@@ -3335,9 +3330,7 @@ pub const Object = struct {
33353330 return int_ty;
33363331 }
33373332
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);
33413334
33423335 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};
33433336 defer llvm_field_types.deinit(o.gpa);
......@@ -3402,7 +3395,7 @@ pub const Object = struct {
34023395 );
34033396 }
34043397
3405 const ty = try o.builder.opaqueType(name);
3398 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
34063399 try o.type_map.put(o.gpa, t.toIntern(), ty);
34073400
34083401 o.builder.namedTypeSetBody(
......@@ -3491,9 +3484,7 @@ pub const Object = struct {
34913484 return enum_tag_ty;
34923485 }
34933486
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);
34973488
34983489 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
34993490 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
......@@ -3513,7 +3504,7 @@ pub const Object = struct {
35133504 };
35143505
35153506 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)));
35173508 try o.type_map.put(o.gpa, t.toIntern(), ty);
35183509
35193510 o.builder.namedTypeSetBody(
......@@ -3541,7 +3532,7 @@ pub const Object = struct {
35413532 llvm_fields_len += 1;
35423533 }
35433534
3544 const ty = try o.builder.opaqueType(name);
3535 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
35453536 try o.type_map.put(o.gpa, t.toIntern(), ty);
35463537
35473538 o.builder.namedTypeSetBody(
......@@ -3554,8 +3545,8 @@ pub const Object = struct {
35543545 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
35553546 if (!gop.found_existing) {
35563547 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)));
35593550 }
35603551 return gop.value_ptr.*;
35613552 },
......@@ -3859,7 +3850,9 @@ pub const Object = struct {
38593850 },
38603851 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {
38613852 .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 )),
38633856 .elems => |elems| {
38643857 const array_ty = try o.lowerType(ty);
38653858 const elem_ty = array_ty.childType(&o.builder);
......@@ -3892,8 +3885,7 @@ pub const Object = struct {
38923885 },
38933886 .repeated_elem => |elem| {
38943887 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());
38973889 const array_ty = try o.lowerType(ty);
38983890 const elem_ty = array_ty.childType(&o.builder);
38993891
......@@ -3942,7 +3934,7 @@ pub const Object = struct {
39423934 defer allocator.free(vals);
39433935
39443936 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| {
39463938 result_val.* = try o.builder.intConst(.i8, byte);
39473939 },
39483940 .elems => |elems| for (vals, elems) |*result_val, elem| {
......@@ -4633,7 +4625,7 @@ pub const Object = struct {
46334625 defer wip_switch.finish(&wip);
46344626
46354627 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));
46374629 const name_init = try o.builder.stringConst(name);
46384630 const name_variable_index =
46394631 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
......@@ -4693,6 +4685,7 @@ pub const DeclGen = struct {
46934685 fn genDecl(dg: *DeclGen) !void {
46944686 const o = dg.object;
46954687 const zcu = o.module;
4688 const ip = &zcu.intern_pool;
46964689 const decl = dg.decl;
46974690 const decl_index = dg.decl_index;
46984691 assert(decl.has_tv);
......@@ -4705,7 +4698,7 @@ pub const DeclGen = struct {
47054698 decl.getAlignment(zcu).toLlvm(),
47064699 &o.builder,
47074700 );
4708 if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section|
4701 if (decl.@"linksection".toSlice(ip)) |section|
47094702 variable_index.setSection(try o.builder.string(section), &o.builder);
47104703 assert(decl.has_tv);
47114704 const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: {
......@@ -4728,7 +4721,7 @@ pub const DeclGen = struct {
47284721 const debug_file = try o.getDebugFile(namespace.file_scope);
47294722
47304723 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
47324725 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name
47334726 debug_file, // File
47344727 debug_file, // Scope
......@@ -5156,8 +5149,8 @@ pub const FuncGen = struct {
51565149
51575150 self.scope = try o.builder.debugSubprogram(
51585151 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)),
51615154 line_number,
51625155 line_number + func.lbrace_line,
51635156 try o.lowerDebugType(fn_ty),
src/codegen/spirv.zig+17-26
......@@ -1028,39 +1028,30 @@ const DeclGen = struct {
10281028 inline .array_type, .vector_type => |array_type, tag| {
10291029 const elem_ty = Type.fromInterned(array_type.child);
10301030
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)));
10321032 defer self.gpa.free(constituents);
10331033
10341034 switch (aggregate.storage) {
10351035 .bytes => |bytes| {
10361036 // TODO: This is really space inefficient, perhaps there is a better
10371037 // 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);
10401040 }
10411041 },
10421042 .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);
10451045 }
10461046 },
10471047 .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));
10521049 },
10531050 }
10541051
10551052 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),
10641055 else => unreachable,
10651056 }
10661057 },
......@@ -1683,9 +1674,9 @@ const DeclGen = struct {
16831674 }
16841675
16851676 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);
16871678 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));
16891680 }
16901681
16911682 const result_id = try self.spv.structType(member_types.items, member_names.items);
......@@ -2123,12 +2114,12 @@ const DeclGen = struct {
21232114 // Append the actual code into the functions section.
21242115 try self.spv.addFunction(spv_decl_index, self.func);
21252116
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));
21282119
21292120 // Temporarily generate a test kernel declaration if this is a test function.
21302121 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);
21322123 }
21332124 },
21342125 .global => {
......@@ -2152,8 +2143,8 @@ const DeclGen = struct {
21522143 .storage_class = final_storage_class,
21532144 });
21542145
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));
21572148 try self.spv.declareDeclDeps(spv_decl_index, &.{});
21582149 },
21592150 .invocation_global => {
......@@ -2197,8 +2188,8 @@ const DeclGen = struct {
21972188 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});
21982189 try self.spv.addFunction(spv_decl_index, self.func);
21992190
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)});
22022193
22032194 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{
22042195 .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
11761176 gop.value_ptr.* = .{};
11771177 }
11781178 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);
11801180 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 });
11821182 defer gpa.free(sym_name);
11831183 const ty = val.typeOf(mod);
11841184 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(
12571257 if (decl.isExtern(mod)) {
12581258 // TODO make this part of getGlobalSymbol
12591259 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);
12621262 const global_index = try self.getGlobalSymbol(name, lib_name);
12631263 try self.need_got_table.put(gpa, global_index, {});
12641264 return;
......@@ -1425,9 +1425,9 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
14251425 const mod = self.base.comp.module.?;
14261426 const decl = mod.declPtr(decl_index);
14271427
1428 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));
1428 const decl_name = try decl.fullyQualifiedName(mod);
14291429
1430 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });
1430 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
14311431 const required_alignment: u32 = @intCast(decl.getAlignment(mod).toByteUnits() orelse 0);
14321432
14331433 const decl_metadata = self.decls.get(decl_index).?;
......@@ -1439,7 +1439,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
14391439
14401440 if (atom.size != 0) {
14411441 const sym = atom.getSymbolPtr(self);
1442 try self.setSymbolName(sym, decl_name);
1442 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
14431443 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
14441444 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14451445
......@@ -1447,7 +1447,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
14471447 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);
14481448 if (need_realloc) {
14491449 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 });
14511451 log.debug(" (required alignment 0x{x}", .{required_alignment});
14521452
14531453 if (vaddr != sym.value) {
......@@ -1463,13 +1463,13 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
14631463 self.getAtomPtr(atom_index).size = code_len;
14641464 } else {
14651465 const sym = atom.getSymbolPtr(self);
1466 try self.setSymbolName(sym, decl_name);
1466 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
14671467 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
14681468 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14691469
14701470 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
14711471 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 });
14731473 self.getAtomPtr(atom_index).size = code_len;
14741474 sym.value = vaddr;
14751475
......@@ -1534,20 +1534,18 @@ pub fn updateExports(
15341534 else => std.builtin.CallingConvention.C,
15351535 };
15361536 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) {
15401538 mod.stage1_flags.have_c_main = true;
15411539 } 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)) {
15431541 mod.stage1_flags.have_winmain = true;
1544 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMain")) {
1542 } else if (exp.opts.name.eqlSlice("wWinMain", ip)) {
15451543 mod.stage1_flags.have_wwinmain = true;
1546 } else if (ip.stringEqlSlice(exp.opts.name, "WinMainCRTStartup")) {
1544 } else if (exp.opts.name.eqlSlice("WinMainCRTStartup", ip)) {
15471545 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)) {
15491547 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)) {
15511549 mod.stage1_flags.have_dllmain_crt_startup = true;
15521550 }
15531551 }
......@@ -1585,7 +1583,7 @@ pub fn updateExports(
15851583 for (exports) |exp| {
15861584 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});
15871585
1588 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section_name| {
1586 if (exp.opts.section.toSlice(&mod.intern_pool)) |section_name| {
15891587 if (!mem.eql(u8, section_name, ".text")) {
15901588 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
15911589 gpa,
......@@ -1607,7 +1605,7 @@ pub fn updateExports(
16071605 continue;
16081606 }
16091607
1610 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
1608 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
16111609 const sym_index = metadata.getExport(self, exp_name) orelse blk: {
16121610 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {
16131611 const global = self.globals.items[global_index];
......@@ -1646,18 +1644,18 @@ pub fn updateExports(
16461644pub fn deleteDeclExport(
16471645 self: *Coff,
16481646 decl_index: InternPool.DeclIndex,
1649 name_ip: InternPool.NullTerminatedString,
1647 name: InternPool.NullTerminatedString,
16501648) void {
16511649 if (self.llvm_object) |_| return;
16521650 const metadata = self.decls.getPtr(decl_index) orelse return;
16531651 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;
16561654
16571655 const gpa = self.base.comp.gpa;
16581656 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };
16591657 const sym = self.getSymbolPtr(sym_loc);
1660 log.debug("deleting export '{s}'", .{name});
1658 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
16611659 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);
16621660 sym.* = .{
16631661 .name = [_]u8{0} ** 8,
......@@ -1669,7 +1667,7 @@ pub fn deleteDeclExport(
16691667 };
16701668 self.locals_free_list.append(gpa, sym_index.*) catch {};
16711669
1672 if (self.resolver.fetchRemove(name)) |entry| {
1670 if (self.resolver.fetchRemove(name_slice)) |entry| {
16731671 defer gpa.free(entry.key);
16741672 self.globals_free_list.append(gpa, entry.value) catch {};
16751673 self.globals.items[entry.value] = .{
src/link/Dwarf.zig+17-20
......@@ -339,15 +339,14 @@ pub const DeclState = struct {
339339 struct_type.field_names.get(ip),
340340 struct_type.field_types.get(ip),
341341 struct_type.offsets.get(ip),
342 ) |field_name_ip, field_ty, field_off| {
342 ) |field_name, field_ty, field_off| {
343343 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);
345345 // DW.AT.member
346 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2);
346 try dbg_info_buffer.ensureUnusedCapacity(field_name_slice.len + 2);
347347 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.struct_member));
348348 // 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]);
351350 // DW.AT.type, DW.FORM.ref4
352351 const index = dbg_info_buffer.items.len;
353352 try dbg_info_buffer.appendNTimes(0, 4);
......@@ -374,14 +373,13 @@ pub const DeclState = struct {
374373 try dbg_info_buffer.append(0);
375374
376375 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);
379378 // 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));
381380 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));
382381 // 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]);
385383 // DW.AT.const_value, DW.FORM.data8
386384 const value: u64 = value: {
387385 if (enum_type.values.len == 0) break :value field_i; // auto-numbered
......@@ -443,11 +441,11 @@ pub const DeclState = struct {
443441
444442 for (union_obj.field_types.get(ip), union_obj.loadTagType(ip).names.get(ip)) |field_ty, field_name| {
445443 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
444 const field_name_slice = field_name.toSlice(ip);
446445 // DW.AT.member
447446 try dbg_info_buffer.append(@intFromEnum(AbbrevCode.struct_member));
448447 // 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]);
451449 // DW.AT.type, DW.FORM.ref4
452450 const index = dbg_info_buffer.items.len;
453451 try dbg_info_buffer.appendNTimes(0, 4);
......@@ -1155,8 +1153,8 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
11551153 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
11561154
11571155 // .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);
11601158 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
11611159 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
11621160
......@@ -2866,15 +2864,14 @@ fn addDbgInfoErrorSetNames(
28662864 // DW.AT.const_value, DW.FORM.data8
28672865 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), 0, target_endian);
28682866
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);
28722870 // 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));
28742872 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));
28752873 // 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]);
28782875 // DW.AT.const_value, DW.FORM.data8
28792876 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), int, target_endian);
28802877 }
src/link/Elf.zig+21-8
......@@ -1517,7 +1517,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
15171517
15181518 if (self.base.isStatic()) {
15191519 try argv.append("-static");
1520 } else if (self.base.isDynLib()) {
1520 } else if (self.isEffectivelyDynLib()) {
15211521 try argv.append("-shared");
15221522 }
15231523
......@@ -1997,7 +1997,7 @@ fn markImportsExports(self: *Elf) void {
19971997 }
19981998 if (file_ptr.index() == file_index) {
19991999 global.flags.@"export" = true;
2000 if (elf_file.base.isDynLib() and vis != .PROTECTED) {
2000 if (elf_file.isEffectivelyDynLib() and vis != .PROTECTED) {
20012001 global.flags.import = true;
20022002 }
20032003 }
......@@ -2005,7 +2005,7 @@ fn markImportsExports(self: *Elf) void {
20052005 }
20062006 }.mark;
20072007
2008 if (!self.base.isDynLib()) {
2008 if (!self.isEffectivelyDynLib()) {
20092009 for (self.shared_objects.items) |index| {
20102010 for (self.file(index).?.globals()) |global_index| {
20112011 const global = self.symbol(global_index);
......@@ -2469,7 +2469,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
24692469 } else {
24702470 try argv.append("-static");
24712471 }
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 }) {
24732476 try argv.append("-shared");
24742477 }
24752478
......@@ -2925,7 +2928,7 @@ pub fn writeElfHeader(self: *Elf) !void {
29252928 const output_mode = comp.config.output_mode;
29262929 const link_mode = comp.config.link_mode;
29272930 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,
29292932 .Obj => .REL,
29302933 .Lib => switch (link_mode) {
29312934 .static => @as(elf.ET, .REL),
......@@ -3114,7 +3117,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
31143117 }
31153118 }
31163119
3117 if (self.getTarget().cpu.arch == .riscv64 and self.base.isDynLib()) {
3120 if (self.getTarget().cpu.arch == .riscv64 and self.isEffectivelyDynLib()) {
31183121 self.global_pointer_index = try linker_defined.addGlobal("__global_pointer$", self);
31193122 }
31203123
......@@ -3420,7 +3423,7 @@ fn initSyntheticSections(self: *Elf) !void {
34203423 });
34213424 }
34223425
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) {
34243427 self.dynstrtab_section_index = try self.addSection(.{
34253428 .name = ".dynstr",
34263429 .flags = elf.SHF_ALLOC,
......@@ -3657,7 +3660,7 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void {
36573660 try self.dynamic.addNeeded(shared_object, self);
36583661 }
36593662
3660 if (self.base.isDynLib()) {
3663 if (self.isEffectivelyDynLib()) {
36613664 if (self.soname) |soname| {
36623665 try self.dynamic.setSoname(soname, self);
36633666 }
......@@ -5246,6 +5249,16 @@ const CsuObjects = struct {
52465249 }
52475250};
52485251
5252/// If a target compiles other output modes as dynamic libraries,
5253/// this function returns true for those too.
5254pub 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
52495262pub fn isZigSection(self: Elf, shndx: u32) bool {
52505263 inline for (&[_]?u32{
52515264 self.zig_text_section_index,
src/link/Elf/Atom.zig+2-2
......@@ -1054,7 +1054,7 @@ const x86_64 = struct {
10541054 it: *RelocsIterator,
10551055 ) !void {
10561056 const is_static = elf_file.base.isStatic();
1057 const is_dyn_lib = elf_file.base.isDynLib();
1057 const is_dyn_lib = elf_file.isEffectivelyDynLib();
10581058
10591059 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
10601060 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
......@@ -1599,7 +1599,7 @@ const aarch64 = struct {
15991599 _ = it;
16001600
16011601 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();
16031603
16041604 switch (r_type) {
16051605 .ABS64 => {
src/link/Elf/Object.zig+1-1
......@@ -568,7 +568,7 @@ pub fn claimUnresolved(self: *Object, elf_file: *Elf) void {
568568 }
569569
570570 const is_import = blk: {
571 if (!elf_file.base.isDynLib()) break :blk false;
571 if (!elf_file.isEffectivelyDynLib()) break :blk false;
572572 const vis = @as(elf.STV, @enumFromInt(esym.st_other));
573573 if (vis == .HIDDEN) break :blk false;
574574 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
105105 return symbol.pltAddress(elf_file);
106106 }
107107 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 }
108131 return atom_ptr.address(elf_file) + symbol.value;
109132 }
110133 return symbol.value;
......@@ -432,6 +455,7 @@ pub const Index = u32;
432455
433456const assert = std.debug.assert;
434457const elf = std.elf;
458const mem = std.mem;
435459const std = @import("std");
436460const synthetic_sections = @import("synthetic_sections.zig");
437461
src/link/Elf/ZigObject.zig+17-17
......@@ -367,7 +367,7 @@ pub fn claimUnresolved(self: ZigObject, elf_file: *Elf) void {
367367 }
368368
369369 const is_import = blk: {
370 if (!elf_file.base.isDynLib()) break :blk false;
370 if (!elf_file.isEffectivelyDynLib()) break :blk false;
371371 const vis = @as(elf.STV, @enumFromInt(esym.st_other));
372372 if (vis == .HIDDEN) break :blk false;
373373 break :blk true;
......@@ -902,9 +902,9 @@ fn updateDeclCode(
902902 const gpa = elf_file.base.comp.gpa;
903903 const mod = elf_file.base.comp.module.?;
904904 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);
906906
907 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });
907 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
908908
909909 const required_alignment = decl.getAlignment(mod);
910910
......@@ -915,7 +915,7 @@ fn updateDeclCode(
915915 sym.output_section_index = shdr_index;
916916 atom_ptr.output_section_index = shdr_index;
917917
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));
919919 atom_ptr.flags.alive = true;
920920 atom_ptr.name_offset = sym.name_offset;
921921 esym.st_name = sym.name_offset;
......@@ -932,7 +932,7 @@ fn updateDeclCode(
932932 const need_realloc = code.len > capacity or !required_alignment.check(atom_ptr.value);
933933 if (need_realloc) {
934934 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 });
936936 if (old_vaddr != atom_ptr.value) {
937937 sym.value = 0;
938938 esym.st_value = 0;
......@@ -1000,9 +1000,9 @@ fn updateTlv(
10001000 const gpa = elf_file.base.comp.gpa;
10011001 const mod = elf_file.base.comp.module.?;
10021002 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);
10041004
1005 log.debug("updateTlv {s} ({*})", .{ decl_name, decl });
1005 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
10061006
10071007 const required_alignment = decl.getAlignment(mod);
10081008
......@@ -1014,7 +1014,7 @@ fn updateTlv(
10141014 sym.output_section_index = shndx;
10151015 atom_ptr.output_section_index = shndx;
10161016
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));
10181018 atom_ptr.flags.alive = true;
10191019 atom_ptr.name_offset = sym.name_offset;
10201020 esym.st_value = 0;
......@@ -1136,8 +1136,8 @@ pub fn updateDecl(
11361136 if (decl.isExtern(mod)) {
11371137 // Extern variable gets a .got entry only.
11381138 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);
11411141 const esym_index = try self.getGlobalSymbol(elf_file, name, lib_name);
11421142 elf_file.symbol(self.symbol(esym_index)).flags.needs_got = true;
11431143 return;
......@@ -1293,9 +1293,9 @@ pub fn lowerUnnamedConst(
12931293 }
12941294 const unnamed_consts = gop.value_ptr;
12951295 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);
12971297 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 });
12991299 defer gpa.free(name);
13001300 const ty = val.typeOf(mod);
13011301 const sym_index = switch (try self.lowerConst(
......@@ -1418,7 +1418,7 @@ pub fn updateExports(
14181418
14191419 for (exports) |exp| {
14201420 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)) {
14221422 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
14231423 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
14241424 gpa,
......@@ -1445,7 +1445,7 @@ pub fn updateExports(
14451445 },
14461446 };
14471447 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);
14491449 const name_off = try self.strtab.insert(gpa, exp_name);
14501450 const global_esym_index = if (metadata.@"export"(self, exp_name)) |exp_index|
14511451 exp_index.*
......@@ -1476,9 +1476,9 @@ pub fn updateDeclLineNumber(
14761476 defer tracy.end();
14771477
14781478 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);
14801480
1481 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });
1481 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
14821482
14831483 if (self.dwarf) |*dw| {
14841484 try dw.updateDeclLineNumber(mod, decl_index);
......@@ -1493,7 +1493,7 @@ pub fn deleteDeclExport(
14931493) void {
14941494 const metadata = self.decls.getPtr(decl_index) orelse return;
14951495 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);
14971497 const esym_index = metadata.@"export"(self, exp_name) orelse return;
14981498 log.debug("deleting export '{s}'", .{exp_name});
14991499 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 {
8989 if (elf_file.verneed_section_index != null) nentries += 2; // VERNEED
9090 if (dt.getFlags(elf_file) != null) nentries += 1; // FLAGS
9191 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
9393 nentries += 1; // NULL
9494 return nentries * @sizeOf(elf.Elf64_Dyn);
9595 }
......@@ -216,7 +216,7 @@ pub const DynamicSection = struct {
216216 }
217217
218218 // 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 });
220220
221221 // NULL
222222 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_NULL, .d_val = 0 });
......@@ -256,7 +256,7 @@ pub const ZigGotSection = struct {
256256 entry.* = sym_index;
257257 const symbol = elf_file.symbol(sym_index);
258258 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)) {
260260 zig_got.flags.needs_rela = true;
261261 }
262262 if (symbol.extra(elf_file)) |extra| {
......@@ -495,7 +495,7 @@ pub const GotSection = struct {
495495 const symbol = elf_file.symbol(sym_index);
496496 symbol.flags.has_got = true;
497497 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)))
499499 {
500500 got.flags.needs_rela = true;
501501 }
......@@ -528,7 +528,7 @@ pub const GotSection = struct {
528528 entry.symbol_index = sym_index;
529529 const symbol = elf_file.symbol(sym_index);
530530 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;
532532 if (symbol.extra(elf_file)) |extra| {
533533 var new_extra = extra;
534534 new_extra.tlsgd = index;
......@@ -545,7 +545,7 @@ pub const GotSection = struct {
545545 entry.symbol_index = sym_index;
546546 const symbol = elf_file.symbol(sym_index);
547547 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;
549549 if (symbol.extra(elf_file)) |extra| {
550550 var new_extra = extra;
551551 new_extra.gottp = index;
......@@ -580,7 +580,7 @@ pub const GotSection = struct {
580580
581581 pub fn write(got: GotSection, elf_file: *Elf, writer: anytype) !void {
582582 const comp = elf_file.base.comp;
583 const is_dyn_lib = elf_file.base.isDynLib();
583 const is_dyn_lib = elf_file.isEffectivelyDynLib();
584584 const apply_relocs = true; // TODO add user option for this
585585
586586 for (got.entries.items) |entry| {
......@@ -595,7 +595,7 @@ pub const GotSection = struct {
595595 if (symbol.?.flags.import) break :blk 0;
596596 if (symbol.?.isIFunc(elf_file))
597597 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
599599 !symbol.?.isAbs(elf_file))
600600 {
601601 break :blk if (apply_relocs) value else 0;
......@@ -653,7 +653,7 @@ pub const GotSection = struct {
653653 pub fn addRela(got: GotSection, elf_file: *Elf) !void {
654654 const comp = elf_file.base.comp;
655655 const gpa = comp.gpa;
656 const is_dyn_lib = elf_file.base.isDynLib();
656 const is_dyn_lib = elf_file.isEffectivelyDynLib();
657657 const cpu_arch = elf_file.getTarget().cpu.arch;
658658 try elf_file.rela_dyn.ensureUnusedCapacity(gpa, got.numRela(elf_file));
659659
......@@ -683,7 +683,7 @@ pub const GotSection = struct {
683683 });
684684 continue;
685685 }
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
687687 !symbol.?.isAbs(elf_file))
688688 {
689689 elf_file.addRelaDynAssumeCapacity(.{
......@@ -758,7 +758,7 @@ pub const GotSection = struct {
758758
759759 pub fn numRela(got: GotSection, elf_file: *Elf) usize {
760760 const comp = elf_file.base.comp;
761 const is_dyn_lib = elf_file.base.isDynLib();
761 const is_dyn_lib = elf_file.isEffectivelyDynLib();
762762 var num: usize = 0;
763763 for (got.entries.items) |entry| {
764764 const symbol = switch (entry.tag) {
......@@ -767,7 +767,7 @@ pub const GotSection = struct {
767767 };
768768 switch (entry.tag) {
769769 .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
771771 !symbol.?.isAbs(elf_file)))
772772 {
773773 num += 1;
src/link/MachO/ZigObject.zig+19-19
......@@ -716,8 +716,8 @@ pub fn updateDecl(
716716 if (decl.isExtern(mod)) {
717717 // Extern variable gets a __got entry only
718718 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);
721721 const index = try self.getGlobalSymbol(macho_file, name, lib_name);
722722 const actual_index = self.symbols.items[index];
723723 macho_file.getSymbol(actual_index).flags.needs_got = true;
......@@ -786,9 +786,9 @@ fn updateDeclCode(
786786 const gpa = macho_file.base.comp.gpa;
787787 const mod = macho_file.base.comp.module.?;
788788 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);
790790
791 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });
791 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
792792
793793 const required_alignment = decl.getAlignment(mod);
794794
......@@ -800,7 +800,7 @@ fn updateDeclCode(
800800 sym.out_n_sect = sect_index;
801801 atom.out_n_sect = sect_index;
802802
803 sym.name = try self.strtab.insert(gpa, decl_name);
803 sym.name = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
804804 atom.flags.alive = true;
805805 atom.name = sym.name;
806806 nlist.n_strx = sym.name;
......@@ -819,7 +819,7 @@ fn updateDeclCode(
819819
820820 if (need_realloc) {
821821 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 });
823823 if (old_vaddr != atom.value) {
824824 sym.value = 0;
825825 nlist.n_value = 0;
......@@ -870,23 +870,24 @@ fn updateTlv(
870870) !void {
871871 const mod = macho_file.base.comp.module.?;
872872 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);
874874
875 log.debug("updateTlv {s} ({*})", .{ decl_name, decl });
875 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
876876
877 const decl_name_slice = decl_name.toSlice(&mod.intern_pool);
877878 const required_alignment = decl.getAlignment(mod);
878879
879880 // 1. Lower TLV initializer
880881 const init_sym_index = try self.createTlvInitializer(
881882 macho_file,
882 decl_name,
883 decl_name_slice,
883884 required_alignment,
884885 sect_index,
885886 code,
886887 );
887888
888889 // 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);
890891}
891892
892893fn createTlvInitializer(
......@@ -1073,9 +1074,9 @@ pub fn lowerUnnamedConst(
10731074 }
10741075 const unnamed_consts = gop.value_ptr;
10751076 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);
10771078 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 });
10791080 defer gpa.free(name);
10801081 const sym_index = switch (try self.lowerConst(
10811082 macho_file,
......@@ -1199,7 +1200,7 @@ pub fn updateExports(
11991200
12001201 for (exports) |exp| {
12011202 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)) {
12031204 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
12041205 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
12051206 gpa,
......@@ -1220,7 +1221,7 @@ pub fn updateExports(
12201221 continue;
12211222 }
12221223
1223 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
1224 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
12241225 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|
12251226 exp_index.*
12261227 else blk: {
......@@ -1349,13 +1350,12 @@ pub fn deleteDeclExport(
13491350 decl_index: InternPool.DeclIndex,
13501351 name: InternPool.NullTerminatedString,
13511352) void {
1352 const metadata = self.decls.getPtr(decl_index) orelse return;
1353
13541353 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;
13571354
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)});
13591359
13601360 const nlist = &self.symtab.items(.nlist)[nlist_index.*];
13611361 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
477477 }
478478 const unnamed_consts = gop.value_ptr;
479479
480 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));
480 const decl_name = try decl.fullyQualifiedName(mod);
481481
482482 const index = unnamed_consts.items.len;
483483 // 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 });
485485
486486 const sym_index = try self.allocateSymbolIndex();
487487 const new_atom_idx = try self.createAtom();
......@@ -529,7 +529,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
529529 const decl = mod.declPtr(decl_index);
530530
531531 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)});
533533 return;
534534 }
535535 const atom_idx = try self.seeDecl(decl_index);
......@@ -573,7 +573,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
573573 const sym: aout.Sym = .{
574574 .value = undefined, // the value of stuff gets filled in in flushModule
575575 .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)),
577577 };
578578
579579 if (atom.sym_index) |s| {
......@@ -1013,10 +1013,12 @@ fn addDeclExports(
10131013 const atom = self.getAtom(metadata.index);
10141014
10151015 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);
10171017 // plan9 does not support custom sections
10181018 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 {
10201022 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
10211023 gpa,
10221024 mod.declPtr(decl_index).srcLoc(mod),
......@@ -1129,19 +1131,21 @@ pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index {
11291131 // handle externs here because they might not get updateDecl called on them
11301132 const mod = self.base.comp.module.?;
11311133 const decl = mod.declPtr(decl_index);
1132 const name = mod.intern_pool.stringToSlice(decl.name);
11331134 if (decl.isExtern(mod)) {
11341135 // 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)) {
11361137 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)) {
11381139 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)) {
11401141 self.etext_edata_end_atom_indices[2] = atom_idx;
11411142 }
11421143 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)});
11451149 return atom_idx;
11461150}
11471151
......@@ -1393,7 +1397,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
13931397 const sym = self.syms.items[atom.sym_index.?];
13941398 try self.writeSym(writer, sym);
13951399 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| {
13971401 try self.writeSym(writer, self.syms.items[exp_i]);
13981402 };
13991403 }
......@@ -1440,7 +1444,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
14401444 const sym = self.syms.items[atom.sym_index.?];
14411445 try self.writeSym(writer, sym);
14421446 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| {
14441448 const s = self.syms.items[exp_i];
14451449 if (mem.eql(u8, s.name, "_start"))
14461450 self.entry_val = s.value;
......@@ -1483,25 +1487,25 @@ pub fn getDeclVAddr(
14831487 reloc_info: link.File.RelocInfo,
14841488) !u64 {
14851489 const mod = self.base.comp.module.?;
1490 const ip = &mod.intern_pool;
14861491 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)});
14881493 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)) {
14911495 try self.addReloc(reloc_info.parent_atom_index, .{
14921496 .target = undefined,
14931497 .offset = reloc_info.offset,
14941498 .addend = reloc_info.addend,
14951499 .type = .special_etext,
14961500 });
1497 } else if (std.mem.eql(u8, extern_name, "edata")) {
1501 } else if (decl.name.eqlSlice("edata", ip)) {
14981502 try self.addReloc(reloc_info.parent_atom_index, .{
14991503 .target = undefined,
15001504 .offset = reloc_info.offset,
15011505 .addend = reloc_info.addend,
15021506 .type = .special_edata,
15031507 });
1504 } else if (std.mem.eql(u8, extern_name, "end")) {
1508 } else if (decl.name.eqlSlice("end", ip)) {
15051509 try self.addReloc(reloc_info.parent_atom_index, .{
15061510 .target = undefined,
15071511 .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
130130
131131 const func = module.funcInfo(func_index);
132132 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)});
134134
135135 try self.object.updateFunc(module, func_index, air, liveness);
136136}
......@@ -141,7 +141,7 @@ pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclInde
141141 }
142142
143143 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)});
145145
146146 try self.object.updateDecl(module, decl_index);
147147}
......@@ -178,7 +178,7 @@ pub fn updateExports(
178178 for (exports) |exp| {
179179 try self.object.spv.declareEntryPoint(
180180 spv_decl_index,
181 mod.intern_pool.stringToSlice(exp.opts.name),
181 exp.opts.name.toSlice(&mod.intern_pool),
182182 execution_model,
183183 );
184184 }
......@@ -227,14 +227,13 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
227227
228228 try error_info.appendSlice("zig_errors");
229229 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| {
232231 // Errors can contain pretty much any character - to encode them in a string we must escape
233232 // them somehow. Easiest here is to use some established scheme, one which also preseves the
234233 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
235234 // We're using : as separator, which is a reserved character.
236235
237 const escaped_name = try std.Uri.escapeString(gpa, name);
236 const escaped_name = try std.Uri.escapeString(gpa, name.toSlice(&mod.intern_pool));
238237 defer gpa.free(escaped_name);
239238 try error_info.writer().print(":{s}", .{escaped_name});
240239 }
src/link/Wasm/ZigObject.zig+22-26
......@@ -258,8 +258,8 @@ pub fn updateDecl(
258258
259259 if (decl.isExtern(mod)) {
260260 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);
263263 return zig_object.addOrUpdateImport(wasm_file, name, atom.sym_index, lib_name, null);
264264 }
265265 const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
......@@ -341,8 +341,8 @@ fn finishUpdateDecl(
341341 const atom_index = decl_info.atom;
342342 const atom = wasm_file.getAtomPtr(atom_index);
343343 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));
346346 try atom.code.appendSlice(gpa, code);
347347 atom.size = @intCast(code.len);
348348
......@@ -382,7 +382,7 @@ fn finishUpdateDecl(
382382 // Will be freed upon freeing of decl or after cleanup of Wasm binary.
383383 const full_segment_name = try std.mem.concat(gpa, u8, &.{
384384 segment_name,
385 full_name,
385 full_name.toSlice(&mod.intern_pool),
386386 });
387387 errdefer gpa.free(full_segment_name);
388388 sym.tag = .data;
......@@ -427,9 +427,9 @@ pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_ind
427427 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
428428 const mod = wasm_file.base.comp.module.?;
429429 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);
431431 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));
433433 }
434434 return gop.value_ptr.atom;
435435}
......@@ -478,9 +478,9 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
478478 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
479479 const parent_atom = wasm_file.getAtom(parent_atom_index);
480480 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,
484484 });
485485 defer gpa.free(name);
486486
......@@ -623,11 +623,11 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {
623623 // Addend for each relocation to the table
624624 var addend: u32 = 0;
625625 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| {
627627 const atom = wasm_file.getAtomPtr(atom_index);
628628
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
631631
632632 const slice_ty = Type.slice_const_u8_sentinel_0;
633633 const offset = @as(u32, @intCast(atom.code.items.len));
......@@ -646,10 +646,9 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {
646646
647647 // as we updated the error name table, we now store the actual name within the names atom
648648 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]);
651650
652 log.debug("Populated error name: '{s}'", .{error_name});
651 log.debug("Populated error name: '{}'", .{error_name.fmt(&mod.intern_pool)});
653652 }
654653 names_atom.size = addend;
655654 zig_object.error_names_atom = names_atom_index;
......@@ -833,8 +832,7 @@ pub fn deleteDeclExport(
833832) void {
834833 const mod = wasm_file.base.comp.module.?;
835834 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| {
838836 const sym = zig_object.symbol(sym_index);
839837 decl_info.deleteExport(sym_index);
840838 std.debug.assert(zig_object.global_syms.remove(sym.name));
......@@ -864,10 +862,10 @@ pub fn updateExports(
864862 const atom = wasm_file.getAtom(atom_index);
865863 const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*;
866864 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)});
868866
869867 for (exports) |exp| {
870 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section| {
868 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
871869 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
872870 gpa,
873871 decl.srcLoc(mod),
......@@ -877,10 +875,8 @@ pub fn updateExports(
877875 continue;
878876 }
879877
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: {
884880 const sym_index = try zig_object.allocateSymbol(gpa);
885881 try decl_info.appendExport(gpa, sym_index);
886882 break :index sym_index;
......@@ -1089,9 +1085,9 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde
10891085pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void {
10901086 if (zig_object.dwarf) |*dw| {
10911087 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);
10931089
1094 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });
1090 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
10951091 try dw.updateDeclLineNumber(mod, decl_index);
10961092 }
10971093}
src/mutable_value.zig+6-6
......@@ -73,7 +73,7 @@ pub const MutableValue = union(enum) {
7373 } }),
7474 .bytes => |b| try ip.get(gpa, .{ .aggregate = .{
7575 .ty = b.ty,
76 .storage = .{ .bytes = b.data },
76 .storage = .{ .bytes = try ip.getOrPutString(gpa, b.data, .maybe_embedded_nulls) },
7777 } }),
7878 .aggregate => |a| {
7979 const elems = try arena.alloc(InternPool.Index, a.elems.len);
......@@ -158,18 +158,18 @@ pub const MutableValue = union(enum) {
158158 },
159159 .aggregate => |agg| switch (agg.storage) {
160160 .bytes => |bytes| {
161 assert(bytes.len == ip.aggregateTypeLenIncludingSentinel(agg.ty));
161 const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(agg.ty));
162162 assert(ip.childType(agg.ty) == .u8_type);
163163 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));
166166 mv.* = .{ .bytes = .{
167167 .ty = agg.ty,
168168 .data = arena_bytes,
169169 } };
170170 } 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| {
173173 mut_elem.* = .{ .interned = try ip.get(gpa, .{ .int = .{
174174 .ty = .u8_type,
175175 .storage = .{ .u64 = b },
src/print_value.zig+29-20
......@@ -204,26 +204,35 @@ fn printAggregate(
204204 try writer.writeAll(" }");
205205 return;
206206 },
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 }
227236 },
228237 .Vector => if (ty.arrayLen(zcu) == 0) {
229238 if (is_ref) try writer.writeByte('&');
src/target.zig+9-4
......@@ -59,10 +59,15 @@ pub fn alwaysSingleThreaded(target: std.Target) bool {
5959}
6060
6161pub 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;
6671}
6772
6873/// Valgrind supports more, but Zig does not support them yet.
src/type.zig+7-15
......@@ -490,18 +490,10 @@ pub const Type = struct {
490490 };
491491 },
492492 .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),
505497 .opt_type => |child| {
506498 const child_ty = Type.fromInterned(child);
507499 if (child_ty.isNoReturn(mod)) {
......@@ -1240,7 +1232,7 @@ pub const Type = struct {
12401232 .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
12411233
12421234 .array_type => |array_type| {
1243 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
1235 const len = array_type.lenIncludingSentinel();
12441236 if (len == 0) return .{ .scalar = 0 };
12451237 switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) {
12461238 .scalar => |elem_size| return .{ .scalar = len * elem_size },
......@@ -1577,7 +1569,7 @@ pub const Type = struct {
15771569 .anyframe_type => return target.ptrBitWidth(),
15781570
15791571 .array_type => |array_type| {
1580 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
1572 const len = array_type.lenIncludingSentinel();
15811573 if (len == 0) return 0;
15821574 const elem_ty = Type.fromInterned(array_type.child);
15831575 const elem_size = @max(
......@@ -1731,7 +1723,7 @@ pub const Type = struct {
17311723 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),
17321724 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),
17331725 .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;
17351727 return Type.fromInterned(array_type.child).layoutIsResolved(mod);
17361728 },
17371729 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ