authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-15 18:23:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-15 18:23:47-04:00
logd5648d264031f21413824ec5fc90b4ba6e463355
tree983f5bfd5d6fa93c4a39cd04658b4dbe37e24750
parent378d3e44034e817093966ea42c2940d6a0482dd8
signature Commit is signed but in an unrecognized format.

remove implicit cast from T to *const T

closes #1465

29 files changed, 112 insertions(+), 270 deletions(-)

build.zig+1-1
...@@ -121,7 +121,7 @@ pub fn build(b: *Builder) !void {...@@ -121,7 +121,7 @@ pub fn build(b: *Builder) !void {
121 test_step.dependOn(docs_step);121 test_step.dependOn(docs_step);
122}122}
123123
124fn dependOnLib(lib_exe_obj: var, dep: *const LibraryDep) void {124fn dependOnLib(lib_exe_obj: var, dep: LibraryDep) void {
125 for (dep.libdirs.toSliceConst()) |lib_dir| {125 for (dep.libdirs.toSliceConst()) |lib_dir| {
126 lib_exe_obj.addLibPath(lib_dir);126 lib_exe_obj.addLibPath(lib_dir);
127 }127 }
doc/docgen.zig+3-3
...@@ -191,7 +191,7 @@ const Tokenizer = struct.{...@@ -191,7 +191,7 @@ const Tokenizer = struct.{
191 line_end: usize,191 line_end: usize,
192 };192 };
193193
194 fn getTokenLocation(self: *Tokenizer, token: *const Token) Location {194 fn getTokenLocation(self: *Tokenizer, token: Token) Location {
195 var loc = Location.{195 var loc = Location.{
196 .line = 0,196 .line = 0,
197 .column = 0,197 .column = 0,
...@@ -216,7 +216,7 @@ const Tokenizer = struct.{...@@ -216,7 +216,7 @@ const Tokenizer = struct.{
216 }216 }
217};217};
218218
219fn parseError(tokenizer: *Tokenizer, token: *const Token, comptime fmt: []const u8, args: ...) error {219fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: ...) error {
220 const loc = tokenizer.getTokenLocation(token);220 const loc = tokenizer.getTokenLocation(token);
221 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);221 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
222 if (loc.line_start <= loc.line_end) {222 if (loc.line_start <= loc.line_end) {
...@@ -239,7 +239,7 @@ fn parseError(tokenizer: *Tokenizer, token: *const Token, comptime fmt: []const...@@ -239,7 +239,7 @@ fn parseError(tokenizer: *Tokenizer, token: *const Token, comptime fmt: []const
239 return error.ParseError;239 return error.ParseError;
240}240}
241241
242fn assertToken(tokenizer: *Tokenizer, token: *const Token, id: Token.Id) !void {242fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void {
243 if (token.id != id) {243 if (token.id != id) {
244 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));244 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
245 }245 }
doc/langref.html.in+3-6
...@@ -1905,7 +1905,7 @@ const Vec3 = struct.{...@@ -1905,7 +1905,7 @@ const Vec3 = struct.{
1905 };1905 };
1906 }1906 }
19071907
1908 pub fn dot(self: *const Vec3, other: *const Vec3) f32 {1908 pub fn dot(self: Vec3, other: Vec3) f32 {
1909 return self.x * other.x + self.y * other.y + self.z * other.z;1909 return self.x * other.x + self.y * other.y + self.z * other.z;
1910 }1910 }
1911};1911};
...@@ -2243,8 +2243,8 @@ const Variant = union(enum).{...@@ -2243,8 +2243,8 @@ const Variant = union(enum).{
2243 Int: i32,2243 Int: i32,
2244 Bool: bool,2244 Bool: bool,
22452245
2246 fn truthy(self: *const Variant) bool {2246 fn truthy(self: Variant) bool {
2247 return switch (self.*) {2247 return switch (self) {
2248 Variant.Int => |x_int| x_int != 0,2248 Variant.Int => |x_int| x_int != 0,
2249 Variant.Bool => |x_bool| x_bool,2249 Variant.Bool => |x_bool| x_bool,
2250 };2250 };
...@@ -4040,9 +4040,6 @@ test "float widening" {...@@ -4040,9 +4040,6 @@ test "float widening" {
4040 {#header_open|Implicit Cast: undefined#}4040 {#header_open|Implicit Cast: undefined#}
4041 <p>TODO</p>4041 <p>TODO</p>
4042 {#header_close#}4042 {#header_close#}
4043 {#header_open|Implicit Cast: T to *const T#}
4044 <p>TODO</p>
4045 {#header_close#}
4046 {#header_close#}4043 {#header_close#}
40474044
4048 {#header_open|Explicit Casts#}4045 {#header_open|Explicit Casts#}
src-self-hosted/main.zig+1-1
...@@ -658,7 +658,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -658,7 +658,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
658 const main_handle = try async<allocator> asyncFmtMainChecked(658 const main_handle = try async<allocator> asyncFmtMainChecked(
659 &result,659 &result,
660 &loop,660 &loop,
661 flags,661 &flags,
662 color,662 color,
663 );663 );
664 defer cancel main_handle;664 defer cancel main_handle;
src/ir.cpp-48
...@@ -9758,46 +9758,6 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -9758,46 +9758,6 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
9758 return result;9758 return result;
9759}9759}
97609760
9761static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr,
9762 IrInstruction *value, ZigType *wanted_type)
9763{
9764 if (instr_is_comptime(value)) {
9765 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
9766 if (!val)
9767 return ira->codegen->invalid_instruction;
9768
9769 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
9770 source_instr->scope, source_instr->source_node);
9771 const_instruction->base.value.type = wanted_type;
9772 const_instruction->base.value.special = ConstValSpecialStatic;
9773 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef;
9774 const_instruction->base.value.data.x_ptr.data.ref.pointee = val;
9775 return &const_instruction->base;
9776 }
9777
9778 if (value->id == IrInstructionIdLoadPtr) {
9779 IrInstructionLoadPtr *load_ptr_inst = (IrInstructionLoadPtr *)value;
9780 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type,
9781 load_ptr_inst->ptr->value.type, source_instr->source_node, false);
9782 if (const_cast_result.id == ConstCastResultIdInvalid)
9783 return ira->codegen->invalid_instruction;
9784 if (const_cast_result.id == ConstCastResultIdOk)
9785 return load_ptr_inst->ptr;
9786 }
9787 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instr->scope,
9788 source_instr->source_node, value, true, false);
9789 new_instruction->value.type = wanted_type;
9790
9791 ZigType *child_type = wanted_type->data.pointer.child_type;
9792 if (type_has_bits(child_type)) {
9793 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
9794 assert(fn_entry);
9795 fn_entry->alloca_list.append(new_instruction);
9796 }
9797 ir_add_alloca(ira, new_instruction, child_type);
9798 return new_instruction;
9799}
9800
9801static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {9761static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9802 assert(wanted_type->id == ZigTypeIdOptional);9762 assert(wanted_type->id == ZigTypeIdOptional);
9803 assert(instr_is_comptime(value));9763 assert(instr_is_comptime(value));
...@@ -10929,14 +10889,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10929,14 +10889,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10929 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);10889 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
10930 }10890 }
1093110891
10932 // cast from something to const pointer of it
10933 if (!type_requires_comptime(actual_type)) {
10934 ZigType *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
10935 if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) {
10936 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
10937 }
10938 }
10939
10940 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,10892 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
10941 buf_sprintf("expected type '%s', found '%s'",10893 buf_sprintf("expected type '%s', found '%s'",
10942 buf_ptr(&wanted_type->name),10894 buf_ptr(&wanted_type->name),
std/buffer.zig+2-2
...@@ -32,7 +32,7 @@ pub const Buffer = struct.{...@@ -32,7 +32,7 @@ pub const Buffer = struct.{
32 }32 }
3333
34 /// Must deinitialize with deinit.34 /// Must deinitialize with deinit.
35 pub fn initFromBuffer(buffer: *const Buffer) !Buffer {35 pub fn initFromBuffer(buffer: Buffer) !Buffer {
36 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());36 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
37 }37 }
3838
...@@ -148,7 +148,7 @@ test "simple Buffer" {...@@ -148,7 +148,7 @@ test "simple Buffer" {
148 assert(buf.eql("hello world"));148 assert(buf.eql("hello world"));
149 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));149 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
150150
151 var buf2 = try Buffer.initFromBuffer(&buf);151 var buf2 = try Buffer.initFromBuffer(buf);
152 assert(buf.eql(buf2.toSliceConst()));152 assert(buf.eql(buf2.toSliceConst()));
153153
154 assert(buf.startsWith("hell"));154 assert(buf.startsWith("hell"));
std/build.zig+13-11
...@@ -37,7 +37,7 @@ pub const Builder = struct.{...@@ -37,7 +37,7 @@ pub const Builder = struct.{
37 invalid_user_input: bool,37 invalid_user_input: bool,
38 zig_exe: []const u8,38 zig_exe: []const u8,
39 default_step: *Step,39 default_step: *Step,
40 env_map: BufMap,40 env_map: *const BufMap,
41 top_level_steps: ArrayList(*TopLevelStep),41 top_level_steps: ArrayList(*TopLevelStep),
42 prefix: []const u8,42 prefix: []const u8,
43 search_prefixes: ArrayList([]const u8),43 search_prefixes: ArrayList([]const u8),
...@@ -89,6 +89,8 @@ pub const Builder = struct.{...@@ -89,6 +89,8 @@ pub const Builder = struct.{
89 };89 };
9090
91 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {91 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {
92 const env_map = allocator.createOne(BufMap) catch unreachable;
93 env_map.* = os.getEnvMap(allocator) catch unreachable;
92 var self = Builder.{94 var self = Builder.{
93 .zig_exe = zig_exe,95 .zig_exe = zig_exe,
94 .build_root = build_root,96 .build_root = build_root,
...@@ -110,7 +112,7 @@ pub const Builder = struct.{...@@ -110,7 +112,7 @@ pub const Builder = struct.{
110 .available_options_list = ArrayList(AvailableOption).init(allocator),112 .available_options_list = ArrayList(AvailableOption).init(allocator),
111 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),113 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
112 .default_step = undefined,114 .default_step = undefined,
113 .env_map = os.getEnvMap(allocator) catch unreachable,115 .env_map = env_map,
114 .prefix = undefined,116 .prefix = undefined,
115 .search_prefixes = ArrayList([]const u8).init(allocator),117 .search_prefixes = ArrayList([]const u8).init(allocator),
116 .lib_dir = undefined,118 .lib_dir = undefined,
...@@ -155,7 +157,7 @@ pub const Builder = struct.{...@@ -155,7 +157,7 @@ pub const Builder = struct.{
155 return LibExeObjStep.createObject(self, name, root_src);157 return LibExeObjStep.createObject(self, name, root_src);
156 }158 }
157159
158 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {160 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
159 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);161 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);
160 }162 }
161163
...@@ -178,7 +180,7 @@ pub const Builder = struct.{...@@ -178,7 +180,7 @@ pub const Builder = struct.{
178 return LibExeObjStep.createCStaticLibrary(self, name);180 return LibExeObjStep.createCStaticLibrary(self, name);
179 }181 }
180182
181 pub fn addCSharedLibrary(self: *Builder, name: []const u8, ver: *const Version) *LibExeObjStep {183 pub fn addCSharedLibrary(self: *Builder, name: []const u8, ver: Version) *LibExeObjStep {
182 return LibExeObjStep.createCSharedLibrary(self, name, ver);184 return LibExeObjStep.createCSharedLibrary(self, name, ver);
183 }185 }
184186
...@@ -541,7 +543,7 @@ pub const Builder = struct.{...@@ -541,7 +543,7 @@ pub const Builder = struct.{
541 }543 }
542544
543 fn spawnChild(self: *Builder, argv: []const []const u8) !void {545 fn spawnChild(self: *Builder, argv: []const []const u8) !void {
544 return self.spawnChildEnvMap(null, &self.env_map, argv);546 return self.spawnChildEnvMap(null, self.env_map, argv);
545 }547 }
546548
547 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {549 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
...@@ -850,12 +852,12 @@ pub const LibExeObjStep = struct.{...@@ -850,12 +852,12 @@ pub const LibExeObjStep = struct.{
850 Obj,852 Obj,
851 };853 };
852854
853 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {855 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
854 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable;856 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable;
855 return self;857 return self;
856 }858 }
857859
858 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep {860 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: Version) *LibExeObjStep {
859 const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable;861 const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable;
860 return self;862 return self;
861 }863 }
...@@ -891,7 +893,7 @@ pub const LibExeObjStep = struct.{...@@ -891,7 +893,7 @@ pub const LibExeObjStep = struct.{
891 return self;893 return self;
892 }894 }
893895
894 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, static: bool, ver: *const Version) LibExeObjStep {896 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, static: bool, ver: Version) LibExeObjStep {
895 var self = LibExeObjStep.{897 var self = LibExeObjStep.{
896 .no_rosegment = false,898 .no_rosegment = false,
897 .strip = false,899 .strip = false,
...@@ -909,7 +911,7 @@ pub const LibExeObjStep = struct.{...@@ -909,7 +911,7 @@ pub const LibExeObjStep = struct.{
909 .step = Step.init(name, builder.allocator, make),911 .step = Step.init(name, builder.allocator, make),
910 .output_path = null,912 .output_path = null,
911 .output_h_path = null,913 .output_h_path = null,
912 .version = ver.*,914 .version = ver,
913 .out_filename = undefined,915 .out_filename = undefined,
914 .out_h_filename = builder.fmt("{}.h", name),916 .out_h_filename = builder.fmt("{}.h", name),
915 .major_only_filename = undefined,917 .major_only_filename = undefined,
...@@ -933,13 +935,13 @@ pub const LibExeObjStep = struct.{...@@ -933,13 +935,13 @@ pub const LibExeObjStep = struct.{
933 return self;935 return self;
934 }936 }
935937
936 fn initC(builder: *Builder, name: []const u8, kind: Kind, version: *const Version, static: bool) LibExeObjStep {938 fn initC(builder: *Builder, name: []const u8, kind: Kind, version: Version, static: bool) LibExeObjStep {
937 var self = LibExeObjStep.{939 var self = LibExeObjStep.{
938 .no_rosegment = false,940 .no_rosegment = false,
939 .builder = builder,941 .builder = builder,
940 .name = name,942 .name = name,
941 .kind = kind,943 .kind = kind,
942 .version = version.*,944 .version = version,
943 .static = static,945 .static = static,
944 .target = Target.Native,946 .target = Target.Native,
945 .cflags = ArrayList([]const u8).init(builder.allocator),947 .cflags = ArrayList([]const u8).init(builder.allocator),
std/debug/index.zig+1-1
...@@ -976,7 +976,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {...@@ -976,7 +976,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {
976 };976 };
977}977}
978978
979fn printLineFromFile(out_stream: var, line_info: *const LineInfo) !void {979fn printLineFromFile(out_stream: var, line_info: LineInfo) !void {
980 var f = try os.File.openRead(line_info.file_name);980 var f = try os.File.openRead(line_info.file_name);
981 defer f.close();981 defer f.close();
982 // TODO fstat and make sure that the file has the correct size982 // TODO fstat and make sure that the file has the correct size
std/event/net.zig+7-7
...@@ -8,7 +8,7 @@ const posix = os.posix;...@@ -8,7 +8,7 @@ const posix = os.posix;
8const Loop = std.event.Loop;8const Loop = std.event.Loop;
99
10pub const Server = struct.{10pub const Server = struct.{
11 handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const os.File) void,11 handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, os.File) void,
1212
13 loop: *Loop,13 loop: *Loop,
14 sockfd: ?i32,14 sockfd: ?i32,
...@@ -40,7 +40,7 @@ pub const Server = struct.{...@@ -40,7 +40,7 @@ pub const Server = struct.{
40 pub fn listen(40 pub fn listen(
41 self: *Server,41 self: *Server,
42 address: *const std.net.Address,42 address: *const std.net.Address,
43 handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const os.File) void,43 handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, os.File) void,
44 ) !void {44 ) !void {
45 self.handleRequestFn = handleRequestFn;45 self.handleRequestFn = handleRequestFn;
4646
...@@ -82,7 +82,7 @@ pub const Server = struct.{...@@ -82,7 +82,7 @@ pub const Server = struct.{
82 continue;82 continue;
83 }83 }
84 var socket = os.File.openHandle(accepted_fd);84 var socket = os.File.openHandle(accepted_fd);
85 _ = async<self.loop.allocator> self.handleRequestFn(self, accepted_addr, socket) catch |err| switch (err) {85 _ = async<self.loop.allocator> self.handleRequestFn(self, &accepted_addr, socket) catch |err| switch (err) {
86 error.OutOfMemory => {86 error.OutOfMemory => {
87 socket.close();87 socket.close();
88 continue;88 continue;
...@@ -278,9 +278,9 @@ test "listen on a port, send bytes, receive bytes" {...@@ -278,9 +278,9 @@ test "listen on a port, send bytes, receive bytes" {
278 tcp_server: Server,278 tcp_server: Server,
279279
280 const Self = @This();280 const Self = @This();
281 async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: *const os.File) void {281 async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: os.File) void {
282 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);282 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
283 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/1592283 var socket = _socket; // TODO https://github.com/ziglang/zig/issues/1592
284 defer socket.close();284 defer socket.close();
285 // TODO guarantee elision of this allocation285 // TODO guarantee elision of this allocation
286 const next_handler = async errorableHandler(self, _addr, socket) catch unreachable;286 const next_handler = async errorableHandler(self, _addr, socket) catch unreachable;
...@@ -307,9 +307,9 @@ test "listen on a port, send bytes, receive bytes" {...@@ -307,9 +307,9 @@ test "listen on a port, send bytes, receive bytes" {
307 try loop.initSingleThreaded(std.debug.global_allocator);307 try loop.initSingleThreaded(std.debug.global_allocator);
308 var server = MyServer.{ .tcp_server = Server.init(&loop) };308 var server = MyServer.{ .tcp_server = Server.init(&loop) };
309 defer server.tcp_server.deinit();309 defer server.tcp_server.deinit();
310 try server.tcp_server.listen(addr, MyServer.handler);310 try server.tcp_server.listen(&addr, MyServer.handler);
311311
312 const p = try async<std.debug.global_allocator> doAsyncTest(&loop, server.tcp_server.listen_address, &server.tcp_server);312 const p = try async<std.debug.global_allocator> doAsyncTest(&loop, &server.tcp_server.listen_address, &server.tcp_server);
313 defer cancel p;313 defer cancel p;
314 loop.run();314 loop.run();
315}315}
std/fmt/errol/index.zig+1-1
...@@ -217,7 +217,7 @@ fn tableLowerBound(k: u64) usize {...@@ -217,7 +217,7 @@ fn tableLowerBound(k: u64) usize {
217/// @in: The HP number.217/// @in: The HP number.
218/// @val: The double.218/// @val: The double.
219/// &returns: The HP number.219/// &returns: The HP number.
220fn hpProd(in: *const HP, val: f64) HP {220fn hpProd(in: HP, val: f64) HP {
221 var hi: f64 = undefined;221 var hi: f64 = undefined;
222 var lo: f64 = undefined;222 var lo: f64 = undefined;
223 split(in.val, &hi, &lo);223 split(in.val, &hi, &lo);
std/json.zig+12-12
...@@ -74,7 +74,7 @@ pub const Token = struct.{...@@ -74,7 +74,7 @@ pub const Token = struct.{
74 }74 }
7575
76 // Slice into the underlying input string.76 // Slice into the underlying input string.
77 pub fn slice(self: *const Token, input: []const u8, i: usize) []const u8 {77 pub fn slice(self: Token, input: []const u8, i: usize) []const u8 {
78 return input[i + self.offset - self.count .. i + self.offset];78 return input[i + self.offset - self.count .. i + self.offset];
79 }79 }
80};80};
...@@ -1008,8 +1008,8 @@ pub const Value = union(enum).{...@@ -1008,8 +1008,8 @@ pub const Value = union(enum).{
1008 Array: ArrayList(Value),1008 Array: ArrayList(Value),
1009 Object: ObjectMap,1009 Object: ObjectMap,
10101010
1011 pub fn dump(self: *const Value) void {1011 pub fn dump(self: Value) void {
1012 switch (self.*) {1012 switch (self) {
1013 Value.Null => {1013 Value.Null => {
1014 debug.warn("null");1014 debug.warn("null");
1015 },1015 },
...@@ -1055,7 +1055,7 @@ pub const Value = union(enum).{...@@ -1055,7 +1055,7 @@ pub const Value = union(enum).{
1055 }1055 }
1056 }1056 }
10571057
1058 pub fn dumpIndent(self: *const Value, indent: usize) void {1058 pub fn dumpIndent(self: Value, indent: usize) void {
1059 if (indent == 0) {1059 if (indent == 0) {
1060 self.dump();1060 self.dump();
1061 } else {1061 } else {
...@@ -1063,8 +1063,8 @@ pub const Value = union(enum).{...@@ -1063,8 +1063,8 @@ pub const Value = union(enum).{
1063 }1063 }
1064 }1064 }
10651065
1066 fn dumpIndentLevel(self: *const Value, indent: usize, level: usize) void {1066 fn dumpIndentLevel(self: Value, indent: usize, level: usize) void {
1067 switch (self.*) {1067 switch (self) {
1068 Value.Null => {1068 Value.Null => {
1069 debug.warn("null");1069 debug.warn("null");
1070 },1070 },
...@@ -1178,7 +1178,7 @@ pub const Parser = struct.{...@@ -1178,7 +1178,7 @@ pub const Parser = struct.{
11781178
1179 // Even though p.allocator exists, we take an explicit allocator so that allocation state1179 // Even though p.allocator exists, we take an explicit allocator so that allocation state
1180 // can be cleaned up on error correctly during a `parse` on call.1180 // can be cleaned up on error correctly during a `parse` on call.
1181 fn transition(p: *Parser, allocator: *Allocator, input: []const u8, i: usize, token: *const Token) !void {1181 fn transition(p: *Parser, allocator: *Allocator, input: []const u8, i: usize, token: Token) !void {
1182 switch (p.state) {1182 switch (p.state) {
1183 State.ObjectKey => switch (token.id) {1183 State.ObjectKey => switch (token.id) {
1184 Token.Id.ObjectEnd => {1184 Token.Id.ObjectEnd => {
...@@ -1311,19 +1311,19 @@ pub const Parser = struct.{...@@ -1311,19 +1311,19 @@ pub const Parser = struct.{
1311 }1311 }
1312 }1312 }
13131313
1314 fn pushToParent(p: *Parser, value: *const Value) !void {1314 fn pushToParent(p: *Parser, value: Value) !void {
1315 switch (p.stack.at(p.stack.len - 1)) {1315 switch (p.stack.at(p.stack.len - 1)) {
1316 // Object Parent -> [ ..., object, <key>, value ]1316 // Object Parent -> [ ..., object, <key>, value ]
1317 Value.String => |key| {1317 Value.String => |key| {
1318 _ = p.stack.pop();1318 _ = p.stack.pop();
13191319
1320 var object = &p.stack.items[p.stack.len - 1].Object;1320 var object = &p.stack.items[p.stack.len - 1].Object;
1321 _ = try object.put(key, value.*);1321 _ = try object.put(key, value);
1322 p.state = State.ObjectKey;1322 p.state = State.ObjectKey;
1323 },1323 },
1324 // Array Parent -> [ ..., <array>, value ]1324 // Array Parent -> [ ..., <array>, value ]
1325 Value.Array => |*array| {1325 Value.Array => |*array| {
1326 try array.append(value.*);1326 try array.append(value);
1327 p.state = State.ArrayValue;1327 p.state = State.ArrayValue;
1328 },1328 },
1329 else => {1329 else => {
...@@ -1332,14 +1332,14 @@ pub const Parser = struct.{...@@ -1332,14 +1332,14 @@ pub const Parser = struct.{
1332 }1332 }
1333 }1333 }
13341334
1335 fn parseString(p: *Parser, allocator: *Allocator, token: *const Token, input: []const u8, i: usize) !Value {1335 fn parseString(p: *Parser, allocator: *Allocator, token: Token, input: []const u8, i: usize) !Value {
1336 // TODO: We don't strictly have to copy values which do not contain any escape1336 // TODO: We don't strictly have to copy values which do not contain any escape
1337 // characters if flagged with the option.1337 // characters if flagged with the option.
1338 const slice = token.slice(input, i);1338 const slice = token.slice(input, i);
1339 return Value.{ .String = try mem.dupe(p.allocator, u8, slice) };1339 return Value.{ .String = try mem.dupe(p.allocator, u8, slice) };
1340 }1340 }
13411341
1342 fn parseNumber(p: *Parser, token: *const Token, input: []const u8, i: usize) !Value {1342 fn parseNumber(p: *Parser, token: Token, input: []const u8, i: usize) !Value {
1343 return if (token.number_is_integer)1343 return if (token.number_is_integer)
1344 Value.{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }1344 Value.{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
1345 else1345 else
std/math/complex/cosh.zig+2-2
...@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {...@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {
15 };15 };
16}16}
1717
18fn cosh32(z: *const Complex(f32)) Complex(f32) {18fn cosh32(z: Complex(f32)) Complex(f32) {
19 const x = z.re;19 const x = z.re;
20 const y = z.im;20 const y = z.im;
2121
...@@ -78,7 +78,7 @@ fn cosh32(z: *const Complex(f32)) Complex(f32) {...@@ -78,7 +78,7 @@ fn cosh32(z: *const Complex(f32)) Complex(f32) {
78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
79}79}
8080
81fn cosh64(z: *const Complex(f64)) Complex(f64) {81fn cosh64(z: Complex(f64)) Complex(f64) {
82 const x = z.re;82 const x = z.re;
83 const y = z.im;83 const y = z.im;
8484
std/math/complex/pow.zig+1-1
...@@ -4,7 +4,7 @@ const math = std.math;...@@ -4,7 +4,7 @@ const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7pub fn pow(comptime T: type, z: *const T, c: *const T) T {7pub fn pow(comptime T: type, z: T, c: T) T {
8 const p = cmath.log(z);8 const p = cmath.log(z);
9 const q = c.mul(p);9 const q = c.mul(p);
10 return cmath.exp(q);10 return cmath.exp(q);
std/net.zig+2-2
...@@ -46,8 +46,8 @@ pub const Address = struct.{...@@ -46,8 +46,8 @@ pub const Address = struct.{
46 };46 };
47 }47 }
4848
49 pub fn initPosix(addr: *const posix.sockaddr) Address {49 pub fn initPosix(addr: posix.sockaddr) Address {
50 return Address.{ .os_addr = addr.* };50 return Address.{ .os_addr = addr };
51 }51 }
5252
53 pub fn format(self: *const Address, out_stream: var) !void {53 pub fn format(self: *const Address, out_stream: var) !void {
std/os/child_process.zig+3-3
...@@ -777,9 +777,9 @@ fn makePipe() ![2]i32 {...@@ -777,9 +777,9 @@ fn makePipe() ![2]i32 {
777 return fds;777 return fds;
778}778}
779779
780fn destroyPipe(pipe: *const [2]i32) void {780fn destroyPipe(pipe: [2]i32) void {
781 os.close((pipe.*)[0]);781 os.close(pipe[0]);
782 os.close((pipe.*)[1]);782 os.close(pipe[1]);
783}783}
784784
785// Child of fork calls this to report an error to the fork parent.785// Child of fork calls this to report an error to the fork parent.
std/segmented_list.zig+3-3
...@@ -122,13 +122,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -122,13 +122,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
122 return self.uncheckedAt(i);122 return self.uncheckedAt(i);
123 }123 }
124124
125 pub fn count(self: *const Self) usize {125 pub fn count(self: Self) usize {
126 return self.len;126 return self.len;
127 }127 }
128128
129 pub fn push(self: *Self, item: *const T) !void {129 pub fn push(self: *Self, item: T) !void {
130 const new_item_ptr = try self.addOne();130 const new_item_ptr = try self.addOne();
131 new_item_ptr.* = item.*;131 new_item_ptr.* = item;
132 }132 }
133133
134 pub fn pushMany(self: *Self, items: []const T) !void {134 pub fn pushMany(self: *Self, items: []const T) !void {
std/zig/ast.zig+3-3
...@@ -400,7 +400,7 @@ pub const Node = struct.{...@@ -400,7 +400,7 @@ pub const Node = struct.{
400 Id.While => {400 Id.While => {
401 const while_node = @fieldParentPtr(While, "base", n);401 const while_node = @fieldParentPtr(While, "base", n);
402 if (while_node.@"else") |@"else"| {402 if (while_node.@"else") |@"else"| {
403 n = @"else".base;403 n = &@"else".base;
404 continue;404 continue;
405 }405 }
406406
...@@ -409,7 +409,7 @@ pub const Node = struct.{...@@ -409,7 +409,7 @@ pub const Node = struct.{
409 Id.For => {409 Id.For => {
410 const for_node = @fieldParentPtr(For, "base", n);410 const for_node = @fieldParentPtr(For, "base", n);
411 if (for_node.@"else") |@"else"| {411 if (for_node.@"else") |@"else"| {
412 n = @"else".base;412 n = &@"else".base;
413 continue;413 continue;
414 }414 }
415415
...@@ -418,7 +418,7 @@ pub const Node = struct.{...@@ -418,7 +418,7 @@ pub const Node = struct.{
418 Id.If => {418 Id.If => {
419 const if_node = @fieldParentPtr(If, "base", n);419 const if_node = @fieldParentPtr(If, "base", n);
420 if (if_node.@"else") |@"else"| {420 if (if_node.@"else") |@"else"| {
421 n = @"else".base;421 n = &@"else".base;
422 continue;422 continue;
423 }423 }
424424
std/zig/parse.zig+16-16
...@@ -1848,7 +1848,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1848,7 +1848,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1848 continue;1848 continue;
1849 },1849 },
1850 else => {1850 else => {
1851 if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr, token_index)) {1851 if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr.*, token_index)) {
1852 prevToken(&tok_it, &tree);1852 prevToken(&tok_it, &tree);
1853 stack.append(State.{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable;1853 stack.append(State.{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
1854 }1854 }
...@@ -2665,7 +2665,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2665,7 +2665,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2665 continue;2665 continue;
2666 },2666 },
2667 else => {2667 else => {
2668 if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr, token.index)) {2668 if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr.*, token.index)) {
2669 prevToken(&tok_it, &tree);2669 prevToken(&tok_it, &tree);
2670 if (opt_ctx != OptionalCtx.Optional) {2670 if (opt_ctx != OptionalCtx.Optional) {
2671 try tree.errors.push(Error.{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr.{ .token = token.index } });2671 try tree.errors.push(Error.{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr.{ .token = token.index } });
...@@ -2949,29 +2949,29 @@ const OptionalCtx = union(enum).{...@@ -2949,29 +2949,29 @@ const OptionalCtx = union(enum).{
2949 RequiredNull: *?*ast.Node,2949 RequiredNull: *?*ast.Node,
2950 Required: **ast.Node,2950 Required: **ast.Node,
29512951
2952 pub fn store(self: *const OptionalCtx, value: *ast.Node) void {2952 pub fn store(self: OptionalCtx, value: *ast.Node) void {
2953 switch (self.*) {2953 switch (self) {
2954 OptionalCtx.Optional => |ptr| ptr.* = value,2954 OptionalCtx.Optional => |ptr| ptr.* = value,
2955 OptionalCtx.RequiredNull => |ptr| ptr.* = value,2955 OptionalCtx.RequiredNull => |ptr| ptr.* = value,
2956 OptionalCtx.Required => |ptr| ptr.* = value,2956 OptionalCtx.Required => |ptr| ptr.* = value,
2957 }2957 }
2958 }2958 }
29592959
2960 pub fn get(self: *const OptionalCtx) ?*ast.Node {2960 pub fn get(self: OptionalCtx) ?*ast.Node {
2961 switch (self.*) {2961 switch (self) {
2962 OptionalCtx.Optional => |ptr| return ptr.*,2962 OptionalCtx.Optional => |ptr| return ptr.*,
2963 OptionalCtx.RequiredNull => |ptr| return ptr.*.?,2963 OptionalCtx.RequiredNull => |ptr| return ptr.*.?,
2964 OptionalCtx.Required => |ptr| return ptr.*,2964 OptionalCtx.Required => |ptr| return ptr.*,
2965 }2965 }
2966 }2966 }
29672967
2968 pub fn toRequired(self: *const OptionalCtx) OptionalCtx {2968 pub fn toRequired(self: OptionalCtx) OptionalCtx {
2969 switch (self.*) {2969 switch (self) {
2970 OptionalCtx.Optional => |ptr| {2970 OptionalCtx.Optional => |ptr| {
2971 return OptionalCtx.{ .RequiredNull = ptr };2971 return OptionalCtx.{ .RequiredNull = ptr };
2972 },2972 },
2973 OptionalCtx.RequiredNull => |ptr| return self.*,2973 OptionalCtx.RequiredNull => |ptr| return self,
2974 OptionalCtx.Required => |ptr| return self.*,2974 OptionalCtx.Required => |ptr| return self,
2975 }2975 }
2976 }2976 }
2977};2977};
...@@ -3161,7 +3161,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato...@@ -3161,7 +3161,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
3161 }3161 }
3162}3162}
31633163
3164fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {3164fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: OptionalCtx, token_ptr: Token, token_index: TokenIndex) !bool {
3165 switch (token_ptr.id) {3165 switch (token_ptr.id) {
3166 Token.Id.Keyword_suspend => {3166 Token.Id.Keyword_suspend => {
3167 const node = try arena.create(ast.Node.Suspend.{3167 const node = try arena.create(ast.Node.Suspend.{
...@@ -3199,7 +3199,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3199,7 +3199,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3199 .label = null,3199 .label = null,
3200 .inline_token = null,3200 .inline_token = null,
3201 .loop_token = token_index,3201 .loop_token = token_index,
3202 .opt_ctx = ctx.*,3202 .opt_ctx = ctx,
3203 },3203 },
3204 }) catch unreachable;3204 }) catch unreachable;
3205 return true;3205 return true;
...@@ -3210,7 +3210,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3210,7 +3210,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3210 .label = null,3210 .label = null,
3211 .inline_token = null,3211 .inline_token = null,
3212 .loop_token = token_index,3212 .loop_token = token_index,
3213 .opt_ctx = ctx.*,3213 .opt_ctx = ctx,
3214 },3214 },
3215 }) catch unreachable;3215 }) catch unreachable;
3216 return true;3216 return true;
...@@ -3295,10 +3295,10 @@ fn expectCommaOrEnd(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, end:...@@ -3295,10 +3295,10 @@ fn expectCommaOrEnd(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, end:
3295 }3295 }
3296}3296}
32973297
3298fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {3298fn tokenIdToAssignment(id: Token.Id) ?ast.Node.InfixOp.Op {
3299 // TODO: We have to cast all cases because of this:3299 // TODO: We have to cast all cases because of this:
3300 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'3300 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'
3301 return switch (id.*) {3301 return switch (id) {
3302 Token.Id.AmpersandEqual => ast.Node.InfixOp.Op.{ .AssignBitAnd = {} },3302 Token.Id.AmpersandEqual => ast.Node.InfixOp.Op.{ .AssignBitAnd = {} },
3303 Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftLeft = {} },3303 Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftLeft = {} },
3304 Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftRight = {} },3304 Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftRight = {} },
...@@ -3396,7 +3396,7 @@ fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenInde...@@ -3396,7 +3396,7 @@ fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenInde
3396 });3396 });
3397}3397}
33983398
3399fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: *const OptionalCtx, comptime T: type, token_index: TokenIndex) !*T {3399fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: OptionalCtx, comptime T: type, token_index: TokenIndex) !*T {
3400 const node = try createLiteral(arena, T, token_index);3400 const node = try createLiteral(arena, T, token_index);
3401 opt_ctx.store(&node.base);3401 opt_ctx.store(&node.base);
34023402
test/cases/bugs/655.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const other_file = @import("655_other_file.zig");2const other_file = @import("655_other_file.zig");
33
4test "function with &const parameter with type dereferenced by namespace" {4test "function with *const parameter with type dereferenced by namespace" {
5 const x: other_file.Integer = 1234;5 const x: other_file.Integer = 1234;
6 comptime std.debug.assert(@typeOf(&x) == *const other_file.Integer);6 comptime std.debug.assert(@typeOf(&x) == *const other_file.Integer);
7 foo(x);7 foo(&x);
8}8}
99
10fn foo(x: *const other_file.Integer) void {10fn foo(x: *const other_file.Integer) void {
test/cases/cast.zig-96
...@@ -22,88 +22,6 @@ test "pointer reinterpret const float to int" {...@@ -22,88 +22,6 @@ test "pointer reinterpret const float to int" {
22 assert(int_val == 858993411);22 assert(int_val == 858993411);
23}23}
2424
25test "implicitly cast a pointer to a const pointer of it" {
26 var x: i32 = 1;
27 const xp = &x;
28 funcWithConstPtrPtr(xp);
29 assert(x == 2);
30}
31
32fn funcWithConstPtrPtr(x: *const *i32) void {
33 x.*.* += 1;
34}
35
36test "implicitly cast a container to a const pointer of it" {
37 const z = Struct(void).{ .x = void.{} };
38 assert(0 == @sizeOf(@typeOf(z)));
39 assert(void.{} == Struct(void).pointer(z).x);
40 assert(void.{} == Struct(void).pointer(&z).x);
41 assert(void.{} == Struct(void).maybePointer(z).x);
42 assert(void.{} == Struct(void).maybePointer(&z).x);
43 assert(void.{} == Struct(void).maybePointer(null).x);
44 const s = Struct(u8).{ .x = 42 };
45 assert(0 != @sizeOf(@typeOf(s)));
46 assert(42 == Struct(u8).pointer(s).x);
47 assert(42 == Struct(u8).pointer(&s).x);
48 assert(42 == Struct(u8).maybePointer(s).x);
49 assert(42 == Struct(u8).maybePointer(&s).x);
50 assert(0 == Struct(u8).maybePointer(null).x);
51 const u = Union.{ .x = 42 };
52 assert(42 == Union.pointer(u).x);
53 assert(42 == Union.pointer(&u).x);
54 assert(42 == Union.maybePointer(u).x);
55 assert(42 == Union.maybePointer(&u).x);
56 assert(0 == Union.maybePointer(null).x);
57 const e = Enum.Some;
58 assert(Enum.Some == Enum.pointer(e));
59 assert(Enum.Some == Enum.pointer(&e));
60 assert(Enum.Some == Enum.maybePointer(e));
61 assert(Enum.Some == Enum.maybePointer(&e));
62 assert(Enum.None == Enum.maybePointer(null));
63}
64
65fn Struct(comptime T: type) type {
66 return struct.{
67 const Self = @This();
68 x: T,
69
70 fn pointer(self: *const Self) Self {
71 return self.*;
72 }
73
74 fn maybePointer(self: ?*const Self) Self {
75 const none = Self.{ .x = if (T == void) void.{} else 0 };
76 return (self orelse &none).*;
77 }
78 };
79}
80
81const Union = union.{
82 x: u8,
83
84 fn pointer(self: *const Union) Union {
85 return self.*;
86 }
87
88 fn maybePointer(self: ?*const Union) Union {
89 const none = Union.{ .x = 0 };
90 return (self orelse &none).*;
91 }
92};
93
94const Enum = enum.{
95 None,
96 Some,
97
98 fn pointer(self: *const Enum) Enum {
99 return self.*;
100 }
101
102 fn maybePointer(self: ?*const Enum) Enum {
103 return (self orelse &Enum.None).*;
104 }
105};
106
107test "implicitly cast indirect pointer to maybe-indirect pointer" {25test "implicitly cast indirect pointer to maybe-indirect pointer" {
108 const S = struct.{26 const S = struct.{
109 const Self = @This();27 const Self = @This();
...@@ -125,13 +43,9 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -125,13 +43,9 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
125 const p = &s;43 const p = &s;
126 const q = &p;44 const q = &p;
127 const r = &q;45 const r = &q;
128 assert(42 == S.constConst(p));
129 assert(42 == S.constConst(q));46 assert(42 == S.constConst(q));
130 assert(42 == S.maybeConstConst(p));
131 assert(42 == S.maybeConstConst(q));47 assert(42 == S.maybeConstConst(q));
132 assert(42 == S.constConstConst(q));
133 assert(42 == S.constConstConst(r));48 assert(42 == S.constConstConst(r));
134 assert(42 == S.maybeConstConstConst(q));
135 assert(42 == S.maybeConstConstConst(r));49 assert(42 == S.maybeConstConstConst(r));
136}50}
13751
...@@ -166,16 +80,6 @@ fn testPeerResolveArrayConstSlice(b: bool) void {...@@ -166,16 +80,6 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
166 assert(mem.eql(u8, value2, "zz"));80 assert(mem.eql(u8, value2, "zz"));
167}81}
16882
169test "integer literal to &const int" {
170 const x: *const i32 = 3;
171 assert(x.* == 3);
172}
173
174test "string literal to &const []const u8" {
175 const x: *const []const u8 = "hello";
176 assert(mem.eql(u8, x.*, "hello"));
177}
178
179test "implicitly cast from T to error!?T" {83test "implicitly cast from T to error!?T" {
180 castToOptionalTypeError(1);84 castToOptionalTypeError(1);
181 comptime castToOptionalTypeError(1);85 comptime castToOptionalTypeError(1);
test/cases/enum.zig+4-4
...@@ -56,15 +56,15 @@ test "constant enum with payload" {...@@ -56,15 +56,15 @@ test "constant enum with payload" {
56 shouldBeNotEmpty(full);56 shouldBeNotEmpty(full);
57}57}
5858
59fn shouldBeEmpty(x: *const AnEnumWithPayload) void {59fn shouldBeEmpty(x: AnEnumWithPayload) void {
60 switch (x.*) {60 switch (x) {
61 AnEnumWithPayload.Empty => {},61 AnEnumWithPayload.Empty => {},
62 else => unreachable,62 else => unreachable,
63 }63 }
64}64}
6565
66fn shouldBeNotEmpty(x: *const AnEnumWithPayload) void {66fn shouldBeNotEmpty(x: AnEnumWithPayload) void {
67 switch (x.*) {67 switch (x) {
68 AnEnumWithPayload.Empty => unreachable,68 AnEnumWithPayload.Empty => unreachable,
69 else => {},69 else => {},
70 }70 }
test/cases/incomplete_struct_param_tld.zig+1-1
...@@ -16,7 +16,7 @@ const C = struct.{...@@ -16,7 +16,7 @@ const C = struct.{
16 }16 }
17};17};
1818
19fn foo(a: *const A) i32 {19fn foo(a: A) i32 {
20 return a.b.c.d();20 return a.b.c.d();
21}21}
2222
test/cases/misc.zig+6-6
...@@ -353,8 +353,8 @@ const test3_foo = Test3Foo.{...@@ -353,8 +353,8 @@ const test3_foo = Test3Foo.{
353 },353 },
354};354};
355const test3_bar = Test3Foo.{ .Two = 13 };355const test3_bar = Test3Foo.{ .Two = 13 };
356fn test3_1(f: *const Test3Foo) void {356fn test3_1(f: Test3Foo) void {
357 switch (f.*) {357 switch (f) {
358 Test3Foo.Three => |pt| {358 Test3Foo.Three => |pt| {
359 assert(pt.x == 3);359 assert(pt.x == 3);
360 assert(pt.y == 4);360 assert(pt.y == 4);
...@@ -362,8 +362,8 @@ fn test3_1(f: *const Test3Foo) void {...@@ -362,8 +362,8 @@ fn test3_1(f: *const Test3Foo) void {
362 else => unreachable,362 else => unreachable,
363 }363 }
364}364}
365fn test3_2(f: *const Test3Foo) void {365fn test3_2(f: Test3Foo) void {
366 switch (f.*) {366 switch (f) {
367 Test3Foo.Two => |x| {367 Test3Foo.Two => |x| {
368 assert(x == 13);368 assert(x == 13);
369 },369 },
...@@ -672,10 +672,10 @@ const PackedEnum = packed enum.{...@@ -672,10 +672,10 @@ const PackedEnum = packed enum.{
672};672};
673673
674test "packed struct, enum, union parameters in extern function" {674test "packed struct, enum, union parameters in extern function" {
675 testPackedStuff(PackedStruct.{675 testPackedStuff(&(PackedStruct.{
676 .a = 1,676 .a = 1,
677 .b = 2,677 .b = 2,
678 }, PackedUnion.{ .a = 1 }, PackedEnum.A);678 }), &(PackedUnion.{ .a = 1 }), PackedEnum.A);
679}679}
680680
681export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: PackedEnum) void {}681export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: PackedEnum) void {}
test/cases/null.zig+2-2
...@@ -65,8 +65,8 @@ test "if var maybe pointer" {...@@ -65,8 +65,8 @@ test "if var maybe pointer" {
65 .d = 1,65 .d = 1,
66 }) == 15);66 }) == 15);
67}67}
68fn shouldBeAPlus1(p: *const Particle) u64 {68fn shouldBeAPlus1(p: Particle) u64 {
69 var maybe_particle: ?Particle = p.*;69 var maybe_particle: ?Particle = p;
70 if (maybe_particle) |*particle| {70 if (maybe_particle) |*particle| {
71 particle.a += 1;71 particle.a += 1;
72 }72 }
test/cases/struct.zig+5-5
...@@ -55,7 +55,7 @@ const StructFoo = struct.{...@@ -55,7 +55,7 @@ const StructFoo = struct.{
55 b: bool,55 b: bool,
56 c: f32,56 c: f32,
57};57};
58fn testFoo(foo: *const StructFoo) void {58fn testFoo(foo: StructFoo) void {
59 assert(foo.b);59 assert(foo.b);
60}60}
61fn testMutation(foo: *StructFoo) void {61fn testMutation(foo: *StructFoo) void {
...@@ -112,7 +112,7 @@ fn aFunc() i32 {...@@ -112,7 +112,7 @@ fn aFunc() i32 {
112 return 13;112 return 13;
113}113}
114114
115fn callStructField(foo: *const Foo) i32 {115fn callStructField(foo: Foo) i32 {
116 return foo.ptr();116 return foo.ptr();
117}117}
118118
...@@ -124,7 +124,7 @@ test "store member function in variable" {...@@ -124,7 +124,7 @@ test "store member function in variable" {
124}124}
125const MemberFnTestFoo = struct.{125const MemberFnTestFoo = struct.{
126 x: i32,126 x: i32,
127 fn member(foo: *const MemberFnTestFoo) i32 {127 fn member(foo: MemberFnTestFoo) i32 {
128 return foo.x;128 return foo.x;
129 }129 }
130};130};
...@@ -443,8 +443,8 @@ test "implicit cast packed struct field to const ptr" {...@@ -443,8 +443,8 @@ test "implicit cast packed struct field to const ptr" {
443 move_id: u9,443 move_id: u9,
444 level: u7,444 level: u7,
445445
446 fn toInt(value: *const u7) u7 {446 fn toInt(value: u7) u7 {
447 return value.*;447 return value;
448 }448 }
449 };449 };
450450
test/cases/switch.zig+2-2
...@@ -90,8 +90,8 @@ const SwitchProngWithVarEnum = union(enum).{...@@ -90,8 +90,8 @@ const SwitchProngWithVarEnum = union(enum).{
90 Two: f32,90 Two: f32,
91 Meh: void,91 Meh: void,
92};92};
93fn switchProngWithVarFn(a: *const SwitchProngWithVarEnum) void {93fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
94 switch (a.*) {94 switch (a) {
95 SwitchProngWithVarEnum.One => |x| {95 SwitchProngWithVarEnum.One => |x| {
96 assert(x == 13);96 assert(x == 13);
97 },97 },
test/cases/union.zig+8-21
...@@ -108,9 +108,9 @@ fn doTest() void {...@@ -108,9 +108,9 @@ fn doTest() void {
108 assert(bar(Payload.{ .A = 1234 }) == -10);108 assert(bar(Payload.{ .A = 1234 }) == -10);
109}109}
110110
111fn bar(value: *const Payload) i32 {111fn bar(value: Payload) i32 {
112 assert(Letter(value.*) == Letter.A);112 assert(Letter(value) == Letter.A);
113 return switch (value.*) {113 return switch (value) {
114 Payload.A => |x| return x - 1244,114 Payload.A => |x| return x - 1244,
115 Payload.B => |x| if (x == 12.34) i32(20) else 21,115 Payload.B => |x| if (x == 12.34) i32(20) else 21,
116 Payload.C => |x| if (x) i32(30) else 31,116 Payload.C => |x| if (x) i32(30) else 31,
...@@ -147,9 +147,9 @@ test "union(enum(u32)) with specified and unspecified tag values" {...@@ -147,9 +147,9 @@ test "union(enum(u32)) with specified and unspecified tag values" {
147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.{ .C = 123 });147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.{ .C = 123 });
148}148}
149149
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
151 assert(@enumToInt(@TagType(MultipleChoice2)(x.*)) == 60);151 assert(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 assert(1123 == switch (x.*) {152 assert(1123 == switch (x) {
153 MultipleChoice2.A => 1,153 MultipleChoice2.A => 1,
154 MultipleChoice2.B => 2,154 MultipleChoice2.B => 2,
155 MultipleChoice2.C => |v| i32(1000) + v,155 MultipleChoice2.C => |v| i32(1000) + v,
...@@ -206,8 +206,8 @@ test "cast union to tag type of union" {...@@ -206,8 +206,8 @@ test "cast union to tag type of union" {
206 comptime testCastUnionToTagType(TheUnion.{ .B = 1234 });206 comptime testCastUnionToTagType(TheUnion.{ .B = 1234 });
207}207}
208208
209fn testCastUnionToTagType(x: *const TheUnion) void {209fn testCastUnionToTagType(x: TheUnion) void {
210 assert(TheTag(x.*) == TheTag.B);210 assert(TheTag(x) == TheTag.B);
211}211}
212212
213test "cast tag type of union to union" {213test "cast tag type of union to union" {
...@@ -234,19 +234,6 @@ fn giveMeLetterB(x: Letter2) void {...@@ -234,19 +234,6 @@ fn giveMeLetterB(x: Letter2) void {
234 assert(x == Value2.B);234 assert(x == Value2.B);
235}235}
236236
237test "implicit cast from @EnumTagType(TheUnion) to &const TheUnion" {
238 assertIsTheUnion2Item1(TheUnion2.Item1);
239}
240
241const TheUnion2 = union(enum).{
242 Item1,
243 Item2: i32,
244};
245
246fn assertIsTheUnion2Item1(value: *const TheUnion2) void {
247 assert(value.* == TheUnion2.Item1);
248}
249
250pub const PackThis = union(enum).{237pub const PackThis = union(enum).{
251 Invalid: bool,238 Invalid: bool,
252 StringLiteral: u2,239 StringLiteral: u2,
test/standalone/brace_expansion/main.zig+3-3
...@@ -116,7 +116,7 @@ fn expandString(input: []const u8, output: *Buffer) !void {...@@ -116,7 +116,7 @@ fn expandString(input: []const u8, output: *Buffer) !void {
116 }116 }
117117
118 var token_index: usize = 0;118 var token_index: usize = 0;
119 const root = try parse(tokens, &token_index);119 const root = try parse(&tokens, &token_index);
120 const last_token = tokens.items[token_index];120 const last_token = tokens.items[token_index];
121 switch (last_token) {121 switch (last_token) {
122 Token.Eof => {},122 Token.Eof => {},
...@@ -139,9 +139,9 @@ fn expandString(input: []const u8, output: *Buffer) !void {...@@ -139,9 +139,9 @@ fn expandString(input: []const u8, output: *Buffer) !void {
139139
140const ExpandNodeError = error.{OutOfMemory};140const ExpandNodeError = error.{OutOfMemory};
141141
142fn expandNode(node: *const Node, output: *ArrayList(Buffer)) ExpandNodeError!void {142fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
143 assert(output.len == 0);143 assert(output.len == 0);
144 switch (node.*) {144 switch (node) {
145 Node.Scalar => |scalar| {145 Node.Scalar => |scalar| {
146 try output.append(try Buffer.init(global_allocator, scalar));146 try output.append(try Buffer.init(global_allocator, scalar));
147 },147 },
test/tests.zig+5-5
...@@ -271,7 +271,7 @@ pub const CompareOutputContext = struct.{...@@ -271,7 +271,7 @@ pub const CompareOutputContext = struct.{
271 child.stdin_behavior = StdIo.Ignore;271 child.stdin_behavior = StdIo.Ignore;
272 child.stdout_behavior = StdIo.Pipe;272 child.stdout_behavior = StdIo.Pipe;
273 child.stderr_behavior = StdIo.Pipe;273 child.stderr_behavior = StdIo.Pipe;
274 child.env_map = &b.env_map;274 child.env_map = b.env_map;
275275
276 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));276 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
277277
...@@ -347,7 +347,7 @@ pub const CompareOutputContext = struct.{...@@ -347,7 +347,7 @@ pub const CompareOutputContext = struct.{
347 const child = os.ChildProcess.init([][]u8.{full_exe_path}, b.allocator) catch unreachable;347 const child = os.ChildProcess.init([][]u8.{full_exe_path}, b.allocator) catch unreachable;
348 defer child.deinit();348 defer child.deinit();
349349
350 child.env_map = &b.env_map;350 child.env_map = b.env_map;
351 child.stdin_behavior = StdIo.Ignore;351 child.stdin_behavior = StdIo.Ignore;
352 child.stdout_behavior = StdIo.Ignore;352 child.stdout_behavior = StdIo.Ignore;
353 child.stderr_behavior = StdIo.Ignore;353 child.stderr_behavior = StdIo.Ignore;
...@@ -417,7 +417,7 @@ pub const CompareOutputContext = struct.{...@@ -417,7 +417,7 @@ pub const CompareOutputContext = struct.{
417 self.addCase(tc);417 self.addCase(tc);
418 }418 }
419419
420 pub fn addCase(self: *CompareOutputContext, case: *const TestCase) void {420 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
421 const b = self.b;421 const b = self.b;
422422
423 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;423 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
...@@ -583,7 +583,7 @@ pub const CompileErrorContext = struct.{...@@ -583,7 +583,7 @@ pub const CompileErrorContext = struct.{
583 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;583 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
584 defer child.deinit();584 defer child.deinit();
585585
586 child.env_map = &b.env_map;586 child.env_map = b.env_map;
587 child.stdin_behavior = StdIo.Ignore;587 child.stdin_behavior = StdIo.Ignore;
588 child.stdout_behavior = StdIo.Pipe;588 child.stdout_behavior = StdIo.Pipe;
589 child.stderr_behavior = StdIo.Pipe;589 child.stderr_behavior = StdIo.Pipe;
...@@ -847,7 +847,7 @@ pub const TranslateCContext = struct.{...@@ -847,7 +847,7 @@ pub const TranslateCContext = struct.{
847 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;847 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
848 defer child.deinit();848 defer child.deinit();
849849
850 child.env_map = &b.env_map;850 child.env_map = b.env_map;
851 child.stdin_behavior = StdIo.Ignore;851 child.stdin_behavior = StdIo.Ignore;
852 child.stdout_behavior = StdIo.Pipe;852 child.stdout_behavior = StdIo.Pipe;
853 child.stderr_behavior = StdIo.Pipe;853 child.stderr_behavior = StdIo.Pipe;