From 3268276b58d8b65cb295b738d7c14174005bd84e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 11 Jan 2018 20:58:28 -0500 Subject: the same string literal codegens to the same constant this makes it so that you can send the same string literal as a comptime slice and get the same type --- src/analyze.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 2c6f0f209e..7e4a861f0f 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4370,6 +4370,12 @@ bool type_requires_comptime(TypeTableEntry *type_entry) { } void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { + auto entry = g->string_literals_table.maybe_get(str); + if (entry != nullptr) { + *const_val = *entry->value; + return; + } + const_val->special = ConstValSpecialStatic; const_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str)); const_val->data.x_array.s_none.elements = create_const_vals(buf_len(str)); @@ -4380,6 +4386,8 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { this_char->type = g->builtin_types.entry_u8; bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(str)[i]); } + + g->string_literals_table.put(str, const_val); } ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) { -- cgit v1.2.3