| ... | ... | @@ -170,6 +170,9 @@ pub const Decl = struct { |
| 170 | 170 | /// This flag is set when this Decl is added to a check_for_deletion set, and cleared |
| 171 | 171 | /// when removed. |
| 172 | 172 | deletion_flag: bool, |
| 173 | /// Whether the corresponding AST decl has a `pub` keyword. |
| 174 | is_pub: bool, |
| 175 | |
| 173 | 176 | /// An integer that can be checked against the corresponding incrementing |
| 174 | 177 | /// generation field of Module. This is used to determine whether `complete` status |
| 175 | 178 | /// represents pre- or post- re-analysis. |
| ... | ... | @@ -290,8 +293,6 @@ pub const Fn = struct { |
| 290 | 293 | }, |
| 291 | 294 | owner_decl: *Decl, |
| 292 | 295 | |
| 293 | | is_pub: bool, |
| 294 | | |
| 295 | 296 | /// This memory is temporary and points to stack memory for the duration |
| 296 | 297 | /// of Fn analysis. |
| 297 | 298 | pub const Analysis = struct { |
| ... | ... | @@ -323,10 +324,10 @@ pub const Fn = struct { |
| 323 | 324 | }; |
| 324 | 325 | |
| 325 | 326 | pub const Var = struct { |
| 326 | | value: ?Value, |
| 327 | init: Value, |
| 327 | 328 | owner_decl: *Decl, |
| 328 | 329 | |
| 329 | | is_pub: bool, |
| 330 | has_init: bool, |
| 330 | 331 | is_extern: bool, |
| 331 | 332 | is_mutable: bool, |
| 332 | 333 | is_threadlocal: bool, |
| ... | ... | @@ -1247,7 +1248,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1247 | 1248 | }; |
| 1248 | 1249 | defer fn_type_scope.instructions.deinit(self.gpa); |
| 1249 | 1250 | |
| 1250 | | const is_pub = fn_proto.getTrailer("visib_token") != null; |
| 1251 | decl.is_pub = fn_proto.getTrailer("visib_token") != null; |
| 1251 | 1252 | const body_node = fn_proto.getTrailer("body_node") orelse |
| 1252 | 1253 | return self.failTok(&fn_type_scope.base, fn_proto.fn_token, "TODO implement extern functions", .{}); |
| 1253 | 1254 | |
| ... | ... | @@ -1385,7 +1386,6 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1385 | 1386 | new_func.* = .{ |
| 1386 | 1387 | .analysis = .{ .queued = fn_zir }, |
| 1387 | 1388 | .owner_decl = decl, |
| 1388 | | .is_pub = is_pub, |
| 1389 | 1389 | }; |
| 1390 | 1390 | fn_payload.* = .{ .func = new_func }; |
| 1391 | 1391 | |
| ... | ... | @@ -1452,7 +1452,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1452 | 1452 | }; |
| 1453 | 1453 | defer block_scope.instructions.deinit(self.gpa); |
| 1454 | 1454 | |
| 1455 | | const is_pub = var_decl.getTrailer("visib_token") != null; |
| 1455 | decl.is_pub = var_decl.getTrailer("visib_token") != null; |
| 1456 | 1456 | const is_extern = blk: { |
| 1457 | 1457 | const maybe_extern_token = var_decl.getTrailer("extern_export_token") orelse |
| 1458 | 1458 | break :blk false; |
| ... | ... | @@ -1477,7 +1477,6 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1477 | 1477 | return self.failNode(&block_scope.base, sect_expr, "TODO implement function section expression", .{}); |
| 1478 | 1478 | } |
| 1479 | 1479 | |
| 1480 | | |
| 1481 | 1480 | const explicit_type = blk: { |
| 1482 | 1481 | const type_node = var_decl.getTrailer("type_node") orelse |
| 1483 | 1482 | break :blk null; |
| ... | ... | @@ -1568,9 +1567,9 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1568 | 1567 | const new_variable = try decl_arena.allocator.create(Var); |
| 1569 | 1568 | const var_payload = try decl_arena.allocator.create(Value.Payload.Variable); |
| 1570 | 1569 | new_variable.* = .{ |
| 1571 | | .value = value, |
| 1572 | 1570 | .owner_decl = decl, |
| 1573 | | .is_pub = is_pub, |
| 1571 | .init = value orelse undefined, |
| 1572 | .has_init = value != null, |
| 1574 | 1573 | .is_extern = is_extern, |
| 1575 | 1574 | .is_mutable = is_mutable, |
| 1576 | 1575 | .is_threadlocal = is_threadlocal, |
| ... | ... | @@ -2004,6 +2003,7 @@ fn allocateNewDecl( |
| 2004 | 2003 | .wasm => .{ .wasm = null }, |
| 2005 | 2004 | }, |
| 2006 | 2005 | .generation = 0, |
| 2006 | .is_pub = false, |
| 2007 | 2007 | }; |
| 2008 | 2008 | return new_decl; |
| 2009 | 2009 | } |
| ... | ... | @@ -2440,15 +2440,15 @@ fn analyzeVarRef(self: *Module, scope: *Scope, src: usize, tv: TypedValue) Inner |
| 2440 | 2440 | const variable = tv.val.cast(Value.Payload.Variable).?.variable; |
| 2441 | 2441 | |
| 2442 | 2442 | const ty = try self.singlePtrType(scope, src, variable.is_mutable, tv.ty); |
| 2443 | | if (!variable.is_mutable and !variable.is_extern and variable.value != null) { |
| 2443 | if (!variable.is_mutable and !variable.is_extern and variable.has_init) { |
| 2444 | 2444 | const val_payload = try scope.arena().create(Value.Payload.RefVal); |
| 2445 | | val_payload.* = .{ .val = variable.value.? }; |
| 2445 | val_payload.* = .{ .val = variable.init }; |
| 2446 | 2446 | return self.constInst(scope, src, .{ |
| 2447 | 2447 | .ty = ty, |
| 2448 | 2448 | .val = Value.initPayload(&val_payload.base), |
| 2449 | 2449 | }); |
| 2450 | 2450 | } |
| 2451 | | |
| 2451 | |
| 2452 | 2452 | const b = try self.requireRuntimeBlock(scope, src); |
| 2453 | 2453 | const inst = try b.arena.create(Inst.VarPtr); |
| 2454 | 2454 | inst.* = .{ |