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 {
121121 test_step.dependOn(docs_step);
122122}
123123
124fn dependOnLib(lib_exe_obj: var, dep: *const LibraryDep) void {
124fn dependOnLib(lib_exe_obj: var, dep: LibraryDep) void {
125125 for (dep.libdirs.toSliceConst()) |lib_dir| {
126126 lib_exe_obj.addLibPath(lib_dir);
127127 }
doc/docgen.zig+3-3
......@@ -191,7 +191,7 @@ const Tokenizer = struct.{
191191 line_end: usize,
192192 };
193193
194 fn getTokenLocation(self: *Tokenizer, token: *const Token) Location {
194 fn getTokenLocation(self: *Tokenizer, token: Token) Location {
195195 var loc = Location.{
196196 .line = 0,
197197 .column = 0,
......@@ -216,7 +216,7 @@ const Tokenizer = struct.{
216216 }
217217};
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 {
220220 const loc = tokenizer.getTokenLocation(token);
221221 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
222222 if (loc.line_start <= loc.line_end) {
......@@ -239,7 +239,7 @@ fn parseError(tokenizer: *Tokenizer, token: *const Token, comptime fmt: []const
239239 return error.ParseError;
240240}
241241
242fn assertToken(tokenizer: *Tokenizer, token: *const Token, id: Token.Id) !void {
242fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void {
243243 if (token.id != id) {
244244 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
245245 }
doc/langref.html.in+3-6
......@@ -1905,7 +1905,7 @@ const Vec3 = struct.{
19051905 };
19061906 }
19071907
1908 pub fn dot(self: *const Vec3, other: *const Vec3) f32 {
1908 pub fn dot(self: Vec3, other: Vec3) f32 {
19091909 return self.x * other.x + self.y * other.y + self.z * other.z;
19101910 }
19111911};
......@@ -2243,8 +2243,8 @@ const Variant = union(enum).{
22432243 Int: i32,
22442244 Bool: bool,
22452245
2246 fn truthy(self: *const Variant) bool {
2247 return switch (self.*) {
2246 fn truthy(self: Variant) bool {
2247 return switch (self) {
22482248 Variant.Int => |x_int| x_int != 0,
22492249 Variant.Bool => |x_bool| x_bool,
22502250 };
......@@ -4040,9 +4040,6 @@ test "float widening" {
40404040 {#header_open|Implicit Cast: undefined#}
40414041 <p>TODO</p>
40424042 {#header_close#}
4043 {#header_open|Implicit Cast: T to *const T#}
4044 <p>TODO</p>
4045 {#header_close#}
40464043 {#header_close#}
40474044
40484045 {#header_open|Explicit Casts#}
src-self-hosted/main.zig+1-1
......@@ -658,7 +658,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
658658 const main_handle = try async<allocator> asyncFmtMainChecked(
659659 &result,
660660 &loop,
661 flags,
661 &flags,
662662 color,
663663 );
664664 defer cancel main_handle;
src/ir.cpp-48
......@@ -9758,46 +9758,6 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
97589758 return result;
97599759}
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
98019761static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
98029762 assert(wanted_type->id == ZigTypeIdOptional);
98039763 assert(instr_is_comptime(value));
......@@ -10929,14 +10889,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1092910889 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
1093010890 }
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
1094010892 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
1094110893 buf_sprintf("expected type '%s', found '%s'",
1094210894 buf_ptr(&wanted_type->name),
std/buffer.zig+2-2
......@@ -32,7 +32,7 @@ pub const Buffer = struct.{
3232 }
3333
3434 /// Must deinitialize with deinit.
35 pub fn initFromBuffer(buffer: *const Buffer) !Buffer {
35 pub fn initFromBuffer(buffer: Buffer) !Buffer {
3636 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
3737 }
3838
......@@ -148,7 +148,7 @@ test "simple Buffer" {
148148 assert(buf.eql("hello world"));
149149 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);
152152 assert(buf.eql(buf2.toSliceConst()));
153153
154154 assert(buf.startsWith("hell"));
std/build.zig+13-11
......@@ -37,7 +37,7 @@ pub const Builder = struct.{
3737 invalid_user_input: bool,
3838 zig_exe: []const u8,
3939 default_step: *Step,
40 env_map: BufMap,
40 env_map: *const BufMap,
4141 top_level_steps: ArrayList(*TopLevelStep),
4242 prefix: []const u8,
4343 search_prefixes: ArrayList([]const u8),
......@@ -89,6 +89,8 @@ pub const Builder = struct.{
8989 };
9090
9191 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;
9294 var self = Builder.{
9395 .zig_exe = zig_exe,
9496 .build_root = build_root,
......@@ -110,7 +112,7 @@ pub const Builder = struct.{
110112 .available_options_list = ArrayList(AvailableOption).init(allocator),
111113 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
112114 .default_step = undefined,
113 .env_map = os.getEnvMap(allocator) catch unreachable,
115 .env_map = env_map,
114116 .prefix = undefined,
115117 .search_prefixes = ArrayList([]const u8).init(allocator),
116118 .lib_dir = undefined,
......@@ -155,7 +157,7 @@ pub const Builder = struct.{
155157 return LibExeObjStep.createObject(self, name, root_src);
156158 }
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 {
159161 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);
160162 }
161163
......@@ -178,7 +180,7 @@ pub const Builder = struct.{
178180 return LibExeObjStep.createCStaticLibrary(self, name);
179181 }
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 {
182184 return LibExeObjStep.createCSharedLibrary(self, name, ver);
183185 }
184186
......@@ -541,7 +543,7 @@ pub const Builder = struct.{
541543 }
542544
543545 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);
545547 }
546548
547549 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
......@@ -850,12 +852,12 @@ pub const LibExeObjStep = struct.{
850852 Obj,
851853 };
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 {
854856 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable;
855857 return self;
856858 }
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 {
859861 const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable;
860862 return self;
861863 }
......@@ -891,7 +893,7 @@ pub const LibExeObjStep = struct.{
891893 return self;
892894 }
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 {
895897 var self = LibExeObjStep.{
896898 .no_rosegment = false,
897899 .strip = false,
......@@ -909,7 +911,7 @@ pub const LibExeObjStep = struct.{
909911 .step = Step.init(name, builder.allocator, make),
910912 .output_path = null,
911913 .output_h_path = null,
912 .version = ver.*,
914 .version = ver,
913915 .out_filename = undefined,
914916 .out_h_filename = builder.fmt("{}.h", name),
915917 .major_only_filename = undefined,
......@@ -933,13 +935,13 @@ pub const LibExeObjStep = struct.{
933935 return self;
934936 }
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 {
937939 var self = LibExeObjStep.{
938940 .no_rosegment = false,
939941 .builder = builder,
940942 .name = name,
941943 .kind = kind,
942 .version = version.*,
944 .version = version,
943945 .static = static,
944946 .target = Target.Native,
945947 .cflags = ArrayList([]const u8).init(builder.allocator),
std/debug/index.zig+1-1
......@@ -976,7 +976,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {
976976 };
977977}
978978
979fn printLineFromFile(out_stream: var, line_info: *const LineInfo) !void {
979fn printLineFromFile(out_stream: var, line_info: LineInfo) !void {
980980 var f = try os.File.openRead(line_info.file_name);
981981 defer f.close();
982982 // 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;
88const Loop = std.event.Loop;
99
1010pub 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
1313 loop: *Loop,
1414 sockfd: ?i32,
......@@ -40,7 +40,7 @@ pub const Server = struct.{
4040 pub fn listen(
4141 self: *Server,
4242 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,
4444 ) !void {
4545 self.handleRequestFn = handleRequestFn;
4646
......@@ -82,7 +82,7 @@ pub const Server = struct.{
8282 continue;
8383 }
8484 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) {
8686 error.OutOfMemory => {
8787 socket.close();
8888 continue;
......@@ -278,9 +278,9 @@ test "listen on a port, send bytes, receive bytes" {
278278 tcp_server: Server,
279279
280280 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 {
282282 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
283 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/1592
283 var socket = _socket; // TODO https://github.com/ziglang/zig/issues/1592
284284 defer socket.close();
285285 // TODO guarantee elision of this allocation
286286 const next_handler = async errorableHandler(self, _addr, socket) catch unreachable;
......@@ -307,9 +307,9 @@ test "listen on a port, send bytes, receive bytes" {
307307 try loop.initSingleThreaded(std.debug.global_allocator);
308308 var server = MyServer.{ .tcp_server = Server.init(&loop) };
309309 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);
313313 defer cancel p;
314314 loop.run();
315315}
std/fmt/errol/index.zig+1-1
......@@ -217,7 +217,7 @@ fn tableLowerBound(k: u64) usize {
217217/// @in: The HP number.
218218/// @val: The double.
219219/// &returns: The HP number.
220fn hpProd(in: *const HP, val: f64) HP {
220fn hpProd(in: HP, val: f64) HP {
221221 var hi: f64 = undefined;
222222 var lo: f64 = undefined;
223223 split(in.val, &hi, &lo);
std/json.zig+12-12
......@@ -74,7 +74,7 @@ pub const Token = struct.{
7474 }
7575
7676 // 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 {
7878 return input[i + self.offset - self.count .. i + self.offset];
7979 }
8080};
......@@ -1008,8 +1008,8 @@ pub const Value = union(enum).{
10081008 Array: ArrayList(Value),
10091009 Object: ObjectMap,
10101010
1011 pub fn dump(self: *const Value) void {
1012 switch (self.*) {
1011 pub fn dump(self: Value) void {
1012 switch (self) {
10131013 Value.Null => {
10141014 debug.warn("null");
10151015 },
......@@ -1055,7 +1055,7 @@ pub const Value = union(enum).{
10551055 }
10561056 }
10571057
1058 pub fn dumpIndent(self: *const Value, indent: usize) void {
1058 pub fn dumpIndent(self: Value, indent: usize) void {
10591059 if (indent == 0) {
10601060 self.dump();
10611061 } else {
......@@ -1063,8 +1063,8 @@ pub const Value = union(enum).{
10631063 }
10641064 }
10651065
1066 fn dumpIndentLevel(self: *const Value, indent: usize, level: usize) void {
1067 switch (self.*) {
1066 fn dumpIndentLevel(self: Value, indent: usize, level: usize) void {
1067 switch (self) {
10681068 Value.Null => {
10691069 debug.warn("null");
10701070 },
......@@ -1178,7 +1178,7 @@ pub const Parser = struct.{
11781178
11791179 // Even though p.allocator exists, we take an explicit allocator so that allocation state
11801180 // 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 {
11821182 switch (p.state) {
11831183 State.ObjectKey => switch (token.id) {
11841184 Token.Id.ObjectEnd => {
......@@ -1311,19 +1311,19 @@ pub const Parser = struct.{
13111311 }
13121312 }
13131313
1314 fn pushToParent(p: *Parser, value: *const Value) !void {
1314 fn pushToParent(p: *Parser, value: Value) !void {
13151315 switch (p.stack.at(p.stack.len - 1)) {
13161316 // Object Parent -> [ ..., object, <key>, value ]
13171317 Value.String => |key| {
13181318 _ = p.stack.pop();
13191319
13201320 var object = &p.stack.items[p.stack.len - 1].Object;
1321 _ = try object.put(key, value.*);
1321 _ = try object.put(key, value);
13221322 p.state = State.ObjectKey;
13231323 },
13241324 // Array Parent -> [ ..., <array>, value ]
13251325 Value.Array => |*array| {
1326 try array.append(value.*);
1326 try array.append(value);
13271327 p.state = State.ArrayValue;
13281328 },
13291329 else => {
......@@ -1332,14 +1332,14 @@ pub const Parser = struct.{
13321332 }
13331333 }
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 {
13361336 // TODO: We don't strictly have to copy values which do not contain any escape
13371337 // characters if flagged with the option.
13381338 const slice = token.slice(input, i);
13391339 return Value.{ .String = try mem.dupe(p.allocator, u8, slice) };
13401340 }
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 {
13431343 return if (token.number_is_integer)
13441344 Value.{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
13451345 else
std/math/complex/cosh.zig+2-2
......@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {
1515 };
1616}
1717
18fn cosh32(z: *const Complex(f32)) Complex(f32) {
18fn cosh32(z: Complex(f32)) Complex(f32) {
1919 const x = z.re;
2020 const y = z.im;
2121
......@@ -78,7 +78,7 @@ fn cosh32(z: *const Complex(f32)) Complex(f32) {
7878 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
7979}
8080
81fn cosh64(z: *const Complex(f64)) Complex(f64) {
81fn cosh64(z: Complex(f64)) Complex(f64) {
8282 const x = z.re;
8383 const y = z.im;
8484
std/math/complex/pow.zig+1-1
......@@ -4,7 +4,7 @@ const math = std.math;
44const cmath = math.complex;
55const 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 {
88 const p = cmath.log(z);
99 const q = c.mul(p);
1010 return cmath.exp(q);
std/net.zig+2-2
......@@ -46,8 +46,8 @@ pub const Address = struct.{
4646 };
4747 }
4848
49 pub fn initPosix(addr: *const posix.sockaddr) Address {
50 return Address.{ .os_addr = addr.* };
49 pub fn initPosix(addr: posix.sockaddr) Address {
50 return Address.{ .os_addr = addr };
5151 }
5252
5353 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 {
777777 return fds;
778778}
779779
780fn destroyPipe(pipe: *const [2]i32) void {
781 os.close((pipe.*)[0]);
782 os.close((pipe.*)[1]);
780fn destroyPipe(pipe: [2]i32) void {
781 os.close(pipe[0]);
782 os.close(pipe[1]);
783783}
784784
785785// 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
122122 return self.uncheckedAt(i);
123123 }
124124
125 pub fn count(self: *const Self) usize {
125 pub fn count(self: Self) usize {
126126 return self.len;
127127 }
128128
129 pub fn push(self: *Self, item: *const T) !void {
129 pub fn push(self: *Self, item: T) !void {
130130 const new_item_ptr = try self.addOne();
131 new_item_ptr.* = item.*;
131 new_item_ptr.* = item;
132132 }
133133
134134 pub fn pushMany(self: *Self, items: []const T) !void {
std/zig/ast.zig+3-3
......@@ -400,7 +400,7 @@ pub const Node = struct.{
400400 Id.While => {
401401 const while_node = @fieldParentPtr(While, "base", n);
402402 if (while_node.@"else") |@"else"| {
403 n = @"else".base;
403 n = &@"else".base;
404404 continue;
405405 }
406406
......@@ -409,7 +409,7 @@ pub const Node = struct.{
409409 Id.For => {
410410 const for_node = @fieldParentPtr(For, "base", n);
411411 if (for_node.@"else") |@"else"| {
412 n = @"else".base;
412 n = &@"else".base;
413413 continue;
414414 }
415415
......@@ -418,7 +418,7 @@ pub const Node = struct.{
418418 Id.If => {
419419 const if_node = @fieldParentPtr(If, "base", n);
420420 if (if_node.@"else") |@"else"| {
421 n = @"else".base;
421 n = &@"else".base;
422422 continue;
423423 }
424424
std/zig/parse.zig+16-16
......@@ -1848,7 +1848,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18481848 continue;
18491849 },
18501850 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)) {
18521852 prevToken(&tok_it, &tree);
18531853 stack.append(State.{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
18541854 }
......@@ -2665,7 +2665,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
26652665 continue;
26662666 },
26672667 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)) {
26692669 prevToken(&tok_it, &tree);
26702670 if (opt_ctx != OptionalCtx.Optional) {
26712671 try tree.errors.push(Error.{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr.{ .token = token.index } });
......@@ -2949,29 +2949,29 @@ const OptionalCtx = union(enum).{
29492949 RequiredNull: *?*ast.Node,
29502950 Required: **ast.Node,
29512951
2952 pub fn store(self: *const OptionalCtx, value: *ast.Node) void {
2953 switch (self.*) {
2952 pub fn store(self: OptionalCtx, value: *ast.Node) void {
2953 switch (self) {
29542954 OptionalCtx.Optional => |ptr| ptr.* = value,
29552955 OptionalCtx.RequiredNull => |ptr| ptr.* = value,
29562956 OptionalCtx.Required => |ptr| ptr.* = value,
29572957 }
29582958 }
29592959
2960 pub fn get(self: *const OptionalCtx) ?*ast.Node {
2961 switch (self.*) {
2960 pub fn get(self: OptionalCtx) ?*ast.Node {
2961 switch (self) {
29622962 OptionalCtx.Optional => |ptr| return ptr.*,
29632963 OptionalCtx.RequiredNull => |ptr| return ptr.*.?,
29642964 OptionalCtx.Required => |ptr| return ptr.*,
29652965 }
29662966 }
29672967
2968 pub fn toRequired(self: *const OptionalCtx) OptionalCtx {
2969 switch (self.*) {
2968 pub fn toRequired(self: OptionalCtx) OptionalCtx {
2969 switch (self) {
29702970 OptionalCtx.Optional => |ptr| {
29712971 return OptionalCtx.{ .RequiredNull = ptr };
29722972 },
2973 OptionalCtx.RequiredNull => |ptr| return self.*,
2974 OptionalCtx.Required => |ptr| return self.*,
2973 OptionalCtx.RequiredNull => |ptr| return self,
2974 OptionalCtx.Required => |ptr| return self,
29752975 }
29762976 }
29772977};
......@@ -3161,7 +3161,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
31613161 }
31623162}
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 {
31653165 switch (token_ptr.id) {
31663166 Token.Id.Keyword_suspend => {
31673167 const node = try arena.create(ast.Node.Suspend.{
......@@ -3199,7 +3199,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
31993199 .label = null,
32003200 .inline_token = null,
32013201 .loop_token = token_index,
3202 .opt_ctx = ctx.*,
3202 .opt_ctx = ctx,
32033203 },
32043204 }) catch unreachable;
32053205 return true;
......@@ -3210,7 +3210,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
32103210 .label = null,
32113211 .inline_token = null,
32123212 .loop_token = token_index,
3213 .opt_ctx = ctx.*,
3213 .opt_ctx = ctx,
32143214 },
32153215 }) catch unreachable;
32163216 return true;
......@@ -3295,10 +3295,10 @@ fn expectCommaOrEnd(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, end:
32953295 }
32963296}
32973297
3298fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
3298fn tokenIdToAssignment(id: Token.Id) ?ast.Node.InfixOp.Op {
32993299 // TODO: We have to cast all cases because of this:
33003300 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'
3301 return switch (id.*) {
3301 return switch (id) {
33023302 Token.Id.AmpersandEqual => ast.Node.InfixOp.Op.{ .AssignBitAnd = {} },
33033303 Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftLeft = {} },
33043304 Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op.{ .AssignBitShiftRight = {} },
......@@ -3396,7 +3396,7 @@ fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenInde
33963396 });
33973397}
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 {
34003400 const node = try createLiteral(arena, T, token_index);
34013401 opt_ctx.store(&node.base);
34023402
test/cases/bugs/655.zig+2-2
......@@ -1,10 +1,10 @@
11const std = @import("std");
22const 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" {
55 const x: other_file.Integer = 1234;
66 comptime std.debug.assert(@typeOf(&x) == *const other_file.Integer);
7 foo(x);
7 foo(&x);
88}
99
1010fn foo(x: *const other_file.Integer) void {
test/cases/cast.zig-96
......@@ -22,88 +22,6 @@ test "pointer reinterpret const float to int" {
2222 assert(int_val == 858993411);
2323}
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
10725test "implicitly cast indirect pointer to maybe-indirect pointer" {
10826 const S = struct.{
10927 const Self = @This();
......@@ -125,13 +43,9 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
12543 const p = &s;
12644 const q = &p;
12745 const r = &q;
128 assert(42 == S.constConst(p));
12946 assert(42 == S.constConst(q));
130 assert(42 == S.maybeConstConst(p));
13147 assert(42 == S.maybeConstConst(q));
132 assert(42 == S.constConstConst(q));
13348 assert(42 == S.constConstConst(r));
134 assert(42 == S.maybeConstConstConst(q));
13549 assert(42 == S.maybeConstConstConst(r));
13650}
13751
......@@ -166,16 +80,6 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
16680 assert(mem.eql(u8, value2, "zz"));
16781}
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
17983test "implicitly cast from T to error!?T" {
18084 castToOptionalTypeError(1);
18185 comptime castToOptionalTypeError(1);
test/cases/enum.zig+4-4
......@@ -56,15 +56,15 @@ test "constant enum with payload" {
5656 shouldBeNotEmpty(full);
5757}
5858
59fn shouldBeEmpty(x: *const AnEnumWithPayload) void {
60 switch (x.*) {
59fn shouldBeEmpty(x: AnEnumWithPayload) void {
60 switch (x) {
6161 AnEnumWithPayload.Empty => {},
6262 else => unreachable,
6363 }
6464}
6565
66fn shouldBeNotEmpty(x: *const AnEnumWithPayload) void {
67 switch (x.*) {
66fn shouldBeNotEmpty(x: AnEnumWithPayload) void {
67 switch (x) {
6868 AnEnumWithPayload.Empty => unreachable,
6969 else => {},
7070 }
test/cases/incomplete_struct_param_tld.zig+1-1
......@@ -16,7 +16,7 @@ const C = struct.{
1616 }
1717};
1818
19fn foo(a: *const A) i32 {
19fn foo(a: A) i32 {
2020 return a.b.c.d();
2121}
2222
test/cases/misc.zig+6-6
......@@ -353,8 +353,8 @@ const test3_foo = Test3Foo.{
353353 },
354354};
355355const test3_bar = Test3Foo.{ .Two = 13 };
356fn test3_1(f: *const Test3Foo) void {
357 switch (f.*) {
356fn test3_1(f: Test3Foo) void {
357 switch (f) {
358358 Test3Foo.Three => |pt| {
359359 assert(pt.x == 3);
360360 assert(pt.y == 4);
......@@ -362,8 +362,8 @@ fn test3_1(f: *const Test3Foo) void {
362362 else => unreachable,
363363 }
364364}
365fn test3_2(f: *const Test3Foo) void {
366 switch (f.*) {
365fn test3_2(f: Test3Foo) void {
366 switch (f) {
367367 Test3Foo.Two => |x| {
368368 assert(x == 13);
369369 },
......@@ -672,10 +672,10 @@ const PackedEnum = packed enum.{
672672};
673673
674674test "packed struct, enum, union parameters in extern function" {
675 testPackedStuff(PackedStruct.{
675 testPackedStuff(&(PackedStruct.{
676676 .a = 1,
677677 .b = 2,
678 }, PackedUnion.{ .a = 1 }, PackedEnum.A);
678 }), &(PackedUnion.{ .a = 1 }), PackedEnum.A);
679679}
680680
681681export 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" {
6565 .d = 1,
6666 }) == 15);
6767}
68fn shouldBeAPlus1(p: *const Particle) u64 {
69 var maybe_particle: ?Particle = p.*;
68fn shouldBeAPlus1(p: Particle) u64 {
69 var maybe_particle: ?Particle = p;
7070 if (maybe_particle) |*particle| {
7171 particle.a += 1;
7272 }
test/cases/struct.zig+5-5
......@@ -55,7 +55,7 @@ const StructFoo = struct.{
5555 b: bool,
5656 c: f32,
5757};
58fn testFoo(foo: *const StructFoo) void {
58fn testFoo(foo: StructFoo) void {
5959 assert(foo.b);
6060}
6161fn testMutation(foo: *StructFoo) void {
......@@ -112,7 +112,7 @@ fn aFunc() i32 {
112112 return 13;
113113}
114114
115fn callStructField(foo: *const Foo) i32 {
115fn callStructField(foo: Foo) i32 {
116116 return foo.ptr();
117117}
118118
......@@ -124,7 +124,7 @@ test "store member function in variable" {
124124}
125125const MemberFnTestFoo = struct.{
126126 x: i32,
127 fn member(foo: *const MemberFnTestFoo) i32 {
127 fn member(foo: MemberFnTestFoo) i32 {
128128 return foo.x;
129129 }
130130};
......@@ -443,8 +443,8 @@ test "implicit cast packed struct field to const ptr" {
443443 move_id: u9,
444444 level: u7,
445445
446 fn toInt(value: *const u7) u7 {
447 return value.*;
446 fn toInt(value: u7) u7 {
447 return value;
448448 }
449449 };
450450
test/cases/switch.zig+2-2
......@@ -90,8 +90,8 @@ const SwitchProngWithVarEnum = union(enum).{
9090 Two: f32,
9191 Meh: void,
9292};
93fn switchProngWithVarFn(a: *const SwitchProngWithVarEnum) void {
94 switch (a.*) {
93fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
94 switch (a) {
9595 SwitchProngWithVarEnum.One => |x| {
9696 assert(x == 13);
9797 },
test/cases/union.zig+8-21
......@@ -108,9 +108,9 @@ fn doTest() void {
108108 assert(bar(Payload.{ .A = 1234 }) == -10);
109109}
110110
111fn bar(value: *const Payload) i32 {
112 assert(Letter(value.*) == Letter.A);
113 return switch (value.*) {
111fn bar(value: Payload) i32 {
112 assert(Letter(value) == Letter.A);
113 return switch (value) {
114114 Payload.A => |x| return x - 1244,
115115 Payload.B => |x| if (x == 12.34) i32(20) else 21,
116116 Payload.C => |x| if (x) i32(30) else 31,
......@@ -147,9 +147,9 @@ test "union(enum(u32)) with specified and unspecified tag values" {
147147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.{ .C = 123 });
148148}
149149
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {
151 assert(@enumToInt(@TagType(MultipleChoice2)(x.*)) == 60);
152 assert(1123 == switch (x.*) {
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
151 assert(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 assert(1123 == switch (x) {
153153 MultipleChoice2.A => 1,
154154 MultipleChoice2.B => 2,
155155 MultipleChoice2.C => |v| i32(1000) + v,
......@@ -206,8 +206,8 @@ test "cast union to tag type of union" {
206206 comptime testCastUnionToTagType(TheUnion.{ .B = 1234 });
207207}
208208
209fn testCastUnionToTagType(x: *const TheUnion) void {
210 assert(TheTag(x.*) == TheTag.B);
209fn testCastUnionToTagType(x: TheUnion) void {
210 assert(TheTag(x) == TheTag.B);
211211}
212212
213213test "cast tag type of union to union" {
......@@ -234,19 +234,6 @@ fn giveMeLetterB(x: Letter2) void {
234234 assert(x == Value2.B);
235235}
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
250237pub const PackThis = union(enum).{
251238 Invalid: bool,
252239 StringLiteral: u2,
test/standalone/brace_expansion/main.zig+3-3
......@@ -116,7 +116,7 @@ fn expandString(input: []const u8, output: *Buffer) !void {
116116 }
117117
118118 var token_index: usize = 0;
119 const root = try parse(tokens, &token_index);
119 const root = try parse(&tokens, &token_index);
120120 const last_token = tokens.items[token_index];
121121 switch (last_token) {
122122 Token.Eof => {},
......@@ -139,9 +139,9 @@ fn expandString(input: []const u8, output: *Buffer) !void {
139139
140140const ExpandNodeError = error.{OutOfMemory};
141141
142fn expandNode(node: *const Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
142fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
143143 assert(output.len == 0);
144 switch (node.*) {
144 switch (node) {
145145 Node.Scalar => |scalar| {
146146 try output.append(try Buffer.init(global_allocator, scalar));
147147 },
test/tests.zig+5-5
......@@ -271,7 +271,7 @@ pub const CompareOutputContext = struct.{
271271 child.stdin_behavior = StdIo.Ignore;
272272 child.stdout_behavior = StdIo.Pipe;
273273 child.stderr_behavior = StdIo.Pipe;
274 child.env_map = &b.env_map;
274 child.env_map = b.env_map;
275275
276276 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
277277
......@@ -347,7 +347,7 @@ pub const CompareOutputContext = struct.{
347347 const child = os.ChildProcess.init([][]u8.{full_exe_path}, b.allocator) catch unreachable;
348348 defer child.deinit();
349349
350 child.env_map = &b.env_map;
350 child.env_map = b.env_map;
351351 child.stdin_behavior = StdIo.Ignore;
352352 child.stdout_behavior = StdIo.Ignore;
353353 child.stderr_behavior = StdIo.Ignore;
......@@ -417,7 +417,7 @@ pub const CompareOutputContext = struct.{
417417 self.addCase(tc);
418418 }
419419
420 pub fn addCase(self: *CompareOutputContext, case: *const TestCase) void {
420 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
421421 const b = self.b;
422422
423423 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.{
583583 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
584584 defer child.deinit();
585585
586 child.env_map = &b.env_map;
586 child.env_map = b.env_map;
587587 child.stdin_behavior = StdIo.Ignore;
588588 child.stdout_behavior = StdIo.Pipe;
589589 child.stderr_behavior = StdIo.Pipe;
......@@ -847,7 +847,7 @@ pub const TranslateCContext = struct.{
847847 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
848848 defer child.deinit();
849849
850 child.env_map = &b.env_map;
850 child.env_map = b.env_map;
851851 child.stdin_behavior = StdIo.Ignore;
852852 child.stdout_behavior = StdIo.Pipe;
853853 child.stderr_behavior = StdIo.Pipe;