Generic faults is disallowed.

This commit is contained in:
Christoffer Lerno
2025-05-30 19:12:08 +02:00
parent e685414829
commit da25a411f9
7 changed files with 36 additions and 19 deletions

View File

@@ -25,6 +25,7 @@
- Allow recursive generic modules.
- Add deprecation for `@param foo "abc"`.
- Add `--header-output` and `header-output` options for controlling header output folder.
- Generic faults is disallowed.
### Fixes
- Assert triggered when casting from `int[2]` to `uint[2]` #2115

View File

@@ -237,6 +237,10 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
continue;
case DECL_ATTRIBUTE:
break;
case DECL_FAULT:
PRINT_ERROR_AT(decl, "Generic modules cannot use 'faultdef', place the declaration in a separate sub module or parent module instead.");
decl_poison(decl);
break;
case DECL_BODYPARAM:
case DECL_GROUP:
UNREACHABLE
@@ -247,7 +251,6 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
case DECL_TYPEDEF:
case DECL_UNION:
case DECL_VAR:
case DECL_FAULT:
case DECL_BITSTRUCT:
case DECL_INTERFACE:
break;

View File

@@ -201,8 +201,6 @@ fn Type getMult(Type a)
}
Type argh = 234;
faultdef X, Y;
enum Hello : int
{
FOO,

View File

@@ -203,8 +203,6 @@ fn Type getMult(Type a)
}
Type argh = 234;
faultdef X, Y;
enum Hello : int
{
FOO,

View File

@@ -0,0 +1,11 @@
module abc {Type};
attrdef @Hello = @inline;
faultdef ABC; // #error: Generic modules cannot use 'faultdef'
module bcd;
fn void main()
{
Abc{int} a;
}

View File

@@ -1,13 +1,15 @@
// #target: macos-x64
module abc_faults;
faultdef UNTERMINATED_TAG, EMPTY_TAG, MISSING_TAG, UNSUPPORTED_TAG;
<* @require Type.kindof == STRUCT *>
module abc{Type};
import std::io;
import std::collections::list;
import std::io, abc_faults, std::collections::list;
alias TextTagList = List{TextTag};
faultdef UNTERMINATED_TAG, EMPTY_TAG, MISSING_TAG, UNSUPPORTED_TAG;
enum TextTagKind: char
{
@@ -50,9 +52,9 @@ fn void? TextTemplate.init(&self, String template, String tag_start = "{{", Stri
tmpl = tmpl[start + tag_start.len..];
usz? end = tmpl.index_of(tag_end);
if (catch end) return UNTERMINATED_TAG?;
if (catch end) return abc_faults::UNTERMINATED_TAG?;
String name = tmpl[:end].trim();
if (name == "") return EMPTY_TAG?;
if (name == "") return abc_faults::EMPTY_TAG?;
// Check that the tag exists in the data struct.
TextTag tag @noinit;
@@ -80,7 +82,7 @@ fn void? TextTemplate.init(&self, String template, String tag_start = "{{", Stri
//return UNSUPPORTED_TAG?;
}
$endforeach
return MISSING_TAG?;
return abc_faults::MISSING_TAG?;
};
tmpl = tmpl[end + tag_end.len..];
@@ -201,7 +203,7 @@ panic_block: ; preds = %assign_optional
%4 = insertvalue %"any[]" undef, ptr %varargslots, 0
%"$$temp" = insertvalue %"any[]" %4, i64 1, 1
store %"any[]" %"$$temp", ptr %indirectarg1, align 8
call void @std.core.builtin.panicf(ptr @.panic_msg, i64 36, ptr @.file, i64 25, ptr @.func, i64 4, i32 159, ptr byval(%"any[]") align 8 %indirectarg1) #3
call void @std.core.builtin.panicf(ptr @.panic_msg,
unreachable
noerr_block: ; preds = %after_check
@@ -224,7 +226,7 @@ panic_block6: ; preds = %assign_optional4
%9 = insertvalue %"any[]" undef, ptr %varargslots7, 0
%"$$temp8" = insertvalue %"any[]" %9, i64 1, 1
store %"any[]" %"$$temp8", ptr %indirectarg9, align 8
call void @std.core.builtin.panicf(ptr @.panic_msg, i64 36, ptr @.file, i64 25, ptr @.func, i64 4, i32 160, ptr byval(%"any[]") align 8 %indirectarg9) #3
call void @std.core.builtin.panicf(ptr @.panic_msg, i64 36,
unreachable
noerr_block10: ; preds = %after_check5

View File

@@ -1,5 +1,10 @@
// #target: macos-x64
module lexer::faults;
faultdef UNTERMINATED_STRING, UNTERMINATED_RUNE, UNTERMINATED_COMMENT;
faultdef TRIE_FULL;
<*
@require Token.kindof == ENUM && $typefrom(Token.inner).kindof == UNSIGNED_INT
@require $defined((Token){}.token)
@@ -19,7 +24,6 @@ enum Kind : char
IDENTIFIER,
}
faultdef UNTERMINATED_STRING, UNTERMINATED_RUNE, UNTERMINATED_COMMENT;
alias TokenTrie = Trie{Token, ushort};
@@ -316,7 +320,7 @@ fn char? Lexer.parse_rune(&self) @private
{
char x = self.reader.read_byte()!;
char c = self.reader.read_byte()!;
if (c != '\'') return UNTERMINATED_RUNE?;
if (c != '\'') return faults::UNTERMINATED_RUNE?;
return x;
}
@@ -325,7 +329,7 @@ macro char? Lexer.read_char_for_string(&self) @private
char? c = self.reader.read_byte();
if (catch err = c)
{
if (err == io::EOF) return UNTERMINATED_STRING?;
if (err == io::EOF) return faults::UNTERMINATED_STRING?;
return err?;
}
return c;
@@ -350,7 +354,7 @@ fn void? Lexer.parse_comment(&self, String end) @private
{
if (catch err = io::read_all(self.reader, buf))
{
if (err == io::UNEXPECTED_EOF || err == io::EOF) return UNTERMINATED_COMMENT?;
if (err == io::UNEXPECTED_EOF || err == io::EOF) return faults::UNTERMINATED_COMMENT?;
return err?;
}
if (end == (String)buf)
@@ -455,11 +459,11 @@ fn int main(String[] args)
module trie{Value, Index};
import std::collections::list;
import trie::bitmap;
import lexer::faults;
alias TrieNodeList = List{TrieNode};
alias TriePath @private = List{Index};
faultdef TRIE_FULL;
struct Trie
{
@@ -566,7 +570,7 @@ fn void? TrieNode.set(&self, Trie *t, char[] key, Value value) @private
{
usz new_idx = t.nodes.len();
assert(new_idx != 0);
if (new_idx > Index.max) return TRIE_FULL?;
if (new_idx > Index.max) return faults::TRIE_FULL?;
idx = (Index)new_idx;
self.children[c] = idx;
t.nodes.push((TrieNode){});