authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-29 18:51:04+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-30 00:09:24+03:00
log312260124279027a248d669e6096c3ab603fa188
tree6a09e77470321e38cf6687e6e6d345f8fc7c98c5
parentb3c6d774d292e6e4ddf4cd54455c4ef3c6386d66

AstGen: do not set decl_line for containers

Previously AstGen would set decl_line for containers so that declarations inside them would be relative to the start of the container but Sema was not aware of the line offset of the container and would make them relative to the containers parent decl which would then break for generic structs. In the future when working on incremental compilation it will likely be better to communicate the line delta to Sema but for now this is a simpler fix that correctly handles the non-incremental case. Closes #12725 Closes #12818

1 files changed, 4 insertions(+), 7 deletions(-)

src/AstGen.zig+4-7
...@@ -4233,13 +4233,10 @@ fn structDeclInner(...@@ -4233,13 +4233,10 @@ fn structDeclInner(
4233 // are in scope, so that field types, alignments, and default value expressions4233 // are in scope, so that field types, alignments, and default value expressions
4234 // can refer to decls within the struct itself.4234 // can refer to decls within the struct itself.
4235 astgen.advanceSourceCursorToNode(node);4235 astgen.advanceSourceCursorToNode(node);
4236 // If `node == 0` then this is the root struct and all the declarations should
4237 // be relative to the beginning of the file.
4238 const decl_line = if (node == 0) 0 else astgen.source_line;
4239 var block_scope: GenZir = .{4236 var block_scope: GenZir = .{
4240 .parent = &namespace.base,4237 .parent = &namespace.base,
4241 .decl_node_index = node,4238 .decl_node_index = node,
4242 .decl_line = decl_line,4239 .decl_line = gz.decl_line,
4243 .astgen = astgen,4240 .astgen = astgen,
4244 .force_comptime = true,4241 .force_comptime = true,
4245 .instructions = gz.instructions,4242 .instructions = gz.instructions,
...@@ -4439,7 +4436,7 @@ fn unionDeclInner(...@@ -4439,7 +4436,7 @@ fn unionDeclInner(
4439 var block_scope: GenZir = .{4436 var block_scope: GenZir = .{
4440 .parent = &namespace.base,4437 .parent = &namespace.base,
4441 .decl_node_index = node,4438 .decl_node_index = node,
4442 .decl_line = astgen.source_line,4439 .decl_line = gz.decl_line,
4443 .astgen = astgen,4440 .astgen = astgen,
4444 .force_comptime = true,4441 .force_comptime = true,
4445 .instructions = gz.instructions,4442 .instructions = gz.instructions,
...@@ -4722,7 +4719,7 @@ fn containerDecl(...@@ -4722,7 +4719,7 @@ fn containerDecl(
4722 var block_scope: GenZir = .{4719 var block_scope: GenZir = .{
4723 .parent = &namespace.base,4720 .parent = &namespace.base,
4724 .decl_node_index = node,4721 .decl_node_index = node,
4725 .decl_line = astgen.source_line,4722 .decl_line = gz.decl_line,
4726 .astgen = astgen,4723 .astgen = astgen,
4727 .force_comptime = true,4724 .force_comptime = true,
4728 .instructions = gz.instructions,4725 .instructions = gz.instructions,
...@@ -4827,7 +4824,7 @@ fn containerDecl(...@@ -4827,7 +4824,7 @@ fn containerDecl(
4827 var block_scope: GenZir = .{4824 var block_scope: GenZir = .{
4828 .parent = &namespace.base,4825 .parent = &namespace.base,
4829 .decl_node_index = node,4826 .decl_node_index = node,
4830 .decl_line = astgen.source_line,4827 .decl_line = gz.decl_line,
4831 .astgen = astgen,4828 .astgen = astgen,
4832 .force_comptime = true,4829 .force_comptime = true,
4833 .instructions = gz.instructions,4830 .instructions = gz.instructions,