Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignments not aligned when using bit_set #294

Closed
leidegre opened this issue Jan 14, 2024 · 4 comments
Closed

Assignments not aligned when using bit_set #294

leidegre opened this issue Jan 14, 2024 · 4 comments

Comments

@leidegre
Copy link

leidegre commented Jan 14, 2024

Incorrect

rtv_desc := d3d12.DESCRIPTOR_HEAP_DESC {
  Type = .RTV,
  NumDescriptors = BACK_BUFFER_COUNT,
  Flags = {.SHADER_VISIBLE},
}

Now without Flags = {.SHADER_VISIBLE},

rtv_desc := d3d12.DESCRIPTOR_HEAP_DESC {
  Type           = .RTV,
  NumDescriptors = BACK_BUFFER_COUNT,
}

The consecutive assignments inside the initializer are no longer aligned.

@leidegre
Copy link
Author

leidegre commented Jan 18, 2024

Here's another repo

Foo :: struct {
	A:     string,
	BBB:   string,
	CCCCC: Bar,
	DD:    Baz,
	EEEE:  int,
}

Bar :: struct {
	A:   string,
	BBB: string,
}

Baz :: bit_set[BazFlag]
BazFlag :: enum {
	A,
	B,
	C,
}
main :: proc() {
	// aligned
	foo := Foo {
		A    = "foo",
		BBB  = "bar",
		EEEE = 42,
	}

	// unaligned
	bar := Foo {
		A = "foo",
		BBB = "bar",
		CCCCC = Bar{},
	}

	baz := Foo {
		A = "foo",
		BBB = "bar",
		DD = {},
	}
}

The alignment of consecutive assignments within the aggregate initializer changes to unaligned when there's a nested brace of some sort. Is this intentional or unwarranted?

@DanielGavin
Copy link
Owner

DanielGavin commented Jan 18, 2024

The aggregate initializer currently disables alignment, because I'm worried of having to align stuff like this:

baz := Foo {
	A = "foo",
	BBB = "bar",
	DD = {
             my_value = 123123,
        },
}

It's both quite hard to align this correctly. There could even more than just one nest of braces. But in your example there is no named assignments in the aggregate initializer, so it could be possible to have it align anyway for that case.

Making that exception probably helps for most cases where braces are used like:

rtv_desc := d3d12.DESCRIPTOR_HEAP_DESC {
  Type = .RTV,
  NumDescriptors = BACK_BUFFER_COUNT,
  Flags = {.SHADER_VISIBLE},
}

@leidegre
Copy link
Author

Yeah, I think it should be consistent. Either align assignments or not but don't change the behavior.

I've done plenty of compiler work in my days and I could give this a shot.

@DanielGavin
Copy link
Owner

I have now switched it so the bitsets get aligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants