~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH harec] type_init_from_atype: drop type_is_complete

Details
Message ID
<20230913225405.5111-1-ecs@d2evs.net>
DKIM signature
missing
Download raw message
Patch: +11 -23
fixes a bug with forward declarations of packed structs

Signed-off-by: Ember Sawady <ecs@d2evs.net>
---
 include/types.h        |  1 -
 src/type_store.c       | 15 +++++----------
 src/types.c            | 12 ------------
 tests/26-regression.ha |  6 ++++++
 4 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/include/types.h b/include/types.h
index e4a824c..470701b 100644
--- a/include/types.h
+++ b/include/types.h
@@ -192,7 +192,6 @@ bool type_is_assignable(struct context *ctx,
	const struct type *to, const struct type *from);
const struct type *type_is_castable(struct context *ctx,
	const struct type *to, const struct type *from);
bool type_is_complete(const struct type *type);

const struct type *type_create_const(enum type_storage storage,
	int64_t min, int64_t max);
diff --git a/src/type_store.c b/src/type_store.c
index 4d572fc..c5a93d3 100644
--- a/src/type_store.c
+++ b/src/type_store.c
@@ -910,20 +910,15 @@ type_init_from_atype(struct type_store *store,
		break;
	}

	bool packed = false;
	if (type_is_complete(type)) {
		const struct type *final = type_dealias(store->check_context, type);
		if (final->storage == STORAGE_STRUCT) {
			packed = final->struct_union.packed;
		}
	}

	struct dimensions dim = {
		.size = type->size,
		.align = type->align,
	};
	if (!packed) {
		add_padding(&dim.size, dim.align);
	if (type->storage != STORAGE_STRUCT || !type->struct_union.packed) {
		// padding an alias can only break packed structs
		if (type->storage != STORAGE_ALIAS) {
			add_padding(&dim.size, dim.align);
		};
	}
	return dim;
}
diff --git a/src/types.c b/src/types.c
index 0456551..ecb52ae 100644
--- a/src/types.c
+++ b/src/types.c
@@ -67,18 +67,6 @@ type_dealias(struct context *ctx, const struct type *type)
	return type;
}

bool
type_is_complete(const struct type *type)
{
	while (type->storage == STORAGE_ALIAS) {
		if (type->alias.type == NULL) {
			return false;
		}
		type = type->alias.type;
	}
	return true;
}

const struct struct_field *
type_get_field(struct context *ctx, const struct type *type, const char *name)
{
diff --git a/tests/26-regression.ha b/tests/26-regression.ha
index 3aed22d..e22ccb1 100644
--- a/tests/26-regression.ha
+++ b/tests/26-regression.ha
@@ -26,6 +26,10 @@ type b = struct { c: c };
type a = struct { b };
type c = *a;

// order of these two matters
let packedsz = size(packed);
type packed = struct @packed { a: u64, b: u8 };

type d = [3]int;
type e = bool;
let x = [1, 2, 3]: d: []int;
@@ -204,4 +208,6 @@ export fn main() void = {
	assert(rt::compile(*(&buf: *str)) as rt::exited == rt::EXIT_SUCCESS);
	static insert(buf[n], rt::toutf8("::a")...);
	assert(rt::compile(*(&buf: *str)) as rt::exited != rt::EXIT_SUCCESS);
	assert(size(packed) == packedsz);
	assert(size(packed) == 9);
};
-- 
2.42.0

[harec/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CVI5RNFL1WRM.S5QXZPPG4ELO@cirno2>
In-Reply-To
<20230913225405.5111-1-ecs@d2evs.net> (view parent)
DKIM signature
missing
Download raw message
harec/patches: SUCCESS in 58s

[type_init_from_atype: drop type_is_complete][0] from [Ember Sawady][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/44653
[1]: ecs@d2evs.net

✓ #1057265 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1057265
✓ #1057264 SUCCESS harec/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1057264
✓ #1057266 SUCCESS harec/patches/netbsd.yml  https://builds.sr.ht/~sircmpwn/job/1057266
Details
Message ID
<CVIHBP5L72XO.2XQSQPP5NKGQV@taiga>
In-Reply-To
<20230913225405.5111-1-ecs@d2evs.net> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/harec
   c8c81f3..edd7b87  master -> master
Reply to thread Export thread (mbox)