Skip to content

Commit d7049fc

Browse files
authored
Merge pull request #7920 from ziglang/ast-memory-layout
Rework AST memory layout for better memory usage and performance
2 parents 8b94348 + 9ada763 commit d7049fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+20800
-16573
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ set(ZIG_STAGE2_SOURCES
370370
"${CMAKE_SOURCE_DIR}/lib/std/heap.zig"
371371
"${CMAKE_SOURCE_DIR}/lib/std/heap/arena_allocator.zig"
372372
"${CMAKE_SOURCE_DIR}/lib/std/io.zig"
373-
"${CMAKE_SOURCE_DIR}/lib/std/io/auto_indenting_stream.zig"
374373
"${CMAKE_SOURCE_DIR}/lib/std/io/buffered_atomic_file.zig"
375374
"${CMAKE_SOURCE_DIR}/lib/std/io/buffered_writer.zig"
376375
"${CMAKE_SOURCE_DIR}/lib/std/io/change_detection_stream.zig"
@@ -408,6 +407,7 @@ set(ZIG_STAGE2_SOURCES
408407
"${CMAKE_SOURCE_DIR}/lib/std/meta.zig"
409408
"${CMAKE_SOURCE_DIR}/lib/std/meta/trailer_flags.zig"
410409
"${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
410+
"${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
411411
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
412412
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
413413
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
@@ -573,6 +573,7 @@ set(ZIG_STAGE2_SOURCES
573573
"${CMAKE_SOURCE_DIR}/src/target.zig"
574574
"${CMAKE_SOURCE_DIR}/src/tracy.zig"
575575
"${CMAKE_SOURCE_DIR}/src/translate_c.zig"
576+
"${CMAKE_SOURCE_DIR}/src/translate_c/ast.zig"
576577
"${CMAKE_SOURCE_DIR}/src/type.zig"
577578
"${CMAKE_SOURCE_DIR}/src/value.zig"
578579
"${CMAKE_SOURCE_DIR}/src/windows_sdk.zig"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A general-purpose programming language and toolchain for maintaining
55

66
## Resources
77

8-
* [Introduction](https://ziglang.org/#Introduction)
8+
* [Introduction](https://ziglang.org/learn/#introduction)
99
* [Download & Documentation](https://ziglang.org/download)
1010
* [Chapter 0 - Getting Started | ZigLearn.org](https://ziglearn.org/)
1111
* [Community](https://github.com/ziglang/zig/wiki/Community)

build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ pub fn build(b: *Builder) !void {
7777

7878
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
7979
const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
80+
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
8081

8182
const main_file = if (is_stage1) "src/stage1.zig" else "src/main.zig";
8283

8384
var exe = b.addExecutable("zig", main_file);
85+
exe.strip = strip;
8486
exe.install();
8587
exe.setBuildMode(mode);
8688
exe.setTarget(target);

doc/docgen.zig

Lines changed: 134 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -781,106 +781,119 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
781781
next_tok_is_fn = false;
782782

783783
const token = tokenizer.next();
784+
if (mem.indexOf(u8, src[index..token.loc.start], "//")) |comment_start_off| {
785+
// render one comment
786+
const comment_start = index + comment_start_off;
787+
const comment_end_off = mem.indexOf(u8, src[comment_start .. token.loc.start], "\n");
788+
const comment_end = if (comment_end_off) |o| comment_start + o else token.loc.start;
789+
790+
try writeEscaped(out, src[index..comment_start]);
791+
try out.writeAll("<span class=\"tok-comment\">");
792+
try writeEscaped(out, src[comment_start .. comment_end]);
793+
try out.writeAll("</span>");
794+
index = comment_end;
795+
tokenizer.index = index;
796+
continue;
797+
}
798+
784799
try writeEscaped(out, src[index..token.loc.start]);
785-
switch (token.id) {
786-
.Eof => break,
787-
788-
.Keyword_align,
789-
.Keyword_and,
790-
.Keyword_asm,
791-
.Keyword_async,
792-
.Keyword_await,
793-
.Keyword_break,
794-
.Keyword_catch,
795-
.Keyword_comptime,
796-
.Keyword_const,
797-
.Keyword_continue,
798-
.Keyword_defer,
799-
.Keyword_else,
800-
.Keyword_enum,
801-
.Keyword_errdefer,
802-
.Keyword_error,
803-
.Keyword_export,
804-
.Keyword_extern,
805-
.Keyword_for,
806-
.Keyword_if,
807-
.Keyword_inline,
808-
.Keyword_noalias,
809-
.Keyword_noinline,
810-
.Keyword_nosuspend,
811-
.Keyword_opaque,
812-
.Keyword_or,
813-
.Keyword_orelse,
814-
.Keyword_packed,
815-
.Keyword_anyframe,
816-
.Keyword_pub,
817-
.Keyword_resume,
818-
.Keyword_return,
819-
.Keyword_linksection,
820-
.Keyword_callconv,
821-
.Keyword_struct,
822-
.Keyword_suspend,
823-
.Keyword_switch,
824-
.Keyword_test,
825-
.Keyword_threadlocal,
826-
.Keyword_try,
827-
.Keyword_union,
828-
.Keyword_unreachable,
829-
.Keyword_usingnamespace,
830-
.Keyword_var,
831-
.Keyword_volatile,
832-
.Keyword_allowzero,
833-
.Keyword_while,
834-
.Keyword_anytype,
800+
switch (token.tag) {
801+
.eof => break,
802+
803+
.keyword_align,
804+
.keyword_and,
805+
.keyword_asm,
806+
.keyword_async,
807+
.keyword_await,
808+
.keyword_break,
809+
.keyword_catch,
810+
.keyword_comptime,
811+
.keyword_const,
812+
.keyword_continue,
813+
.keyword_defer,
814+
.keyword_else,
815+
.keyword_enum,
816+
.keyword_errdefer,
817+
.keyword_error,
818+
.keyword_export,
819+
.keyword_extern,
820+
.keyword_for,
821+
.keyword_if,
822+
.keyword_inline,
823+
.keyword_noalias,
824+
.keyword_noinline,
825+
.keyword_nosuspend,
826+
.keyword_opaque,
827+
.keyword_or,
828+
.keyword_orelse,
829+
.keyword_packed,
830+
.keyword_anyframe,
831+
.keyword_pub,
832+
.keyword_resume,
833+
.keyword_return,
834+
.keyword_linksection,
835+
.keyword_callconv,
836+
.keyword_struct,
837+
.keyword_suspend,
838+
.keyword_switch,
839+
.keyword_test,
840+
.keyword_threadlocal,
841+
.keyword_try,
842+
.keyword_union,
843+
.keyword_unreachable,
844+
.keyword_usingnamespace,
845+
.keyword_var,
846+
.keyword_volatile,
847+
.keyword_allowzero,
848+
.keyword_while,
849+
.keyword_anytype,
835850
=> {
836851
try out.writeAll("<span class=\"tok-kw\">");
837852
try writeEscaped(out, src[token.loc.start..token.loc.end]);
838853
try out.writeAll("</span>");
839854
},
840855

841-
.Keyword_fn => {
856+
.keyword_fn => {
842857
try out.writeAll("<span class=\"tok-kw\">");
843858
try writeEscaped(out, src[token.loc.start..token.loc.end]);
844859
try out.writeAll("</span>");
845860
next_tok_is_fn = true;
846861
},
847862

848-
.Keyword_undefined,
849-
.Keyword_null,
850-
.Keyword_true,
851-
.Keyword_false,
863+
.keyword_undefined,
864+
.keyword_null,
865+
.keyword_true,
866+
.keyword_false,
852867
=> {
853868
try out.writeAll("<span class=\"tok-null\">");
854869
try writeEscaped(out, src[token.loc.start..token.loc.end]);
855870
try out.writeAll("</span>");
856871
},
857872

858-
.StringLiteral,
859-
.MultilineStringLiteralLine,
860-
.CharLiteral,
873+
.string_literal,
874+
.multiline_string_literal_line,
875+
.char_literal,
861876
=> {
862877
try out.writeAll("<span class=\"tok-str\">");
863878
try writeEscaped(out, src[token.loc.start..token.loc.end]);
864879
try out.writeAll("</span>");
865880
},
866881

867-
.Builtin => {
882+
.builtin => {
868883
try out.writeAll("<span class=\"tok-builtin\">");
869884
try writeEscaped(out, src[token.loc.start..token.loc.end]);
870885
try out.writeAll("</span>");
871886
},
872887

873-
.LineComment,
874-
.DocComment,
875-
.ContainerDocComment,
876-
.ShebangLine,
888+
.doc_comment,
889+
.container_doc_comment,
877890
=> {
878891
try out.writeAll("<span class=\"tok-comment\">");
879892
try writeEscaped(out, src[token.loc.start..token.loc.end]);
880893
try out.writeAll("</span>");
881894
},
882895

883-
.Identifier => {
896+
.identifier => {
884897
if (prev_tok_was_fn) {
885898
try out.writeAll("<span class=\"tok-fn\">");
886899
try writeEscaped(out, src[token.loc.start..token.loc.end]);
@@ -908,71 +921,71 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
908921
}
909922
},
910923

911-
.IntegerLiteral,
912-
.FloatLiteral,
924+
.integer_literal,
925+
.float_literal,
913926
=> {
914927
try out.writeAll("<span class=\"tok-number\">");
915928
try writeEscaped(out, src[token.loc.start..token.loc.end]);
916929
try out.writeAll("</span>");
917930
},
918931

919-
.Bang,
920-
.Pipe,
921-
.PipePipe,
922-
.PipeEqual,
923-
.Equal,
924-
.EqualEqual,
925-
.EqualAngleBracketRight,
926-
.BangEqual,
927-
.LParen,
928-
.RParen,
929-
.Semicolon,
930-
.Percent,
931-
.PercentEqual,
932-
.LBrace,
933-
.RBrace,
934-
.LBracket,
935-
.RBracket,
936-
.Period,
937-
.PeriodAsterisk,
938-
.Ellipsis2,
939-
.Ellipsis3,
940-
.Caret,
941-
.CaretEqual,
942-
.Plus,
943-
.PlusPlus,
944-
.PlusEqual,
945-
.PlusPercent,
946-
.PlusPercentEqual,
947-
.Minus,
948-
.MinusEqual,
949-
.MinusPercent,
950-
.MinusPercentEqual,
951-
.Asterisk,
952-
.AsteriskEqual,
953-
.AsteriskAsterisk,
954-
.AsteriskPercent,
955-
.AsteriskPercentEqual,
956-
.Arrow,
957-
.Colon,
958-
.Slash,
959-
.SlashEqual,
960-
.Comma,
961-
.Ampersand,
962-
.AmpersandEqual,
963-
.QuestionMark,
964-
.AngleBracketLeft,
965-
.AngleBracketLeftEqual,
966-
.AngleBracketAngleBracketLeft,
967-
.AngleBracketAngleBracketLeftEqual,
968-
.AngleBracketRight,
969-
.AngleBracketRightEqual,
970-
.AngleBracketAngleBracketRight,
971-
.AngleBracketAngleBracketRightEqual,
972-
.Tilde,
932+
.bang,
933+
.pipe,
934+
.pipe_pipe,
935+
.pipe_equal,
936+
.equal,
937+
.equal_equal,
938+
.equal_angle_bracket_right,
939+
.bang_equal,
940+
.l_paren,
941+
.r_paren,
942+
.semicolon,
943+
.percent,
944+
.percent_equal,
945+
.l_brace,
946+
.r_brace,
947+
.l_bracket,
948+
.r_bracket,
949+
.period,
950+
.period_asterisk,
951+
.ellipsis2,
952+
.ellipsis3,
953+
.caret,
954+
.caret_equal,
955+
.plus,
956+
.plus_plus,
957+
.plus_equal,
958+
.plus_percent,
959+
.plus_percent_equal,
960+
.minus,
961+
.minus_equal,
962+
.minus_percent,
963+
.minus_percent_equal,
964+
.asterisk,
965+
.asterisk_equal,
966+
.asterisk_asterisk,
967+
.asterisk_percent,
968+
.asterisk_percent_equal,
969+
.arrow,
970+
.colon,
971+
.slash,
972+
.slash_equal,
973+
.comma,
974+
.ampersand,
975+
.ampersand_equal,
976+
.question_mark,
977+
.angle_bracket_left,
978+
.angle_bracket_left_equal,
979+
.angle_bracket_angle_bracket_left,
980+
.angle_bracket_angle_bracket_left_equal,
981+
.angle_bracket_right,
982+
.angle_bracket_right_equal,
983+
.angle_bracket_angle_bracket_right,
984+
.angle_bracket_angle_bracket_right_equal,
985+
.tilde,
973986
=> try writeEscaped(out, src[token.loc.start..token.loc.end]),
974987

975-
.Invalid, .Invalid_ampersands, .Invalid_periodasterisks => return parseError(
988+
.invalid, .invalid_ampersands, .invalid_periodasterisks => return parseError(
976989
docgen_tokenizer,
977990
source_token,
978991
"syntax error",

0 commit comments

Comments
 (0)