Deprecated inline generic types, deprecated tuple / triple types.

This commit is contained in:
Christoffer Lerno
2024-09-05 23:42:20 +02:00
parent ed5d338a39
commit ad0e97ab7b
8 changed files with 21 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
module std::collections::tuple(<Type1, Type2>);
struct Tuple
struct Tuple @deprecated
{
Type1 first;
Type2 second;
@@ -8,7 +8,7 @@ struct Tuple
module std::collections::triple(<Type1, Type2, Type3>);
struct Triple
struct Triple @deprecated
{
Type1 first;
Type2 second;

View File

@@ -8,6 +8,8 @@
### Fixes
- Issue where a lambda wasn't correctly registered as external. #1408
- Generic methods were incorrectly registered as functions, leading to naming collisions. #1402
- Deprecated inline generic types.
- Deprecated tuple / triple types.
### Stdlib changes
*None yet*

View File

@@ -296,6 +296,7 @@ struct TypeInfo_
ResolveStatus resolve_status : 3;
TypeInfoKind kind : 6;
bool optional : 1;
bool in_def : 1;
TypeInfoCompressedKind subtype : 4;
Type *type;
SourceSpan span;

View File

@@ -1382,6 +1382,7 @@ static inline bool sema_analyse_typedef(SemaContext *context, Decl *decl, bool *
return true;
}
TypeInfo *info = decl->typedef_decl.type_info;
info->in_def = true;
if (!sema_resolve_type_info(context, info, RESOLVE_TYPE_DEFAULT)) return false;
decl->type->canonical = info->type->canonical;
// Do we need anything else?
@@ -1404,6 +1405,7 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool
// Infer the underlying type normally.
TypeInfo *info = decl->distinct;
info->in_def = true;
if (!sema_resolve_type_info(context, info, RESOLVE_TYPE_DEFAULT)) return false;
// Optional isn't allowed of course.

View File

@@ -362,6 +362,12 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info)
Decl *type = sema_analyse_parameterized_identifier(context, inner->unresolved.path, inner->unresolved.name, inner->span, type_info->generic.params);
if (!decl_ok(type)) return false;
type_info->type = type->type;
if (!context->current_macro && !type_info->in_def)
{
if (!compiler.context.silence_deprecation) SEMA_NOTE(type_info, "Direct generic type declarations outside of macros is a deprecated feature, please use 'def' to create an alias.");
// TODO, completely disallow
// RETURN_SEMA_ERROR(type_info, "Direct generic type declarations are only allowed inside of macros. Use `def` to define an alias for the type instead.");
}
return true;
}

View File

@@ -2,8 +2,10 @@ import std::thread;
import std::io;
import std::atomic::types;
Atomic(<uint>) a;
Atomic(<float>) fa;
def AtomicUint = Atomic(<uint>);
def AtomicFloat = Atomic(<float>);
AtomicUint a;
AtomicFloat fa;
fn void! add() @test
{

View File

@@ -2,6 +2,7 @@ module test;
import std::io;
import std::collections::map;
def IntMap = HashMap(<String, int>);
fn void! copy_map() @test
{
TrackingAllocator alloc;
@@ -9,7 +10,7 @@ fn void! copy_map() @test
assert(alloc.allocated() == 0);
mem::@scoped(&alloc)
{
HashMap(<String, int>) x;
IntMap x;
x.new_init();
DString y;
y.append("hello");

View File

@@ -9,9 +9,10 @@ struct Overalign
float[<4>] x @align(128);
}
def OveralignList = List(<Overalign>);
fn void overaligned_type()
{
List(<Overalign>) l;
OveralignList l;
Overalign y;
for (int i = 0; i < 1000; i++) l.push(y);
assert((usz)l.get_ref(2) - (usz)l.get_ref(1) == Overalign.sizeof);